Skip to content

Commit 7eec625

Browse files
committed
transient-use-accessible-values: New option
1 parent 8efb181 commit 7eec625

1 file changed

Lines changed: 71 additions & 34 deletions

File tree

lisp/transient.el

Lines changed: 71 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,25 @@ in a more natural order."
563563
:group 'transient
564564
:type 'boolean)
565565

566+
(defcustom transient-use-accessible-values nil
567+
"Whether to show values in a way that does not rely on coloring.
568+
569+
By default faces are used to indicate the state of arguments and
570+
other values, in a way that makes those faces necessary. For example,
571+
if a command-line switch is enabled, it is shown in green, and if it
572+
disabled, it is shown in gray. Coloring aside, the exact same text
573+
is inserted in both cases.
574+
575+
If this is non-nil, then different text is inserted after the argument.
576+
For example, for a switch either \" is disable\" or \" is disabled\" is
577+
inserted after the switch.
578+
579+
If you enable this, then `transient-prefer-reading-value' should also
580+
be enabled. Also consider enabling `transient-use-accessible-formats'."
581+
:package-version '(transient . "0.13.0")
582+
:group 'transient
583+
:type 'boolean)
584+
566585
(defcustom transient-use-accessible-formats nil
567586
"Whether to use a more accessible formats for menu elements.
568587
@@ -574,7 +593,9 @@ By default the format specified by an elements `format' slot is used.
574593
When this is non-nil, then the `accessible-format' is used instead.
575594
The most notable difference is that for an element represent an
576595
argument or variable, the description is moved after the variable
577-
and value."
596+
and value.
597+
598+
Also consider enabling `transient-use-accessible-values'."
578599
:package-version '(transient . "0.13.0")
579600
:group 'transient
580601
:type 'boolean)
@@ -4971,44 +4992,60 @@ apply the face `transient-unreachable' to the complete string."
49714992
"Format OBJ's value for display and return the result.")
49724993

49734994
(cl-defmethod transient-format-value ((obj transient-suffix))
4974-
(propertize (oref obj argument) 'face (transient-argument-face obj)))
4995+
(with-slots (argument value inapt) obj
4996+
(concat (propertize argument 'face (transient-argument-face obj))
4997+
(cond ((not transient-use-accessible-values) nil)
4998+
(inapt " is inapt")
4999+
(value " is enabled")
5000+
(t " is disabled")))))
49755001

49765002
(cl-defmethod transient-format-value ((obj transient-option))
4977-
(let ((argument (prin1-to-string (oref obj argument) t)))
5003+
(let ((argument (prin1-to-string (oref obj argument) t))
5004+
(aface (transient-argument-face obj))
5005+
(vface (transient-value-face obj)))
49785006
(if-let ((value (oref obj value)))
4979-
(let* ((aface (transient-argument-face obj))
4980-
(vface (transient-value-face obj)))
4981-
(pcase-exhaustive (oref obj multi-value)
4982-
('nil
4983-
(concat (propertize argument 'face aface)
4984-
(propertize value 'face vface)))
4985-
((or 't 'rest)
4986-
(concat (propertize (if (string-suffix-p " " argument)
4987-
argument
4988-
(concat argument " "))
4989-
'face aface)
4990-
(propertize (mapconcat #'prin1-to-string value " ")
4991-
'face vface)))
4992-
('repeat
4993-
(mapconcat (lambda (value)
4994-
(concat (propertize argument 'face aface)
4995-
(propertize value 'face vface)))
4996-
value " "))))
4997-
(propertize argument 'face 'transient-inactive-argument))))
5007+
(pcase-exhaustive (oref obj multi-value)
5008+
('nil
5009+
(concat (propertize argument 'face aface)
5010+
(propertize value 'face vface)))
5011+
((or 't 'rest)
5012+
(concat (propertize (if (string-suffix-p " " argument)
5013+
argument
5014+
(concat argument " "))
5015+
'face aface)
5016+
(propertize (mapconcat #'prin1-to-string value " ")
5017+
'face vface)))
5018+
('repeat
5019+
(mapconcat (lambda (value)
5020+
(concat (propertize argument 'face aface)
5021+
(propertize value 'face vface)))
5022+
value " ")))
5023+
(concat (propertize (if (string-suffix-p "=" argument)
5024+
(substring argument 0 -1)
5025+
argument)
5026+
'face aface)
5027+
(and transient-use-accessible-values " is disabled")))))
49985028

49995029
(cl-defmethod transient-format-value ((obj transient-switches))
5000-
(with-slots (value argument-format choices) obj
5001-
(format (propertize argument-format 'face (transient-argument-face obj))
5002-
(format
5003-
(propertize "[%s]" 'face 'transient-delimiter)
5004-
(mapconcat
5005-
(lambda (choice)
5006-
(propertize choice 'face
5007-
(transient-value-face
5008-
obj
5009-
(equal (format argument-format choice) value))))
5010-
choices
5011-
(propertize "|" 'face 'transient-delimiter))))))
5030+
(pcase-let (((eieio value argument-format choices) obj)
5031+
(face (transient-argument-face obj)))
5032+
(cond
5033+
((not transient-use-accessible-values)
5034+
(format (propertize argument-format 'face face)
5035+
(format
5036+
(propertize "[%s]" 'face 'transient-delimiter)
5037+
(mapconcat
5038+
(lambda (choice)
5039+
(propertize choice 'face
5040+
(transient-value-face
5041+
obj
5042+
(equal (format argument-format choice) value))))
5043+
choices
5044+
(propertize "|" 'face 'transient-delimiter)))))
5045+
(value (propertize value 'face face))
5046+
((format "No %s argument is enabled"
5047+
(propertize (string-replace "%s" "*" argument-format)
5048+
'face face))))))
50125049

50135050
(defun transient-argument-face (obj)
50145051
(if (oref obj value)

0 commit comments

Comments
 (0)