[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/transient 248862c58e 178/366: Add experimental support
From: |
Jonas Bernoulli |
Subject: |
[elpa] externals/transient 248862c58e 178/366: Add experimental support for semantic coloring |
Date: |
Tue, 25 Jan 2022 18:54:39 -0500 (EST) |
branch: externals/transient
commit 248862c58e3bc0c13c6e3315adc2f3bb43c3c476
Author: Jonas Bernoulli <jonas@bernoul.li>
Commit: Jonas Bernoulli <jonas@bernoul.li>
Add experimental support for semantic coloring
This emulates the coloring used by Hydra.
See https://github.com/abo-abo/hydra#color.
Or better from https://oremacs.com/2015/02/19/hydra-colors-reloaded:
|----------+-----------+-----------------------+-----------------|
| Body | Head | Executing NON-HEADS | Executing HEADS |
| Color | Inherited | | |
| | Color | | |
|----------+-----------+-----------------------+-----------------|
| amaranth | red | Disallow and Continue | Continue |
| teal | blue | Disallow and Continue | Quit |
| pink | red | Allow and Continue | Continue |
| red | red | Allow and Quit | Continue |
| blue | blue | Allow and Quit | Quit |
|----------+-----------+-----------------------+-----------------|
---
lisp/transient.el | 115 +++++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 106 insertions(+), 9 deletions(-)
diff --git a/lisp/transient.el b/lisp/transient.el
index 2f4250c377..c8312999e3 100644
--- a/lisp/transient.el
+++ b/lisp/transient.el
@@ -242,6 +242,22 @@ 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.
+
+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")
+ :group 'transient
+ :type 'boolean)
+
(defcustom transient-detect-key-conflicts nil
"Whether to detect key binding conflicts.
@@ -409,6 +425,38 @@ This is only used if `transient-mode-line-format' is
`line'.
Only the background color is significant."
:group 'transient-faces)
+(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."
+ :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)
+
;;; Persistence
(defun transient--read-file-contents (file)
@@ -1993,6 +2041,18 @@ to `transient--do-warn'."
(setq this-command 'transient-popup-navigation-help))
transient--stay)
+(put 'transient--do-stay 'transient-color 'transient-blue)
+(put 'transient--do-noop 'transient-color 'transient-blue)
+(put 'transient--do-warn 'transient-color 'transient-blue)
+(put 'transient--do-warn-inapt 'transient-color 'transient-blue)
+(put 'transient--do-call 'transient-color 'transient-blue)
+(put 'transient--do-exit 'transient-color 'transient-red)
+(put 'transient--do-replace 'transient-color 'transient-red)
+(put 'transient--do-suspend 'transient-color 'transient-red)
+(put 'transient--do-quit-one 'transient-color 'transient-red)
+(put 'transient--do-quit-all 'transient-color 'transient-red)
+(put 'transient--do-move 'transient-color 'transient-blue)
+
;;; Commands
(defun transient-noop ()
@@ -2645,9 +2705,14 @@ have a history of their own.")
(transient--insert-help))
(when (and (eq transient-mode-line-format 'line)
window-system)
- (insert (propertize "__" 'face 'transient-separator
- 'display '(space :height (1))))
- (insert (propertize "\n" 'face 'transient-separator 'line-height t)))
+ (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)))
+ (insert (propertize "__" 'face face 'display '(space :height (1))))
+ (insert (propertize "\n" 'face face 'line-height t))))
(let ((window-resize-pixelwise t)
(window-size-fixed nil))
(fit-window-to-buffer nil nil 1))
@@ -2796,7 +2861,8 @@ Optional support for popup buttons is also implemented
here."
(cl-defmethod transient-format-key ((obj transient-suffix))
"Format OBJ's `key' for display and return the result."
- (let ((key (oref obj key)))
+ (let ((key (oref obj key))
+ (cmd (oref obj command)))
(if transient--redisplay-key
(let ((len (length transient--redisplay-key))
(seq (cl-coerce (edmacro-parse-keys key t) 'list)))
@@ -2818,19 +2884,21 @@ Optional support for popup buttons is also implemented
here."
(setq suf (replace-regexp-in-string " " "" suf)))
(concat (propertize pre 'face 'default)
(and (string-prefix-p (concat pre " ") key) " ")
- (transient--colorize-key suf)
+ (transient--colorize-key suf cmd)
(save-excursion
(when (string-match " +\\'" key)
(match-string 0 key))))))
((transient--lookup-key transient-sticky-map (kbd key))
- (transient--colorize-key key))
+ (transient--colorize-key key cmd))
(t
(propertize key 'face 'transient-unreachable-key))))
- (transient--colorize-key key))))
+ (transient--colorize-key key cmd))))
-(defun transient--colorize-key (key)
+(defun transient--colorize-key (key command)
(propertize key 'face
- 'transient-key))
+ (or (and (transient--semantic-coloring-p)
+ (transient--suffix-color command))
+ 'transient-key)))
(cl-defmethod transient-format-key :around ((obj transient-argument))
(let ((key (cl-call-next-method obj)))
@@ -3196,6 +3264,35 @@ 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-predicate-for 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-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--recursive-edit (fn arg-mode)
- [elpa] externals/transient c8cc9f6d24 147/366: Add .mailmap, (continued)
- [elpa] externals/transient c8cc9f6d24 147/366: Add .mailmap, Jonas Bernoulli, 2022/01/25
- [elpa] externals/transient a269614c69 151/366: Release version 0.2.0, Jonas Bernoulli, 2022/01/25
- [elpa] externals/transient c94cff7474 159/366: Fix typo, Jonas Bernoulli, 2022/01/25
- [elpa] externals/transient dd0c44cb2d 160/366: Use the package prefix for everything, Jonas Bernoulli, 2022/01/25
- [elpa] externals/transient 30387690fd 161/366: Autoload functions that users might use without requiring transient, Jonas Bernoulli, 2022/01/25
- [elpa] externals/transient 4f0bd45d88 166/366: transient--make-predicate-map: Cosmetics, Jonas Bernoulli, 2022/01/25
- [elpa] externals/transient 9b777fa120 167/366: transient--invalid: New function, Jonas Bernoulli, 2022/01/25
- [elpa] externals/transient 38fd406eac 168/366: transient--invalid: Emphasize command name, Jonas Bernoulli, 2022/01/25
- [elpa] externals/transient 769fa4380a 169/366: transient-set-level: Fix edge-case, Jonas Bernoulli, 2022/01/25
- [elpa] externals/transient b52c623217 177/366: transient--colorize-key: New function, Jonas Bernoulli, 2022/01/25
- [elpa] externals/transient 248862c58e 178/366: Add experimental support for semantic coloring,
Jonas Bernoulli <=
- [elpa] externals/transient dd9c40adc3 180/366: transient-setup: Handle edge-case, Jonas Bernoulli, 2022/01/25
- [elpa] externals/transient 4d44d08e90 181/366: Tell package.el to compile this library properly, Jonas Bernoulli, 2022/01/25
- [elpa] externals/transient 53d3885371 182/366: transient--emergency-exit: Show debug message, Jonas Bernoulli, 2022/01/25
- [elpa] externals/transient 879f45f0c9 184/366: transient--with-emergency-exit: Define earlier, Jonas Bernoulli, 2022/01/25
- [elpa] externals/transient a7f6c3c23d 191/366: transient-plist-to-alist: New utility function, Jonas Bernoulli, 2022/01/25
- [elpa] externals/transient cb740f5a4e 203/366: transient-lisp-variable: Add new set-value slot, Jonas Bernoulli, 2022/01/25
- [elpa] externals/transient afdf1f0050 066/366: Clean echo-area when the timer shows the popup, Jonas Bernoulli, 2022/01/25
- [elpa] externals/transient e7a16d2006 076/366: Bring back isearch in transient popups, Jonas Bernoulli, 2022/01/25
- [elpa] externals/transient 17ad01e0c7 079/366: Don't explicitly require isearch, Jonas Bernoulli, 2022/01/25
- [elpa] externals/transient 1e090b0cd4 240/366: Fixup changelog, Jonas Bernoulli, 2022/01/25