summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Bernoulli <jonas@bernoul.li>2023-11-11 18:08:02 +0100
committerJonas Bernoulli <jonas@bernoul.li>2023-11-11 18:08:02 +0100
commit9617b6c77c36b2e49895d5626c895cc4b8660873 (patch)
treef88ddd2357bd11168aca15efc709527305c55c2a
parent94661e0ccd5471f190022d34e76f600c46eb8b88 (diff)
transient--make-predicate-map: Support shorthands
-rw-r--r--docs/transient.org3
-rw-r--r--docs/transient.texi3
-rw-r--r--lisp/transient.el16
3 files changed, 17 insertions, 5 deletions
diff --git a/docs/transient.org b/docs/transient.org
index 615adbb..8b13efb 100644
--- a/docs/transient.org
+++ b/docs/transient.org
@@ -1262,7 +1262,8 @@ The default behavior while a transient is active is as follows:
The behavior can be changed for all suffixes of a particular prefix
and/or for individual suffixes. The values should nearly always be
booleans, but certain functions, called “pre-commands”, can also be
-used.
+used. These functions are named ~transient--do-VERB~, and the symbol
+~VERB~ can be used as a shorthand.
A boolean is interpreted as answering the question "does the
transient stay active, when this command is invoked?" ~t~ means that
diff --git a/docs/transient.texi b/docs/transient.texi
index 9c4730f..bed2501 100644
--- a/docs/transient.texi
+++ b/docs/transient.texi
@@ -1450,7 +1450,8 @@ warning. This does not ``deactivate'' the transient.
The behavior can be changed for all suffixes of a particular prefix
and/or for individual suffixes. The values should nearly always be
booleans, but certain functions, called “pre-commands”, can also be
-used.
+used. These functions are named @code{transient--do-VERB}, and the symbol
+@code{VERB} can be used as a shorthand.
A boolean is interpreted as answering the question "does the
transient stay active, when this command is invoked?" @code{t} means that
diff --git a/lisp/transient.el b/lisp/transient.el
index 2b81822..e015678 100644
--- a/lisp/transient.el
+++ b/lisp/transient.el
@@ -1760,7 +1760,8 @@ of the corresponding object."
map))
(defun transient--make-predicate-map ()
- (let* ((default (oref transient--prefix transient-suffix))
+ (let* ((default (transient--resolve-pre-command
+ (oref transient--prefix transient-suffix)))
(return (eq default t))
(map (make-sparse-keymap)))
(set-keymap-parent map transient-predicate-map)
@@ -1777,7 +1778,9 @@ of the corresponding object."
(define-key map (vector cmd) #'transient--do-warn-inapt))
((slot-boundp obj 'transient)
(define-key map (vector cmd)
- (pcase (list kind (oref obj transient) return)
+ (pcase (list kind
+ (transient--resolve-pre-command (oref obj transient))
+ return)
(`(prefix t ,_) #'transient--do-recurse)
(`(prefix nil ,_) #'transient--do-stack)
(`(infix t ,_) #'transient--do-stay)
@@ -2151,12 +2154,19 @@ value. Otherwise return CHILDREN as is."
(or (ignore-errors
(lookup-key transient--predicate-map (vector cmd)))
(and (not suffix-only)
- (let ((pred (oref transient--prefix transient-non-suffix)))
+ (let ((pred (transient--resolve-pre-command
+ (oref transient--prefix transient-non-suffix))))
(pcase pred
('t #'transient--do-stay)
('nil #'transient--do-warn)
(_ pred))))))
+(defun transient--resolve-pre-command (pre)
+ (cond ((booleanp pre) pre)
+ ((string-match-p "--do-" (symbol-name pre)) pre)
+ ((let ((sym (intern (format "transient--do-%s" pre))))
+ (if (functionp sym) sym pre)))))
+
(defun transient--pre-exit ()
(transient--debug 'pre-exit)
(transient--delete-window)