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

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

[elpa] externals/transient ed2febd005 16/19: Support use of an infix arg


From: Jonas Bernoulli
Subject: [elpa] externals/transient ed2febd005 16/19: Support use of an infix argument following a prefix argument
Date: Mon, 2 May 2022 05:08:26 -0400 (EDT)

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

    Support use of an infix argument following a prefix argument
    
    Using a prefix argument activates `universal-argument--mode' whose
    keymap, `universal-argument-map', binds "-" to `negative-argument'.
    That binding conflicts with the prefix key used for most infix
    arguments.
    
    Counter that by "remapping" `negative-argument' to `transient-update',
    using a dedicated pre-command, but only if `negative-argument' was
    invoked using "-".  "C--", own binding for that command, remains
    functional.
    
    When remapped from `negative-argument', `transient-update' has to
    preserve the prefix argument for the next command.  This cannot happen
    earlier in the pre-command, because Emacs consumes `prefix-arg' in
    between `pre-command-hook' and the actual invocation of the command
    itself.
    
    `prefix-arg' has to be set directly because the function normally used
    to do so, `prefix-command-preserve-state', sets `this-command' to
    `last-command', which would mess with `transient--post-command'.
    Otherwise if the sequence of commands is (1) transient prefix command,
    (2) prefix argument, (3) infix argument, then `transient--post-command'
    would then act as if the prefix and infix arguments were never invoked.
---
 lisp/transient.el | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/lisp/transient.el b/lisp/transient.el
index c740c4779f..6213ccebaf 100644
--- a/lisp/transient.el
+++ b/lisp/transient.el
@@ -1605,7 +1605,7 @@ to `transient-predicate-map'.  Also see 
`transient-base-map'.")
     (define-key map [transient-history-prev]  #'transient--do-stay)
     (define-key map [transient-history-next]  #'transient--do-stay)
     (define-key map [universal-argument]      #'transient--do-stay)
-    (define-key map [negative-argument]       #'transient--do-stay)
+    (define-key map [negative-argument]       #'transient--do-minus)
     (define-key map [digit-argument]          #'transient--do-stay)
     (define-key map [transient-quit-all]      #'transient--do-quit-all)
     (define-key map [transient-quit-one]      #'transient--do-quit-one)
@@ -2416,6 +2416,14 @@ to `transient--do-warn'."
     (setq this-command 'transient-popup-navigation-help))
   transient--stay)
 
+(defun transient--do-minus ()
+  "Call `negative-argument' or pivot to `transient-update'.
+If `negative-argument' is invoked using \"-\" then preserve the
+prefix argument and pivot to `transient-update'."
+  (when (equal (this-command-keys) "-")
+    (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)
@@ -2429,6 +2437,7 @@ to `transient--do-warn'."
 (put 'transient--do-quit-one   'transient-color 'transient-blue)
 (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)
 
 ;;; Commands
 
@@ -2496,7 +2505,9 @@ transient is active."
 
 (defun transient-update ()
   "Redraw the transient's state in the popup buffer."
-  (interactive))
+  (interactive)
+  (when (equal this-original-command 'negative-argument)
+    (setq prefix-arg current-prefix-arg)))
 
 (defun transient-show ()
   "Show the transient's state in the popup buffer."



reply via email to

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