2017-11-02 03:03:24 +01:00
|
|
|
= Scopes
|
2016-10-13 10:55:09 +02:00
|
|
|
|
2017-11-02 03:03:24 +01:00
|
|
|
== Description
|
2016-10-13 10:55:09 +02:00
|
|
|
|
2018-04-28 17:41:24 +02:00
|
|
|
Scopes are groups in which a particular Kakoune object can have different
|
|
|
|
values depending on the group the value was declared in.
|
|
|
|
|
|
|
|
These scoped objects are:
|
|
|
|
|
2018-06-18 23:41:55 +02:00
|
|
|
- aliases (See <<commands#,`:doc commands`>>)
|
|
|
|
- faces (See <<faces#,`:doc faces`>>)
|
|
|
|
- highlighters (See <<highlighters#,`:doc highlighters`>>)
|
|
|
|
- hooks (See <<hooks#,`:doc hooks`>>)
|
|
|
|
- keymaps (See <<mapping#,`:doc mapping`>>)
|
|
|
|
- options (See <<options#,`:doc options`>>)
|
2016-10-13 10:55:09 +02:00
|
|
|
|
2017-11-02 03:03:24 +01:00
|
|
|
== Names and hierarchy
|
2016-10-13 10:55:09 +02:00
|
|
|
|
|
|
|
Scopes are named as follows:
|
|
|
|
|
|
|
|
*window*::
|
2018-06-02 19:51:39 +02:00
|
|
|
context linked to the window displaying a buffer.
|
|
|
|
|
|
|
|
In Kakoune, the concept of a *window* must not be confused with
|
|
|
|
the concept of a window at the OS level.
|
|
|
|
In other terms, a window is *not* a client (like a terminal or GUI)
|
|
|
|
but one of many 'views' into a buffer.
|
|
|
|
|
|
|
|
There is a N:1 relationship between windows and buffers; once a
|
|
|
|
window is linked to a buffer, the window's buffer never changes.
|
|
|
|
Windows store a set of selections and the scroll position.
|
2018-03-11 18:04:05 +01:00
|
|
|
|
2016-10-13 10:55:09 +02:00
|
|
|
*buffer*::
|
2017-11-02 10:37:39 +01:00
|
|
|
context linked directly to the buffer
|
2018-03-11 18:04:05 +01:00
|
|
|
|
2016-10-13 10:55:09 +02:00
|
|
|
*global*::
|
2017-11-02 10:37:39 +01:00
|
|
|
global context linked to the instance of Kakoune
|
2016-10-13 10:55:09 +02:00
|
|
|
|
2024-04-11 03:37:18 +02:00
|
|
|
*local*::
|
|
|
|
A local scope is inserted by each *evaluate-commands* invocations
|
|
|
|
for its duration. Nested *evaluate-commands* each inject a new
|
2024-04-29 04:18:25 +02:00
|
|
|
local scope whose parent is the previous local scope. User declared
|
|
|
|
commands defined with *define-command* also introduce a local scope
|
|
|
|
while executing.
|
2024-04-11 03:37:18 +02:00
|
|
|
|
|
|
|
A local scope is intended for temporarily overwriting some scoped
|
|
|
|
value, such as an option or an alias.
|
|
|
|
|
|
|
|
|
2016-10-13 10:55:09 +02:00
|
|
|
The following order of priority applies to the above scopes:
|
|
|
|
|
2024-04-11 03:37:18 +02:00
|
|
|
-----------------------------------
|
|
|
|
local ]> window ]> buffer ]> global
|
|
|
|
-----------------------------------
|
2016-10-13 10:55:09 +02:00
|
|
|
|
2024-04-11 03:37:18 +02:00
|
|
|
The above priority line implies that objects can have individual values
|
|
|
|
that will be resolved first in the *local* scope (if it exists), then the
|
|
|
|
*window* scope, then in the *buffer* scope, and finally in the *global*
|
|
|
|
scope.
|
2016-10-13 10:55:09 +02:00
|
|
|
|
2019-01-23 02:34:02 +01:00
|
|
|
Normally, the *buffer* scope keyword means the scope associated with the
|
|
|
|
currently active buffer, but it's possible to specify any existing buffer by
|
|
|
|
adding an `=` and the value of `%val{buffile}` for that buffer
|
|
|
|
(See <<expansions#value-expansions,`:doc expansions value-expansions`>>).
|
|
|
|
For example, to set the `indentwidth` option for the `/etc/fstab` buffer::
|
|
|
|
|
|
|
|
----
|
|
|
|
set-option buffer=/etc/fstab indentwidth 8
|
|
|
|
----
|
|
|
|
|
2018-03-11 18:04:05 +01:00
|
|
|
The `set-option` and `unset-option` commands also accept *current* as
|
|
|
|
a valid scope name. It refers to the narrowest scope the option is set in.
|
|
|
|
|
2017-11-02 03:03:24 +01:00
|
|
|
== Uses
|
2016-10-13 10:55:09 +02:00
|
|
|
|
|
|
|
The scope paradigm is very useful as it allows the user to customize the
|
|
|
|
behavior of the editor without modifying the configuration globally, as
|
|
|
|
is the case with other editors who only have a single *global* scope by
|
|
|
|
default.
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
|
|
|
*filetype*::
|
2017-11-02 10:37:39 +01:00
|
|
|
A single buffer opened in two separate windows can have different
|
2018-06-02 19:51:39 +02:00
|
|
|
filetypes declared in the *window* scope with 'set-option'.
|
2017-11-06 10:08:59 +01:00
|
|
|
(See <<options#,`:doc options`>>)
|
2016-10-13 10:55:09 +02:00
|
|
|
|
|
|
|
*status line*::
|
2017-11-02 10:37:39 +01:00
|
|
|
All the buffers of the current session can have the same information
|
|
|
|
displayed in the status line, except for a specific buffer (the
|
|
|
|
'modelinefmt' option can be declared in the *global* scope, and
|
2018-06-02 19:51:39 +02:00
|
|
|
customized in the *buffer* scope with 'set-option'.
|
2017-11-06 10:08:59 +01:00
|
|
|
(See <<options#,`:doc options`>>)
|
2016-10-13 10:55:09 +02:00
|
|
|
|
2017-11-02 03:03:24 +01:00
|
|
|
== Execution context
|
2016-10-13 10:55:09 +02:00
|
|
|
|
|
|
|
Some commands work in a specific context that might exclude one or
|
|
|
|
several scopes altogether, consequently ignoring some values of a given
|
|
|
|
object.
|
|
|
|
|
|
|
|
Example: the *window* scope is never considered when resolving the
|
|
|
|
values of options when writing a buffer (e.g. 'BOM', 'eolformat').
|