[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/transient c8a9ac5124 18/26: Simplify how colors are use
|
From: |
Jonas Bernoulli |
|
Subject: |
[elpa] externals/transient c8a9ac5124 18/26: Simplify how colors are used to indicate transient behavior |
|
Date: |
Sun, 26 Nov 2023 19:42:08 -0500 (EST) |
branch: externals/transient
commit c8a9ac512432398a10b788a915c924b105f520a8
Author: Jonas Bernoulli <jonas@bernoul.li>
Commit: Jonas Bernoulli <jonas@bernoul.li>
Simplify how colors are used to indicate transient behavior
The old implementation mimicked how Hydra uses them. It's was a neat
idea, but in practice I was never able to remember what the difference
between a pink and a amaranth prefix/hydra is, for example.
So I'm giving up on encoding the separate behaviors of suffixes and
non-suffixes, using a single color. Instead the behavior of each
individual suffix is visualized by coloring its key binding (as
before), and by using the separator line to visualize the behavior
common to all non-suffixes (without additionally encoding the default
suffix behavior by blending colors).
Also change the colors used for "exit" and "stay" behavior. IMO it
makes more sense if "red" means "exit" instead of "stay", but of
course you are welcome to disagree. Its much less mind-bending to do
that now, because the new faces use names that describe their behavior
instead of an arbitrary color encoding. Previously one would have had
to make `transient-red' "green" and `transient-blue' "red" to achieve
the new default behavior, for example.
Finally, now that this has been simplified, enable it by default.
---
docs/transient.org | 22 +++---
docs/transient.texi | 22 +++---
lisp/transient.el | 211 +++++++++++++++++++++-------------------------------
3 files changed, 108 insertions(+), 147 deletions(-)
diff --git a/docs/transient.org b/docs/transient.org
index ea30dbd8c1..3358af4e88 100644
--- a/docs/transient.org
+++ b/docs/transient.org
@@ -623,28 +623,30 @@ Also see [[* Common Suffix Commands]].
displayed right above the echo area, then this probably is not a
good value.
- If ~line~ (the default), then the buffer also has no mode-line, but a
- thin line is drawn instead, using the background color of the face
- ~transient-separator~. Text-mode frames cannot display thin lines,
- and therefore fall back to treating ~line~ like ~nil~.
+ If ~line~ (the default), then the buffer also has no mode-line,
+ but a thin line is drawn instead. On termcap frames that is is
+ not possible, so there ~line~ is treated as a synonym for ~nil~.
+
+ The color of the line is used to indicate if non-suffixes are
+ allowed and whether they exit the transient. The foreground
+ color of ~transient-key-noop~ (if non-suffix are disallowed),
+ ~transient-key-stay~ (if allowed and transient stays active), or
+ ~transient-key-exit~ (if allowed and they exit the transient) is
+ used to draw the line.
Otherwise this can be any mode-line format. See [[info:elisp#Mode
Line Format]], for details.
- User Option: transient-semantic-coloring ::
- This option controls whether prefixes and suffixes are colored in
- a Hydra-like fashion.
+ This option controls whether colors are used to indicate the
+ transient behavior of commands.
If non-~nil~, then the key binding of each suffix is colorized to
indicate whether it exits the transient state or not. The color of
the prefix is indicated using the line that is drawn when the value
of ~transient-mode-line-format~ is ~line~.
- For more information about how Hydra uses colors see
- https://github.com/abo-abo/hydra#color and
- https://oremacs.com/2015/02/19/hydra-colors-reloaded.
-
- User Option: transient-highlight-mismatched-keys ::
This option controls whether key bindings of infix commands that do
diff --git a/docs/transient.texi b/docs/transient.texi
index 3abd54c1d3..b7efd031aa 100644
--- a/docs/transient.texi
+++ b/docs/transient.texi
@@ -770,26 +770,28 @@ If @code{nil}, then the buffer has no mode-line. If the
buffer is not
displayed right above the echo area, then this probably is not a
good value.
-If @code{line} (the default), then the buffer also has no mode-line, but a
-thin line is drawn instead, using the background color of the face
-@code{transient-separator}. Text-mode frames cannot display thin lines,
-and therefore fall back to treating @code{line} like @code{nil}.
+If @code{line} (the default), then the buffer also has no mode-line,
+but a thin line is drawn instead. On termcap frames that is is
+not possible, so there @code{line} is treated as a synonym for @code{nil}.
+
+The color of the line is used to indicate if non-suffixes are
+allowed and whether they exit the transient. The foreground
+color of @code{transient-key-noop} (if non-suffix are disallowed),
+@code{transient-key-stay} (if allowed and transient stays active), or
+@code{transient-key-exit} (if allowed and they exit the transient) is
+used to draw the line.
Otherwise this can be any mode-line format. See @ref{Mode Line
Format,,,elisp,}, for details.
@end defopt
@defopt transient-semantic-coloring
-This option controls whether prefixes and suffixes are colored in
-a Hydra-like fashion.
+This option controls whether colors are used to indicate the
+transient behavior of commands.
If non-@code{nil}, then the key binding of each suffix is colorized to
indicate whether it exits the transient state or not. The color of
the prefix is indicated using the line that is drawn when the value
of @code{transient-mode-line-format} is @code{line}.
-
-For more information about how Hydra uses colors see
-@uref{https://github.com/abo-abo/hydra#color} and
-@uref{https://oremacs.com/2015/02/19/hydra-colors-reloaded}.
@end defopt
@defopt transient-highlight-mismatched-keys
diff --git a/lisp/transient.el b/lisp/transient.el
index 6d46d5809e..c763bc7629 100644
--- a/lisp/transient.el
+++ b/lisp/transient.el
@@ -205,9 +205,15 @@ displayed right above the echo area, then this probably is
not
a good value.
If `line' (the default), then the buffer also has no mode-line,
-but a thin line is drawn instead, using the background color of
-the face `transient-separator'. Termcap frames cannot display
-thin lines and therefore fallback to treating `line' like nil.
+but a thin line is drawn instead. On termcap frames that is is
+not possible, so there `line' is treated as a synonym for nil.
+
+The color of the line is used to indicate if non-suffixes are
+allowed and whether they exit the transient. The foreground
+color of `transient-key-noop' (if non-suffix are disallowed),
+`transient-key-stay' (if allowed and transient stays active), or
+`transient-key-exit' (if allowed and they exit the transient) is
+used to draw the line.
Otherwise this can be any mode-line format.
See `mode-line-format' for details."
@@ -291,19 +297,14 @@ using a layout optimized for Lisp.
:group 'transient
:type '(choice (const :tag "Transform no keys (nil)" nil) function))
-(defcustom transient-semantic-coloring nil
- "Whether to color prefixes and suffixes in Hydra-like fashion.
-This feature is experimental.
+(defcustom transient-semantic-coloring t
+ "Whether to use colors to indicate transient behavior.
If non-nil, then the key binding of each suffix is colorized to
-indicate whether it exits the transient state or not. The color
-of the prefix is indicated using the line that is drawn when the
-value of `transient-mode-line-format' is `line'.
-
-For more information about how Hydra uses colors see
-https://github.com/abo-abo/hydra#color and
-https://oremacs.com/2015/02/19/hydra-colors-reloaded."
- :package-version '(transient . "0.3.0")
+indicate whether it exits the transient state or not, and the
+line that is drawn below the transient popup buffer is used to
+indicate the behavior of non-suffix commands."
+ :package-version '(transient . "0.5.0")
:group 'transient
:type 'boolean)
@@ -497,75 +498,60 @@ character used to separate possible values from each
other."
"Face used for keys."
:group 'transient-faces)
-(defface transient-unreachable-key '((t :inherit (shadow transient-key)))
- "Face used for keys unreachable from the current prefix sequence."
+(defface transient-key-stay
+ `((((class color) (background light))
+ :inherit transient-key
+ :foreground "#22aa22")
+ (((class color) (background dark))
+ :inherit transient-key
+ :foreground "#ddffdd"))
+ "Face used for."
:group 'transient-faces)
-(defface transient-nonstandard-key '((t :underline t))
- "Face optionally used to highlight keys conflicting with short-argument.
-Also see option `transient-highlight-mismatched-keys'."
+(defface transient-key-noop
+ `((((class color) (background light))
+ :inherit transient-key
+ :foreground "grey80")
+ (((class color) (background dark))
+ :inherit transient-key
+ :foreground "grey30"))
+ "Face used for."
:group 'transient-faces)
-(defface transient-mismatched-key '((t :underline t))
- "Face optionally used to highlight keys without a short-argument.
-Also see option `transient-highlight-mismatched-keys'."
+(defface transient-key-return
+ `((((class color) (background light))
+ :inherit transient-key
+ :foreground "#aaaa11")
+ (((class color) (background dark))
+ :inherit transient-key
+ :foreground "#ffffcc"))
+ "Face used for."
:group 'transient-faces)
-(defface transient-separator-line
+(defface transient-key-exit
`((((class color) (background light))
- ,@(and (>= emacs-major-version 27) '(:extend t))
- :background "grey80")
- (((class color) (background dark))
- ,@(and (>= emacs-major-version 27) '(:extend t))
- :background "grey30"))
- "Face used to draw line below transient popup window.
-This is only used if `transient-mode-line-format' is `line'.
-Only the background color is significant."
+ :inherit transient-key
+ :foreground "#aa2222")
+ (((class color) (background dark))
+ :inherit transient-key
+ :foreground "#ffdddd"))
+ "Face used for."
:group 'transient-faces)
-(define-obsolete-face-alias 'transient-separator 'transient-separator-line
- "Transient 0.5.0")
-
-(defgroup transient-color-faces
- '((transient-semantic-coloring custom-variable))
- "Faces used by Transient for Hydra-like command coloring.
-These faces are only used if `transient-semantic-coloring'
-\(which see) is non-nil."
+(defface transient-unreachable-key
+ '((t :inherit (shadow transient-key) :weight normal))
+ "Face used for keys unreachable from the current prefix sequence."
:group 'transient-faces)
-(defface transient-red
- '((t :inherit transient-key :foreground "red"))
- "Face used for red prefixes and suffixes."
- :group 'transient-color-faces)
-
-(defface transient-blue
- '((t :inherit transient-key :foreground "blue"))
- "Face used for blue prefixes and suffixes."
- :group 'transient-color-faces)
-
-(defface transient-amaranth
- '((t :inherit transient-key :foreground "#E52B50"))
- "Face used for amaranth prefixes."
- :group 'transient-color-faces)
-
-(defface transient-pink
- '((t :inherit transient-key :foreground "#FF6EB4"))
- "Face used for pink prefixes."
- :group 'transient-color-faces)
-
-(defface transient-teal
- '((t :inherit transient-key :foreground "#367588"))
- "Face used for teal prefixes."
- :group 'transient-color-faces)
-
-(defface transient-purple
- '((t :inherit transient-key :foreground "#a020f0"))
- "Face used for purple prefixes.
+(defface transient-nonstandard-key '((t :underline t))
+ "Face optionally used to highlight keys conflicting with short-argument.
+Also see option `transient-highlight-mismatched-keys'."
+ :group 'transient-faces)
-This is an addition to the colors supported by Hydra. It is
-used by suffixes that quit the current prefix but return to
-the previous prefix."
- :group 'transient-color-faces)
+(defface transient-mismatched-key '((t :underline t))
+ "Face optionally used to highlight keys without a short-argument.
+Also see option `transient-highlight-mismatched-keys'."
+ :group 'transient-faces)
;;; Persistence
@@ -2662,24 +2648,24 @@ prefix argument and pivot to `transient-update'."
(setq this-command 'transient-update))
transient--stay)
-(put 'transient--do-stay 'transient-color 'transient-red)
-(put 'transient--do-noop 'transient-color 'transient-red)
-(put 'transient--do-warn 'transient-color 'transient-red)
-(put 'transient--do-warn-inapt 'transient-color 'transient-red)
-(put 'transient--do-call 'transient-color 'transient-red)
-(put 'transient--do-return 'transient-color 'transient-purple)
-(put 'transient--do-exit 'transient-color 'transient-blue)
-(put 'transient--do-leave 'transient-color 'transient-blue)
-
-(put 'transient--do-recurse 'transient-color 'transient-red)
-(put 'transient--do-stack 'transient-color 'transient-red)
-(put 'transient--do-replace 'transient-color 'transient-blue)
-(put 'transient--do-suspend 'transient-color 'transient-blue)
-
-(put 'transient--do-quit-one 'transient-color 'transient-purple)
-(put 'transient--do-quit-all 'transient-color 'transient-blue)
-(put 'transient--do-move 'transient-color 'transient-red)
-(put 'transient--do-minus 'transient-color 'transient-red)
+(put 'transient--do-stay 'transient-face 'transient-key-stay)
+(put 'transient--do-noop 'transient-face 'transient-key-noop)
+(put 'transient--do-warn 'transient-face 'transient-key-noop)
+(put 'transient--do-warn-inapt 'transient-face 'transient-key-noop)
+(put 'transient--do-call 'transient-face 'transient-key-stay)
+(put 'transient--do-return 'transient-face 'transient-key-return)
+(put 'transient--do-exit 'transient-face 'transient-key-exit)
+(put 'transient--do-leave 'transient-face 'transient-key-exit)
+
+(put 'transient--do-recurse 'transient-face 'transient-key-stay)
+(put 'transient--do-stack 'transient-face 'transient-key-stay)
+(put 'transient--do-replace 'transient-face 'transient-key-exit)
+(put 'transient--do-suspend 'transient-face 'transient-key-exit)
+
+(put 'transient--do-quit-one 'transient-face 'transient-key-return)
+(put 'transient--do-quit-all 'transient-face 'transient-key-exit)
+(put 'transient--do-move 'transient-face 'transient-key-stay)
+(put 'transient--do-minus 'transient-face 'transient-key-stay)
;;; Commands
;;;; Noop
@@ -3528,11 +3514,9 @@ have a history of their own.")
(and (eq transient-mode-line-format 'line)
window-system
(let ((face
- (if-let ((f (and (transient--semantic-coloring-p)
- (transient--prefix-color transient--prefix))))
- `(,@(and (>= emacs-major-version 27) '(:extend t))
- :background ,(face-foreground f))
- 'transient-separator-line)))
+ `(,@(and (>= emacs-major-version 27) '(:extend t))
+ :background ,(or (face-foreground (transient--key-face) nil t)
+ "#gray60"))))
(concat (propertize "__" 'face face 'display '(space :height (1)))
(propertize "\n" 'face face 'line-height t)))))
@@ -3877,9 +3861,12 @@ If the OBJ's `key' is currently unreachable, then apply
the face
face)))
(defun transient--key-face (&optional cmd)
- (or (and (transient--semantic-coloring-p)
- (transient--suffix-color cmd))
- 'transient-key))
+ (or (and transient-semantic-coloring
+ (not transient--helpp)
+ (not transient--editp)
+ (or (and cmd (get cmd 'transient-face))
+ (get (transient--get-pre-command cmd) 'transient-face)))
+ (if cmd 'transient-key 'transient-key-noop)))
(defun transient--key-unreachable-p (obj)
(and transient--redisplay-key
@@ -4205,36 +4192,6 @@ search instead."
(select-window transient--original-window)
(transient--resume-override))
-;;;; Hydra Color Emulation
-
-(defun transient--semantic-coloring-p ()
- (and transient-semantic-coloring
- (not transient--helpp)
- (not transient--editp)))
-
-(defun transient--suffix-color (command)
- (or (get command 'transient-color)
- (get (transient--get-pre-command command) 'transient-color)))
-
-(defun transient--prefix-color (command)
- (let* ((nonsuf (or (oref command transient-non-suffix)
- 'transient--do-warn))
- (nonsuf (if (memq nonsuf '(transient--do-noop transient--do-warn))
- 'disallow
- (get nonsuf 'transient-color)))
- (suffix (if-let ((pred (oref command transient-suffix)))
- (get pred 'transient-color)
- (if (eq nonsuf 'transient-red)
- 'transient-red
- 'transient-blue))))
- (pcase (list suffix nonsuf)
- (`(transient-purple ,_) 'transient-purple)
- ('(transient-red disallow) 'transient-amaranth)
- ('(transient-blue disallow) 'transient-teal)
- ('(transient-red transient-red) 'transient-pink)
- ('(transient-red transient-blue) 'transient-red)
- ('(transient-blue transient-blue) 'transient-blue))))
-
;;;; Edebug
(defun transient--edebug-command-p ()
- [elpa] externals/transient 4c1cda9984 08/26: Rename transient-get-{predicate-for => pre-command}, (continued)
- [elpa] externals/transient 4c1cda9984 08/26: Rename transient-get-{predicate-for => pre-command}, Jonas Bernoulli, 2023/11/26
- [elpa] externals/transient f4b4dd42b9 14/26: Add transient--do-leave's missing color setting, Jonas Bernoulli, 2023/11/26
- [elpa] externals/transient 0509c90e53 11/26: transient--key-face: New function, Jonas Bernoulli, 2023/11/26
- [elpa] externals/transient 05754d1576 13/26: Rearrange pre-command color settings, Jonas Bernoulli, 2023/11/26
- [elpa] externals/transient 98d8cf8016 15/26: Fix transient--do-quit-one's color setting, Jonas Bernoulli, 2023/11/26
- [elpa] externals/transient 9c00fae158 10/26: transient--add-face: Move definition, Jonas Bernoulli, 2023/11/26
- [elpa] externals/transient b1951a87b5 09/26: transient--resolve-pre-command: Optionally resolve boolean as well, Jonas Bernoulli, 2023/11/26
- [elpa] externals/transient 9a21467706 12/26: transient--separator-line: New function, Jonas Bernoulli, 2023/11/26
- [elpa] externals/transient 47d3f01d9f 17/26: Fix/improve some faces, Jonas Bernoulli, 2023/11/26
- [elpa] externals/transient ad7a098349 16/26: Rearrange face definitions, Jonas Bernoulli, 2023/11/26
- [elpa] externals/transient c8a9ac5124 18/26: Simplify how colors are used to indicate transient behavior,
Jonas Bernoulli <=
- [elpa] externals/transient 9f3afe94a9 19/26: transient-format(around:suffix): Reformat docstring, Jonas Bernoulli, 2023/11/26
- [elpa] externals/transient 48a1aa2bea 24/26: transient-highlight-mismatched-keys: Fix docstring typos, Jonas Bernoulli, 2023/11/26
- [elpa] externals/transient 46813a03f6 23/26: In support of the lovely pcase, Jonas Bernoulli, 2023/11/26
- [elpa] externals/transient 307695d2df 21/26: transient-format-description(around:suffix): Combine faces, Jonas Bernoulli, 2023/11/26
- [elpa] externals/transient 7f0215c4df 22/26: transient-format-value(option, value): Use argument faces, Jonas Bernoulli, 2023/11/26
- [elpa] externals/transient d834f76492 20/26: transient-format(around:suffix): Don't attempt to highlight full line, Jonas Bernoulli, 2023/11/26
- [elpa] externals/transient 71d16d86f1 25/26: Improve looks of debugging faces, Jonas Bernoulli, 2023/11/26
- [elpa] externals/transient af6eb31054 26/26: transient-format: Only highlight infix if minibuffer is used, Jonas Bernoulli, 2023/11/26