aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/progmodes/js.el2
-rw-r--r--lisp/progmodes/python.el2
-rw-r--r--lisp/treesit.el54
3 files changed, 33 insertions, 25 deletions
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index 8d1cfbd3c0e..2801a729ebd 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -3573,7 +3573,7 @@ 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) 3576(defun js--fontify-template-string (beg end node _override &rest _)
3577 "Fontify template string but not substitution inside it. 3577 "Fontify template string but not substitution inside it.
3578BEG, END, NODE refers to the template_string node." 3578BEG, END, NODE refers to the template_string node."
3579 (ignore end) 3579 (ignore end)
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index a9aff167767..0b10058eebe 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) 1018(defun python--treesit-fontify-string (_beg _end node _override &rest _)
1019 "Fontify string. 1019 "Fontify string.
1020NODE is the last quote in the string. Do not fontify the initial 1020NODE is the last quote in the string. Do not fontify the initial
1021f for f-strings." 1021f for f-strings."
diff --git a/lisp/treesit.el b/lisp/treesit.el
index 2bd71cdf5d5..72c8186044f 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -410,7 +410,7 @@ omitted, default END to BEG."
410 return rng 410 return rng
411 finally return nil)))) 411 finally return nil))))
412 412
413;;; Font-lock 413;;; Fontification
414 414
415(define-error 'treesit-font-lock-error 415(define-error 'treesit-font-lock-error
416 "Generic tree-sitter font-lock error" 416 "Generic tree-sitter font-lock error"
@@ -500,12 +500,14 @@ Other keywords include:
500Capture names in QUERY should be face names like 500Capture names in QUERY should be face names like
501`font-lock-keyword-face'. The captured node will be fontified 501`font-lock-keyword-face'. The captured node will be fontified
502with that face. Capture names can also be function names, in 502with that face. Capture names can also be function names, in
503which case the function is called with (START END NODE), where 503which case the function is called with (START END NODE OVERRIDE),
504START and END are the start and end position of the node in 504where START and END are the start and end position of the node in
505buffer, and NODE is the tree-sitter node object. If a capture 505buffer, NODE is the tree-sitter node object, and OVERRIDE is the
506name is both a face and a function, the face takes priority. If 506override option of that rule. This function should accept more
507a capture name is not a face name nor a function name, it is 507arguments as optional arguments for future extensibility. If a
508ignored. 508capture name is both a face and a function, the face takes
509priority. If a capture name is not a face name nor a function
510name, it is ignored.
509 511
510\(fn :KEYWORD VALUE QUERY...)" 512\(fn :KEYWORD VALUE QUERY...)"
511 ;; Other tree-sitter function don't tend to be called unless 513 ;; Other tree-sitter function don't tend to be called unless
@@ -600,6 +602,26 @@ Set the ENABLE flag for each setting in
600 do (setf (nth 1 (nth idx treesit-font-lock-settings)) 602 do (setf (nth 1 (nth idx treesit-font-lock-settings))
601 (if (memq feature features) t nil))))) 603 (if (memq feature features) t nil)))))
602 604
605(defun treesit-fontify-with-override (start end face override)
606 "Apply FACE to the region between START and END.
607OVERRIDE can be nil, t, `append', `prepend', or `keep'.
608See `treesit-font-lock-rules' for their semantic."
609 (pcase override
610 ('nil (unless (text-property-not-all
611 start end 'face nil)
612 (put-text-property start end 'face face)))
613 ('t (put-text-property start end 'face face))
614 ('append (font-lock-append-text-property
615 start end 'face face))
616 ('prepend (font-lock-prepend-text-property
617 start end 'face face))
618 ('keep (font-lock-fillin-text-property
619 start end 'face face))
620 (_ (signal 'treesit-font-lock-error
621 (list
622 "Unrecognized value of :override option"
623 override)))))
624
603(defun treesit-font-lock-fontify-region 625(defun treesit-font-lock-fontify-region
604 (start end &optional loudly) 626 (start end &optional loudly)
605 "Fontify the region between START and END. 627 "Fontify the region between START and END.
@@ -633,23 +655,9 @@ If LOUDLY is non-nil, display some debugging information."
633 (end (treesit-node-end node))) 655 (end (treesit-node-end node)))
634 (cond 656 (cond
635 ((facep face) 657 ((facep face)
636 (pcase override 658 (treesit-fontify-with-override start end face override))
637 ('nil (unless (text-property-not-all
638 start end 'face nil)
639 (put-text-property start end 'face face)))
640 ('t (put-text-property start end 'face face))
641 ('append (font-lock-append-text-property
642 start end 'face face))
643 ('prepend (font-lock-prepend-text-property
644 start end 'face face))
645 ('keep (font-lock-fillin-text-property
646 start end 'face face))
647 (_ (signal 'treesit-font-lock-error
648 (list
649 "Unrecognized value of :override option"
650 override)))))
651 ((functionp face) 659 ((functionp face)
652 (funcall face start end node))) 660 (funcall face start end node override)))
653 ;; Don't raise an error if FACE is neither a face nor 661 ;; Don't raise an error if FACE is neither a face nor
654 ;; a function. This is to allow intermediate capture 662 ;; a function. This is to allow intermediate capture
655 ;; names used for #match and #eq. 663 ;; names used for #match and #eq.