diff options
| author | Yuan Fu | 2022-10-13 15:08:20 -0700 |
|---|---|---|
| committer | Yuan Fu | 2022-10-13 15:09:51 -0700 |
| commit | bb8a46e559ec39437a1524b3e9746746768effcc (patch) | |
| tree | 6563e14ce2a6b659f3a9907fa25924b14e1590b4 | |
| parent | af288d813b3c31a528ddcbdce08f497855a56e94 (diff) | |
| download | emacs-bb8a46e559ec39437a1524b3e9746746768effcc.tar.gz emacs-bb8a46e559ec39437a1524b3e9746746768effcc.zip | |
Update tree-sitter manual to reflect the previous commit
* doc/lispref/modes.texi: Update manual to reflect previous change:
remove :toggle and :level, add :feature. Document new variables and
functions.
* doc/lispref/parsing.texi: Add the missing closing bracket in
@code{(t . nil)}.
| -rw-r--r-- | doc/lispref/modes.texi | 75 | ||||
| -rw-r--r-- | doc/lispref/parsing.texi | 6 |
2 files changed, 60 insertions, 21 deletions
diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi index b1287c6ad05..ed232556b28 100644 --- a/doc/lispref/modes.texi +++ b/doc/lispref/modes.texi | |||
| @@ -3911,10 +3911,12 @@ a value that @var{treesit-font-lock-settings} accepts. An example: | |||
| 3911 | @group | 3911 | @group |
| 3912 | (treesit-font-lock-rules | 3912 | (treesit-font-lock-rules |
| 3913 | :language 'javascript | 3913 | :language 'javascript |
| 3914 | :feature 'constant | ||
| 3914 | :override t | 3915 | :override t |
| 3915 | '((true) @@font-lock-constant-face | 3916 | '((true) @@font-lock-constant-face |
| 3916 | (false) @@font-lock-constant-face) | 3917 | (false) @@font-lock-constant-face) |
| 3917 | :language 'html | 3918 | :language 'html |
| 3919 | :feature 'script | ||
| 3918 | "(script_element) @@font-lock-builtin-face") | 3920 | "(script_element) @@font-lock-builtin-face") |
| 3919 | @end group | 3921 | @end group |
| 3920 | @end example | 3922 | @end example |
| @@ -3922,7 +3924,12 @@ a value that @var{treesit-font-lock-settings} accepts. An example: | |||
| 3922 | This function takes a list of text or s-exp queries. Before each | 3924 | This function takes a list of text or s-exp queries. Before each |
| 3923 | query, there are @var{:keyword} and @var{value} pairs that configure | 3925 | query, there are @var{:keyword} and @var{value} pairs that configure |
| 3924 | that query. The @code{:lang} keyword sets the query’s language and | 3926 | that query. The @code{:lang} keyword sets the query’s language and |
| 3925 | every query must specify the language. Other keywords are optional: | 3927 | every query must specify the language. The @code{:feature} keyword |
| 3928 | sets the feature name of the query. Users can control which features | ||
| 3929 | are enabled with @code{font-lock-maximum-decoration} and | ||
| 3930 | @code{treesit-font-lock-feature-list} (see below). | ||
| 3931 | |||
| 3932 | Other keywords are optional: | ||
| 3926 | 3933 | ||
| 3927 | @multitable @columnfractions .15 .15 .6 | 3934 | @multitable @columnfractions .15 .15 .6 |
| 3928 | @headitem Keyword @tab Value @tab Description | 3935 | @headitem Keyword @tab Value @tab Description |
| @@ -3932,21 +3939,8 @@ every query must specify the language. Other keywords are optional: | |||
| 3932 | @item @tab @code{append} @tab Append the new face to existing ones | 3939 | @item @tab @code{append} @tab Append the new face to existing ones |
| 3933 | @item @tab @code{prepend} @tab Prepend the new face to existing ones | 3940 | @item @tab @code{prepend} @tab Prepend the new face to existing ones |
| 3934 | @item @tab @code{keep} @tab Fill-in regions without an existing face | 3941 | @item @tab @code{keep} @tab Fill-in regions without an existing face |
| 3935 | @item @code{:toggle} @tab @var{symbol} @tab | ||
| 3936 | If non-nil, its value should be a variable name. The variable's value | ||
| 3937 | (nil/non-nil) disables/enables the query during fontification. | ||
| 3938 | @item @tab nil @tab Always enable this query. | ||
| 3939 | @item @code{:level} @tab @var{integer} @tab | ||
| 3940 | If non-nil, its value should be the decoration level for this query. | ||
| 3941 | Decoration level is controlled by @code{font-lock-maximum-decoration}. | ||
| 3942 | @item @tab nil @tab Always enable this query. | ||
| 3943 | @end multitable | 3942 | @end multitable |
| 3944 | 3943 | ||
| 3945 | Note that a query is applied only when both @code{:toggle} and | ||
| 3946 | @code{:level} permit it. @code{:level} is used for global, | ||
| 3947 | coarse-grained control, whereas @code{:toggle} is for local, | ||
| 3948 | fine-grained control. | ||
| 3949 | |||
| 3950 | Capture names in @var{query} should be face names like | 3944 | Capture names in @var{query} should be face names like |
| 3951 | @code{font-lock-keyword-face}. The captured node will be fontified | 3945 | @code{font-lock-keyword-face}. The captured node will be fontified |
| 3952 | with that face. Capture names can also be function names, in which | 3946 | with that face. Capture names can also be function names, in which |
| @@ -3957,6 +3951,42 @@ is both a face and a function, the face takes priority. If a capture | |||
| 3957 | name is not a face name nor a function name, it is ignored. | 3951 | name is not a face name nor a function name, it is ignored. |
| 3958 | @end defun | 3952 | @end defun |
| 3959 | 3953 | ||
| 3954 | @defvar treesit-font-lock-feature-list | ||
| 3955 | This is a list of lists of feature symbols. | ||
| 3956 | |||
| 3957 | Each sublist represents a decoration level. | ||
| 3958 | @code{font-lock-maximum-decoration} controls which levels are | ||
| 3959 | activated. | ||
| 3960 | |||
| 3961 | Inside each sublist are feature symbols, which corresponds to the | ||
| 3962 | @code{:feature} value of a query defined in | ||
| 3963 | @code{treesit-font-lock-rules}. Removing a feature symbol from this | ||
| 3964 | list disables the corresponding query during font-lock. | ||
| 3965 | |||
| 3966 | Common feature names (for general programming language) include | ||
| 3967 | function-name, type, variable-name (LHS of assignments), builtin, | ||
| 3968 | constant, keyword, string-interpolation, comment, doc, string, | ||
| 3969 | operator, preprocessor, escape-sequence, key (in key-value | ||
| 3970 | pairs). Major modes are free to subdivide or extend on these | ||
| 3971 | common features. | ||
| 3972 | |||
| 3973 | For example, the value of this variable could be: | ||
| 3974 | @example | ||
| 3975 | @group | ||
| 3976 | ((comment string doc) ; level 1 | ||
| 3977 | (function-name keyword type builtin constant) ; level 2 | ||
| 3978 | (variable-name string-interpolation key)) ; level 3 | ||
| 3979 | @end group | ||
| 3980 | @end example | ||
| 3981 | |||
| 3982 | Major modes should set this variable before calling | ||
| 3983 | @code{treesit-font-lock-enable}. | ||
| 3984 | |||
| 3985 | @findex treesit-font-lock-recompute-features | ||
| 3986 | In addition, for further changes to this variable to take effect, run | ||
| 3987 | @code{treesit-font-lock-recompute-features}. | ||
| 3988 | @end defvar | ||
| 3989 | |||
| 3960 | @defvar treesit-font-lock-settings | 3990 | @defvar treesit-font-lock-settings |
| 3961 | A list of @var{setting}s for tree-sitter font lock. The exact format | 3991 | A list of @var{setting}s for tree-sitter font lock. The exact format |
| 3962 | of this variable is considered internal. One should always use | 3992 | of this variable is considered internal. One should always use |
| @@ -3965,12 +3995,21 @@ of this variable is considered internal. One should always use | |||
| 3965 | Each @var{setting} is of form | 3995 | Each @var{setting} is of form |
| 3966 | 3996 | ||
| 3967 | @example | 3997 | @example |
| 3968 | (@var{language} @var{query}) | 3998 | (@var{query} @var{enable} @var{feature} @var{override}) |
| 3969 | @end example | 3999 | @end example |
| 3970 | 4000 | ||
| 3971 | Each @var{setting} controls one parser (often of different language). | 4001 | @var{query} must be a compiled query (@pxref{Pattern Matching}). |
| 3972 | And @var{language} is the language symbol (@pxref{Language | 4002 | |
| 3973 | Definitions}); @var{query} is the query (@pxref{Pattern Matching}). | 4003 | For @var{setting} to be activated for font-lock, @var{enable} must be |
| 4004 | t. To disable this @var{setting}, set @var{enable} to nil. | ||
| 4005 | |||
| 4006 | @var{feature} is the ``feature name'' of the query, users can control | ||
| 4007 | which features are enabled with @code{font-lock-maximum-decoration} | ||
| 4008 | and @code{treesit-font-lock-feature-list}. | ||
| 4009 | |||
| 4010 | @var{override} is the override flag for this query. Its value can be | ||
| 4011 | t, nil, append, prepend, keep. See more in | ||
| 4012 | @code{treesit-font-lock-rules}. | ||
| 3974 | @end defvar | 4013 | @end defvar |
| 3975 | 4014 | ||
| 3976 | Multi-language major modes should provide range functions in | 4015 | Multi-language major modes should provide range functions in |
diff --git a/doc/lispref/parsing.texi b/doc/lispref/parsing.texi index 8b684d11fcd..d2a333027b9 100644 --- a/doc/lispref/parsing.texi +++ b/doc/lispref/parsing.texi | |||
| @@ -87,9 +87,9 @@ library. | |||
| 87 | This function returns non-nil if @var{language} exists and is | 87 | This function returns non-nil if @var{language} exists and is |
| 88 | loadable. | 88 | loadable. |
| 89 | 89 | ||
| 90 | If @var{detail} is non-nil, return @code{(t . nil) when @var{language} | 90 | If @var{detail} is non-nil, return @code{(t . nil)} when |
| 91 | is available, @code{(nil . DATA)} when unavailable. @var{data} is the | 91 | @var{language} is available, @code{(nil . DATA)} when unavailable. |
| 92 | signal data of @code{treesit-load-language-error}. | 92 | @var{data} is the signal data of @code{treesit-load-language-error}. |
| 93 | @end defun | 93 | @end defun |
| 94 | 94 | ||
| 95 | @vindex treesit-load-name-override-list | 95 | @vindex treesit-load-name-override-list |