Skip to content

Commit 7131bec

Browse files
committed
transient--suffixes: No longer populate by side-effect
This is cleaner but less efficient than the previous approach. We now have to flatten the tree of suffixes when initially displaying the menu. Previously we only had to do so when refreshing the menu. If flattening is fast enough when refreshing, then it should to be fast enough for initial display as well.
1 parent d22c2ca commit 7131bec

1 file changed

Lines changed: 22 additions & 24 deletions

File tree

lisp/transient.el

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2618,11 +2618,10 @@ value. Otherwise return CHILDREN as is.")
26182618
(setq transient--prefix (transient--init-prefix name params))
26192619
(setq name (oref transient--prefix command)))
26202620
(setq transient--refreshp (oref transient--prefix refresh-suffixes))
2621-
(cond ((and (not transient--refreshp) layout)
2622-
(setq transient--layout layout)
2623-
(setq transient--suffixes (transient--flatten-suffixes layout)))
2624-
((pcase-setq `(,transient--layout ,transient--suffixes)
2625-
(transient--init-suffixes name))))
2621+
(setq transient--layout
2622+
(or (and (not transient--refreshp) layout)
2623+
(transient--init-suffixes name)))
2624+
(setq transient--suffixes (transient--flatten-suffixes transient--layout))
26262625
(slot-makeunbound transient--prefix 'value))
26272626

26282627
(defun transient--init-prefix (name &optional params)
@@ -2638,24 +2637,23 @@ value. Otherwise return CHILDREN as is.")
26382637
obj))
26392638

26402639
(defun transient--init-suffixes (name)
2641-
(let ((levels (alist-get name transient-levels))
2642-
(transient--suffixes nil))
2643-
(list (mapcan (lambda (c) (transient--init-child levels c nil))
2644-
(append (transient--get-children name)
2645-
(and (not transient--editp)
2646-
(transient--get-children
2647-
'transient-common-commands))))
2648-
(nreverse transient--suffixes))))
2640+
(let ((levels (alist-get name transient-levels)))
2641+
(mapcan (lambda (c) (transient--init-child levels c nil))
2642+
(append (transient--get-children name)
2643+
(and (not transient--editp)
2644+
(transient--get-children
2645+
'transient-common-commands))))))
26492646

26502647
(defun transient--flatten-suffixes (layout)
2651-
(named-let flatten ((def layout))
2652-
(cond ((stringp def) nil)
2653-
((cl-typep def 'transient-information) nil)
2654-
((listp def) (mapcan #'flatten def))
2655-
((cl-typep def 'transient-group)
2656-
(mapcan #'flatten (oref def suffixes)))
2657-
((cl-typep def 'transient-suffix)
2658-
(list def)))))
2648+
(nreverse
2649+
(named-let flatten ((def layout))
2650+
(cond ((stringp def) nil)
2651+
((cl-typep def 'transient-information) nil)
2652+
((listp def) (mapcan #'flatten def))
2653+
((cl-typep def 'transient-group)
2654+
(mapcan #'flatten (oref def suffixes)))
2655+
((cl-typep def 'transient-suffix)
2656+
(list def))))))
26592657

26602658
(defun transient--init-child (levels spec parent)
26612659
(cl-etypecase spec
@@ -2723,8 +2721,7 @@ value. Otherwise return CHILDREN as is.")
27232721
(cond ((not (cl-typep obj 'transient-information))
27242722
(transient--init-suffix-key obj)
27252723
(transient-init-scope obj)
2726-
(transient-init-value obj)
2727-
(push obj transient--suffixes)))
2724+
(transient-init-value obj)))
27282725
(list obj)))
27292726

27302727
(cl-defmethod transient--init-suffix-key ((obj transient-suffix))
@@ -4319,7 +4316,8 @@ they can be returned. That does not cause the menu to be displayed."
43194316
(if (eq transient-current-command prefix)
43204317
transient-current-suffixes
43214318
(let ((transient--prefix (transient--init-prefix prefix)))
4322-
(cdr (transient--init-suffixes prefix)))))
4319+
(transient--flatten-suffixes
4320+
(transient--init-suffixes prefix)))))
43234321

43244322
(defun transient-get-value ()
43254323
"Return the value of the extant prefix.

0 commit comments

Comments
 (0)