aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/lispref/positions.texi32
-rw-r--r--lisp/treesit.el10
2 files changed, 22 insertions, 20 deletions
diff --git a/doc/lispref/positions.texi b/doc/lispref/positions.texi
index c065cc11e25..7acf2d052a8 100644
--- a/doc/lispref/positions.texi
+++ b/doc/lispref/positions.texi
@@ -836,35 +836,37 @@ of using its normal method.
836 836
837@findex treesit-beginning-of-defun 837@findex treesit-beginning-of-defun
838@findex treesit-end-of-defun 838@findex treesit-end-of-defun
839If Emacs is compiled with tree-sitter, it can use the tree-sitter parser 839If Emacs is compiled with tree-sitter, it can use the tree-sitter
840information to move across syntax constructs. A major mode can set 840parser information to move across syntax constructs. Since what
841@code{treesit-defun-type-regexp} and get navigation functionality for 841exactly is considered a defun varies between languages, a major mode
842free, by using @code{treesit-beginning-of-defun} and 842should set @code{treesit-defun-type-regexp} to determine that. Then
843@code{treesit-end-of-defun}. 843the mode can get navigation-by-defun functionality for free, by using
844@code{treesit-beginning-of-defun} and @code{treesit-end-of-defun}.
844 845
845@defvar treesit-defun-type-regexp 846@defvar treesit-defun-type-regexp
846The value of this variable is a regexp matching the node type of defun 847The value of this variable is a regexp matching the node type of defun
847nodes. (For ``node'', ``node type'', @pxref{Parsing Program Source}.) 848nodes. (For ``node'' and ``node type'', @pxref{Parsing Program Source}.)
848 849
849For example, @code{python-mode} sets this variable to a regexp that 850For example, @code{python-mode} sets this variable to a regexp that
850matches either @code{function_definition} or @code{class_definition}. 851matches either @code{function_definition} or @code{class_definition}.
851@end defvar 852@end defvar
852 853
853@defvar treesit-defun-prefer-top-level 854@defvar treesit-defun-prefer-top-level
854If this variable is non-@code{nil}, Emacs skips nested defun and 855If this variable is non-@code{nil}, Emacs skips nested defuns, when it
855prefers the top-level defun. 856looks for beginning and end of a defun, and prefers to go to the
857top-level defun instead.
856 858
857In some languages, a defun could be nested in another one. Normally 859In some languages, a defun could be nested in another one. By default,
858Emacs stops at the first defun it encounters. If this variable's 860Emacs stops at the first defun it encounters. But if this variable's
859value is @code{t}, whenever Emacs finds a defun node, it tries to go 861value is @code{t}, whenever Emacs finds a defun node, it tries to go
860up the parse tree and find the top-level defun. 862up the parse tree until it finds the top-level defun.
861 863
862This variable can also be a list of cons cells of the form 864This variable can also be a list of cons cells of the form
863@w{@code{(@var{from} . @var{to}))}}, where @var{from} and @var{to} are 865@w{@code{(@var{from} . @var{to}))}}, where @var{from} and @var{to} are
864regexp matching tree-sitter node types. When Emacs finds a defun node 866regexps matching tree-sitter node types. When Emacs finds a defun
865whose type matches any of the @var{from} regexp in the list, Emacs 867node whose type matches any of the @var{from} regexps in the list, it
866then tries to go up the parse tree to find the top-level node matching 868then tries to go up the parse tree until it finds a higher-level node
867the corresponding @var{to} regexp. 869matching the corresponding @var{to} regexp.
868@end defvar 870@end defvar
869 871
870@node Skipping Characters 872@node Skipping Characters
diff --git a/lisp/treesit.el b/lisp/treesit.el
index dd7895683ff..0de0e283c3b 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -1561,11 +1561,11 @@ Normally Emacs stops at the first defun it encounters. If this
1561variable's value is t, Emacs tries to find the top-level defun, 1561variable's value is t, Emacs tries to find the top-level defun,
1562and ignores nested ones. 1562and ignores nested ones.
1563 1563
1564This variable can also be a list of cons cells of the form (FROM 1564This variable can also be a list of cons cells of the
1565. TO), where FROM and TO are tree-sitter node type regexps. When 1565form (FROM . TO), where FROM and TO are tree-sitter node type
1566Emacs finds a defun node whose type matches any of the FROM 1566regexps. When Emacs finds a defun node whose type matches any of
1567regexp in the list, Emacs then tries to find the top-level node 1567the FROM regexps in the list, it then tries to find a
1568matching the corresponding TO regexp.") 1568higher-level node matching the corresponding TO regexp.")
1569 1569
1570(defun treesit--defun-maybe-top-level (node) 1570(defun treesit--defun-maybe-top-level (node)
1571 "Maybe return the top-level equivalent of NODE. 1571 "Maybe return the top-level equivalent of NODE.