From: Yuan Fu Date: Sun, 2 Oct 2022 03:25:25 +0000 (-0700) Subject: Ignore some capture name in treesit-font-lock-fontify-region X-Git-Tag: emacs-29.0.90~1864 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=9b5ecffeb00f22ca6663aa14e7807c9886ed1716;p=emacs.git 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. --- diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi index ab83d8712b2..0d58c28e271 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 91e3d05a515..4f56a143871 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)))))))))