From 1f1443498238ce56fc7f728327b73d942a38794b Mon Sep 17 00:00:00 2001 From: Jonas Bernoulli Date: Mon, 24 Jun 2024 13:38:35 +0200 Subject: [PATCH] Update to Transient v0.7.2-1-gf273c0c8 This fixes two bugs, one of them restoring compatibility with the version that ships with Emacs 29, making emoji-insert usable again. The other changes are of cosmetic nature. The only exception is a new command, whose creation lead to the discovery of one of the bugs, and remains unused until a package author actually binds it in a prefix. I.e., unless someone actually uses this, the risk of a regression is close to zero, and even if it is used, it can only affect the prefix that binds it. (cherry picked from commit 4fcc38966bf58cc9977fc9fea0f7cec7eea30f6b) --- doc/misc/transient.texi | 4 +-- lisp/transient.el | 62 +++++++++++++++++++++++++++++++++++------ 2 files changed, 56 insertions(+), 10 deletions(-) diff --git a/doc/misc/transient.texi b/doc/misc/transient.texi index 7e8ffcf91bf..407b55ee017 100644 --- a/doc/misc/transient.texi +++ b/doc/misc/transient.texi @@ -31,7 +31,7 @@ General Public License for more details. @finalout @titlepage @title Transient User and Developer Manual -@subtitle for version 0.7.0 +@subtitle for version 0.7.2 @author Jonas Bernoulli @page @vskip 0pt plus 1filll @@ -53,7 +53,7 @@ resource to get over that hurdle is Psionic K's interactive tutorial, available at @uref{https://github.com/positron-solutions/transient-showcase}. @noindent -This manual is for Transient version 0.7.0. +This manual is for Transient version 0.7.2. @insertcopying @end ifnottex diff --git a/lisp/transient.el b/lisp/transient.el index 34458bec688..805b0acd6f3 100644 --- a/lisp/transient.el +++ b/lisp/transient.el @@ -5,7 +5,7 @@ ;; Author: Jonas Bernoulli ;; URL: https://github.com/magit/transient ;; Keywords: extensions -;; Version: 0.7.0 +;; Version: 0.7.2 ;; SPDX-License-Identifier: GPL-3.0-or-later @@ -835,6 +835,11 @@ Technically a suffix object with no associated command.") All remaining arguments are treated as files. They become the value of this argument.") +(defclass transient-value-preset (transient-suffix) + ((transient :initform t) + (set :initarg := :initform nil)) + "Class used by the `transient-preset' suffix command.") + ;;;; Group (defclass transient-group (transient-child) @@ -1075,7 +1080,10 @@ commands are aliases for." (and val (not (eq val 'transient--default-infix-command)) val))) (eval-and-compile ;transient--expand-define-args - (defun transient--expand-define-args (args arglist form &optional nobody) + (defun transient--expand-define-args (args &optional arglist form nobody) + ;; ARGLIST and FORM are only optional for backward compatibility. + ;; This is necessary because "emoji.el" from Emacs 29 calls this + ;; function directly, with just one argument. (unless (listp arglist) (error "Mandatory ARGLIST is missing")) (let (class keys suffixes docstr declare (interactive-only t)) @@ -2020,7 +2028,7 @@ transient. In that case NAME is mandatory, LAYOUT and EDIT must be nil and PARAMS may be (but usually is not) used to set, e.g., the \"scope\" of the transient (see `transient-define-prefix'). -This function is also called internally in which case LAYOUT and +This function is also called internally, in which case LAYOUT and EDIT may be non-nil." (transient--debug 'setup) (transient--with-emergency-exit :setup @@ -2275,6 +2283,12 @@ value. Otherwise return CHILDREN as is." (transient--pop-keymap 'transient--predicate-map) (transient--pop-keymap 'transient--transient-map) (transient--pop-keymap 'transient--redisplay-map) + (if (eq transient--refreshp 'updated-value) + ;; Preserve the prefix value this once, because the + ;; invoked suffix indicates that it has updated that. + (setq transient--refreshp (oref transient--prefix refresh-suffixes)) + ;; Otherwise update the prefix value from suffix values. + (oset transient--prefix value (transient-get-value))) (transient--init-objects) (transient--init-keymaps) (transient--push-keymap 'transient--transient-map) @@ -3081,6 +3095,12 @@ transient is active." (oset obj value (nth pos hst)) (mapc #'transient-init-value transient--suffixes)))) +(transient-define-suffix transient-preset () + "Put this preset into action." + :class transient-value-preset + (interactive) + (transient-prefix-set (oref (transient-suffix-object) set))) + ;;;; Auxiliary (defun transient-toggle-common () @@ -3258,7 +3278,7 @@ it\", in which case it is pointless to preserve history.)" (reader (oref obj reader)) (choices (if (functionp choices) (funcall choices) choices)) (prompt (transient-prompt obj)) - (value (if multi-value (mapconcat #'identity value ",") value)) + (value (if multi-value (string-join value ",") value)) (history-key (or (oref obj history-key) (oref obj command))) (transient--history (alist-get history-key transient-history)) @@ -3405,10 +3425,10 @@ prompt." ;;;; Set (cl-defgeneric transient-infix-set (obj value) - "Set the value of infix object OBJ to value.") + "Set the value of infix object OBJ to VALUE.") (cl-defmethod transient-infix-set ((obj transient-infix) value) - "Set the value of infix object OBJ to value." + "Set the value of infix object OBJ to VALUE." (oset obj value value)) (cl-defmethod transient-infix-set :after ((obj transient-argument) value) @@ -3438,8 +3458,16 @@ prompt." (member arg incomp))))) (transient-infix-set obj nil))))) +(defun transient-prefix-set (value) + "Set the value of the active transient prefix to VALUE. +Intended for use by transient suffix commands." + (oset transient--prefix value value) + (setq transient--refreshp 'updated-value)) + (cl-defgeneric transient-set-value (obj) - "Set the value of the transient prefix OBJ.") + "Persist the value of the transient prefix OBJ. +Only intended for use by `transient-set'. +Also see `transient-prefix-set'.") (cl-defmethod transient-set-value ((obj transient-prefix)) (oset (oref obj prototype) value (transient-get-value)) @@ -3495,7 +3523,7 @@ the set, saved or default value for PREFIX." (and (or (not (slot-exists-p obj 'unsavable)) (not (oref obj unsavable))) (transient--get-wrapped-value obj))) - transient-current-suffixes))) + (or transient--suffixes transient-current-suffixes)))) (defun transient--get-wrapped-value (obj) (and-let* ((value (transient-infix-value obj))) @@ -3954,6 +3982,24 @@ called inside the correct buffer (see `transient--insert-group') and its value is returned to the caller." (transient--get-description obj)) +(cl-defmethod transient-format-description ((obj transient-value-preset)) + (pcase-let* (((eieio description key set) obj) + ((eieio value) transient--prefix) + (active (seq-set-equal-p set value))) + (format + "%s %s" + (propertize (or description (format "Preset %s" key)) + 'face (and active 'transient-argument)) + (format (propertize "(%s)" 'face 'transient-delimiter) + (mapconcat (lambda (arg) + (propertize + arg 'face (cond (active 'transient-argument) + ((member arg value) + '((:weight demibold) + transient-inactive-argument)) + ('transient-inactive-argument)))) + set " "))))) + (cl-defmethod transient-format-description ((obj transient-group)) "Format the description by calling the next method. If the result doesn't use the `face' property at all, then apply the face -- 2.39.2