2017-11-02 03:03:24 +01:00
|
|
|
= Hooks
|
2016-02-03 18:15:35 +01:00
|
|
|
|
2017-11-02 03:03:24 +01:00
|
|
|
== Description
|
2016-02-02 20:15:12 +01:00
|
|
|
|
2016-04-08 18:00:24 +02:00
|
|
|
Commands can be registered to be executed when certain events arise. To
|
2016-02-10 22:03:49 +01:00
|
|
|
register a hook use the following command:
|
2016-02-02 20:15:12 +01:00
|
|
|
|
2021-04-19 04:46:47 +02:00
|
|
|
------------------------------------------------------------------
|
|
|
|
hook [<switches>] <scope> <hook_name> <filtering_regex> <commands>
|
|
|
|
------------------------------------------------------------------
|
2016-02-02 20:15:12 +01:00
|
|
|
|
2017-11-01 12:49:13 +01:00
|
|
|
*scope* can be one of *global*, *buffer* or *window* (See
|
|
|
|
<<scopes#,`:doc scopes`>>).
|
2016-02-02 20:15:12 +01:00
|
|
|
|
2018-09-22 10:43:56 +02:00
|
|
|
*hook_name* must be one of the hook names in the list below, like `InsertKey`
|
|
|
|
or `BufSetOption`.
|
2016-02-02 20:15:12 +01:00
|
|
|
|
2018-09-22 10:43:56 +02:00
|
|
|
*filtering_regex* must match the entire parameter string in order for the
|
|
|
|
commands to be executed.
|
2016-02-02 20:15:12 +01:00
|
|
|
|
2018-09-22 10:43:56 +02:00
|
|
|
*command* is a string containing the commands to execute when the hook
|
|
|
|
is called.
|
2016-02-03 18:15:35 +01:00
|
|
|
|
2021-04-19 04:46:47 +02:00
|
|
|
For *switches*, see <<commands#hooks,`:doc commands hooks`>>.
|
|
|
|
|
|
|
|
If a hook is registered with the `-group` switch, it can later be removed with
|
|
|
|
the `remove-hooks` command:
|
2016-02-03 18:15:35 +01:00
|
|
|
|
2018-08-16 19:06:57 +02:00
|
|
|
----------------------------
|
2017-01-04 01:07:45 +01:00
|
|
|
remove-hooks <scope> <group>
|
2018-08-16 19:06:57 +02:00
|
|
|
----------------------------
|
2016-02-03 18:15:35 +01:00
|
|
|
|
2021-04-19 04:46:47 +02:00
|
|
|
This command removes all hooks originally registered in *scope* whose
|
|
|
|
`-group` switch matches the regex *group*.
|
2018-09-22 10:43:56 +02:00
|
|
|
|
|
|
|
For example to automatically use line numbering with .cc files, use the
|
|
|
|
following command:
|
|
|
|
|
|
|
|
--------------------------------------------------------------
|
|
|
|
hook global WinCreate .*\.cc %{ add-highlighter number-lines }
|
|
|
|
--------------------------------------------------------------
|
2018-08-16 19:06:57 +02:00
|
|
|
|
2017-11-02 03:03:24 +01:00
|
|
|
== Default hooks
|
|
|
|
|
2018-09-22 10:43:56 +02:00
|
|
|
The parameter string associated with each hook is described after the hook
|
|
|
|
name. Hooks with no description will always use an empty string.
|
|
|
|
|
2016-02-03 18:15:35 +01:00
|
|
|
*NormalIdle*::
|
2019-05-12 22:56:38 +02:00
|
|
|
a certain duration has passed since the last keypress in normal mode
|
2016-02-03 18:15:35 +01:00
|
|
|
|
2017-12-16 15:31:31 +01:00
|
|
|
*NormalKey* `key`::
|
2019-12-11 03:08:18 +01:00
|
|
|
a key is received in normal mode. This hook will not trigger when the user
|
|
|
|
presses a key on the left-hand side of a normal-mode mapping (see
|
|
|
|
<<mapping#,`:doc mapping`>>), but will trigger for keys on the right-hand
|
|
|
|
side. See also `RawKey` below.
|
2016-02-03 18:15:35 +01:00
|
|
|
|
|
|
|
*InsertIdle*::
|
2019-05-12 22:56:38 +02:00
|
|
|
a certain duration has passed since the last keypress in insert mode
|
2016-02-03 18:15:35 +01:00
|
|
|
|
2017-12-16 15:31:31 +01:00
|
|
|
*InsertKey* `key`::
|
2019-12-11 03:08:18 +01:00
|
|
|
a key is received in insert mode. This hook will not trigger when the user
|
|
|
|
presses a key on the left-hand side of a insert-mode mapping (see
|
|
|
|
<<mapping#,`:doc mapping`>>), but will trigger for keys on the right-hand
|
|
|
|
side. See also `RawKey` below.
|
2016-02-03 18:15:35 +01:00
|
|
|
|
2017-12-16 15:31:31 +01:00
|
|
|
*InsertChar* `char`::
|
|
|
|
a character is received in insert mode
|
2016-06-20 20:30:28 +02:00
|
|
|
|
2017-12-16 15:31:31 +01:00
|
|
|
*InsertDelete* `deleted char`::
|
|
|
|
a character is deleted in insert mode
|
2017-03-30 11:38:56 +02:00
|
|
|
|
2017-12-16 15:31:31 +01:00
|
|
|
*InsertMove* `move key`::
|
|
|
|
the cursor moved (without inserting) in insert mode
|
2016-02-03 18:15:35 +01:00
|
|
|
|
2017-07-05 13:45:45 +02:00
|
|
|
*PromptIdle*::
|
2019-05-12 22:56:38 +02:00
|
|
|
a certain duration has passed since the last keypress in prompt mode
|
2017-07-05 13:45:45 +02:00
|
|
|
|
2017-12-16 15:31:31 +01:00
|
|
|
*WinCreate* `buffer name`::
|
2019-05-12 22:56:38 +02:00
|
|
|
a window was created. This hook is executed in draft context, so any
|
2018-09-11 12:56:12 +02:00
|
|
|
changes to selections or input state will be discarded.
|
2016-02-03 18:15:35 +01:00
|
|
|
|
2017-12-16 15:31:31 +01:00
|
|
|
*WinClose* `buffer name`::
|
2018-09-11 12:56:12 +02:00
|
|
|
a window was destroyed. This hook is executed in a draft context, so any
|
|
|
|
changes to selections or input state will be discarded.
|
2016-02-03 18:15:35 +01:00
|
|
|
|
2017-12-16 15:31:31 +01:00
|
|
|
*WinResize* `<line>.<column>`::
|
2018-09-11 12:56:12 +02:00
|
|
|
a window was resized. This hook is executed in a draft context, so any
|
|
|
|
changes to selections or input state will be discarded.
|
2016-05-13 10:33:11 +02:00
|
|
|
|
2017-12-16 15:31:31 +01:00
|
|
|
*WinDisplay* `buffer name`::
|
2018-09-11 12:56:12 +02:00
|
|
|
a client switched to displaying the given buffer.
|
2016-02-03 18:15:35 +01:00
|
|
|
|
2017-12-16 15:31:31 +01:00
|
|
|
*WinSetOption* `<option_name>=<new_value>`::
|
2018-09-11 12:56:12 +02:00
|
|
|
an option was set in a window context. This hook is executed in a draft
|
2019-05-12 22:56:38 +02:00
|
|
|
context, so any changes to selections or input state will be discarded.
|
2016-02-03 18:15:35 +01:00
|
|
|
|
2018-03-05 01:20:17 +01:00
|
|
|
*GlobalSetOption* `<option_name>=<new_value>`::
|
|
|
|
an option was set at the global scope
|
|
|
|
|
2017-12-16 15:31:31 +01:00
|
|
|
*BufSetOption* `<option_name>=<new_value>`::
|
|
|
|
an option was set in a buffer context
|
2016-02-03 18:15:35 +01:00
|
|
|
|
2017-12-16 15:31:31 +01:00
|
|
|
*BufNewFile* `filename`::
|
|
|
|
a buffer for a new file has been created
|
2016-02-03 18:15:35 +01:00
|
|
|
|
2017-12-16 15:31:31 +01:00
|
|
|
*BufOpenFile* `filename`::
|
|
|
|
a buffer for an existing file has been created
|
2016-02-03 18:15:35 +01:00
|
|
|
|
2017-12-16 15:31:31 +01:00
|
|
|
*BufCreate* `filename`::
|
|
|
|
a buffer has been created
|
2016-02-03 18:15:35 +01:00
|
|
|
|
2017-12-16 15:31:31 +01:00
|
|
|
*BufWritePre* `filename`::
|
|
|
|
executed just before a buffer is written
|
2016-02-03 18:15:35 +01:00
|
|
|
|
2017-12-16 15:31:31 +01:00
|
|
|
*BufWritePost* `filename`::
|
|
|
|
executed just after a buffer is written
|
2016-02-03 18:15:35 +01:00
|
|
|
|
2018-06-13 00:38:39 +02:00
|
|
|
*BufReload* `filename`::
|
|
|
|
executed after a buffer reload has been triggered by an external
|
|
|
|
modification to its file
|
|
|
|
|
2017-12-16 15:31:31 +01:00
|
|
|
*BufClose* `buffer name`::
|
2017-11-02 10:37:39 +01:00
|
|
|
executed when a buffer is deleted, while it is still valid
|
2016-02-03 18:15:35 +01:00
|
|
|
|
2017-12-16 15:31:31 +01:00
|
|
|
*BufOpenFifo* `buffer name`::
|
2017-11-02 10:37:39 +01:00
|
|
|
executed when a buffer opens a fifo
|
2016-02-03 18:15:35 +01:00
|
|
|
|
2018-11-14 07:52:57 +01:00
|
|
|
*BufReadFifo* `<start line>.<start column>,<end line>.<end column>`::
|
2017-11-02 10:37:39 +01:00
|
|
|
executed after some data has been read from a fifo and inserted in
|
2018-11-14 07:52:57 +01:00
|
|
|
the buffer. The hook param contains the range of text that was just
|
|
|
|
inserted, in a format compatible with the `select` command.
|
2016-02-03 18:15:35 +01:00
|
|
|
|
|
|
|
*BufCloseFifo*::
|
2017-11-02 10:37:39 +01:00
|
|
|
executed when a fifo buffer closes its fifo file descriptor either
|
2017-12-16 15:31:31 +01:00
|
|
|
because the buffer is being deleted or the writing end has been closed
|
2016-02-03 18:15:35 +01:00
|
|
|
|
2019-04-08 13:58:12 +02:00
|
|
|
*ClientCreate* `client name`::
|
|
|
|
executed when a new client is created.
|
|
|
|
|
|
|
|
*ClientClose* `client name`::
|
|
|
|
executed when a client is closed, after it was removed from the client
|
|
|
|
list.
|
2024-03-03 04:29:32 +01:00
|
|
|
|
|
|
|
*ClientRenamed* `<old name>:<new name>`::
|
|
|
|
executed when a client is renamed using the `rename-client` command
|
2019-04-08 13:58:12 +02:00
|
|
|
|
2024-03-27 17:52:31 +01:00
|
|
|
*SessionRenamed* `<old name>:<new name>`::
|
|
|
|
executed when a session is renamed using the `rename-session` command
|
|
|
|
|
2017-12-16 15:31:31 +01:00
|
|
|
*RuntimeError* `error message`::
|
|
|
|
an error was encountered while executing a user command
|
2016-02-03 18:15:35 +01:00
|
|
|
|
2019-10-16 11:19:43 +02:00
|
|
|
*ModeChange* `[push|pop]:<old mode>:<new mode>`::
|
|
|
|
Triggered whenever a mode is pushed or removed from the mode stack.
|
2020-09-21 09:28:18 +02:00
|
|
|
The mode name can be things like 'normal' or 'insert' for regular
|
|
|
|
interactive modes, or 'next-key[<name>]' for sub-modes where Kakoune
|
|
|
|
prompts for a key. For example, `g` in normal mode pushes 'next-key[goto]'
|
|
|
|
mode, the `enter-user-mode foo` command pushes 'next-key[user.foo]' mode,
|
|
|
|
and the `on-key -mode-name bar` command pushes 'next-key[bar]' mode.
|
2017-12-18 01:03:29 +01:00
|
|
|
|
2017-12-21 22:22:33 +01:00
|
|
|
*KakBegin* `session name`::
|
2021-05-16 03:50:46 +02:00
|
|
|
Kakoune has started, this hook is called just after reading the user
|
2017-11-02 10:37:39 +01:00
|
|
|
configuration files
|
2016-02-03 18:15:35 +01:00
|
|
|
|
|
|
|
*KakEnd*::
|
2021-05-16 03:50:46 +02:00
|
|
|
Kakoune is quitting
|
2016-02-03 18:15:35 +01:00
|
|
|
|
2017-12-16 15:31:31 +01:00
|
|
|
*FocusIn* `client name`::
|
|
|
|
on supported clients, triggered when the client gets focused
|
2016-02-03 18:15:35 +01:00
|
|
|
|
2017-12-16 15:31:31 +01:00
|
|
|
*FocusOut* `client name`::
|
|
|
|
on supported clients, triggered when the client gets unfocused
|
2016-02-02 20:15:12 +01:00
|
|
|
|
2016-09-21 14:38:34 +02:00
|
|
|
*InsertCompletionShow*::
|
2017-11-02 10:37:39 +01:00
|
|
|
Triggered when the insert completion menu gets displayed
|
2016-09-21 14:38:34 +02:00
|
|
|
|
2019-04-16 15:55:51 +02:00
|
|
|
*InsertCompletionHide* `completion`::
|
2020-01-16 10:52:01 +01:00
|
|
|
Triggered when the insert completion menu gets hidden, the list of
|
|
|
|
inserted completions text ranges is passed as filtering text, in the
|
|
|
|
same format the `select` command expects.
|
2016-09-21 14:38:34 +02:00
|
|
|
|
2017-12-16 15:31:31 +01:00
|
|
|
*RawKey* `key`::
|
2019-12-11 03:08:18 +01:00
|
|
|
Triggered whenever a key is pressed by the user, regardless of what mode
|
|
|
|
Kakoune is in, or what mappings are present (see
|
2020-05-28 18:37:26 +02:00
|
|
|
<<mapping#,`:doc mapping`>>). It cannot be triggered by `execute-keys`,
|
2019-12-11 03:08:18 +01:00
|
|
|
even with the `-with-hooks` option (see
|
|
|
|
<<execeval#execute-keys-specific-switches,`:doc execeval execute-keys-specific-switches`>>).
|
2017-01-25 00:57:36 +01:00
|
|
|
|
2020-07-19 04:56:55 +02:00
|
|
|
*RegisterModified* `register`::
|
|
|
|
Triggered after a register has been written to.
|
|
|
|
|
2019-06-25 17:48:24 +02:00
|
|
|
*ModuleLoaded* `module`::
|
|
|
|
Triggered after a module is evaluated by the first `require-module` call
|
2019-03-15 19:52:33 +01:00
|
|
|
|
2020-07-04 05:48:10 +02:00
|
|
|
*User* `param`::
|
|
|
|
Triggered via the `trigger-user-hook` command. Provides a way for plugins
|
|
|
|
to introduce custom hooks by specifying what *param* would be.
|
|
|
|
|
2018-09-22 10:43:56 +02:00
|
|
|
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
|
2016-10-18 14:36:43 +02:00
|
|
|
hook, and will not consider the `window` scope.
|
2017-06-26 18:50:22 +02:00
|
|
|
|
2017-11-12 15:44:04 +01:00
|
|
|
While defining hook commands with a `%sh{}` block, some additional env
|
|
|
|
vars are available:
|
2017-06-26 18:50:22 +02:00
|
|
|
|
|
|
|
* `kak_hook_param`: filtering text passed to the currently executing hook
|
2017-11-28 12:40:07 +01:00
|
|
|
|
2019-04-15 15:53:47 +02:00
|
|
|
* `kak_hook_param_capture_N`: text captured by the hook filter regex capturing
|
|
|
|
group N, N can either be the capturing group number, or its name
|
|
|
|
(See <<regex#groups,`:doc regex groups`>>).
|
2017-06-26 18:50:22 +02:00
|
|
|
|
2017-11-02 03:03:24 +01:00
|
|
|
== Disabling Hooks
|
2017-06-26 18:50:22 +02:00
|
|
|
|
2020-10-22 14:39:10 +02:00
|
|
|
Hooks can be disabled temporarily by prefixing any normal mode command by `\`
|
|
|
|
(see <<keys#,`:doc keys`>>) and permanently by setting the `disabled_hooks` option
|
|
|
|
which accepts a regex describing which hooks won't be executed. For example
|
|
|
|
indentation hooks can be disabled with '.*-indent'.
|
2017-06-26 18:50:22 +02:00
|
|
|
|
2017-11-08 18:38:31 +01:00
|
|
|
Finally, hook execution can be disabled while using the `execute-keys` or
|
|
|
|
`evaluate-commands` commands by using the `-no-hooks` switch.
|
|
|
|
(See <<execeval#,`:doc execeval`>>)
|
2018-08-16 19:06:57 +02:00
|
|
|
|
|
|
|
As an exception to these rules, hooks declared with the `-always` switch
|
|
|
|
are triggered no matter what. A good use case is doing some cleanup on `BufCloseFifo`.
|