Use -group rather than -id in hooks to mirror highlighters closer

This commit is contained in:
Maxime Coste 2014-06-16 20:42:12 +01:00
parent fc6a16a571
commit b8a205b858
9 changed files with 25 additions and 23 deletions

View File

@ -46,7 +46,7 @@ def clang-complete %{
def clang-enable-autocomplete %{ def clang-enable-autocomplete %{
set window completers %sh{ echo "'option=clang_completions:${kak_opt_completers}'" } set window completers %sh{ echo "'option=clang_completions:${kak_opt_completers}'" }
hook window -id clang-autocomplete InsertIdle .* %{ try %{ hook window -group clang-autocomplete InsertIdle .* %{ try %{
exec -draft <a-h><a-k>(\.|->|::).$<ret> exec -draft <a-h><a-k>(\.|->|::).$<ret>
echo 'completing...' echo 'completing...'
clang-complete clang-complete

View File

@ -57,11 +57,11 @@ hook global WinSetOption filetype=cpp %[
addhl ref cpp addhl ref cpp
# cleanup trailing whitespaces when exiting insert mode # cleanup trailing whitespaces when exiting insert mode
hook window InsertEnd .* -id cpp-hooks %{ try %{ exec -draft <a-x>s\h+$<ret>d } } hook window InsertEnd .* -group cpp-hooks %{ try %{ exec -draft <a-x>s\h+$<ret>d } }
hook window InsertChar \n -id cpp-indent _cpp_indent_on_new_line hook window InsertChar \n -group cpp-indent _cpp_indent_on_new_line
hook window InsertChar \{ -id cpp-indent _cpp_indent_on_opening_curly_brace hook window InsertChar \{ -group cpp-indent _cpp_indent_on_opening_curly_brace
hook window InsertChar \} -id cpp-indent _cpp_indent_on_closing_curly_brace hook window InsertChar \} -group cpp-indent _cpp_indent_on_closing_curly_brace
] ]
hook global WinSetOption filetype=(?!cpp).* %{ hook global WinSetOption filetype=(?!cpp).* %{

View File

@ -40,10 +40,10 @@ def funcinfo %{
} }
def ctags-enable-autoinfo %{ def ctags-enable-autoinfo %{
hook window -id ctags-autoinfo NormalIdle .* funcinfo hook window -group ctags-autoinfo NormalIdle .* funcinfo
hook window -id ctags-autoinfo NormalEnd .* info hook window -group ctags-autoinfo NormalEnd .* info
hook window -id ctags-autoinfo NormalKey .* info hook window -group ctags-autoinfo NormalKey .* info
hook window -id ctags-autoinfo InsertIdle .* funcinfo hook window -group ctags-autoinfo InsertIdle .* funcinfo
} }
def ctags-disable-autoinfo %{ rmhooks window ctags-autoinfo } def ctags-disable-autoinfo %{ rmhooks window ctags-autoinfo }

View File

@ -21,7 +21,7 @@ def -shell-params -file-completion \
hook global WinSetOption filetype=grep %{ hook global WinSetOption filetype=grep %{
addhl group grep addhl group grep
addhl -group grep regex "^([^:]+):(\d+):(\d+)?" 1:cyan 2:green 3:green addhl -group grep regex "^([^:]+):(\d+):(\d+)?" 1:cyan 2:green 3:green
hook buffer -id grep-hooks NormalKey <c-m> jump hook buffer -group grep-hooks NormalKey <c-m> jump
} }
hook global WinSetOption filetype=(?!grep).* %{ rmhl grep; rmhooks buffer grep-hooks } hook global WinSetOption filetype=(?!grep).* %{ rmhl grep; rmhooks buffer grep-hooks }

View File

@ -18,7 +18,7 @@ addhl -group /make regex "^([^:\n]+):(\d+):(\d+):\h+(?:((?:fatal )?error)|(warni
hook global WinSetOption filetype=make %{ hook global WinSetOption filetype=make %{
addhl ref make addhl ref make
hook buffer -id make-hooks NormalKey <c-m> errjump hook buffer -group make-hooks NormalKey <c-m> errjump
} }
hook global WinSetOption filetype=(?!make).* %{ rmhl make; rmhooks buffer make-hooks } hook global WinSetOption filetype=(?!make).* %{ rmhl make; rmhooks buffer make-hooks }

View File

@ -5,7 +5,7 @@ hook global WinSetOption filetype=man %{
addhl -group man-highlight regex ^\S.*?$ 0:blue addhl -group man-highlight regex ^\S.*?$ 0:blue
addhl -group man-highlight regex ^\h+-+[-a-zA-Z_]+ 0:yellow addhl -group man-highlight regex ^\h+-+[-a-zA-Z_]+ 0:yellow
addhl -group man-highlight regex [-a-zA-Z_.]+\(\d\) 0:green addhl -group man-highlight regex [-a-zA-Z_.]+\(\d\) 0:green
hook window -id man-hooks NormalKey <c-m> man hook window -group man-hooks NormalKey <c-m> man
set buffer tabstop 8 set buffer tabstop 8
} }

View File

@ -496,7 +496,7 @@ const CommandDesc add_hook_cmd = {
" (and any window for that buffer)\n" " (and any window for that buffer)\n"
" * window: hook is executed only for the current window\n", " * window: hook is executed only for the current window\n",
ParameterDesc{ ParameterDesc{
SwitchMap{ { "id", { true, "set hook id, see rmhooks" } } }, SwitchMap{ { "group", { true, "set hook group, see rmhooks" } } },
ParameterDesc::Flags::None, 4, 4 ParameterDesc::Flags::None, 4, 4
}, },
CommandFlags::None, CommandFlags::None,
@ -523,15 +523,17 @@ const CommandDesc add_hook_cmd = {
CommandManager::instance().execute(command, context, {}, CommandManager::instance().execute(command, context, {},
{ { "hook_param", param } }); { { "hook_param", param } });
}; };
String id = parser.has_option("id") ? parser.option_value("id") : ""; StringView group;
get_hook_manager(parser[0], context).add_hook(parser[1], id, hook_func); if (parser.has_option("group"))
group = parser.option_value("group");
get_hook_manager(parser[0], context).add_hook(parser[1], group, hook_func);
} }
}; };
const CommandDesc rm_hook_cmd = { const CommandDesc rm_hook_cmd = {
"rmhooks", "rmhooks",
nullptr, nullptr,
"rmhooks <id>: remove all hooks whose id is <id>", "rmhooks <group>: remove all hooks whose group is <group>",
ParameterDesc{ SwitchMap{}, ParameterDesc::Flags::None, 2, 2 }, ParameterDesc{ SwitchMap{}, ParameterDesc::Flags::None, 2, 2 },
CommandFlags::None, CommandFlags::None,
CommandCompleter{}, CommandCompleter{},

View File

@ -5,18 +5,18 @@
namespace Kakoune namespace Kakoune
{ {
void HookManager::add_hook(const String& hook_name, String id, HookFunc hook) void HookManager::add_hook(const String& hook_name, String group, HookFunc hook)
{ {
auto& hooks = m_hook[hook_name]; auto& hooks = m_hook[hook_name];
hooks.append({std::move(id), std::move(hook)}); hooks.append({std::move(group), std::move(hook)});
} }
void HookManager::remove_hooks(const String& id) void HookManager::remove_hooks(StringView group)
{ {
if (id.empty()) if (group.empty())
throw runtime_error("invalid id"); throw runtime_error("invalid id");
for (auto& hooks : m_hook) for (auto& hooks : m_hook)
hooks.second.remove_all(id); hooks.second.remove_all(group);
} }
void HookManager::run_hook(const String& hook_name, void HookManager::run_hook(const String& hook_name,

View File

@ -17,8 +17,8 @@ class HookManager
public: public:
HookManager(HookManager& parent) : m_parent(&parent) {} HookManager(HookManager& parent) : m_parent(&parent) {}
void add_hook(const String& hook_name, String id, HookFunc hook); void add_hook(const String& hook_name, String group, HookFunc hook);
void remove_hooks(const String& id); void remove_hooks(StringView group);
void run_hook(const String& hook_name, const String& param, void run_hook(const String& hook_name, const String& param,
Context& context) const; Context& context) const;