Skip to content

Commit

Permalink
Fix expansion of layout variables inside suffix specifications
Browse files Browse the repository at this point in the history
The `transient-define-groups' macro saves the parsed suffixes in the
`transient--layout' property, but later when `transient--parse-child'
is used by `transient-define-prefix', that expects the unparsed group
or suffix specifications in the symbol's value cell.  The latter is an
older approach, which was supposed to be replaced when the macro was
introduced.  Because that didn't happen, the macro never worked.

Additionally change `transient--parse-child' to not deal with embedded
symbols, except for quoting them.  It is now `transient--init-child's
responsibility to fill in the indirectly specified suffixes.  In other
words it happens when a prefix is invoked, not when it is defined.
That has the advantage that indirectly defined suffixes can be
modified the same way as directly specified.

Modifying indirectly specified suffixes) now affects all prefixes
that use those suffixes, without having to re-evaluate the prefix
definitions.
  • Loading branch information
tarsius committed Oct 19, 2023
1 parent c2d9120 commit 78f8130
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions lisp/transient.el
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,18 @@ to the setup function:
(list ,@(cl-mapcan (lambda (s) (transient--parse-child name s))
suffixes))))))

(defmacro transient-define-groups (name &rest groups)
"Define one or more GROUPS and store them in symbol NAME.
GROUPS, defined using this macro, can be used inside the
definition of transient prefix commands, by using the symbol
NAME where a group vector is expected. GROUPS has the same
form as for `transient-define-prefix'."
(declare (debug (&define name [&rest vectorp]))
(indent defun))
`(put ',name 'transient--layout
(list ,@(cl-mapcan (lambda (group) (transient--parse-child name group))
groups))))

(defmacro transient-define-suffix (name arglist &rest args)
"Define NAME as a transient suffix command.
Expand Down Expand Up @@ -1009,12 +1021,7 @@ example, sets a variable, use `transient-define-infix' instead.

(defun transient--parse-child (prefix spec)
(cl-etypecase spec
(symbol (let ((value (symbol-value spec)))
(if (and (listp value)
(or (listp (car value))
(vectorp (car value))))
(cl-mapcan (lambda (s) (transient--parse-child prefix s)) value)
(transient--parse-child prefix value))))
(symbol (list (list 'quote spec)))
(vector (and-let* ((c (transient--parse-group prefix spec))) (list c)))
(list (and-let* ((c (transient--parse-suffix prefix spec))) (list c)))
(string (list spec))))
Expand Down Expand Up @@ -1888,6 +1895,8 @@ value. Otherwise return CHILDREN as is."

(defun transient--init-child (levels spec)
(cl-etypecase spec
(symbol (cl-mapcan (lambda (c) (transient--init-child levels c))
(get spec 'transient--layout)))
(vector (transient--init-group levels spec))
(list (transient--init-suffix levels spec))
(string (list spec))))
Expand Down

0 comments on commit 78f8130

Please sign in to comment.