emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/transient 9617b6c77c 35/41: transient--make-predicate-m


From: Jonas Bernoulli
Subject: [elpa] externals/transient 9617b6c77c 35/41: transient--make-predicate-map: Support shorthands
Date: Sun, 12 Nov 2023 20:04:09 -0500 (EST)

branch: externals/transient
commit 9617b6c77c36b2e49895d5626c895cc4b8660873
Author: Jonas Bernoulli <jonas@bernoul.li>
Commit: Jonas Bernoulli <jonas@bernoul.li>

    transient--make-predicate-map: Support shorthands
---
 docs/transient.org  |  3 ++-
 docs/transient.texi |  3 ++-
 lisp/transient.el   | 16 +++++++++++++---
 3 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/docs/transient.org b/docs/transient.org
index 615adbbcab..8b13efb4fc 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 9c4730fd4d..bed2501e63 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 2b81822baf..e015678c28 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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]