diff options
| author | Yuan Fu | 2022-11-02 11:26:38 -0700 |
|---|---|---|
| committer | Yuan Fu | 2022-11-02 11:26:38 -0700 |
| commit | 040991a4697b50ebcb54e498e7de54b8d0885101 (patch) | |
| tree | e0d1cc29f342653c4b140cb63b0d48d99d83cd81 | |
| parent | 50e33639fe190f0a1c47b8e4c0fcc4735cb60909 (diff) | |
| download | emacs-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.
| -rw-r--r-- | doc/lispref/modes.texi | 15 | ||||
| -rw-r--r-- | lisp/progmodes/js.el | 6 | ||||
| -rw-r--r-- | lisp/progmodes/python.el | 4 | ||||
| -rw-r--r-- | lisp/treesit.el | 14 |
4 files changed, 19 insertions, 20 deletions
diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi index 40d966ef17a..3c91893bbfd 100644 --- a/doc/lispref/modes.texi +++ b/doc/lispref/modes.texi | |||
| @@ -3979,14 +3979,13 @@ with that face. | |||
| 3979 | 3979 | ||
| 3980 | @findex treesit-fontify-with-override | 3980 | @findex treesit-fontify-with-override |
| 3981 | Capture names can also be function names, in which case the function | 3981 | Capture names can also be function names, in which case the function |
| 3982 | is called with 4 arguments: @var{start}, @var{end}, @var{node}, and | 3982 | is called with 2 arguments: @var{node} and @var{override}, where |
| 3983 | @var{override}, where @var{start} and @var{end} are the start and end | 3983 | @var{node} is the node itself, and @var{override} is the override |
| 3984 | position of the node in buffer, @var{node} is the node itself, and | 3984 | property of the rule which captured this node. (If this function |
| 3985 | @var{override} is the override property of the rule which captured | 3985 | wants to respect the @var{override} argument, it can use |
| 3986 | this node. (If this function wants to respect the @var{override} | 3986 | @code{treesit-fontify-with-override}.) Beyond the 2 arguments |
| 3987 | argument, it can use @code{treesit-fontify-with-override}.) Beyond | 3987 | presented, this function should accept more arguments as optional |
| 3988 | the 4 arguments presented, this function should accept more arguments | 3988 | arguments for future extensibility. |
| 3989 | as optional arguments for future extensibility. | ||
| 3990 | 3989 | ||
| 3991 | If a capture name is both a face and a function, the face takes | 3990 | If a capture name is both a face and a function, the face takes |
| 3992 | priority. If a capture name is neither a face nor a function, it is | 3991 | 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 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. |
| 3578 | BEG, END, NODE refers to the template_string node. | 3578 | BEG, END, NODE refers to the template_string node. |
| 3579 | 3579 | ||
| 3580 | OVERRIDE is the override flag described in | 3580 | OVERRIDE 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. |
| 1020 | NODE is the leading quote in the string. Do not fontify the initial | 1020 | NODE is the leading quote in the string. Do not fontify the initial |
| 1021 | f for f-strings. OVERRIDE is the override flag described in | 1021 | 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 | |||
| 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. |
| 1040 | NODE is the ending quote of a string." | 1040 | NODE 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: | |||
| 503 | Capture names in QUERY should be face names like | 503 | Capture 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 |
| 505 | with that face. Capture names can also be function names, in | 505 | with that face. Capture names can also be function names, in |
| 506 | which case the function is called with (START END NODE OVERRIDE), | 506 | which case the function should have a signature (NODE OVERRIDE |
| 507 | where 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 |
| 508 | buffer, NODE is the tree-sitter node object, and OVERRIDE is the | 508 | is the override option of that rule. This function should accept |
| 509 | override option of that rule. This function should accept more | 509 | more arguments as optional arguments for future extensibility. |
| 510 | arguments as optional arguments for future extensibility. If a | 510 | |
| 511 | capture name is both a face and a function, the face takes | 511 | If a capture name is both a face and a function, the face takes |
| 512 | priority. If a capture name is not a face name nor a function | 512 | priority. If a capture name is not a face name nor a function |
| 513 | name, it is ignored. | 513 | name, 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. |