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
|
|
|
|
2016-02-03 18:15:35 +01:00
|
|
|
----------------------------------------------------------------------
|
|
|
|
hook [-group <group>] <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
|
|
|
|
2016-02-10 22:03:49 +01:00
|
|
|
*command* is a string containing the commands to execute when the hook
|
|
|
|
is called.
|
2016-02-02 20:15:12 +01:00
|
|
|
|
2016-02-10 22:03:49 +01:00
|
|
|
For example to automatically use line numbering with .cc files, use the
|
|
|
|
following command:
|
2016-02-02 20:15:12 +01:00
|
|
|
|
2016-02-03 18:15:35 +01:00
|
|
|
----------------------------------------------------
|
2017-01-04 01:07:45 +01:00
|
|
|
hook global WinCreate .*\.cc %{ add-highlighter number_lines }
|
2016-02-03 18:15:35 +01:00
|
|
|
----------------------------------------------------
|
|
|
|
|
2017-04-21 12:32:47 +02:00
|
|
|
If *group* is given, make this hook part of the named group. Groups are used
|
2016-02-10 22:03:49 +01:00
|
|
|
for removing hooks with the following command:
|
2016-02-03 18:15:35 +01:00
|
|
|
|
|
|
|
-----------------------
|
2017-01-04 01:07:45 +01:00
|
|
|
remove-hooks <scope> <group>
|
2016-02-03 18:15:35 +01:00
|
|
|
-----------------------
|
|
|
|
|
2016-02-10 22:03:49 +01:00
|
|
|
A call to the command above will remove every hooks in *scope* that are part
|
|
|
|
of the given *group*.
|
2016-02-03 18:15:35 +01:00
|
|
|
|
2017-11-02 03:03:24 +01:00
|
|
|
== Default hooks
|
|
|
|
|
2016-02-03 18:15:35 +01:00
|
|
|
*NormalIdle*::
|
2017-11-02 10:37:39 +01:00
|
|
|
a certain duration has passed since last key was pressed in normal mode
|
2016-02-03 18:15:35 +01:00
|
|
|
|
|
|
|
*NormalBegin*::
|
2017-11-02 10:37:39 +01:00
|
|
|
entering normal mode
|
2016-02-03 18:15:35 +01:00
|
|
|
|
|
|
|
*NormalEnd*::
|
2017-11-02 10:37:39 +01:00
|
|
|
leaving normal mode
|
2016-02-03 18:15:35 +01:00
|
|
|
|
|
|
|
*NormalKey*::
|
2017-11-02 10:37:39 +01:00
|
|
|
a key is received in normal mode, the key is used for filtering
|
2016-02-03 18:15:35 +01:00
|
|
|
|
|
|
|
*InsertIdle*::
|
2017-11-02 10:37:39 +01:00
|
|
|
a certain duration has passed since last key was pressed in insert mode
|
2016-02-03 18:15:35 +01:00
|
|
|
|
|
|
|
*InsertBegin*::
|
2017-11-02 10:37:39 +01:00
|
|
|
entering insert mode
|
2016-02-03 18:15:35 +01:00
|
|
|
|
|
|
|
*InsertEnd*::
|
2017-11-02 10:37:39 +01:00
|
|
|
leaving insert mode
|
2016-02-03 18:15:35 +01:00
|
|
|
|
|
|
|
*InsertKey*::
|
2017-11-02 10:37:39 +01:00
|
|
|
a key is received in insert mode, the key is used for filtering
|
2016-02-03 18:15:35 +01:00
|
|
|
|
2016-06-20 20:30:28 +02:00
|
|
|
*InsertChar*::
|
2017-11-02 10:37:39 +01:00
|
|
|
a character is received in insert mode, the character is used for
|
|
|
|
filtering
|
2016-06-20 20:30:28 +02:00
|
|
|
|
2017-03-30 11:38:56 +02:00
|
|
|
*InsertDelete*::
|
2017-11-02 10:37:39 +01:00
|
|
|
a character is deleted in insert mode, the character deleted by
|
|
|
|
the main selection is used for filtering
|
2017-03-30 11:38:56 +02:00
|
|
|
|
2016-02-03 18:15:35 +01:00
|
|
|
*InsertMove*::
|
2017-11-02 10:37:39 +01:00
|
|
|
the cursor moved (without inserting) in insert mode, the key that
|
|
|
|
triggered the move is used for filtering
|
2016-02-03 18:15:35 +01:00
|
|
|
|
2017-07-05 13:45:45 +02:00
|
|
|
*PromptIdle*::
|
2017-11-02 10:37:39 +01:00
|
|
|
a certain duration has passed since last key was pressed in prompt mode
|
2017-07-05 13:45:45 +02:00
|
|
|
|
2016-02-03 18:15:35 +01:00
|
|
|
*WinCreate*::
|
2017-11-02 10:37:39 +01:00
|
|
|
a window was created, the filtering text is the buffer name
|
2016-02-03 18:15:35 +01:00
|
|
|
|
|
|
|
*WinClose*::
|
2017-11-02 10:37:39 +01:00
|
|
|
a window was destroyed, the filtering text is the buffer name
|
2016-02-03 18:15:35 +01:00
|
|
|
|
2016-05-13 10:33:11 +02:00
|
|
|
*WinResize*::
|
2017-11-02 10:37:39 +01:00
|
|
|
a window resized, the filtering text is *<line>.<column>*
|
2016-05-13 10:33:11 +02:00
|
|
|
|
2016-02-03 18:15:35 +01:00
|
|
|
*WinDisplay*::
|
2017-11-02 10:37:39 +01:00
|
|
|
a window was bound a client, the filtering text is the buffer name
|
2016-02-03 18:15:35 +01:00
|
|
|
|
|
|
|
*WinSetOption*::
|
2017-11-02 10:37:39 +01:00
|
|
|
an option was set in a window context, the filtering text is
|
|
|
|
*<option_name>=<new_value>*
|
2016-02-03 18:15:35 +01:00
|
|
|
|
|
|
|
*BufSetOption*::
|
2017-11-02 10:37:39 +01:00
|
|
|
an option was set in a buffer context, the filtering text is
|
|
|
|
*<option_name>=<new_value>*
|
2016-02-03 18:15:35 +01:00
|
|
|
|
2017-02-19 14:08:06 +01:00
|
|
|
*BufNewFile*::
|
2017-11-02 10:37:39 +01:00
|
|
|
a buffer for a new file has been created, filename is used for
|
|
|
|
filtering
|
2016-02-03 18:15:35 +01:00
|
|
|
|
2017-02-19 14:08:06 +01:00
|
|
|
*BufOpenFile*::
|
2017-11-02 10:37:39 +01:00
|
|
|
a buffer for an existing file has been created, filename is used
|
|
|
|
for filtering
|
2016-02-03 18:15:35 +01:00
|
|
|
|
|
|
|
*BufCreate*::
|
2017-11-02 10:37:39 +01:00
|
|
|
a buffer has been created, filename is used for filtering
|
2016-02-03 18:15:35 +01:00
|
|
|
|
|
|
|
*BufWritePre*::
|
2017-11-02 10:37:39 +01:00
|
|
|
executed just before a buffer is written, filename is used for
|
|
|
|
filtering
|
2016-02-03 18:15:35 +01:00
|
|
|
|
|
|
|
*BufWritePost*::
|
2017-11-02 10:37:39 +01:00
|
|
|
executed just after a buffer is written, filename is used for filtering
|
2016-02-03 18:15:35 +01:00
|
|
|
|
|
|
|
*BufClose*::
|
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
|
|
|
|
|
|
|
*BufOpenFifo*::
|
2017-11-02 10:37:39 +01:00
|
|
|
executed when a buffer opens a fifo
|
2016-02-03 18:15:35 +01:00
|
|
|
|
|
|
|
*BufReadFifo*::
|
2017-11-02 10:37:39 +01:00
|
|
|
executed after some data has been read from a fifo and inserted in
|
|
|
|
the buffer
|
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
|
|
|
|
because the buffer is being deleted,
|
|
|
|
or because the writing end has been closed
|
2016-02-03 18:15:35 +01:00
|
|
|
|
|
|
|
*RuntimeError*::
|
2017-11-02 10:37:39 +01:00
|
|
|
an error was encountered while executing a user command the error
|
|
|
|
message is used for filtering
|
2016-02-03 18:15:35 +01:00
|
|
|
|
|
|
|
*KakBegin*::
|
2017-11-02 10:37:39 +01:00
|
|
|
kakoune has started, this hook is called just after reading the user
|
|
|
|
configuration files
|
2016-02-03 18:15:35 +01:00
|
|
|
|
|
|
|
*KakEnd*::
|
2017-11-02 10:37:39 +01:00
|
|
|
kakoune is quitting
|
2016-02-03 18:15:35 +01:00
|
|
|
|
|
|
|
*FocusIn*::
|
2017-11-02 10:37:39 +01:00
|
|
|
on supported clients, triggered when the client gets focused. The
|
|
|
|
filtering text is the client name
|
2016-02-03 18:15:35 +01:00
|
|
|
|
|
|
|
*FocusOut*::
|
2017-11-02 10:37:39 +01:00
|
|
|
on supported clients, triggered when the client gets unfocused. The
|
|
|
|
filtering text is the client name
|
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
|
|
|
|
|
|
|
*InsertCompletionHide*::
|
2017-11-02 10:37:39 +01:00
|
|
|
Triggered when the insert completion menu gets hidden
|
2016-09-21 14:38:34 +02:00
|
|
|
|
2017-11-25 06:47:04 +01:00
|
|
|
*InsertCompletionSelect*::
|
|
|
|
Triggered when an entry is selected in the insert completion
|
|
|
|
menu. The filtering text is the selected completion text or
|
|
|
|
the empty string if the original text was selected back.
|
|
|
|
|
2017-01-25 00:57:36 +01:00
|
|
|
*RawKey*::
|
2017-11-02 10:37:39 +01:00
|
|
|
Triggered whenever a key is pressed by the user, the key is
|
|
|
|
used for filtering.
|
2017-01-25 00:57:36 +01:00
|
|
|
|
2016-10-18 14:36:43 +02:00
|
|
|
When not specified, the filtering text is an empty string. 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.
|
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
|
|
|
|
* `kak_hook_param_capture_N`: text captured by the hook filter regex capture N
|
|
|
|
|
2017-11-02 03:03:24 +01:00
|
|
|
== Disabling Hooks
|
2017-06-26 18:50:22 +02:00
|
|
|
|
|
|
|
Any normal mode command can be prefixed with `\` which will disable hook
|
|
|
|
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 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`>>)
|