; Fix recent changes in treesit documentation

* lisp/treesit.el (treesit-defun-name-function, treesit-node-at)
(treesit-node-on): Doc fixes.

* doc/lispref/parsing.texi (Tree-sitter major modes): Fix wording,
punctuation, and indexing.
(Retrieving Nodes): Fix wording and add cross-references.
This commit is contained in:
Eli Zaretskii 2022-12-25 09:29:47 +02:00
parent c36fe3df17
commit ecee3bd420
2 changed files with 24 additions and 19 deletions

View file

@ -580,8 +580,8 @@ If @var{parser-or-lang} is a parser object, this function uses that
parser; if @var{parser-or-lang} is a language, this function uses the parser; if @var{parser-or-lang} is a language, this function uses the
first parser for that language in the current buffer, or creates one first parser for that language in the current buffer, or creates one
if none exists; if @var{parser-or-lang} is @code{nil}, this function if none exists; if @var{parser-or-lang} is @code{nil}, this function
tries to guess the language at @var{pos} by tries to guess the language at @var{pos} by calling
@code{treesit-language-at}. @code{treesit-language-at} (@pxref{Multiple Languages}).
If this function cannot find a suitable node to return, it returns If this function cannot find a suitable node to return, it returns
@code{nil}. @code{nil}.
@ -616,7 +616,7 @@ If @var{parser-or-lang} is a parser object, this function uses that
parser; if @var{parser-or-lang} is a language, this function uses the parser; if @var{parser-or-lang} is a language, this function uses the
first parser for that language in the current buffer, or creates one first parser for that language in the current buffer, or creates one
if none exists; if @var{parser-or-lang} is @code{nil}, this function if none exists; if @var{parser-or-lang} is @code{nil}, this function
tries to guess the language at @var{beg} by tries to guess the language at @var{beg} by calling
@code{treesit-language-at}. @code{treesit-language-at}.
If @var{named} is non-@code{nil}, this function looks for a named node If @var{named} is non-@code{nil}, this function looks for a named node
@ -1717,16 +1717,22 @@ This function activates some tree-sitter features for a major mode.
Currently, it sets up the following features: Currently, it sets up the following features:
@itemize @itemize
@cindex treesit-font-lock-settings
@item @item
If @code{treesit-font-lock-settings} is non-@code{nil}, it sets up If @code{treesit-font-lock-settings} is non-@code{nil}, it sets up
fontification. fontification.
@cindex treesit-simple-indent-rules
@item @item
If @code{treesit-simple-indent-rules} is non-@code{nil}, it sets up If @code{treesit-simple-indent-rules} is non-@code{nil}, it sets up
indentation. indentation.
@cindex treesit-defun-type-regexp
@item @item
If @code{treesit-defun-type-regexp} is non-@code{nil}, it sets up If @code{treesit-defun-type-regexp} is non-@code{nil}, it sets up
navigation functions for @code{beginning-of-defun} and navigation functions for @code{beginning-of-defun} and
@code{end-of-defun}. @code{end-of-defun}.
@item @item
If @code{treesit-defun-name-function} is non-@code{nil}, it sets up If @code{treesit-defun-name-function} is non-@code{nil}, it sets up
add-log functions used by @code{add-log-current-defun}. add-log functions used by @code{add-log-current-defun}.
@ -1747,9 +1753,9 @@ provides some additional functions for working with defuns:
@defun treesit-defun-at-point @defun treesit-defun-at-point
This function returns the defun node at point, or @code{nil} if none This function returns the defun node at point, or @code{nil} if none
is found. It respects @code{treesit-defun-tactic}: it returns the is found. It respects @code{treesit-defun-tactic}: if its value is
top-level defun if the value is @code{top-level}, and returns the @code{top-level}, this function returns the top-level defun, and if
immediate enclosing defun if the value is @code{nested}. its value is @code{nested}, it returns the immediate enclosing defun.
This function requires @code{treesit-defun-type-regexp} to work. If This function requires @code{treesit-defun-type-regexp} to work. If
it is @code{nil}, this function simply returns @code{nil}. it is @code{nil}, this function simply returns @code{nil}.
@ -1760,19 +1766,20 @@ This function returns the defun name of @var{node}. It returns
@code{nil} if there is no defun name for @var{node}, or if @var{node} @code{nil} if there is no defun name for @var{node}, or if @var{node}
is not a defun node, or if @var{node} is @code{nil}. is not a defun node, or if @var{node} is @code{nil}.
The defun name is names like function name, class name, struct name, Depending on the language and major mode, the defun names are names
etc. like function name, class name, struct name, etc.
If @code{treesit-defun-name-function} is @code{nil}, this function If @code{treesit-defun-name-function} is @code{nil}, this function
always returns @code{nil}. always returns @code{nil}.
@end defun @end defun
@defvar treesit-defun-name-function @defvar treesit-defun-name-function
If non-@code{nil}, this variable should store a function that is If non-@code{nil}, this variable's value should be a function that is
called with a node and returns the defun name of it. The function called with a node as its argument, and returns the defun name of the
should have the same semantic as @code{treesit-defun-name}: if the node. The function should have the same semantic as
node is not a defun node, or the node is a defun node but doesn't have @code{treesit-defun-name}: if the node is not a defun node, or the
a name, or the node is @code{nil}, return @code{nil}. node is a defun node but doesn't have a name, or the node is
@code{nil}, it should return @code{nil}.
@end defvar @end defvar
@node Tree-sitter C API @node Tree-sitter C API

