[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/transient fbb46c3f2e 2/3: Provide two implementations o
From: |
Jonas Bernoulli |
Subject: |
[elpa] externals/transient fbb46c3f2e 2/3: Provide two implementations of transient--wrap-command |
Date: |
Fri, 25 Aug 2023 16:27:07 -0400 (EDT) |
branch: externals/transient
commit fbb46c3f2e0d08cea76a70542ae8d6cf8c966604
Author: Jonas Bernoulli <jonas@bernoul.li>
Commit: Jonas Bernoulli <jonas@bernoul.li>
Provide two implementations of transient--wrap-command
Starting with Emacs 30 the `interactive' form of a command can be
advised without any trickery and the new `transient--wrap-command-30'
takes advantage of that. Additionally it uses `letrec'.
On Emacs 29 and before we have to continue to use the old approach.
I was planning to stick to this approach until I can drop support for
these releases, but then Stefan changed `transient--wrap-command' on
Emacs' "master" branch to take advantage of the improved support for
advising commands.
To avoid further complicating the process of merging Transient into
Emacs (I already need a playbook to do it), I have decided to provide
two variants of this function. I actually have implemented just that
a long time ago, but decided against installing it, because, while
quite ugly, the backward compatible implementation continues to work
fine, even in Emacs 30. Now I feel, I have no choice but to do it
anyway.
---
lisp/transient.el | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/lisp/transient.el b/lisp/transient.el
index 0628cee406..55d85d1351 100644
--- a/lisp/transient.el
+++ b/lisp/transient.el
@@ -2163,6 +2163,37 @@ value. Otherwise return CHILDREN as is."
,@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)
(suffix this-command)
(advice nil)