aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorYuan Fu2022-11-02 11:26:38 -0700
committerYuan Fu2022-11-02 11:26:38 -0700
commit040991a4697b50ebcb54e498e7de54b8d0885101 (patch)
treee0d1cc29f342653c4b140cb63b0d48d99d83cd81 /lisp
parent50e33639fe190f0a1c47b8e4c0fcc4735cb60909 (diff)
downloademacs-040991a4697b50ebcb54e498e7de54b8d0885101.tar.gz
emacs-040991a4697b50ebcb54e498e7de54b8d0885101.zip
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.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/progmodes/js.el6
-rw-r--r--lisp/progmodes/python.el4
-rw-r--r--lisp/treesit.el14
3 files changed, 12 insertions, 12 deletions
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index e50bc9017ca..76d4ec748a0 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -3573,19 +3573,19 @@ This function is intended for use in `after-change-functions'."
3573 @font-lock-constant-face))) 3573 @font-lock-constant-face)))
3574 "Tree-sitter font-lock settings.") 3574 "Tree-sitter font-lock settings.")
3575 3575
3576(defun js--fontify-template-string (beg end node override &rest _) 3576(defun js--fontify-template-string (node override &rest _)
3577 "Fontify template string but not substitution inside it. 3577 "Fontify template string but not substitution inside it.
3578BEG, END, NODE refers to the template_string node. 3578BEG, END, NODE refers to the template_string node.
3579 3579
3580OVERRIDE is the override flag described in 3580OVERRIDE is the override flag described in
3581`treesit-font-lock-rules'." 3581`treesit-font-lock-rules'."
3582 (ignore end)
3583 ;; You would have thought that the children of the string node spans 3582 ;; You would have thought that the children of the string node spans
3584 ;; the whole string. No, the children of the template_string only 3583 ;; the whole string. No, the children of the template_string only
3585 ;; includes the starting "`", any template_substitution, and the 3584 ;; includes the starting "`", any template_substitution, and the
3586 ;; closing "`". That's why we have to track BEG instead of just 3585 ;; closing "`". That's why we have to track BEG instead of just
3587 ;; fontifying each child. 3586 ;; fontifying each child.
3588 (let ((child (treesit-node-child node 0))) 3587 (let ((child (treesit-node-child node 0))
3588 (beg (treesit-node-start node)))
3589 (while child 3589 (while child
3590 (if (equal (treesit-node-type child) "template_substitution") 3590 (if (equal (treesit-node-type child) "template_substitution")
3591 (treesit-fontify-with-override 3591 (treesit-fontify-with-override
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index f741688363e..46559db2cd1 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -1015,7 +1015,7 @@ It makes underscores and dots word constituent chars.")
1015 "VMSError" "WindowsError" 1015 "VMSError" "WindowsError"
1016 )) 1016 ))
1017 1017
1018(defun python--treesit-fontify-string (_beg _end node override &rest _) 1018(defun python--treesit-fontify-string (node override &rest _)
1019 "Fontify string. 1019 "Fontify string.
1020NODE is the leading quote in the string. Do not fontify the initial 1020NODE is the leading quote in the string. Do not fontify the initial
1021f for f-strings. OVERRIDE is the override flag described in 1021f 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
1035 (cl-incf string-beg)) 1035 (cl-incf string-beg))
1036 (treesit-fontify-with-override string-beg string-end face override))) 1036 (treesit-fontify-with-override string-beg string-end face override)))
1037 1037
1038(defun python--treesit-fontify-string-end (_beg _end node &rest _) 1038(defun python--treesit-fontify-string-end (node &rest _)
1039 "Mark the whole string as to-be-fontified. 1039 "Mark the whole string as to-be-fontified.
1040NODE is the ending quote of a string." 1040NODE is the ending quote of a string."
1041 (let ((string (treesit-node-parent node))) 1041 (let ((string (treesit-node-parent node)))
diff --git a/lisp/treesit.el b/lisp/treesit.el
index b4f79dc1572..248c23bf888 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -503,12 +503,12 @@ Other keywords include:
503Capture names in QUERY should be face names like 503Capture names in QUERY should be face names like
504`font-lock-keyword-face'. The captured node will be fontified 504`font-lock-keyword-face'. The captured node will be fontified
505with that face. Capture names can also be function names, in 505with that face. Capture names can also be function names, in
506which case the function is called with (START END NODE OVERRIDE), 506which case the function should have a signature (NODE OVERRIDE
507where START and END are the start and end position of the node in 507&rest _), where NODE is the tree-sitter node object, and OVERRIDE
508buffer, NODE is the tree-sitter node object, and OVERRIDE is the 508is the override option of that rule. This function should accept
509override option of that rule. This function should accept more 509more arguments as optional arguments for future extensibility.
510arguments as optional arguments for future extensibility. If a 510
511capture name is both a face and a function, the face takes 511If a capture name is both a face and a function, the face takes
512priority. If a capture name is not a face name nor a function 512priority. If a capture name is not a face name nor a function
513name, it is ignored. 513name, it is ignored.
514 514
@@ -672,7 +672,7 @@ If LOUDLY is non-nil, display some debugging information."
672 ((facep face) 672 ((facep face)
673 (treesit-fontify-with-override start end face override)) 673 (treesit-fontify-with-override start end face override))
674 ((functionp face) 674 ((functionp face)
675 (funcall face start end node override))) 675 (funcall face node override)))
676 ;; Don't raise an error if FACE is neither a face nor 676 ;; Don't raise an error if FACE is neither a face nor
677 ;; a function. This is to allow intermediate capture 677 ;; a function. This is to allow intermediate capture
678 ;; names used for #match and #eq. 678 ;; names used for #match and #eq.