emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

feature/tree-sitter b471f7f614 2/3: Make treesit-language-at work in mor


From: Yuan Fu
Subject: feature/tree-sitter b471f7f614 2/3: Make treesit-language-at work in more situations
Date: Sat, 5 Nov 2022 20:59:35 -0400 (EDT)

branch: feature/tree-sitter
commit b471f7f6141b3db8fb00f62f12900846f59beb9a
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>

    Make treesit-language-at work in more situations
    
    ; * lisp/treesit.el (treesit-language-at): Return sometime sensible
    even if treesit-language-at-point-function is nil.
---
 lisp/treesit.el | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/lisp/treesit.el b/lisp/treesit.el
index 515caf568c..02bf026bc0 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -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
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]