From: Yuan Fu Date: Sat, 5 Nov 2022 23:55:17 +0000 (-0700) Subject: Make treesit-language-at work in more situations X-Git-Tag: emacs-29.0.90~1708 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=b471f7f6141b3db8fb00f62f12900846f59beb9a;p=emacs.git 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. --- diff --git a/lisp/treesit.el b/lisp/treesit.el index 515caf568c2..02bf026bc0e 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