diff options
author | Yuan Fu <casouri@gmail.com> | 2022-12-27 20:37:29 -0800 |
---|---|---|
committer | Yuan Fu <casouri@gmail.com> | 2022-12-27 20:37:29 -0800 |
commit | b39dc7ab27a696a8607ab859aeff3c71509231f5 (patch) | |
tree | d5cb2e1b25887ec4f58b650049b5fd13dcc0a474 /doc/lispref/modes.texi | |
parent | ba1ddea9dabf51c9c6e463d667bcce0b48294453 (diff) | |
download | emacs-b39dc7ab27a696a8607ab859aeff3c71509231f5.tar.gz |
Add tree-sitter helper functions for Imenu
We didn't add an integration for Imenu because we aren't sure what
should it look like. Now we have a pretty good idea. All the major
modes copy-paste the two Imenu functions and tweaks them in a standard
way. With the addition of treesit-defun-type-regexp and
treesit-defun-name-function, now is a good time to standardize Imenu
integration.
In the next commit we update all the major modes to use this
integration.
* doc/lispref/modes.texi (Imenu): Add manual.
* doc/lispref/parsing.texi (Tree-sitter major modes): Update manual.
* lisp/treesit.el (treesit-simple-imenu-settings): New varaible.
(treesit--simple-imenu-1)
(treesit-simple-imenu): New functions.
(treesit-major-mode-setup): Setup Imenu.
Diffstat (limited to 'doc/lispref/modes.texi')
-rw-r--r-- | doc/lispref/modes.texi | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi index 449529a4307..de17969566d 100644 --- a/doc/lispref/modes.texi +++ b/doc/lispref/modes.texi @@ -2841,6 +2841,35 @@ function uses @code{imenu-generic-expression} instead. Setting this variable makes it buffer-local in the current buffer. @end defvar +If built with tree-sitter, Emacs can automatically generate an Imenu +index if the major mode sets relevant variables. + +@defvar treesit-simple-imenu-settings +This variable instructs Emacs how to generate Imenu indexes. It +should be a list of @w{(@var{category} @var{regexp} @var{pred} +@var{name-fn})}. + +@var{category} should be the name of a category, like "Function", +"Class", etc. @var{regexp} should be a regexp matching the type of +nodes that belong to @var{category}. @var{pred} should be either +@code{nil} or a function that takes a node as the argument. It should +return non-@code{nil} if the node is a valid node for @var{category}, +or @code{nil} if not. + +@var{category} could also be @code{nil}. In which case the entries +matched by @var{regexp} and @var{pred} are not grouped under +@var{category}. + +@var{name-fn} should be either @var{nil} or a function that takes a +defun node and returns the name of that defun, e.g., the function name +for a function definition. If @var{name-fn} is @var{nil}, +@code{treesit-defun-name} (@pxref{Tree-sitter major modes}) is used +instead. + +@code{treesit-major-mode-setup} (@pxref{Tree-sitter major modes}) +automatically sets up Imenu if this variable is non-@code{nil}. +@end defvar + @node Font Lock Mode @section Font Lock Mode @cindex Font Lock mode |