View file

@ -174,8 +174,7 @@ only look for named nodes.
If PARSER-OR-LANG is a parser, use that parser; if PARSER-OR-LANG If PARSER-OR-LANG is a parser, use that parser; if PARSER-OR-LANG
is a language, find the first parser for that language in the is a language, find the first parser for that language in the
current buffer, or create one if none exists; If PARSER-OR-LANG current buffer, or create one if none exists; If PARSER-OR-LANG
is nil, try to guess the language at POS by is nil, try to guess the language at POS using `treesit-language-at'."
`treesit-language-at'."
(let* ((root (if (treesit-parser-p parser-or-lang) (let* ((root (if (treesit-parser-p parser-or-lang)
(treesit-parser-root-node parser-or-lang) (treesit-parser-root-node parser-or-lang)
(treesit-buffer-root-node (treesit-buffer-root-node
@ -224,8 +223,7 @@ named node.
If PARSER-OR-LANG is a parser, use that parser; if PARSER-OR-LANG If PARSER-OR-LANG is a parser, use that parser; if PARSER-OR-LANG
is a language, find the first parser for that language in the is a language, find the first parser for that language in the
current buffer, or create one if none exists; If PARSER-OR-LANG current buffer, or create one if none exists; If PARSER-OR-LANG
is nil, try to guess the language at BEG by is nil, try to guess the language at BEG using `treesit-language-at'."
`treesit-language-at'."
(let ((root (if (treesit-parser-p parser-or-lang) (let ((root (if (treesit-parser-p parser-or-lang)
(treesit-parser-root-node parser-or-lang) (treesit-parser-root-node parser-or-lang)
(treesit-buffer-root-node (treesit-buffer-root-node
@ -1613,8 +1611,8 @@ newline after a defun, or the beginning of a defun.
If the value is nil, no skipping is performed.") If the value is nil, no skipping is performed.")
(defvar-local treesit-defun-name-function nil (defvar-local treesit-defun-name-function nil
"A function called with a node and returns the name of it. "A function that is called with a node and returns its defun name or nil.
If the node is a defun node, return the defun name. E.g., the If the node is a defun node, return the defun name, e.g., the
function name of a function. If the node is not a defun node, or function name of a function. If the node is not a defun node, or
the defun node doesn't have a name, or the node is nil, return the defun node doesn't have a name, or the node is nil, return
nil.") nil.")