From 8fc230e40d85d5acb61cc538c7b67a513dc0fd77 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 21 Aug 2014 13:37:59 +0100 Subject: [PATCH] Add a 'disabled_hooks' regex option Hooks whose group matches this regex wont get executed. --- README.asciidoc | 2 ++ src/hook_manager.cc | 6 ++++++ src/option_manager.cc | 3 +++ 3 files changed, 11 insertions(+) diff --git a/README.asciidoc b/README.asciidoc index c6540630..4ec12932 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -552,6 +552,8 @@ Some options are built in Kakoune, and can be used to control it's behaviour: * +ignored_files+ _regex_: filenames matching this regex wont be considered as candidates on filename completion (except if the text being completed already matches it). + * +disabled_hooks+ _regex_: hooks whose group matches this regex wont be + executed. For example indentation hooks can be disabled with '.*-indent'. * +filetype+ _str_: arbitrary string defining the type of the file filetype dependant actions should hook on this option changing for activation/deactivation. diff --git a/src/hook_manager.cc b/src/hook_manager.cc index 7efafbbd..7d804696 100644 --- a/src/hook_manager.cc +++ b/src/hook_manager.cc @@ -1,5 +1,6 @@ #include "hook_manager.hh" +#include "context.hh" #include "debug.hh" namespace Kakoune @@ -45,8 +46,13 @@ void HookManager::run_hook(const String& hook_name, if (hook_list_it == m_hook.end()) return; + auto& disabled_hooks = context.options()["disabled_hooks"].get(); for (auto& hook : hook_list_it->second) { + if (not hook.first.empty() and not disabled_hooks.empty() and + boost::regex_match(hook.first, disabled_hooks)) + continue; + try { hook.second(param, context); diff --git a/src/option_manager.cc b/src/option_manager.cc index f66de005..ce806b27 100644 --- a/src/option_manager.cc +++ b/src/option_manager.cc @@ -157,6 +157,9 @@ GlobalOptions::GlobalOptions() declare_option("ignored_files", "patterns to ignore when completing filenames", Regex{R"(^(\..*|.*\.(o|so|a))$)"}); + declare_option("disabled_hooks", + "patterns to disable hooks whose group is matched", + Regex{}); declare_option("filetype", "buffer filetype", ""_str); declare_option("path", "path to consider when trying to find a file", std::vector({ "./", "/usr/include" }));