branch: externals/transient commit d88cacfc6919c5642be7f3c343e12861f7e683b7 Author: Jonas Bernoulli <jo...@bernoul.li> Commit: Jonas Bernoulli <jo...@bernoul.li>
Fix setting up return to outer prefix We need a separate prefix slot, `return', to store the return behavior; re-purposing the `transient-suffix' slot, as we did before, was ambiguous. When the `transient-suffix' prefix slot is t, that means that suffixes, that do not specify their own transient behavior, should be called without the prefix being exited. In [1: 784887b7] we tried to overload that meaning of that value in the case of sub-prefixes: > When the prefix's `transient-suffix' is t, and the current prefix > is a sub-prefix, then suffixes have to use `transient--do-return', > to exit the sub-prefix but not the outer prefix. If a suffixes `transient' slot is nil, that works, but merely because the ambiguous value t of `transient-suffix' does not enter the picture. However if a suffix leaves `transient' undefined, then we relied on the same boolean to encode the three possible behaviors `call', `exit' and `return'. I.e., it was not possible to chose between `exit' and `return', and we always used `exit'. Closes #352. 1: 2023-10-31 784887b78160e0c820b44924d12b2e2e0bf90ef0 Account for t as transient-suffix for nested prefixes --- lisp/transient.el | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/lisp/transient.el b/lisp/transient.el index 6f1d5f3331..846890b7a2 100644 --- a/lisp/transient.el +++ b/lisp/transient.el @@ -736,6 +736,7 @@ If `transient-save-history' is nil, then do nothing." (level :initarg :level) (init-value :initarg :init-value) (value) (default-value :initarg :value) + (return :initarg :return :initform nil) (scope :initarg :scope :initform nil) (history :initarg :history :initform nil) (history-pos :initarg :history-pos :initform 0) @@ -2097,7 +2098,7 @@ of the corresponding object." (defun transient--make-predicate-map () (let* ((default (transient--resolve-pre-command (oref transient--prefix transient-suffix))) - (return (and transient--stack (eq default t))) + (return (and transient--stack (oref transient--prefix return))) (map (make-sparse-keymap))) (set-keymap-parent map transient-predicate-map) (when (or (and (slot-boundp transient--prefix 'transient-switch-frame) @@ -2274,9 +2275,9 @@ value. Otherwise return CHILDREN as is.") :level (or (alist-get t (alist-get name transient-levels)) transient-default-level) params)))) - (transient--setup-recursion obj) - (transient-init-scope obj) - (transient-init-value obj) + (transient-init-value obj) + (transient-init-return obj) + (transient-init-scope obj) obj)) (defun transient--init-suffixes (name) @@ -2828,9 +2829,9 @@ value. Otherwise return CHILDREN as is.") (push (list (oref transient--prefix command) transient--layout transient--editp - :transient-suffix (oref transient--prefix transient-suffix) - :scope (oref transient--prefix scope) - :value (transient-get-value)) + :value (transient-get-value) + :return (oref transient--prefix return) + :scope (oref transient--prefix scope)) transient--stack)) (defun transient--stack-pop () @@ -3010,16 +3011,6 @@ Use that command's pre-command to determine transient behavior." If there is no parent prefix, then just call the command." (transient--do-stack)) -(defun transient--setup-recursion (prefix-obj) - (when-let* ((transient--stack) - (command (oref prefix-obj command)) - (suffix-obj (transient-suffix-object command)) - ((memq (if (slot-boundp suffix-obj 'transient) - (oref suffix-obj transient) - (oref transient-current-prefix transient-suffix)) - (list t 'recurse #'transient--do-recurse)))) - (oset prefix-obj transient-suffix t))) - (defun transient--do-stack () "Call the transient prefix command, stacking the active transient. Push the active transient to the transient stack." @@ -3932,6 +3923,18 @@ Append \"=\ to ARG to indicate that it is an option." (or (match-string 1 match) ""))) (and (member arg args) t))) +;;; Return + +(defun transient-init-return (obj) + (when-let* ((transient--stack) + (command (oref obj command)) + (suffix-obj (transient-suffix-object command)) + ((memq (if (slot-boundp suffix-obj 'transient) + (oref suffix-obj transient) + (oref transient-current-prefix transient-suffix)) + (list t 'recurse #'transient--do-recurse)))) + (oset obj return t))) + ;;; Scope ;;;; Init