[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feature/tree-sitter 9b5ecffeb0 04/12: Ignore some capture name in treesi
From: |
Yuan Fu |
Subject: |
feature/tree-sitter 9b5ecffeb0 04/12: Ignore some capture name in treesit-font-lock-fontify-region |
Date: |
Wed, 5 Oct 2022 22:52:20 -0400 (EDT) |
branch: feature/tree-sitter
commit 9b5ecffeb00f22ca6663aa14e7807c9886ed1716
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
Ignore some capture name in treesit-font-lock-fontify-region
* doc/lispref/modes.texi (Parser-based Font Lock): Update manual.
* lisp/treesit.el: (treesit-font-lock-fontify-region): Ignore names
that are not face nor function.
(treesit-font-lock-rules): Update docstring.
---
doc/lispref/modes.texi | 3 ++-
lisp/treesit.el | 10 +++++++---
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi
index ab83d8712b..0d58c28e27 100644
--- a/doc/lispref/modes.texi
+++ b/doc/lispref/modes.texi
@@ -3929,7 +3929,8 @@ with that face. Capture names can also be function
names, in which
case the function is called with (@var{start} @var{end} @var{node}),
where @var{start} and @var{end} are the start and end position of the
node in buffer, and @var{node} is the node itself. If a capture name
-is both a face and a function, the face takes priority.
+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.
@end defun
@defvar treesit-font-lock-settings
diff --git a/lisp/treesit.el b/lisp/treesit.el
index 91e3d05a51..4f56a14387 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -325,7 +325,9 @@ with that face. Capture names can also be function names,
in
which case the function is called with (START END NODE), where
START and END are the start and end position of the node in
buffer, and NODE is the tree-sitter node object. If a capture
-name is both a face and a function, the face takes priority.
+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.
\(fn :KEYWORD VALUE QUERY...)"
(let (;; Tracks the current language that following queries will
@@ -382,8 +384,10 @@ If LOUDLY is non-nil, message some debugging information."
(cond ((facep face)
(put-text-property start end 'face face))
((functionp face)
- (funcall face start end node))
- (t (error "Capture name %s is neither a face nor a
function" face)))
+ (funcall face start end node)))
+ ;; 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.
(when loudly
(message "Fontifying text from %d to %d, Face: %s Language:
%s"
start end face language)))))))))
- feature/tree-sitter updated (9ed53535f5 -> 7ebbd4efc3), Yuan Fu, 2022/10/05
- feature/tree-sitter 23bb724c92 09/12: Add :override flag for tree-sitter font-lock, Yuan Fu, 2022/10/05
- feature/tree-sitter e504eabe88 02/12: Change tree-sitter indent anchor preset 'prev-line', Yuan Fu, 2022/10/05
- feature/tree-sitter 6a3caeab58 03/12: Remove treesit-query-in, Yuan Fu, 2022/10/05
- feature/tree-sitter 10f96a8c57 05/12: Improve documentation of tree-sitter search functions, Yuan Fu, 2022/10/05
- feature/tree-sitter cb183f6467 11/12: Add tree-sitter admin notes, Yuan Fu, 2022/10/05
- feature/tree-sitter 96d44c4321 06/12: Add treesit-language-version, Yuan Fu, 2022/10/05
- feature/tree-sitter 9b5ecffeb0 04/12: Ignore some capture name in treesit-font-lock-fontify-region,
Yuan Fu <=
- feature/tree-sitter 1ea503ed4b 10/12: Add :override flag for python tree-sitter font-lock settings, Yuan Fu, 2022/10/05
- feature/tree-sitter 253126bf33 07/12: Fix python tree-sitter font-lock, Yuan Fu, 2022/10/05
- feature/tree-sitter 6e60d46418 01/12: Fix tree-sitter manuals, Yuan Fu, 2022/10/05
- feature/tree-sitter 7a4380b905 08/12: ; * doc/lispref/parsing.texi (Language Definitions): Fix typo., Yuan Fu, 2022/10/05
- feature/tree-sitter 7ebbd4efc3 12/12: Merge branch 'master' into feature/tree-sitter, Yuan Fu, 2022/10/05