Function: treemacs-do-for-button-state

treemacs-do-for-button-state is a macro defined in treemacs-macros.el.

Signature

(treemacs-do-for-button-state &key NO-ERROR FALLBACK ON-ROOT-NODE-OPEN ON-ROOT-NODE-CLOSED ON-FILE-NODE-OPEN ON-FILE-NODE-CLOSED ON-DIR-NODE-OPEN ON-DIR-NODE-CLOSED ON-TAG-NODE-OPEN ON-TAG-NODE-CLOSED ON-TAG-NODE-LEAF ON-NIL)

Documentation

Building block macro to execute a form based on the current node state.

Will bind to current button to 'btn' for the execution of the action forms. When NO-ERROR is non-nil no error will be thrown if no match for the button state is achieved. A general FALLBACK can also be used instead of NO-ERROR. In that case the unknown state will be bound as state in the FALLBACK form.

Otherwise either one of ON-ROOT-NODE-OPEN, ON-ROOT-NODE-CLOSED, ON-FILE-NODE-OPEN, ON-FILE-NODE-CLOSED, ON-DIR-NODE-OPEN, ON-DIR-NODE-CLOSED, ON-TAG-NODE-OPEN, ON-TAG-NODE-CLOSED, ON-TAG-NODE-LEAF or ON-NIL will be executed.

Source Code

;; Defined in ~/.emacs.d/elpa/treemacs-20251226.1307/treemacs-macros.el
(cl-defmacro treemacs-do-for-button-state
    (&key no-error
          fallback
          on-root-node-open
          on-root-node-closed
          on-file-node-open
          on-file-node-closed
          on-dir-node-open
          on-dir-node-closed
          on-tag-node-open
          on-tag-node-closed
          on-tag-node-leaf
          on-nil)
"Building block macro to execute a form based on the current node state.
Will bind to current button to \\='btn' for the execution of the action forms.
When NO-ERROR is non-nil no error will be thrown if no match for the button
state is achieved.  A general FALLBACK can also be used instead of NO-ERROR.  In
that case the unknown state will be bound as `state' in the FALLBACK form.

Otherwise either one of ON-ROOT-NODE-OPEN, ON-ROOT-NODE-CLOSED,
ON-FILE-NODE-OPEN, ON-FILE-NODE-CLOSED, ON-DIR-NODE-OPEN, ON-DIR-NODE-CLOSED,
ON-TAG-NODE-OPEN, ON-TAG-NODE-CLOSED, ON-TAG-NODE-LEAF or ON-NIL will be
executed."
  (declare (debug (&rest [sexp form])))

  (treemacs-static-assert (or (null no-error) (null fallback))
    "no-error and fallback arguments are mutually exclusive.")

  `(-if-let (btn (treemacs-current-button))
       (pcase (treemacs-button-get btn :state)
         ,@(when on-root-node-open
             `((`root-node-open
                ,on-root-node-open)))
         ,@(when on-root-node-closed
             `((`root-node-closed
                ,on-root-node-closed)))
         ,@(when on-file-node-open
             `((`file-node-open
                ,on-file-node-open)))
         ,@(when on-file-node-closed
             `((`file-node-closed
                ,on-file-node-closed)))
         ,@(when on-dir-node-open
             `((`dir-node-open
                ,on-dir-node-open)))
         ,@(when on-dir-node-closed
             `((`dir-node-closed
                ,on-dir-node-closed)))
         ,@(when on-tag-node-open
             `((`tag-node-open
                ,on-tag-node-open)))
         ,@(when on-tag-node-closed
             `((`tag-node-closed
                ,on-tag-node-closed)))
         ,@(when on-tag-node-leaf
             `((`tag-node
                ,on-tag-node-leaf)))
         ,@(when fallback
             `((state
                (ignore state)
                ,fallback)))
         ,@(unless (or fallback no-error)
             `((state (error "[Treemacs] Unexpected button state %s" state)))))
     ,on-nil))