Starting with Emacs 29, we've got native TreeSitter support using treesit
. My question is: how do I know I can use treesit-*
functions in the current buffer? The feature check only checks if Emacs itself has been compiled with treesit-support. Here's what happens when you ask *scratch*
whether it has treesit enabled:
major-mode ; ⇒ lisp-interaction-mode
(treesit-available-p) ; ⇒ t
My current workaround is to check if the treesit language at point is defined:
(defun treesit-enabled-p ()
"Checks if the current buffer has a treesit parser."
(and (fboundp 'treesit-available-p)
(treesit-available-p)
(treesit-language-at (point))))
This yields the correct truth conditions, but it doesn't seem terribly idiomatic to query the language at point. Is there a better way?