Add User hook support

This commit is contained in:
Maxime Coste 2020-07-04 13:48:10 +10:00
parent e509a8e9cd
commit f2cc7bc891
5 changed files with 29 additions and 2 deletions

View File

@ -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.

View File

@ -210,6 +210,10 @@ of the file onto the filesystem
remove every hooks in *scope* that are part of the given *group*
(See <<hooks#,`:doc hooks`>> and <<scopes#,`:doc scopes`>>)
*trigger-user-hook* <param>::
trigger the `User` hook with the given *param* as filter string in
the current context. (See <<hooks#,`:doc hooks`>>)
== Display
*echo* [<switches>] <text>::

View File

@ -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.

View File

@ -1093,6 +1093,20 @@ const CommandDesc remove_hook_cmd = {
}
};
const CommandDesc trigger_user_hook_cmd = {
"trigger-user-hook",
nullptr,
"trigger-user-hook <param>: run 'User' hook with <param> 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<String> params_to_shell(const ParametersParser& parser)
{
Vector<String> 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);

View File

@ -54,7 +54,8 @@ enum class Hook
WinDisplay,
WinResize,
WinSetOption,
ModuleLoaded
ModuleLoaded,
User
};
constexpr auto enum_desc(Meta::Type<Hook>)
@ -97,7 +98,8 @@ constexpr auto enum_desc(Meta::Type<Hook>)
{Hook::WinDisplay, "WinDisplay"},
{Hook::WinResize, "WinResize"},
{Hook::WinSetOption, "WinSetOption"},
{Hook::ModuleLoaded, "ModuleLoaded"}
{Hook::ModuleLoaded, "ModuleLoaded"},
{Hook::User, "User"}
});
}