From be03fdce2a963a4b3e350b4ddc229fffc4c36e6a Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 20 Nov 2016 11:17:13 +0000 Subject: [PATCH] Support completing hook names Fixes #879 --- src/commands.cc | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/commands.cc b/src/commands.cc index 1b869b98..a1c028b4 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -746,11 +746,25 @@ const CommandDesc remove_highlighter_cmd = { } }; +static Completions complete_hooks(const Context&, CompletionFlags, + const String& prefix, ByteCount cursor_pos) +{ + static constexpr auto hooks = { + "BufWritePost", "BufWritePre", "FocusIn", "FocusOut", + "InsertBegin", "InsertChar", "InsertEnd", "InsertIdle", + "InsertKey", "InsertMove", "KakBegin", "KakEnd", + "InsertCompletionHide", "InsertCompletionShow", + "NormalBegin", "NormalEnd", "NormalIdle", "NormalKey", + "RuntimeError", "WinDisplay", + }; + return { 0_byte, cursor_pos, complete(prefix, cursor_pos, hooks) }; +} + const CommandDesc add_hook_cmd = { "hook", nullptr, - "hook : add in " - "to be executed on hook \n" + "hook : add in " + "to be executed on hook when its parameter matches the regex\n" "scope can be: \n" " * global: hook is executed for any buffer or window\n" " * buffer: hook is executed only for the current buffer\n" @@ -762,7 +776,7 @@ const CommandDesc add_hook_cmd = { }, CommandFlags::None, CommandHelper{}, - make_completer(complete_scope, complete_nothing, complete_nothing, + make_completer(complete_scope, complete_hooks, complete_nothing, [](const Context& context, CompletionFlags flags, const String& prefix, ByteCount cursor_pos) { return CommandManager::instance().complete(