branch: externals/transient
commit e8eb3ebdc0c69c7eefc6c4e913c4c8f315d20f63
Author: Jonas Bernoulli <jo...@bernoul.li>
Commit: Jonas Bernoulli <jo...@bernoul.li>

    Provide shorthand to define transient-cons-option suffixes
    
    Command-line switches can be defined inline in a prefix definition
    like so:
    
      ("-s" "My switch" "--switch")
      ("-o" "My option" "--option=")
    
    Support something similar for `transient-cons-option':
    
      ("c" "My option" :cons option)
      ("o" :cons other-option)
      ("r" :cons number-option :reader read-number)
---
 lisp/transient.el | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/lisp/transient.el b/lisp/transient.el
index 4852a34f7f..40f8a60ac6 100644
--- a/lisp/transient.el
+++ b/lisp/transient.el
@@ -1350,9 +1350,10 @@ commands are aliases for."
               (guard (commandp (cadr spec))))
          (use :description (macroexp-quote (pop spec)))))
       (pcase (car spec)
-        ((or :info :info*))
+        ((or :info :info* :cons))
         ((and (cl-type keyword) invalid)
-         (error "Need command, argument, `:info' or `:info*'; got `%s'" 
invalid))
+         (error "Need command, argument, `:info', `:info*' or `:cons'; got 
`%s'"
+                invalid))
         ((cl-type symbol)
          (use :command (macroexp-quote (pop spec))))
         ;; During macro-expansion this is expected to be a `lambda'
@@ -1407,6 +1408,15 @@ commands are aliases for."
                     (use :description val))
             (:info* (setq class 'transient-information*)
                     (use :description val))
+            (:cons
+             (setq class 'transient-cons-option)
+             (use :command
+                  (let ((sym (intern (format "transient:%s:%s" prefix val))))
+                    `(prog1 ',sym
+                       (put ',sym 'interactive-only t)
+                       (put ',sym 'completion-predicate 
#'transient--suffix-only)
+                       (defalias ',sym #'transient--default-infix-command))))
+             (use :argument val))
             ((guard (eq (car-safe val) '\,))
              (use key (cadr val)))
             ((guard (or (symbolp val)

Reply via email to