[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feature/tree-sitter 040991a469 1/3: Change signature of tree-sitter font
From: |
Yuan Fu |
Subject: |
feature/tree-sitter 040991a469 1/3: Change signature of tree-sitter font-lock functions |
Date: |
Wed, 2 Nov 2022 20:23:01 -0400 (EDT) |
branch: feature/tree-sitter
commit 040991a4697b50ebcb54e498e7de54b8d0885101
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
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.
---
doc/lispref/modes.texi | 15 +++++++--------
lisp/progmodes/js.el | 6 +++---
lisp/progmodes/python.el | 4 ++--
lisp/treesit.el | 14 +++++++-------
4 files changed, 19 insertions(+), 20 deletions(-)
diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi
index 40d966ef17..3c91893bbf 100644
--- a/doc/lispref/modes.texi
+++ b/doc/lispref/modes.texi
@@ -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
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index e50bc9017c..76d4ec748a 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'."
@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
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index f741688363..46559db2cd 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -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)))
diff --git a/lisp/treesit.el b/lisp/treesit.el
index b4f79dc157..248c23bf88 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -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.