Skip to content

Commit

Permalink
transient--quote: New function
Browse files Browse the repository at this point in the history
That makes it possible drop branches that treated `lambda' specifically,
with reduces the risk of forgetting to do that in some places, such as
when setting `:reader', where we previously failed to do it.

Also start treating `closure' the same as `lambda'.  Fixing the failure
to do that, is now simpler, since it only has to happen in one place,
the new `transient--quote'.

In two places where we know we always have to quote, start doing that
explicitly, instead of sticking to `macroexp-quote' or even switching
to `transient--quote'.
  • Loading branch information
tarsius committed Oct 17, 2024
1 parent b1acf76 commit 7ca43bd
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions lisp/transient.el
Original file line number Diff line number Diff line change
Expand Up @@ -1149,10 +1149,7 @@ commands are aliases for."
(val (if spec (pop spec) (error "No value for `%s'" key))))
(cond ((eq key :class)
(setq class val))
((or (symbolp val)
(and (listp val) (not (eq (car val) 'lambda))))
(setq args (plist-put args key (macroexp-quote val))))
((setq args (plist-put args key val))))))
((setq args (plist-put args key (transient--quote val)))))))
(unless (or spec class (not (plist-get args :setup-children)))
(message "WARNING: %s: When %s is used, %s must also be specified"
'transient-define-prefix :setup-children :class))
Expand Down Expand Up @@ -1180,19 +1177,17 @@ commands are aliases for."
((cl-type (or string vector))
(use :key (pop spec))))
(pcase (car spec)
((guard (or (stringp (car spec))
(and (eq (car-safe (car spec)) 'lambda)
(not (commandp (car spec))))))
(use :description (pop spec)))
((and (cl-type (and symbol (not keyword) (not command)))
(guard (commandp (cadr spec))))
(use :description (macroexp-quote (pop spec)))))
((or (cl-type string)
(cl-type (and function (not command)))
(and (cl-type (and symbol (not keyword) (not command)))
(guard (commandp (cadr spec)))))
(use :description (transient--quote (pop spec)))))
(pcase (car spec)
((or :info :info*))
((and (cl-type keyword) invalid)
(error "Need command, argument, `:info' or `:info*'; got `%s'" invalid))
((cl-type symbol)
(use :command (macroexp-quote (pop spec))))
(use :command (list 'quote (pop spec))))
;; During macro-expansion this is expected to be a `lambda'
;; expression (i.e., source code). When this is called from a
;; `:setup-children' function, it may also be a function object
Expand Down Expand Up @@ -1230,7 +1225,7 @@ commands are aliases for."
(pcase (car spec)
((cl-type (and (not null) (not keyword)))
(setq class 'transient-option)
(use :reader (macroexp-quote (pop spec))))
(use :reader (transient--quote (pop spec))))
((guard (string-suffix-p "=" arg))
(setq class 'transient-option))
(_ (setq class 'transient-switch)))))
Expand All @@ -1248,20 +1243,20 @@ commands are aliases for."
(use :description val))
((guard (eq (car-safe val) '\,))
(use key (cadr val)))
((guard (or (symbolp val)
(and (listp val) (not (eq (car val) 'lambda)))))
(use key (macroexp-quote val)))
(_ (use key val)))))
(_ (use key (transient--quote val))))))
(when spec
(error "Need keyword, got %S" (car spec)))
(when-let* (((not (plist-get args :key)))
(shortarg (plist-get args :shortarg)))
(use :key shortarg)))
(list 'list
(or level transient--default-child-level)
(macroexp-quote (or class 'transient-suffix))
(list 'quote (or class 'transient-suffix))
(cons 'list args))))

(defun transient--quote (v)
(if (memq (car-safe v) '(lambda closure)) v (macroexp-quote v)))

(defun transient--derive-shortarg (arg)
(save-match-data
(and (string-match "\\`\\(-[a-zA-Z]\\)\\(\\'\\|=\\)" arg)
Expand Down

0 comments on commit 7ca43bd

Please sign in to comment.