Skip to content

Commit

Permalink
Support using an alist as the value of an infix's choices slot
Browse files Browse the repository at this point in the history
  • Loading branch information
tarsius committed Oct 19, 2023
1 parent 0f0b1f6 commit c2d9120
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lisp/transient.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
Expand Down

0 comments on commit c2d9120

Please sign in to comment.