From c2d9120514687088a56bb6972ecf1c91e2fe72ef Mon Sep 17 00:00:00 2001 From: Jonas Bernoulli Date: Sun, 8 Jan 2023 18:59:21 +0100 Subject: [PATCH] Support using an alist as the value of an infix's choices slot --- lisp/transient.el | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lisp/transient.el b/lisp/transient.el index 3bf2307c..31a10f8e 100644 --- a/lisp/transient.el +++ b/lisp/transient.el @@ -3232,7 +3232,12 @@ does nothing." nil) (cl-defmethod transient-infix-value ((obj transient-option)) "Return ARGUMENT and VALUE as a unit or nil if the latter is nil." (and-let* ((value (oref obj value))) - (let ((arg (oref obj argument))) + (with-slots ((arg argument) choices multi-value) obj + (when (consp (car choices)) + (setq value + (if multi-value + (mapcar (lambda (v) (car (rassoc v choices))) value) + (car (rassoc value choices))))) (cl-ecase (oref obj multi-value) ((nil) (concat arg value)) ((t rest) (cons arg value)) @@ -3252,6 +3257,12 @@ not contribute to the value of the transient." (oset obj choices (funcall choices obj)) choices))) +(cl-defmethod transient-infix-choices ((obj transient-argument)) + (let ((choices (cl-call-next-method obj))) + (if (consp (car choices)) + (mapcar #'cdr choices) + choices))) + ;;;; Utilities (defun transient-arg-value (arg args)