aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorYuan Fu2022-12-24 15:31:03 -0800
committerYuan Fu2022-12-24 18:43:03 -0800
commit35c2ca2ca64070f6ebc75011e5e6e2d688124bec (patch)
treea44c4da06fa49b33ce2369a987318b347f6228c7 /doc
parent7f7def2ae62c80fa2fd0c73087b59060b303c230 (diff)
downloademacs-35c2ca2ca64070f6ebc75011e5e6e2d688124bec.tar.gz
emacs-35c2ca2ca64070f6ebc75011e5e6e2d688124bec.zip
Make treesit-node-at/on guess language at point
If PARSER-OR-LANG is nil, it makes more sense to guess the language at point by treesit-language-at than to simply use the first parser in the parser list. * doc/lispref/parsing.texi (Retrieving Nodes): Update manual. * lisp/treesit.el (treesit-node-at) (treesit-node-on): Guess language at point. Update docstring. (treesit-buffer-root-node): Update docstring.
Diffstat (limited to 'doc')
-rw-r--r--doc/lispref/parsing.texi32
1 files changed, 17 insertions, 15 deletions
diff --git a/doc/lispref/parsing.texi b/doc/lispref/parsing.texi
index adb4c5e6e0c..e213363298d 100644
--- a/doc/lispref/parsing.texi
+++ b/doc/lispref/parsing.texi
@@ -576,12 +576,12 @@ leaf node after @var{pos}.
576Finally, if there is no leaf node after @var{pos}, return the first 576Finally, if there is no leaf node after @var{pos}, return the first
577leaf node before @var{pos}. 577leaf node before @var{pos}.
578 578
579When @var{parser-or-lang} is @code{nil} or omitted, this function uses 579If @var{parser-or-lang} is a parser object, this function uses that
580the first parser in @code{(treesit-parser-list)} of the current 580parser; if @var{parser-or-lang} is a language, this function uses the
581buffer. If @var{parser-or-lang} is a parser object, it uses that 581first parser for that language in the current buffer, or creates one
582parser; if @var{parser-or-lang} is a language, it finds the first 582if none exists; if @var{parser-or-lang} is @code{nil}, this function
583parser using that language in @code{(treesit-parser-list)}, and uses 583tries to guess the language at @var{pos} by
584that. 584@code{treesit-language-at}.
585 585
586If this function cannot find a suitable node to return, it returns 586If this function cannot find a suitable node to return, it returns
587@code{nil}. 587@code{nil}.
@@ -610,13 +610,14 @@ is at or after @var{end}.
610inside any top-level construct (function definition, etc.) most 610inside any top-level construct (function definition, etc.) most
611probably will give you the root node, because the root node is the 611probably will give you the root node, because the root node is the
612smallest node that covers that empty line. Most of the time, you want 612smallest node that covers that empty line. Most of the time, you want
613to use @code{treesit-node-at}, described above, instead. 613to use @code{treesit-node-at} instead.
614 614
615When @var{parser-or-lang} is @code{nil}, this function uses the first 615If @var{parser-or-lang} is a parser object, this function uses that
616parser in @code{(treesit-parser-list)} of the current buffer. If 616parser; if @var{parser-or-lang} is a language, this function uses the
617@var{parser-or-lang} is a parser object, it uses that parser; if 617first parser for that language in the current buffer, or creates one
618@var{parser-or-lang} is a language, it finds the first parser using 618if none exists; if @var{parser-or-lang} is @code{nil}, this function
619that language in @code{(treesit-parser-list)}, and uses that. 619tries to guess the language at @var{beg} by
620@code{treesit-language-at}.
620 621
621If @var{named} is non-@code{nil}, this function looks for a named node 622If @var{named} is non-@code{nil}, this function looks for a named node
622only (@pxref{tree-sitter named node, named node}). 623only (@pxref{tree-sitter named node, named node}).
@@ -628,9 +629,10 @@ This function returns the root node of the syntax tree generated by
628@end defun 629@end defun
629 630
630@defun treesit-buffer-root-node &optional language 631@defun treesit-buffer-root-node &optional language
631This function finds the first parser that uses @var{language} in 632This function finds the first parser for @var{language} in the current
632@code{(treesit-parser-list)} of the current buffer, and returns the 633buffer, or creates one if none exists, and returns the root node
633root node generated by that parser. If it cannot find an appropriate 634generated by that parser. If @var{language} is omitted, it uses the
635first parser in the parser list. If it cannot find an appropriate
634parser, it returns @code{nil}. 636parser, it returns @code{nil}.
635@end defun 637@end defun
636 638