Skip to content

Commit

Permalink
Add User hook support
Browse files Browse the repository at this point in the history
  • Loading branch information
mawww committed Jul 4, 2020
1 parent e509a8e commit f2cc7bc
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
2 changes: 2 additions & 0 deletions doc/pages/changelog.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions doc/pages/commands.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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>::
Expand Down
4 changes: 4 additions & 0 deletions doc/pages/hooks.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 15 additions & 0 deletions src/commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions src/hook_manager.hh
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ enum class Hook
WinDisplay,
WinResize,
WinSetOption,
ModuleLoaded
ModuleLoaded,
User
};

constexpr auto enum_desc(Meta::Type<Hook>)
Expand Down Expand Up @@ -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"}
});
}

Expand Down

0 comments on commit f2cc7bc

Please sign in to comment.