branch: externals/transient
commit 4dfc3e78161700884c3c0ad81d14f68308ef56fd
Author: Jonas Bernoulli <[email protected]>
Commit: Jonas Bernoulli <[email protected]>

    transient-prefer-reading-value: New option
---
 docs/transient.org  | 18 ++++++++++++++++++
 docs/transient.texi | 18 ++++++++++++++++++
 lisp/transient.el   | 41 +++++++++++++++++++++++++++++++++++------
 3 files changed, 71 insertions(+), 6 deletions(-)

diff --git a/docs/transient.org b/docs/transient.org
index 4f232e695d..7fabeff12b 100644
--- a/docs/transient.org
+++ b/docs/transient.org
@@ -758,6 +758,24 @@ text at point, to be run when a transient menu is active, 
for example:
   related commands are displayed in the same column but navigation
   first moves horizontally to the next item on the same row.
 
+- User Option: transient-prefer-reading-value ::
+
+  This option controls whether reading a new value is preferred over
+  other value selection methods.
+
+  If this is ~nil~ (the default), then certain arguments are directly
+  disabled when they are invoked, while they have a non-~nil~ value.  I.e.,
+  to switch from one non-~nil~ value to another non-~nil~ value, such commands
+  have to be invoked twice.  For other arguments, which happen to have a
+  small set of possible values, all values are displayed at all times,
+  using solely coloring to indicate which of the values is active.  When
+  such an infix command is invoked it cycles to the next value.
+
+  This default does not work for visually impaired user.  If this option
+  is non-~nil~, then more arguments immediately read the new value, instead
+  of being toggled off on first invocation, or instead of cycling through
+  values.
+
 *** Auxiliary Options
 :PROPERTIES:
 :UNNUMBERED: notoc
diff --git a/docs/transient.texi b/docs/transient.texi
index e2baf0f827..faf2bb5228 100644
--- a/docs/transient.texi
+++ b/docs/transient.texi
@@ -912,6 +912,24 @@ related commands are displayed in the same column but 
navigation
 first moves horizontally to the next item on the same row.
 @end defopt
 
+@defopt transient-prefer-reading-value
+This option controls whether reading a new value is preferred over
+other value selection methods.
+
+If this is @code{nil} (the default), then certain arguments are directly
+disabled when they are invoked, while they have a non-@code{nil} value.  I.e.,
+to switch from one non-@code{nil} value to another non-@code{nil} value, such 
commands
+have to be invoked twice.  For other arguments, which happen to have a
+small set of possible values, all values are displayed at all times,
+using solely coloring to indicate which of the values is active.  When
+such an infix command is invoked it cycles to the next value.
+
+This default does not work for visually impaired user.  If this option
+is non-@code{nil}, then more arguments immediately read the new value, instead
+of being toggled off on first invocation, or instead of cycling through
+values.
+@end defopt
+
 @anchor{Auxiliary Options}
 @subheading Auxiliary Options
 
diff --git a/lisp/transient.el b/lisp/transient.el
index 22584f32e4..8aa469c479 100644
--- a/lisp/transient.el
+++ b/lisp/transient.el
@@ -428,6 +428,25 @@ This command is not bound by default, see its docstring 
for instructions."
   :group 'transient
   :type 'boolean)
 
+(defcustom transient-prefer-reading-value nil
+  "Whether to prefer reading new value over other value selection methods.
+
+If this is nil (the default), then certain arguments are directly
+disabled when they are invoked, while they have a non-nil value.  I.e.,
+to switch from one non-nil value to another non-nil value, such commands
+have to be invoked twice.  For other arguments, which happen to have a
+small set of possible values, all values are displayed at all times,
+using solely coloring to indicate which of the values is active.  When
+such an infix command is invoked it cycles to the next value.
+
+This default does not work for visually impaired user.  If this option
+is non-nil, then more arguments immediately read the new value, instead
+of being toggled off on first invocation, or instead of cycling through
+values."
+  :package-version '(transient . "0.13.0")
+  :group 'transient
+  :type 'boolean)
+
 (defcustom transient-highlight-mismatched-keys nil
   "Whether to highlight keys that do not match their argument.
 
@@ -3884,6 +3903,7 @@ it\", in which case it is pointless to preserve history.)"
   (with-slots (value multi-value always-read allow-empty choices) obj
     (if (and value
              (not multi-value)
+             (not transient-prefer-reading-value)
              (not always-read)
              transient--prefix)
         (oset obj value nil)
@@ -3928,16 +3948,24 @@ it\", in which case it is pointless to preserve 
history.)"
 
 (cl-defmethod transient-infix-read ((obj transient-switch))
   "Toggle the switch on or off."
-  (if (oref obj value) nil (oref obj argument)))
+  (prog1 (if (oref obj value) nil (oref obj argument))
+    (when transient-prefer-reading-value
+      (message "%s is now %s"
+               (oref obj argument)
+               (if (oref obj value) "enabled" "disabled")))))
 
 (cl-defmethod transient-infix-read ((obj transient-switches))
   "Cycle through the mutually exclusive switches.
 The last value is \"don't use any of these switches\"."
   (let ((choices (mapcar (apply-partially #'format (oref obj argument-format))
                          (oref obj choices))))
-    (if-let ((value (oref obj value)))
-        (cadr (member value choices))
-      (car choices))))
+    (cond-let
+      (transient-prefer-reading-value
+       (let ((choice (completing-read (transient-prompt obj) choices nil t)))
+         (if (equal choice "") nil choice)))
+      ([value (oref obj value)]
+       (cadr (member value choices)))
+      ((car choices)))))
 
 (cl-defmethod transient-infix-read ((command symbol))
   "Elsewhere use the reader of the infix command COMMAND.
@@ -4027,8 +4055,9 @@ prompt."
        (if (stringp prompt)
            prompt
          "[BUG: invalid prompt]: ")))
-    ([name (or (and (slot-boundp obj 'argument) (oref obj argument))
-               (and (slot-boundp obj 'variable) (oref obj variable)))]
+    ([name
+      (or (ignore-error (invalid-slot-name unbound-slot) (oref obj argument))
+          (ignore-error (invalid-slot-name unbound-slot) (oref obj variable)))]
      (if (and (stringp name)
               (string-suffix-p "=" name))
          name

Reply via email to