emacs-diffs
[Top][All Lists]
Advanced

[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)))))))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]