From f2cc7bc891922ad48c4372c0b69239ef74bce004 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sat, 4 Jul 2020 13:48:10 +1000 Subject: [PATCH] Add User hook support --- doc/pages/changelog.asciidoc | 2 ++ doc/pages/commands.asciidoc | 4 ++++ doc/pages/hooks.asciidoc | 4 ++++ src/commands.cc | 15 +++++++++++++++ src/hook_manager.hh | 6 ++++-- 5 files changed, 29 insertions(+), 2 deletions(-) diff --git a/doc/pages/changelog.asciidoc b/doc/pages/changelog.asciidoc index 4b160bb8..8bb740ed 100644 --- a/doc/pages/changelog.asciidoc +++ b/doc/pages/changelog.asciidoc @@ -5,6 +5,8 @@ released versions. == Development version +* Introduce `User` hook support. + * The `bold` and `italic` faces are no longer built-in. Highlighters are expected to use face attributes (`+b` and `+i`, respectively) to decorate text. diff --git a/doc/pages/commands.asciidoc b/doc/pages/commands.asciidoc index 9fa82a37..fb35ff3e 100644 --- a/doc/pages/commands.asciidoc +++ b/doc/pages/commands.asciidoc @@ -210,6 +210,10 @@ of the file onto the filesystem remove every hooks in *scope* that are part of the given *group* (See <> and <>) +*trigger-user-hook* :: + trigger the `User` hook with the given *param* as filter string in + the current context. (See <>) + == Display *echo* [] :: diff --git a/doc/pages/hooks.asciidoc b/doc/pages/hooks.asciidoc index a7ba20c8..aee7d876 100644 --- a/doc/pages/hooks.asciidoc +++ b/doc/pages/hooks.asciidoc @@ -178,6 +178,10 @@ name. Hooks with no description will always use an empty string. *ModuleLoaded* `module`:: Triggered after a module is evaluated by the first `require-module` call +*User* `param`:: + Triggered via the `trigger-user-hook` command. Provides a way for plugins + to introduce custom hooks by specifying what *param* would be. + Note that some hooks will not consider underlying scopes depending on what context they are bound to be run into, e.g. the `BufWritePost` hook is a buffer hook, and will not consider the `window` scope. diff --git a/src/commands.cc b/src/commands.cc index c5cd5fdb..abf3a898 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -1093,6 +1093,20 @@ const CommandDesc remove_hook_cmd = { } }; +const CommandDesc trigger_user_hook_cmd = { + "trigger-user-hook", + nullptr, + "trigger-user-hook : run 'User' hook with as filter string", + single_param, + CommandFlags::None, + CommandHelper{}, + CommandCompleter{}, + [](const ParametersParser& parser, Context& context, const ShellContext&) + { + context.hooks().run_hook(Hook::User, parser[0], context); + } +}; + Vector params_to_shell(const ParametersParser& parser) { Vector vars; @@ -2635,6 +2649,7 @@ void register_commands() register_command(remove_highlighter_cmd); register_command(add_hook_cmd); register_command(remove_hook_cmd); + register_command(trigger_user_hook_cmd); register_command(define_command_cmd); register_command(alias_cmd); register_command(unalias_cmd); diff --git a/src/hook_manager.hh b/src/hook_manager.hh index 8fc5f8d4..a6547fa0 100644 --- a/src/hook_manager.hh +++ b/src/hook_manager.hh @@ -54,7 +54,8 @@ enum class Hook WinDisplay, WinResize, WinSetOption, - ModuleLoaded + ModuleLoaded, + User }; constexpr auto enum_desc(Meta::Type) @@ -97,7 +98,8 @@ constexpr auto enum_desc(Meta::Type) {Hook::WinDisplay, "WinDisplay"}, {Hook::WinResize, "WinResize"}, {Hook::WinSetOption, "WinSetOption"}, - {Hook::ModuleLoaded, "ModuleLoaded"} + {Hook::ModuleLoaded, "ModuleLoaded"}, + {Hook::User, "User"} }); }