[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/transient 3bfde52f3a 175/366: Support dimming inapt com
From: |
Jonas Bernoulli |
Subject: |
[elpa] externals/transient 3bfde52f3a 175/366: Support dimming inapt commands |
Date: |
Tue, 25 Jan 2022 18:54:38 -0500 (EST) |
branch: externals/transient
commit 3bfde52f3a1f274d2d2ddcdfabc9904f4fc5001f
Author: Jonas Bernoulli <jonas@bernoul.li>
Commit: Jonas Bernoulli <jonas@bernoul.li>
Support dimming inapt commands
This still is subject to change and once things
have settled it will also needs to be documented.
Closes #80.
---
lisp/transient.el | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 70 insertions(+), 3 deletions(-)
diff --git a/lisp/transient.el b/lisp/transient.el
index 6b8a21f771..f2cbbd2ea9 100644
--- a/lisp/transient.el
+++ b/lisp/transient.el
@@ -381,6 +381,10 @@ Also see option `transient-highlight-mismatched-keys'."
Also see option `transient-highlight-mismatched-keys'."
:group 'transient-faces)
+(defface transient-inapt-suffix '((t :inherit shadow :italic t))
+ "Face used for suffixes that are inapt at this time."
+ :group 'transient-faces)
+
(defface transient-enabled-suffix
'((t :background "green" :foreground "black" :weight bold))
"Face used for enabled levels while editing suffix levels.
@@ -543,7 +547,40 @@ slot is non-nil."
(command :initarg :command)
(transient :initarg :transient)
(format :initarg :format :initform " %k %d")
- (description :initarg :description :initform nil))
+ (description :initarg :description :initform nil)
+ (inapt :initform nil)
+ (inapt-if
+ :initarg :inapt-if
+ :initform nil
+ :documentation "Inapt if predicate returns non-nil.")
+ (inapt-if-not
+ :initarg :inapt-if-not
+ :initform nil
+ :documentation "Inapt if predicate returns nil.")
+ (inapt-if-non-nil
+ :initarg :inapt-if-non-nil
+ :initform nil
+ :documentation "Inapt if variable's value is non-nil.")
+ (inapt-if-nil
+ :initarg :inapt-if-nil
+ :initform nil
+ :documentation "Inapt if variable's value is nil.")
+ (inapt-if-mode
+ :initarg :inapt-if-mode
+ :initform nil
+ :documentation "Inapt if major-mode matches value.")
+ (inapt-if-not-mode
+ :initarg :inapt-if-not-mode
+ :initform nil
+ :documentation "Inapt if major-mode does not match value.")
+ (inapt-if-derived
+ :initarg :inapt-if-derived
+ :initform nil
+ :documentation "Inapt if major-mode derives from value.")
+ (inapt-if-not-derived
+ :initarg :inapt-if-not-derived
+ :initform nil
+ :documentation "Inapt if major-mode does not derive from value."))
"Superclass for suffix command.")
(defclass transient-infix (transient-suffix)
@@ -1423,6 +1460,8 @@ of the corresponding object.")
(sub-prefix (and (symbolp cmd) (get cmd 'transient--prefix)))
(sym (transient--suffix-symbol cmd)))
(cond
+ ((oref obj inapt)
+ (define-key map (vector sym) 'transient--do-warn-inapt))
((slot-boundp obj 'transient)
(define-key map (vector sym)
(let ((do (oref obj transient)))
@@ -1573,8 +1612,10 @@ EDIT may be non-nil."
(transient--init-suffix-key obj)
(transient--ensure-infix-command obj)
(when (transient--use-suffix-p obj)
- (transient-init-scope obj)
- (transient-init-value obj)
+ (if (transient--inapt-suffix-p obj)
+ (oset obj inapt t)
+ (transient-init-scope obj)
+ (transient-init-value obj))
(list obj))))))
(cl-defmethod transient--init-suffix-key ((obj transient-suffix))
@@ -1609,6 +1650,18 @@ EDIT may be non-nil."
(oref obj if-not-derived)
t))
+(defun transient--inapt-suffix-p (obj)
+ (transient--do-suffix-p
+ (oref obj inapt-if)
+ (oref obj inapt-if-not)
+ (oref obj inapt-if-nil)
+ (oref obj inapt-if-non-nil)
+ (oref obj inapt-if-mode)
+ (oref obj inapt-if-not-mode)
+ (oref obj inapt-if-derived)
+ (oref obj inapt-if-not-derived)
+ nil))
+
(defun transient--do-suffix-p
(if if-not if-nil if-non-nil if-mode if-not-mode if-derived if-not-derived
default)
@@ -1884,6 +1937,11 @@ nil, then do nothing."
(setq this-command 'transient-undefined)
transient--stay)
+(defun transient--do-warn-inapt ()
+ "Call `transient-inapt' and stay transient."
+ (setq this-command 'transient-inapt)
+ transient--stay)
+
(defun transient--do-call ()
"Call the command after exporting variables and stay transient."
(transient--export)
@@ -1943,6 +2001,11 @@ to `transient--do-warn'."
(interactive)
(transient--invalid "Unbound suffix"))
+(defun transient-inapt ()
+ "Warn the user that the invoked command is inapt."
+ (interactive)
+ (transient--invalid "Inapt command"))
+
(defun transient--invalid (msg)
(ding)
(message "%s: `%s' (Use `%s' to abort, `%s' for help) [%s]"
@@ -2697,6 +2760,10 @@ Optional support for popup buttons is also implemented
here."
'transient-enabled-suffix
'transient-disabled-suffix))))
(cl-call-next-method obj))))
+ (when (oref obj inapt)
+ (set-text-properties 0 (length str)
+ (list 'face 'transient-inapt-suffix)
+ str))
(if transient-enable-popup-navigation
(make-text-button str nil
'type 'transient-button
- [elpa] externals/transient 37aec3ae59 144/366: Fix typo in doc-string, (continued)
- [elpa] externals/transient 37aec3ae59 144/366: Fix typo in doc-string, Jonas Bernoulli, 2022/01/25
- [elpa] externals/transient 76ac902ea5 149/366: Order CHANGELOG chronologically, Jonas Bernoulli, 2022/01/25
- [elpa] externals/transient fd7bb997ab 150/366: Complete CHANGELOG, Jonas Bernoulli, 2022/01/25
- [elpa] externals/transient afa0c2f984 152/366: Add redundant gitignore rules, Jonas Bernoulli, 2022/01/25
- [elpa] externals/transient 629c963e1f 153/366: manual: Fix typo, Jonas Bernoulli, 2022/01/25
- [elpa] externals/transient 53b71f9cc5 154/366: Fix documentation typo, Jonas Bernoulli, 2022/01/25
- [elpa] externals/transient 35c9d2b541 155/366: Use recommended form of GPLv3 permissions statement, Jonas Bernoulli, 2022/01/25
- [elpa] externals/transient 88d935c7cb 164/366: transient-display-buffer-action: inhibit-same-window by default, Jonas Bernoulli, 2022/01/25
- [elpa] externals/transient c1df3b2121 170/366: Ensure we use symbols in a few more places, Jonas Bernoulli, 2022/01/25
- [elpa] externals/transient b768a30199 174/366: transient--suffix-symbol: Verify that optimized path can be used, Jonas Bernoulli, 2022/01/25
- [elpa] externals/transient 3bfde52f3a 175/366: Support dimming inapt commands,
Jonas Bernoulli <=
- [elpa] externals/transient 2243650b95 183/366: transient--emergency-exit: Signal the error, Jonas Bernoulli, 2022/01/25
- [elpa] externals/transient f5d81ef0ed 186/366: transient-lisp-variable: New class, Jonas Bernoulli, 2022/01/25
- [elpa] externals/transient 96cec8e16e 187/366: manual: Use a favicon in html export, Jonas Bernoulli, 2022/01/25
- [elpa] externals/transient 2a79b61664 192/366: transient--emergency-exit: Always signal the error, Jonas Bernoulli, 2022/01/25
- [elpa] externals/transient 55bad19507 194/366: transient--pp-to-file: Bugfix, Jonas Bernoulli, 2022/01/25
- [elpa] externals/transient d1caef5192 198/366: Add new `init-value' infix slot, Jonas Bernoulli, 2022/01/25
- [elpa] externals/transient 990eb0a292 201/366: Don't bind "M-<key>" to any common commands, Jonas Bernoulli, 2022/01/25
- [elpa] externals/transient c8d0a17eba 207/366: transient--init-prefix: New function, Jonas Bernoulli, 2022/01/25
- [elpa] externals/transient 3c5ac3a989 208/366: transient--init-suffixes: New function, Jonas Bernoulli, 2022/01/25
- [elpa] externals/transient 517fe3b15e 209/366: transient--flatten-suffixes: New function, Jonas Bernoulli, 2022/01/25