From 0b806cd4f17c1ad9e326ad4499192fc57afc12eb Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 21 Nov 2016 09:51:47 +0000 Subject: [PATCH] Add missing hooks to completion list and validate hook name in hook cmd --- src/commands.cc | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/commands.cc b/src/commands.cc index a1c028b40..0c2e42eb5 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -746,17 +746,19 @@ const CommandDesc remove_highlighter_cmd = { } }; +static constexpr auto hooks = { + "BufCreate", "BufNew", "BufOpen", "BufClose", "BufWritePost", "BufWritePre", + "BufOpenFifo", "BufCloseFifo", "BufReadFifo", "BufSetOption", + "InsertBegin", "InsertChar", "InsertEnd", "InsertIdle", "InsertKey", + "InsertMove", "InsertCompletionHide", "InsertCompletionShow", + "KakBegin", "KakEnd", "FocusIn", "FocusOut", "RuntimeError", + "NormalBegin", "NormalEnd", "NormalIdle", "NormalKey", + "WinClose", "WinCreate", "WinDisplay", "WinResize", "WinSetOption", +}; + 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) }; } @@ -783,6 +785,9 @@ const CommandDesc add_hook_cmd = { context, flags, prefix, cursor_pos); }), [](const ParametersParser& parser, Context& context, const ShellContext&) { + if (not contains(hooks, parser[1])) + throw runtime_error{format("Unknown hook '{}'", parser[1])}; + Regex regex(parser[2], Regex::optimize | Regex::nosubs | Regex::ECMAScript); const String& command = parser[3];