]> git.eshelyaron.com Git - emacs.git/commitdiff
Make treesit-language-at work in more situations
authorYuan Fu <casouri@gmail.com>
Sat, 5 Nov 2022 23:55:17 +0000 (16:55 -0700)
committerYuan Fu <casouri@gmail.com>
Sun, 6 Nov 2022 00:41:10 +0000 (17:41 -0700)
; * lisp/treesit.el (treesit-language-at): Return sometime sensible
even if treesit-language-at-point-function is nil.

lisp/treesit.el

index 515caf568c2898b8dfd6438053c7d7586d9b7ae6..02bf026bc0ec14e4324792d58ebafd99534d6ba4 100644 (file)
@@ -147,9 +147,14 @@ The function is called with one argument, the position of point.")
 
 (defun treesit-language-at (position)
   "Return the language at POSITION.
-Assumes parser ranges are up-to-date."
-  (when treesit-language-at-point-function
-    (funcall treesit-language-at-point-function position)))
+Assumes parser ranges are up-to-date.  Returns the return value
+of `treesit-language-at-point-function' if it's non-nil,
+otherwise return the language of the first parser in
+`treesit-parser-list', or nil if there is no parser."
+  (if treesit-language-at-point-function
+      (funcall treesit-language-at-point-function position)
+    (when-let ((parser (car (treesit-parser-list))))
+      (treesit-parser-language parser))))
 
 ;;; Node API supplement