diff options
| author | Jonas Bernoulli <jonas@bernoul.li> | 2026-03-10 17:22:55 +0100 |
|---|---|---|
| committer | Jonas Bernoulli <jonas@bernoul.li> | 2026-03-10 21:36:58 +0100 |
| commit | 7131bec61e558e022ce75e2d2d5e55c748fcf8e0 (patch) | |
| tree | 0b34e6f07026caabf1406d90d1dd07e615c55cde | |
| parent | d22c2caa41b852f5b3ff15d1397d142d3dd084d5 (diff) | |
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.
| -rw-r--r-- | lisp/transient.el | 46 |
1 files changed, 22 insertions, 24 deletions
diff --git a/lisp/transient.el b/lisp/transient.el index d0803c8..bf761fa 100644 --- a/lisp/transient.el +++ b/lisp/transient.el @@ -2618,11 +2618,10 @@ value. Otherwise return CHILDREN as is.") (setq transient--prefix (transient--init-prefix name params)) (setq name (oref transient--prefix command))) (setq transient--refreshp (oref transient--prefix refresh-suffixes)) - (cond ((and (not transient--refreshp) layout) - (setq transient--layout layout) - (setq transient--suffixes (transient--flatten-suffixes layout))) - ((pcase-setq `(,transient--layout ,transient--suffixes) - (transient--init-suffixes name)))) + (setq transient--layout + (or (and (not transient--refreshp) layout) + (transient--init-suffixes name))) + (setq transient--suffixes (transient--flatten-suffixes transient--layout)) (slot-makeunbound transient--prefix 'value)) (defun transient--init-prefix (name &optional params) @@ -2638,24 +2637,23 @@ value. Otherwise return CHILDREN as is.") obj)) (defun transient--init-suffixes (name) - (let ((levels (alist-get name transient-levels)) - (transient--suffixes nil)) - (list (mapcan (lambda (c) (transient--init-child levels c nil)) - (append (transient--get-children name) - (and (not transient--editp) - (transient--get-children - 'transient-common-commands)))) - (nreverse transient--suffixes)))) + (let ((levels (alist-get name transient-levels))) + (mapcan (lambda (c) (transient--init-child levels c nil)) + (append (transient--get-children name) + (and (not transient--editp) + (transient--get-children + 'transient-common-commands)))))) (defun transient--flatten-suffixes (layout) - (named-let flatten ((def layout)) - (cond ((stringp def) nil) - ((cl-typep def 'transient-information) nil) - ((listp def) (mapcan #'flatten def)) - ((cl-typep def 'transient-group) - (mapcan #'flatten (oref def suffixes))) - ((cl-typep def 'transient-suffix) - (list def))))) + (nreverse + (named-let flatten ((def layout)) + (cond ((stringp def) nil) + ((cl-typep def 'transient-information) nil) + ((listp def) (mapcan #'flatten def)) + ((cl-typep def 'transient-group) + (mapcan #'flatten (oref def suffixes))) + ((cl-typep def 'transient-suffix) + (list def)))))) (defun transient--init-child (levels spec parent) (cl-etypecase spec @@ -2723,8 +2721,7 @@ value. Otherwise return CHILDREN as is.") (cond ((not (cl-typep obj 'transient-information)) (transient--init-suffix-key obj) (transient-init-scope obj) - (transient-init-value obj) - (push obj transient--suffixes))) + (transient-init-value obj))) (list obj))) (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." (if (eq transient-current-command prefix) transient-current-suffixes (let ((transient--prefix (transient--init-prefix prefix))) - (cdr (transient--init-suffixes prefix))))) + (transient--flatten-suffixes + (transient--init-suffixes prefix))))) (defun transient-get-value () "Return the value of the extant prefix. |
