aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuan Fu2025-04-17 16:56:07 -0700
committerYuan Fu2025-04-17 16:56:07 -0700
commitf728aa72c047ff8485bce08a6effb1c7790bce9f (patch)
treebf2fe5cbaa018c9642bbb0881b84c12eed302400
parent4f80a116f53c2d8dc58301630f6dc7de6e0e346e (diff)
downloademacs-f728aa72c047ff8485bce08a6effb1c7790bce9f.tar.gz
emacs-f728aa72c047ff8485bce08a6effb1c7790bce9f.zip
Add guard in treesit-language-at-point-default (bug#77870)
* lisp/treesit.el (treesit-language-at-point-default): Return nil if there's no parser in the buffer. (treesit-parsers-at): Add docstring for parser order.
-rw-r--r--lisp/treesit.el16
1 files changed, 12 insertions, 4 deletions
diff --git a/lisp/treesit.el b/lisp/treesit.el
index 59718fd3d3d..c67d7bb996e 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -190,9 +190,14 @@ the return value of that function instead."
190 190
191(defun treesit-language-at-point-default (position) 191(defun treesit-language-at-point-default (position)
192 "Default function for `treesit-language-at-point-function'. 192 "Default function for `treesit-language-at-point-function'.
193Return the deepest parser by embed level." 193
194 (treesit-parser-language 194Returns the language at POSITION, or nil if there's no parser in the
195 (car (treesit-parsers-at position)))) 195buffer. When there are multiple parsers that cover POSITION, use the
196parser with the deepest embed level as it's the \"most relevant\" parser
197at POSITION."
198 (let ((parser (car (treesit-parsers-at position))))
199 (when parser
200 (treesit-parser-language parser))))
196 201
197;;; Node API supplement 202;;; Node API supplement
198 203
@@ -855,7 +860,10 @@ by an overlay with non-nil `treesit-parser-local-p' property.
855If ONLY contains the symbol `global', include non-local parsers 860If ONLY contains the symbol `global', include non-local parsers
856excluding the primary parser. 861excluding the primary parser.
857 862
858If ONLY contains the symbol `primary', include the primary parser." 863If ONLY contains the symbol `primary', include the primary parser.
864
865The returned parsers are sorted in descending order of embed level.
866That is, the deepest embedded parser comes first."
859 (let ((res nil)) 867 (let ((res nil))
860 ;; Refer to (ref:local-parser-overlay) for more explanation of local 868 ;; Refer to (ref:local-parser-overlay) for more explanation of local
861 ;; parser overlays. 869 ;; parser overlays.