diff options
| -rw-r--r-- | doc/lispref/positions.texi | 32 | ||||
| -rw-r--r-- | lisp/treesit.el | 10 |
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 |
| 839 | If Emacs is compiled with tree-sitter, it can use the tree-sitter parser | 839 | If Emacs is compiled with tree-sitter, it can use the tree-sitter |
| 840 | information to move across syntax constructs. A major mode can set | 840 | parser information to move across syntax constructs. Since what |
| 841 | @code{treesit-defun-type-regexp} and get navigation functionality for | 841 | exactly is considered a defun varies between languages, a major mode |
| 842 | free, by using @code{treesit-beginning-of-defun} and | 842 | should set @code{treesit-defun-type-regexp} to determine that. Then |
| 843 | @code{treesit-end-of-defun}. | 843 | the 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 |
| 846 | The value of this variable is a regexp matching the node type of defun | 847 | The value of this variable is a regexp matching the node type of defun |
| 847 | nodes. (For ``node'', ``node type'', @pxref{Parsing Program Source}.) | 848 | nodes. (For ``node'' and ``node type'', @pxref{Parsing Program Source}.) |
| 848 | 849 | ||
| 849 | For example, @code{python-mode} sets this variable to a regexp that | 850 | For example, @code{python-mode} sets this variable to a regexp that |
| 850 | matches either @code{function_definition} or @code{class_definition}. | 851 | matches 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 |
| 854 | If this variable is non-@code{nil}, Emacs skips nested defun and | 855 | If this variable is non-@code{nil}, Emacs skips nested defuns, when it |
| 855 | prefers the top-level defun. | 856 | looks for beginning and end of a defun, and prefers to go to the |
| 857 | top-level defun instead. | ||
| 856 | 858 | ||
| 857 | In some languages, a defun could be nested in another one. Normally | 859 | In some languages, a defun could be nested in another one. By default, |
| 858 | Emacs stops at the first defun it encounters. If this variable's | 860 | Emacs stops at the first defun it encounters. But if this variable's |
| 859 | value is @code{t}, whenever Emacs finds a defun node, it tries to go | 861 | value is @code{t}, whenever Emacs finds a defun node, it tries to go |
| 860 | up the parse tree and find the top-level defun. | 862 | up the parse tree until it finds the top-level defun. |
| 861 | 863 | ||
| 862 | This variable can also be a list of cons cells of the form | 864 | This 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 |
| 864 | regexp matching tree-sitter node types. When Emacs finds a defun node | 866 | regexps matching tree-sitter node types. When Emacs finds a defun |
| 865 | whose type matches any of the @var{from} regexp in the list, Emacs | 867 | node whose type matches any of the @var{from} regexps in the list, it |
| 866 | then tries to go up the parse tree to find the top-level node matching | 868 | then tries to go up the parse tree until it finds a higher-level node |
| 867 | the corresponding @var{to} regexp. | 869 | matching 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 | |||
| 1561 | variable's value is t, Emacs tries to find the top-level defun, | 1561 | variable's value is t, Emacs tries to find the top-level defun, |
| 1562 | and ignores nested ones. | 1562 | and ignores nested ones. |
| 1563 | 1563 | ||
| 1564 | This variable can also be a list of cons cells of the form (FROM | 1564 | This variable can also be a list of cons cells of the |
| 1565 | . TO), where FROM and TO are tree-sitter node type regexps. When | 1565 | form (FROM . TO), where FROM and TO are tree-sitter node type |
| 1566 | Emacs finds a defun node whose type matches any of the FROM | 1566 | regexps. When Emacs finds a defun node whose type matches any of |
| 1567 | regexp in the list, Emacs then tries to find the top-level node | 1567 | the FROM regexps in the list, it then tries to find a |
| 1568 | matching the corresponding TO regexp.") | 1568 | higher-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. |