Function: treemacs--do-apply-annotation

treemacs--do-apply-annotation is a byte-compiled function defined in treemacs-annotations.el.

Signature

(treemacs--do-apply-annotation BTN GIT-FACE)

Documentation

Apply a single BTN's annotations.

GIT-FACE is taken from the latest git cache, or nil if it's not known.

Source Code

;; Defined in ~/.emacs.d/elpa/treemacs-20251226.1307/treemacs-annotations.el
(define-inline treemacs--do-apply-annotation (btn git-face)
  "Apply a single BTN's annotations.
GIT-FACE is taken from the latest git cache, or nil if it's not known."
  (inline-letevals (btn git-face)
    (inline-quote
     (let* ((path (treemacs-button-get ,btn :path))
            (ann (treemacs-get-annotation path))
            (btn-start (treemacs-button-start ,btn))
            (btn-end (treemacs-button-end ,btn)))

       ;; delete current suffix if present
       (goto-char ,btn)
       (goto-char (or (next-single-property-change
                       ,btn
                       'treemacs-suffix-annotation
                       (current-buffer)
                       (line-end-position))
                      btn-end))
       (delete-region (point) (line-end-position))

       (if (null ann)
           ;; No annotation - just put git face
           (when ,git-face
             (put-text-property btn-start btn-end 'face ,git-face)
             ;; git face must be known for initial render
             (ht-set!
              treemacs--annotation-store
              path
              (treemacs-annotation->create!
               :git-face ,git-face
               :face-value ,git-face)))

         ;; annotation present, apply everything
         (let ((face-value (treemacs-annotation->face-value ann))
               (suffix-value (treemacs-annotation->suffix-value ann))
               (faces (treemacs-annotation->face ann))
               (old-git-face (treemacs-annotation->git-face ann)))

           ;; Faces
           ;; annotations are present, value needs updating if the git face
           ;; has changed
           (let ((new-face-value
                  (or
                   (cond
                    ((and ,git-face (not (equal ,git-face old-git-face)))
                     (append (mapcar #'cdr faces)
                             (list ,git-face)))
                    ((and old-git-face (null ,git-face))
                     (mapcar #'cdr faces))
                    (t face-value))
                   (treemacs-button-get ,btn :default-face))))
             (setf (treemacs-annotation->face-value ann)
                   new-face-value
                   (treemacs-annotation->git-face ann)
                   ,git-face)
             (put-text-property
              btn-start btn-end 'face
              new-face-value))

           ;; Suffix
           (when suffix-value (insert suffix-value))))))))