summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2016-11-21 09:51:47 +0000
committerMaxime Coste <frrrwww@gmail.com>2016-11-21 09:51:47 +0000
commit0b806cd4f17c1ad9e326ad4499192fc57afc12eb (patch)
tree69cfbcdbbf884df771b6d5ebba4f069a83ce6c38 /src
parentbe03fdce2a963a4b3e350b4ddc229fffc4c36e6a (diff)
Add missing hooks to completion list and validate hook name in hook cmd
Diffstat (limited to 'src')
-rw-r--r--src/commands.cc21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/commands.cc b/src/commands.cc
index a1c028b4..0c2e42eb 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];