Skip to content

Commit

Permalink
transient--wrap-command: Select implementation using eval-when-compile
Browse files Browse the repository at this point in the history
  • Loading branch information
tarsius committed Oct 24, 2023
1 parent 4f2fcef commit dcbdfcd
Showing 1 changed file with 55 additions and 58 deletions.
113 changes: 55 additions & 58 deletions lisp/transient.el
Original file line number Diff line number Diff line change
Expand Up @@ -2243,66 +2243,63 @@ value. Otherwise return CHILDREN as is."
(remove-hook 'minibuffer-exit-hook ,exit)))
,@body)))

(defun transient--wrap-command ()
(if (>= emacs-major-version 30)
(transient--wrap-command-30)
(transient--wrap-command-29)))

(defun transient--wrap-command-30 ()
(letrec
((prefix transient--prefix)
(suffix this-command)
(advice (lambda (fn &rest args)
(interactive
(lambda (spec)
(let ((abort t))
(unwind-protect
(prog1 (advice-eval-interactive-spec spec)
(setq abort nil))
(when abort
(when-let ((unwind (oref prefix unwind-suffix)))
(transient--debug 'unwind-interactive)
(funcall unwind suffix))
(advice-remove suffix advice)
(oset prefix unwind-suffix nil))))))
(unwind-protect
(apply fn args)
(when-let ((unwind (oref prefix unwind-suffix)))
(transient--debug 'unwind-command)
(funcall unwind suffix))
(advice-remove suffix advice)
(oset prefix unwind-suffix nil)))))
(advice-add suffix :around advice '((depth . -99)))))

(defun transient--wrap-command-29 ()
(let* ((prefix transient--prefix)
(cond
((eval-when-compile (>= emacs-major-version 30))
(defun transient--wrap-command-30 ()
(letrec
((prefix transient--prefix)
(suffix this-command)
(advice nil)
(advice-interactive
(lambda (spec)
(let ((abort t))
(advice (lambda (fn &rest args)
(interactive
(lambda (spec)
(let ((abort t))
(unwind-protect
(prog1 (advice-eval-interactive-spec spec)
(setq abort nil))
(when abort
(when-let ((unwind (oref prefix unwind-suffix)))
(transient--debug 'unwind-interactive)
(funcall unwind suffix))
(advice-remove suffix advice)
(oset prefix unwind-suffix nil))))))
(unwind-protect
(apply fn args)
(when-let ((unwind (oref prefix unwind-suffix)))
(transient--debug 'unwind-command)
(funcall unwind suffix))
(advice-remove suffix advice)
(oset prefix unwind-suffix nil)))))
(advice-add suffix :around advice '((depth . -99))))))

((defun transient--wrap-command ()
(let* ((prefix transient--prefix)
(suffix this-command)
(advice nil)
(advice-interactive
(lambda (spec)
(let ((abort t))
(unwind-protect
(prog1 (advice-eval-interactive-spec spec)
(setq abort nil))
(when abort
(when-let ((unwind (oref prefix unwind-suffix)))
(transient--debug 'unwind-interactive)
(funcall unwind suffix))
(advice-remove suffix advice)
(oset prefix unwind-suffix nil))))))
(advice-body
(lambda (fn &rest args)
(unwind-protect
(prog1 (advice-eval-interactive-spec spec)
(setq abort nil))
(when abort
(when-let ((unwind (oref prefix unwind-suffix)))
(transient--debug 'unwind-interactive)
(funcall unwind suffix))
(advice-remove suffix advice)
(oset prefix unwind-suffix nil))))))
(advice-body
(lambda (fn &rest args)
(unwind-protect
(apply fn args)
(when-let ((unwind (oref prefix unwind-suffix)))
(transient--debug 'unwind-command)
(funcall unwind suffix))
(advice-remove suffix advice)
(oset prefix unwind-suffix nil)))))
(setq advice `(lambda (fn &rest args)
(interactive ,advice-interactive)
(apply ',advice-body fn args)))
(advice-add suffix :around advice '((depth . -99)))))
(apply fn args)
(when-let ((unwind (oref prefix unwind-suffix)))
(transient--debug 'unwind-command)
(funcall unwind suffix))
(advice-remove suffix advice)
(oset prefix unwind-suffix nil)))))
(setq advice `(lambda (fn &rest args)
(interactive ,advice-interactive)
(apply ',advice-body fn args)))
(advice-add suffix :around advice '((depth . -99)))))))

(defun transient--premature-post-command ()
(and (equal (this-command-keys-vector) [])
Expand Down

0 comments on commit dcbdfcd

Please sign in to comment.