branch: externals/transient commit f27c840aec9d37c1784636511e8768ffe3431cab Author: Jonas Bernoulli <jo...@bernoul.li> Commit: Jonas Bernoulli <jo...@bernoul.li>
transient-suffix-object: Disambiguate duplicated suffix commands This makes it possible to bind the same command multiple times as a suffix of a transient command, but still have it do different things depending on what binding is used, based on the value of some slot of the corresponding suffix object, similar to how `self-insert-command' inserts the pressed key. --- lisp/transient.el | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lisp/transient.el b/lisp/transient.el index 6afd9d9d5b..b1b8a90b8c 100644 --- a/lisp/transient.el +++ b/lisp/transient.el @@ -1471,14 +1471,24 @@ probably use this instead: (cl-check-type command command)) (if (or transient--prefix transient-current-prefix) - (cl-find-if (lambda (obj) - (eq (transient--suffix-command obj) + (let ((suffixes + (cl-remove-if-not + (lambda (obj) + (eq (transient--suffix-command obj) + (or command ;; When `this-command' is `transient-set-level', ;; its reader needs to know what command is being ;; configured. - (or command this-original-command))) - (or transient--suffixes - transient-current-suffixes)) + this-original-command))) + (or transient--suffixes + transient-current-suffixes)))) + (or (and (cdr suffixes) + (cl-find-if + (lambda (obj) + (equal (listify-key-sequence (transient--kbd (oref obj key))) + (listify-key-sequence (this-command-keys)))) + suffixes)) + (car suffixes))) (when-let* ((obj (get (or command this-command) 'transient--suffix)) (obj (clone obj))) ;; Cannot use and-let* because of debbugs#31840.