Improve docstring for treesit-language-at

* lisp/treesit.el (treesit-language-at-point-function)
(treesit-language-at): Several people has confused over this, make it
extra clear than treesit-language-at requires
treesit-language-at-point-function to work.
This commit is contained in:
Yuan Fu 2023-09-13 18:14:03 -07:00
parent c916f471ca
commit 8facdb62d3
No known key found for this signature in database
GPG key ID: 56E19BC57664A442

View file

@ -136,14 +136,23 @@ Return the root node of the syntax tree."
This is used by `treesit-language-at', which is used by various
functions to determine which parser to use at point.
The function is called with one argument, the position of point.")
The function is called with one argument, the position of point.
In general, this function should call `treesit-node-at' with an
explicit language (usually the host language), and determine the
language at point using the type of the returned node.")
(defun treesit-language-at (position)
"Return the language at POSITION.
This function assumes that parser ranges are up-to-date. It
returns the return value of `treesit-language-at-point-function'
if it's non-nil, otherwise it returns the language of the first
parser in `treesit-parser-list', or nil if there is no parser."
parser in `treesit-parser-list', or nil if there is no parser.
In a multi-language buffer, make sure
`treesit-language-at-point-function' is implemented! Otherwise
`treesit-language-at' wouldn't return the correct result."
(if treesit-language-at-point-function
(funcall treesit-language-at-point-function position)
(when-let ((parser (car (treesit-parser-list))))