mirror of
https://github.com/mawww/kakoune.git
synced 2024-11-23 15:23:29 +03:00
Use -group rather than -id in hooks to mirror highlighters closer
This commit is contained in:
parent
fc6a16a571
commit
b8a205b858
@ -46,7 +46,7 @@ def clang-complete %{
|
||||
|
||||
def clang-enable-autocomplete %{
|
||||
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>
|
||||
echo 'completing...'
|
||||
clang-complete
|
||||
|
@ -57,11 +57,11 @@ hook global WinSetOption filetype=cpp %[
|
||||
addhl ref cpp
|
||||
|
||||
# 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 \{ -id cpp-indent _cpp_indent_on_opening_curly_brace
|
||||
hook window InsertChar \} -id cpp-indent _cpp_indent_on_closing_curly_brace
|
||||
hook window InsertChar \n -group cpp-indent _cpp_indent_on_new_line
|
||||
hook window InsertChar \{ -group cpp-indent _cpp_indent_on_opening_curly_brace
|
||||
hook window InsertChar \} -group cpp-indent _cpp_indent_on_closing_curly_brace
|
||||
]
|
||||
|
||||
hook global WinSetOption filetype=(?!cpp).* %{
|
||||
|
@ -40,10 +40,10 @@ def funcinfo %{
|
||||
}
|
||||
|
||||
def ctags-enable-autoinfo %{
|
||||
hook window -id ctags-autoinfo NormalIdle .* funcinfo
|
||||
hook window -id ctags-autoinfo NormalEnd .* info
|
||||
hook window -id ctags-autoinfo NormalKey .* info
|
||||
hook window -id ctags-autoinfo InsertIdle .* funcinfo
|
||||
hook window -group ctags-autoinfo NormalIdle .* funcinfo
|
||||
hook window -group ctags-autoinfo NormalEnd .* info
|
||||
hook window -group ctags-autoinfo NormalKey .* info
|
||||
hook window -group ctags-autoinfo InsertIdle .* funcinfo
|
||||
}
|
||||
|
||||
def ctags-disable-autoinfo %{ rmhooks window ctags-autoinfo }
|
||||
|
@ -21,7 +21,7 @@ def -shell-params -file-completion \
|
||||
hook global WinSetOption filetype=grep %{
|
||||
addhl group grep
|
||||
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 }
|
||||
|
@ -18,7 +18,7 @@ addhl -group /make regex "^([^:\n]+):(\d+):(\d+):\h+(?:((?:fatal )?error)|(warni
|
||||
|
||||
hook global WinSetOption filetype=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 }
|
||||
|
@ -5,7 +5,7 @@ hook global WinSetOption filetype=man %{
|
||||
addhl -group man-highlight regex ^\S.*?$ 0:blue
|
||||
addhl -group man-highlight regex ^\h+-+[-a-zA-Z_]+ 0:yellow
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -496,7 +496,7 @@ const CommandDesc add_hook_cmd = {
|
||||
" (and any window for that buffer)\n"
|
||||
" * window: hook is executed only for the current window\n",
|
||||
ParameterDesc{
|
||||
SwitchMap{ { "id", { true, "set hook id, see rmhooks" } } },
|
||||
SwitchMap{ { "group", { true, "set hook group, see rmhooks" } } },
|
||||
ParameterDesc::Flags::None, 4, 4
|
||||
},
|
||||
CommandFlags::None,
|
||||
@ -523,15 +523,17 @@ const CommandDesc add_hook_cmd = {
|
||||
CommandManager::instance().execute(command, context, {},
|
||||
{ { "hook_param", param } });
|
||||
};
|
||||
String id = parser.has_option("id") ? parser.option_value("id") : "";
|
||||
get_hook_manager(parser[0], context).add_hook(parser[1], id, hook_func);
|
||||
StringView group;
|
||||
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 = {
|
||||
"rmhooks",
|
||||
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 },
|
||||
CommandFlags::None,
|
||||
CommandCompleter{},
|
||||
|
@ -5,18 +5,18 @@
|
||||
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];
|
||||
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");
|
||||
for (auto& hooks : m_hook)
|
||||
hooks.second.remove_all(id);
|
||||
hooks.second.remove_all(group);
|
||||
}
|
||||
|
||||
void HookManager::run_hook(const String& hook_name,
|
||||
|
@ -17,8 +17,8 @@ class HookManager
|
||||
public:
|
||||
HookManager(HookManager& parent) : m_parent(&parent) {}
|
||||
|
||||
void add_hook(const String& hook_name, String id, HookFunc hook);
|
||||
void remove_hooks(const String& id);
|
||||
void add_hook(const String& hook_name, String group, HookFunc hook);
|
||||
void remove_hooks(StringView group);
|
||||
void run_hook(const String& hook_name, const String& param,
|
||||
Context& context) const;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user