[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/transient bb056e7156 13/17: Invoke suffix commands dire
From: |
Jonas Bernoulli |
Subject: |
[elpa] externals/transient bb056e7156 13/17: Invoke suffix commands directly when a button is pushed |
Date: |
Fri, 25 Mar 2022 06:22:18 -0400 (EDT) |
branch: externals/transient
commit bb056e7156b3d88f42770ec55e1a7447a95aca96
Author: Jonas Bernoulli <jonas@bernoul.li>
Commit: Jonas Bernoulli <jonas@bernoul.li>
Invoke suffix commands directly when a button is pushed
Using wrapper commands that call `pust-button' messed things up
because the latter selects the window where the user clicked,
which we very much want to avoid doing.
---
lisp/transient.el | 61 +++++++++++++++++++++++++++++++------------------------
1 file changed, 35 insertions(+), 26 deletions(-)
diff --git a/lisp/transient.el b/lisp/transient.el
index 8d8c24413f..6cbb55b63d 100644
--- a/lisp/transient.el
+++ b/lisp/transient.el
@@ -1599,7 +1599,7 @@ to `transient-predicate-map'. Also see
`transient-base-map'.")
(define-key map [scroll-bar-toolkit-scroll] #'transient--do-stay)
(define-key map [transient-noop] #'transient--do-noop)
(define-key map [transient-mouse-push-button] #'transient--do-move)
- (define-key map [transient-push-button] #'transient--do-move)
+ (define-key map [transient-push-button] #'transient--do-push-button)
(define-key map [transient-backward-button] #'transient--do-move)
(define-key map [transient-forward-button] #'transient--do-move)
(define-key map [transient-isearch-backward] #'transient--do-move)
@@ -2314,6 +2314,21 @@ If there is no parent prefix, then behave like
`transient--do-exit'."
(transient--stack-zap)
transient--exit)
+(defun transient--do-push-button ()
+ "Call the command represented by the activated button.
+Use that command's pre-command to determine transient behavior."
+ (if (and (mouse-event-p last-command-event)
+ (not (eq (posn-window (event-start last-command-event))
+ transient--window)))
+ transient--stay
+ (setq this-command
+ (with-selected-window transient--window
+ (get-text-property (if (mouse-event-p last-command-event)
+ (posn-point (event-start
last-command-event))
+ (point))
+ 'command)))
+ (transient--do-pre-command)))
+
(defun transient--do-recurse ()
"Call the transient prefix command, preparing for return to active transient.
If there is no parent prefix, then just call the command."
@@ -2568,6 +2583,10 @@ around `scroll-down-command' (which see)."
(with-selected-window transient--window
(scroll-down-command arg)))
+(defun transient-push-button ()
+ "Invoke the suffix command represented by this button."
+ (interactive))
+
(defun transient-resume ()
"Resume a previously suspended stack of transients."
(interactive)
@@ -3711,37 +3730,27 @@ resumes the suspended transient.")
(message "This command is only available if `%s' is non-nil"
'transient-enable-popup-navigation))
-(define-button-type 'transient-button
- 'face nil
- 'action (lambda (button)
- (let ((command (button-get button 'command)))
- (setq this-command command)
- (transient--pre-command)
- (call-interactively command))))
-
(defvar transient-popup-navigation-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "<down-mouse-1>") #'transient-noop)
- (define-key map (kbd "<mouse-1>") #'transient-mouse-push-button)
- (define-key map (kbd "RET") #'transient-push-button)
- (define-key map (kbd "<up>") #'transient-backward-button)
- (define-key map (kbd "C-p") #'transient-backward-button)
- (define-key map (kbd "<down>") #'transient-forward-button)
- (define-key map (kbd "C-n") #'transient-forward-button)
- (define-key map (kbd "C-r") #'transient-isearch-backward)
- (define-key map (kbd "C-s") #'transient-isearch-forward)
+ (define-key map (kbd "<up>") #'transient-backward-button)
+ (define-key map (kbd "C-p") #'transient-backward-button)
+ (define-key map (kbd "<down>") #'transient-forward-button)
+ (define-key map (kbd "C-n") #'transient-forward-button)
+ (define-key map (kbd "C-r") #'transient-isearch-backward)
+ (define-key map (kbd "C-s") #'transient-isearch-forward)
map))
-(defun transient-mouse-push-button (&optional pos)
- "Invoke the suffix the user clicks on."
- (interactive (list last-command-event))
- (push-button pos))
+(defvar transient-button-map
+ (let ((map (make-sparse-keymap)))
+ (define-key map (kbd "<mouse-1>") #'transient-push-button)
+ (define-key map (kbd "<mouse-2>") #'transient-push-button)
+ (define-key map (kbd "RET") #'transient-push-button)
+ map))
-(defun transient-push-button ()
- "Invoke the selected suffix command."
- (interactive)
- (with-selected-window transient--window
- (push-button)))
+(define-button-type 'transient-button
+ 'face nil
+ 'keymap transient-button-map)
(defun transient-backward-button (n)
"Move to the previous button in the transient popup buffer.
- [elpa] externals/transient 06697f75ac 11/17: Only use this-original-command when necessary, (continued)
- [elpa] externals/transient 06697f75ac 11/17: Only use this-original-command when necessary, Jonas Bernoulli, 2022/03/25
- [elpa] externals/transient 45ef6df3fb 03/17: Update changelog, Jonas Bernoulli, 2022/03/25
- [elpa] externals/transient 08ebdbc85d 02/17: manual: Mention more additions since last release, Jonas Bernoulli, 2022/03/25
- [elpa] externals/transient 8bd182c2de 05/17: Add ignore rules for ELPA, Jonas Bernoulli, 2022/03/25
- [elpa] externals/transient af49fd9447 04/17: Use more function quotes, Jonas Bernoulli, 2022/03/25
- [elpa] externals/transient 017eb7b3cb 07/17: Explicitly define generic functions, Jonas Bernoulli, 2022/03/25
- [elpa] externals/transient da97c6d18a 06/17: Revert most of "Use more function quotes", Jonas Bernoulli, 2022/03/25
- [elpa] externals/transient 0619c7ef19 08/17: Automatically publish statistics, Jonas Bernoulli, 2022/03/25
- [elpa] externals/transient 31d355b596 10/17: transient-set-level: Refresh shown levels after setting one, Jonas Bernoulli, 2022/03/25
- [elpa] externals/transient dd67ff9061 12/17: transient--do-pre-command: New function, Jonas Bernoulli, 2022/03/25
- [elpa] externals/transient bb056e7156 13/17: Invoke suffix commands directly when a button is pushed,
Jonas Bernoulli <=
- [elpa] externals/transient 132090a4b6 17/17: transient-enable-popup-navigation: Enable by default, Jonas Bernoulli, 2022/03/25
- [elpa] externals/transient 75a44f5058 16/17: transient-enable-popup-navigation: Improve docstring, Jonas Bernoulli, 2022/03/25
- [elpa] externals/transient ecf340cbff 09/17: make: Set GITSTATS, Jonas Bernoulli, 2022/03/25
- [elpa] externals/transient 98d5020238 14/17: transient-popup-navigation-map: No longer bind C-p and C-n, Jonas Bernoulli, 2022/03/25
- [elpa] externals/transient 5c746f3146 15/17: No longer consider popup navigation a secondary feature, Jonas Bernoulli, 2022/03/25