2017-11-02 05:03:24 +03:00
|
|
|
= Hooks
|
2016-02-03 20:15:35 +03:00
|
|
|
|
2017-11-02 05:03:24 +03:00
|
|
|
== Description
|
2016-02-02 22:15:12 +03:00
|
|
|
|
2016-04-08 19:00:24 +03:00
|
|
|
Commands can be registered to be executed when certain events arise. To
|
2016-02-11 00:03:49 +03:00
|
|
|
register a hook use the following command:
|
2016-02-02 22:15:12 +03:00
|
|
|
|
2018-09-22 11:43:56 +03:00
|
|
|
------------------------------------------------------------------------------
|
|
|
|
hook [-group <group> | -once] <scope> <hook_name> <filtering_regex> <commands>
|
|
|
|
------------------------------------------------------------------------------
|
2016-02-02 22:15:12 +03:00
|
|
|
|
2017-11-01 14:49:13 +03:00
|
|
|
*scope* can be one of *global*, *buffer* or *window* (See
|
|
|
|
<<scopes#,`:doc scopes`>>).
|
2016-02-02 22:15:12 +03:00
|
|
|
|
2018-09-22 11:43:56 +03:00
|
|
|
*hook_name* must be one of the hook names in the list below, like `InsertKey`
|
|
|
|
or `BufSetOption`.
|
2016-02-02 22:15:12 +03:00
|
|
|
|
2018-09-22 11:43:56 +03:00
|
|
|
*filtering_regex* must match the entire parameter string in order for the
|
|
|
|
commands to be executed.
|
2016-02-02 22:15:12 +03:00
|
|
|
|
2018-09-22 11:43:56 +03:00
|
|
|
*command* is a string containing the commands to execute when the hook
|
|
|
|
is called.
|
2016-02-03 20:15:35 +03:00
|
|
|
|
2017-04-21 13:32:47 +03:00
|
|
|
If *group* is given, make this hook part of the named group. Groups are used
|
2016-02-11 00:03:49 +03:00
|
|
|
for removing hooks with the following command:
|
2016-02-03 20:15:35 +03:00
|
|
|
|
2018-08-16 20:06:57 +03:00
|
|
|
----------------------------
|
2017-01-04 03:07:45 +03:00
|
|
|
remove-hooks <scope> <group>
|
2018-08-16 20:06:57 +03:00
|
|
|
----------------------------
|
2016-02-03 20:15:35 +03:00
|
|
|
|
2018-09-22 11:43:56 +03:00
|
|
|
A call to the command above will remove every hook in *scope* whose group
|
|
|
|
matches the given *group* regex.
|
2016-02-03 20:15:35 +03:00
|
|
|
|
2018-09-22 11:43:56 +03:00
|
|
|
If `-once` is given, the hook is automatically removed after running.
|
|
|
|
|
|
|
|
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 20:06:57 +03:00
|
|
|
|
2017-11-02 05:03:24 +03:00
|
|
|
== Default hooks
|
|
|
|
|
2018-09-22 11:43:56 +03: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 20:15:35 +03:00
|
|
|
*NormalIdle*::
|
2017-11-02 12:37:39 +03:00
|
|
|
a certain duration has passed since last key was pressed in normal mode
|
2016-02-03 20:15:35 +03:00
|
|
|
|
|
|
|
*NormalBegin*::
|
2017-11-02 12:37:39 +03:00
|
|
|
entering normal mode
|
2016-02-03 20:15:35 +03:00
|
|
|
|
|
|
|
*NormalEnd*::
|
2017-11-02 12:37:39 +03:00
|
|
|
leaving normal mode
|
2016-02-03 20:15:35 +03:00
|
|
|
|
2017-12-16 17:31:31 +03:00
|
|
|
*NormalKey* `key`::
|
|
|
|
a key is received in normal mode
|
2016-02-03 20:15:35 +03:00
|
|
|
|
|
|
|
*InsertIdle*::
|
2017-11-02 12:37:39 +03:00
|
|
|
a certain duration has passed since last key was pressed in insert mode
|
2016-02-03 20:15:35 +03:00
|
|
|
|
|
|
|
*InsertBegin*::
|
2017-11-02 12:37:39 +03:00
|
|
|
entering insert mode
|
2016-02-03 20:15:35 +03:00
|
|
|
|
|
|
|
*InsertEnd*::
|
2017-11-02 12:37:39 +03:00
|
|
|
leaving insert mode
|
2016-02-03 20:15:35 +03:00
|
|
|
|
2017-12-16 17:31:31 +03:00
|
|
|
*InsertKey* `key`::
|
|
|
|
a key is received in insert mode
|
2016-02-03 20:15:35 +03:00
|
|
|
|
2017-12-16 17:31:31 +03:00
|
|
|
*InsertChar* `char`::
|
|
|
|
a character is received in insert mode
|
2016-06-20 21:30:28 +03:00
|
|
|
|
2017-12-16 17:31:31 +03:00
|
|
|
*InsertDelete* `deleted char`::
|
|
|
|
a character is deleted in insert mode
|
2017-03-30 12:38:56 +03:00
|
|
|
|
2017-12-16 17:31:31 +03:00
|
|
|
*InsertMove* `move key`::
|
|
|
|
the cursor moved (without inserting) in insert mode
|
2016-02-03 20:15:35 +03:00
|
|
|
|
2017-07-05 14:45:45 +03:00
|
|
|
*PromptIdle*::
|
2017-11-02 12:37:39 +03:00
|
|
|
a certain duration has passed since last key was pressed in prompt mode
|
2017-07-05 14:45:45 +03:00
|
|
|
|
2017-12-16 17:31:31 +03:00
|
|
|
*WinCreate* `buffer name`::
|
2018-09-11 13:56:12 +03:00
|
|
|
a window was created. This hook is executed in draft context, so any a
|
|
|
|
changes to selections or input state will be discarded.
|
2016-02-03 20:15:35 +03:00
|
|
|
|
2017-12-16 17:31:31 +03:00
|
|
|
*WinClose* `buffer name`::
|
2018-09-11 13:56:12 +03: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 20:15:35 +03:00
|
|
|
|
2017-12-16 17:31:31 +03:00
|
|
|
*WinResize* `<line>.<column>`::
|
2018-09-11 13:56:12 +03: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 11:33:11 +03:00
|
|
|
|
2017-12-16 17:31:31 +03:00
|
|
|
*WinDisplay* `buffer name`::
|
2018-09-11 13:56:12 +03:00
|
|
|
a client switched to displaying the given buffer.
|
2016-02-03 20:15:35 +03:00
|
|
|
|
2017-12-16 17:31:31 +03:00
|
|
|
*WinSetOption* `<option_name>=<new_value>`::
|
2018-09-11 13:56:12 +03:00
|
|
|
an option was set in a window context. This hook is executed in a draft
|
|
|
|
acontext, so any changes to selections or input state will be discarded.
|
2016-02-03 20:15:35 +03:00
|
|
|
|
2018-03-05 03:20:17 +03:00
|
|
|
*GlobalSetOption* `<option_name>=<new_value>`::
|
|
|
|
an option was set at the global scope
|
|
|
|
|
2017-12-16 17:31:31 +03:00
|
|
|
*BufSetOption* `<option_name>=<new_value>`::
|
|
|
|
an option was set in a buffer context
|
2016-02-03 20:15:35 +03:00
|
|
|
|
2017-12-16 17:31:31 +03:00
|
|
|
*BufNewFile* `filename`::
|
|
|
|
a buffer for a new file has been created
|
2016-02-03 20:15:35 +03:00
|
|
|
|
2017-12-16 17:31:31 +03:00
|
|
|
*BufOpenFile* `filename`::
|
|
|
|
a buffer for an existing file has been created
|
2016-02-03 20:15:35 +03:00
|
|
|
|
2017-12-16 17:31:31 +03:00
|
|
|
*BufCreate* `filename`::
|
|
|
|
a buffer has been created
|
2016-02-03 20:15:35 +03:00
|
|
|
|
2017-12-16 17:31:31 +03:00
|
|
|
*BufWritePre* `filename`::
|
|
|
|
executed just before a buffer is written
|
2016-02-03 20:15:35 +03:00
|
|
|
|
2017-12-16 17:31:31 +03:00
|
|
|
*BufWritePost* `filename`::
|
|
|
|
executed just after a buffer is written
|
2016-02-03 20:15:35 +03:00
|
|
|
|
2018-06-13 01:38:39 +03:00
|
|
|
*BufReload* `filename`::
|
|
|
|
executed after a buffer reload has been triggered by an external
|
|
|
|
modification to its file
|
|
|
|
|
2017-12-16 17:31:31 +03:00
|
|
|
*BufClose* `buffer name`::
|
2017-11-02 12:37:39 +03:00
|
|
|
executed when a buffer is deleted, while it is still valid
|
2016-02-03 20:15:35 +03:00
|
|
|
|
2017-12-16 17:31:31 +03:00
|
|
|
*BufOpenFifo* `buffer name`::
|
2017-11-02 12:37:39 +03:00
|
|
|
executed when a buffer opens a fifo
|
2016-02-03 20:15:35 +03:00
|
|
|
|
2017-12-16 17:31:31 +03:00
|
|
|
*BufReadFifo* `buffer name`::
|
2017-11-02 12:37:39 +03:00
|
|
|
executed after some data has been read from a fifo and inserted in
|
|
|
|
the buffer
|
2016-02-03 20:15:35 +03:00
|
|
|
|
|
|
|
*BufCloseFifo*::
|
2017-11-02 12:37:39 +03:00
|
|
|
executed when a fifo buffer closes its fifo file descriptor either
|
2017-12-16 17:31:31 +03:00
|
|
|
because the buffer is being deleted or the writing end has been closed
|
2016-02-03 20:15:35 +03:00
|
|
|
|
2017-12-16 17:31:31 +03:00
|
|
|
*RuntimeError* `error message`::
|
|
|
|
an error was encountered while executing a user command
|
2016-02-03 20:15:35 +03:00
|
|
|
|
2018-01-21 02:34:09 +03:00
|
|
|
*ModeChange* `<old mode>:<new mode>`::
|
2017-12-18 03:03:29 +03:00
|
|
|
Triggered whenever the current input mode changes
|
|
|
|
|
2017-12-22 00:22:33 +03:00
|
|
|
*KakBegin* `session name`::
|
2017-11-02 12:37:39 +03:00
|
|
|
kakoune has started, this hook is called just after reading the user
|
|
|
|
configuration files
|
2016-02-03 20:15:35 +03:00
|
|
|
|
|
|
|
*KakEnd*::
|
2017-11-02 12:37:39 +03:00
|
|
|
kakoune is quitting
|
2016-02-03 20:15:35 +03:00
|
|
|
|
2017-12-16 17:31:31 +03:00
|
|
|
*FocusIn* `client name`::
|
|
|
|
on supported clients, triggered when the client gets focused
|
2016-02-03 20:15:35 +03:00
|
|
|
|
2017-12-16 17:31:31 +03:00
|
|
|
*FocusOut* `client name`::
|
|
|
|
on supported clients, triggered when the client gets unfocused
|
2016-02-02 22:15:12 +03:00
|
|
|
|
2016-09-21 15:38:34 +03:00
|
|
|
*InsertCompletionShow*::
|
2017-11-02 12:37:39 +03:00
|
|
|
Triggered when the insert completion menu gets displayed
|
2016-09-21 15:38:34 +03:00
|
|
|
|
|
|
|
*InsertCompletionHide*::
|
2017-11-02 12:37:39 +03:00
|
|
|
Triggered when the insert completion menu gets hidden
|
2016-09-21 15:38:34 +03:00
|
|
|
|
2017-12-16 17:31:31 +03:00
|
|
|
*InsertCompletionSelect* `selected completion`::
|
2017-11-25 08:47:04 +03:00
|
|
|
Triggered when an entry is selected in the insert completion
|
|
|
|
menu. The filtering text is the selected completion text or
|
2018-08-16 20:06:57 +03:00
|
|
|
the empty string if the original text was selected back
|
2017-11-25 08:47:04 +03:00
|
|
|
|
2017-12-16 17:31:31 +03:00
|
|
|
*RawKey* `key`::
|
|
|
|
Triggered whenever a key is pressed by the user
|
2017-01-25 02:57:36 +03:00
|
|
|
|
2018-09-22 11:43:56 +03: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 15:36:43 +03:00
|
|
|
hook, and will not consider the `window` scope.
|
2017-06-26 19:50:22 +03:00
|
|
|
|
2017-11-12 17:44:04 +03:00
|
|
|
While defining hook commands with a `%sh{}` block, some additional env
|
|
|
|
vars are available:
|
2017-06-26 19:50:22 +03:00
|
|
|
|
|
|
|
* `kak_hook_param`: filtering text passed to the currently executing hook
|
2017-11-28 14:40:07 +03:00
|
|
|
|
2017-06-26 19:50:22 +03:00
|
|
|
* `kak_hook_param_capture_N`: text captured by the hook filter regex capture N
|
|
|
|
|
2017-11-02 05:03:24 +03:00
|
|
|
== Disabling Hooks
|
2017-06-26 19:50:22 +03:00
|
|
|
|
2017-11-28 14:40:07 +03:00
|
|
|
Any normal mode command can be prefixed with `\ ` which will disable hook
|
2017-06-26 19:50:22 +03:00
|
|
|
execution for the duration for the command (including the duration of modes
|
|
|
|
the command could move to, so `\i` will disable hooks for the whole insert
|
|
|
|
session).
|
|
|
|
|
|
|
|
As autoindentation is implemented in terms of hooks, this can be used to
|
|
|
|
disable it when pasting text.
|
|
|
|
|
|
|
|
A less temporary alternative is to set 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-11-08 20:38:31 +03: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 20:06:57 +03: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`.
|