branch: externals/transient
commit aea527ed938de32a96ec138b844b5d0c9643dada
Author: Jonas Bernoulli <[email protected]>
Commit: Jonas Bernoulli <[email protected]>
transient--wrap-command: Use add-function and remove-function
While suffixes are guaranteed to be function-bound symbols, the same
isn't necessarily true of non-suffixes. Non-suffixes may also use
the minibuffer or signal an error, so they have to be wrapped as well.
Furthermore when `advice-add' is used on a function whose doc-string
is stored in its `function-documentation' property, then the original
doc-string is lost once `advice-remove' is used.
Re debbugs#76528.
---
lisp/transient.el | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/lisp/transient.el b/lisp/transient.el
index 4f760af67f..ed1c565a7c 100644
--- a/lisp/transient.el
+++ b/lisp/transient.el
@@ -2676,7 +2676,8 @@ value. Otherwise return CHILDREN as is.")
(when-let ((unwind (oref prefix unwind-suffix)))
(transient--debug 'unwind-interactive)
(funcall unwind cmd))
- (advice-remove cmd advice)
+ (remove-function
+ (if (symbolp cmd) (symbol-function cmd) cmd) advice)
(oset prefix unwind-suffix nil))))))
(unwind-protect
(let ((debugger #'transient--exit-and-debug))
@@ -2691,10 +2692,11 @@ value. Otherwise return CHILDREN as is.")
(when-let ((unwind (oref prefix unwind-suffix)))
(transient--debug 'unwind-command)
(funcall unwind cmd))
- (advice-remove cmd advice)
+ (remove-function
+ (if (symbolp cmd) (symbol-function cmd) cmd) advice)
(oset prefix unwind-suffix nil)))))
- (when (symbolp this-command)
- (advice-add cmd :around advice '((depth . -99))))
+ (add-function :around (if (symbolp cmd) (symbol-function cmd) cmd)
+ advice '((depth . -99)))
(cl-assert
(>= emacs-major-version 30) nil
"Emacs was downgraded, making it necessary to recompile Transient"))
@@ -2719,7 +2721,8 @@ value. Otherwise return CHILDREN as is.")
(when-let ((unwind (oref prefix unwind-suffix)))
(transient--debug 'unwind-interactive)
(funcall unwind cmd))
- (advice-remove cmd advice)
+ (remove-function
+ (if (symbolp cmd) (symbol-function cmd) cmd) advice)
(oset prefix unwind-suffix nil))))))
(advice-body
(lambda (fn &rest args)
@@ -2736,13 +2739,14 @@ value. Otherwise return CHILDREN as is.")
(when-let ((unwind (oref prefix unwind-suffix)))
(transient--debug 'unwind-command)
(funcall unwind cmd))
- (advice-remove cmd advice)
+ (remove-function
+ (if (symbolp cmd) (symbol-function cmd) cmd) advice)
(oset prefix unwind-suffix nil)))))
(setq advice `(lambda (fn &rest args)
(interactive ,advice-interactive)
(apply ',advice-body fn args)))
- (when (symbolp this-command)
- (advice-add cmd :around advice '((depth . -99)))))))
+ (add-function :around (if (symbolp cmd) (symbol-function cmd) cmd)
+ advice '((depth . -99))))))
(defun transient--premature-post-command ()
(and (equal (this-command-keys-vector) [])