diff options
| author | Jonas Bernoulli <jonas@bernoul.li> | 2026-03-27 10:15:50 +0100 |
|---|---|---|
| committer | Jonas Bernoulli <jonas@bernoul.li> | 2026-03-27 10:15:50 +0100 |
| commit | 79c49830a80f550728738e378b7f7a53dd908478 (patch) | |
| tree | 06f6800cb6df9f700f94952e1f79fbadca20319f | |
| parent | b71f04ebe7e22e24a3ae3d48e31402f70c477ada (diff) | |
transient--advise-this-command: New function
Removing the duplication gives us a place and some space to add
documentation.
| -rw-r--r-- | lisp/transient.el | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/lisp/transient.el b/lisp/transient.el index 85653fa..c902961 100644 --- a/lisp/transient.el +++ b/lisp/transient.el @@ -3051,13 +3051,7 @@ value. Otherwise return CHILDREN as is.") (when (symbolp command) (remove-function (symbol-function command) advice)) (oset prefix unwind-suffix nil))))) - (add-function :around - (if (and (symbolp this-command) - (not (subr-primitive-p - (symbol-function this-command)))) - (symbol-function this-command) - this-command) - advice '((depth . -99))) + (transient--advise-this-command advice) (cl-assert (>= emacs-major-version 30) nil "Emacs was downgraded, making it necessary to recompile Transient")) @@ -3107,13 +3101,20 @@ value. Otherwise return CHILDREN as is.") (setq advice `(lambda (fn &rest args) (interactive ,advice-interactive) (apply ',advice-body fn args))) - (add-function :around - (if (and (symbolp this-command) - (not (subr-primitive-p - (symbol-function this-command)))) - (symbol-function this-command) - this-command) - advice '((depth . -99)))))) + (transient--advise-this-command advice)))) + +(defun transient--advise-this-command (advice) + "Add ADVICE around `this-command'. +If possible add the advice to the value of `this-command' instead of +the symbol directly, so the command's identity does not get obfuscated. +For primitive and anonymous functions that isn't possible, so fall back +to advising via the symbol in those cases." + (add-function + :around (if (and (symbolp this-command) + (not (subr-primitive-p (symbol-function this-command)))) + (symbol-function this-command) + this-command) + advice '((depth . -99)))) (defun transient--premature-post-command () (and (equal (this-command-keys-vector) []) |
