1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-28 07:50:48 -08:00

Change signature of tree-sitter font-lock functions

Change from

(START END NODE OVERRIDE &rest _)

to

(NODE OVERRIDE &rest _)

START and END aren't used frequently enough to justify.  If a
fontification function needs them, it can get them from NODE.

* doc/lispref/modes.texi (Parser-based Font Lock): Update manual.

* lisp/progmodes/js.el (js--fontify-template-string)
* lisp/progmodes/python.el (python--treesit-fontify-string)
(python--treesit-fontify-string-end): Change signature.

* lisp/treesit.el (treesit-font-lock-rules): Update docstring.
(treesit-font-lock-fontify-region): Remove START and END arguments.
This commit is contained in:
Yuan Fu 2022-11-02 11:26:38 -07:00
parent 50e33639fe
commit 040991a469
No known key found for this signature in database
GPG key ID: 56E19BC57664A442
4 changed files with 19 additions and 20 deletions

View file

@ -3979,14 +3979,13 @@ with that face.
@findex treesit-fontify-with-override
Capture names can also be function names, in which case the function
is called with 4 arguments: @var{start}, @var{end}, @var{node}, and
@var{override}, where @var{start} and @var{end} are the start and end
position of the node in buffer, @var{node} is the node itself, and
@var{override} is the override property of the rule which captured
this node. (If this function wants to respect the @var{override}
argument, it can use @code{treesit-fontify-with-override}.) Beyond
the 4 arguments presented, this function should accept more arguments
as optional arguments for future extensibility.
is called with 2 arguments: @var{node} and @var{override}, where
@var{node} is the node itself, and @var{override} is the override
property of the rule which captured this node. (If this function
wants to respect the @var{override} argument, it can use
@code{treesit-fontify-with-override}.) Beyond the 2 arguments
presented, this function should accept more arguments as optional
arguments for future extensibility.
If a capture name is both a face and a function, the face takes
priority. If a capture name is neither a face nor a function, it is

View file

@ -3573,19 +3573,19 @@ This function is intended for use in `after-change-functions'."
@font-lock-constant-face)))
"Tree-sitter font-lock settings.")
(defun js--fontify-template-string (beg end node override &rest _)
(defun js--fontify-template-string (node override &rest _)
"Fontify template string but not substitution inside it.
BEG, END, NODE refers to the template_string node.
OVERRIDE is the override flag described in
`treesit-font-lock-rules'."
(ignore end)
;; You would have thought that the children of the string node spans
;; the whole string. No, the children of the template_string only
;; includes the starting "`", any template_substitution, and the
;; closing "`". That's why we have to track BEG instead of just
;; fontifying each child.
(let ((child (treesit-node-child node 0)))
(let ((child (treesit-node-child node 0))
(beg (treesit-node-start node)))
(while child
(if (equal (treesit-node-type child) "template_substitution")
(treesit-fontify-with-override

View file

@ -1015,7 +1015,7 @@ It makes underscores and dots word constituent chars.")
"VMSError" "WindowsError"
))
(defun python--treesit-fontify-string (_beg _end node override &rest _)
(defun python--treesit-fontify-string (node override &rest _)
"Fontify string.
NODE is the leading quote in the string. Do not fontify the initial
f for f-strings. OVERRIDE is the override flag described in
@ -1035,7 +1035,7 @@ f for f-strings. OVERRIDE is the override flag described in
(cl-incf string-beg))
(treesit-fontify-with-override string-beg string-end face override)))
(defun python--treesit-fontify-string-end (_beg _end node &rest _)
(defun python--treesit-fontify-string-end (node &rest _)
"Mark the whole string as to-be-fontified.
NODE is the ending quote of a string."
(let ((string (treesit-node-parent node)))

View file

@ -503,12 +503,12 @@ Other keywords include:
Capture names in QUERY should be face names like
`font-lock-keyword-face'. The captured node will be fontified
with that face. Capture names can also be function names, in
which case the function is called with (START END NODE OVERRIDE),
where START and END are the start and end position of the node in
buffer, NODE is the tree-sitter node object, and OVERRIDE is the
override option of that rule. This function should accept more
arguments as optional arguments for future extensibility. If a
capture name is both a face and a function, the face takes
which case the function should have a signature (NODE OVERRIDE
&rest _), where NODE is the tree-sitter node object, and OVERRIDE
is the override option of that rule. This function should accept
more arguments as optional arguments for future extensibility.
If a capture name is both a face and a function, the face takes
priority. If a capture name is not a face name nor a function
name, it is ignored.
@ -672,7 +672,7 @@ If LOUDLY is non-nil, display some debugging information."
((facep face)
(treesit-fontify-with-override start end face override))
((functionp face)
(funcall face start end node override)))
(funcall face node override)))
;; Don't raise an error if FACE is neither a face nor
;; a function. This is to allow intermediate capture
;; names used for #match and #eq.