Function: treemacs--button-close

treemacs--button-close is a macro defined in treemacs-rendering.el.

Signature

(treemacs--button-close &key BUTTON NEW-ICON NEW-STATE POST-CLOSE-ACTION)

Documentation

Close node given by BUTTON, use NEW-ICON and BUTTON's state to NEW-STATE.

Run POST-CLOSE-ACTION after everything else is done.

Source Code

;; Defined in ~/.emacs.d/elpa/treemacs-20251226.1307/treemacs-rendering.el
(cl-defmacro treemacs--button-close (&key button new-icon new-state post-close-action)
  "Close node given by BUTTON, use NEW-ICON and BUTTON's state to NEW-STATE.
Run POST-CLOSE-ACTION after everything else is done."
  `(save-excursion
     (treemacs-with-writable-buffer
      ,@(when new-icon
          `((treemacs--button-symbol-switch ,new-icon)))
      (treemacs-button-put ,button :state ,new-state)
      (-let [next (next-button (button-end ,button))]
        (if (or (null next)
                (/= (1+ (treemacs-button-get ,button :depth))
                    (treemacs-button-get (copy-marker next t) :depth)))
            (delete-trailing-whitespace)
          ;; Delete from end of the current button to end of the last sub-button.
          ;; This will make the EOL of the last button become the EOL of the
          ;; current button, making the treemacs--projects-end marker track
          ;; properly when collapsing the last project or a last directory of the
          ;; last project.
          (let* ((pos-start (line-end-position))
                 (next (treemacs--next-non-child-button ,button))
                 (pos-end (if next
                              (-> next (treemacs-button-start) (previous-button) (treemacs-button-end))
                            (point-max))))
            (delete-region pos-start pos-end))))
      ,post-close-action)))