summaryrefslogtreecommitdiff
path: root/lisp/tab-bar.el
diff options
context:
space:
mode:
authorJuri Linkov <juri@linkov.net>2021-10-17 20:27:16 +0300
committerJuri Linkov <juri@linkov.net>2021-10-17 20:27:16 +0300
commit81e3697600e5c792cf2ee99bd0d2818807e62108 (patch)
treec5dafa6f847393818625766b240f566865718f1f /lisp/tab-bar.el
parenta191d3c725e155bd2d30c0c239cf68021cbd6c6d (diff)
downloademacs-81e3697600e5c792cf2ee99bd0d2818807e62108.tar.gz
* lisp/tab-bar.el: Add a new tab on [mouse-1] instead of [down-mouse-1]
* lisp/tab-bar.el (tab-bar-mouse-down-1): Rename from tab-bar-mouse-select-tab. Ignore 'add-tab'. (tab-bar-mouse-1): Rename from tab-bar-mouse-close-tab-from-button. Use binding of 'add-tab'. (tab-bar-map): Rebind [down-mouse-1] from tab-bar-mouse-select-tab to tab-bar-mouse-down-1, and [mouse-1] from tab-bar-mouse-close-tab-from-button to tab-bar-mouse-1 (bug#51246).
Diffstat (limited to 'lisp/tab-bar.el')
-rw-r--r--lisp/tab-bar.el30
1 files changed, 16 insertions, 14 deletions
diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el
index 8738e387b63..9fb363d90bc 100644
--- a/lisp/tab-bar.el
+++ b/lisp/tab-bar.el
@@ -267,7 +267,7 @@ was clicked."
(setq column (+ column (length (nth 1 binding))))))
keymap))))))
-(defun tab-bar-mouse-select-tab (event)
+(defun tab-bar-mouse-down-1 (event)
"Select the tab at mouse click, or add a new tab on the tab bar.
Whether this command adds a new tab or selects an existing tab
depends on whether the click is on the \"+\" button or on an
@@ -275,29 +275,31 @@ existing tab."
(interactive "e")
(let* ((item (tab-bar--event-to-item (event-start event)))
(tab-number (tab-bar--key-to-number (nth 0 item))))
- ;; Don't close the tab when clicked on the close button.
- ;; Let `tab-bar-mouse-close-tab-from-button' do this.
- (unless (nth 2 item)
+ ;; Don't close the tab when clicked on the close button. Also
+ ;; don't add new tab on down-mouse. Let `tab-bar-mouse-1' do this.
+ (unless (or (eq (car item) 'add-tab) (nth 2 item))
(if (functionp (nth 1 item))
(call-interactively (nth 1 item))
(unless (eq tab-number t)
(tab-bar-select-tab tab-number))))))
-(defun tab-bar-mouse-close-tab-from-button (event)
+(defun tab-bar-mouse-1 (event)
"Close the tab whose \"x\" close button you click.
See also `tab-bar-mouse-close-tab', which closes the tab
-regardless of where you click on it."
+regardless of where you click on it. Also add a new tab."
(interactive "e")
(let* ((item (tab-bar--event-to-item (event-start event)))
(tab-number (tab-bar--key-to-number (nth 0 item))))
- (when (nth 2 item)
- (unless (eq tab-number t)
- (tab-bar-close-tab tab-number)))))
+ (cond
+ ((and (eq (car item) 'add-tab) (functionp (nth 1 item)))
+ (call-interactively (nth 1 item)))
+ ((and (nth 2 item) (not (eq tab-number t)))
+ (tab-bar-close-tab tab-number)))))
(defun tab-bar-mouse-close-tab (event)
"Close the tab you click on.
-This is in contrast with `tab-bar-mouse-close-tab-from-button'
-that closes a tab only when you click on its \"x\" close button."
+This is in contrast with `tab-bar-mouse-1' that closes a tab
+only when you click on its \"x\" close button."
(interactive "e")
(let* ((item (tab-bar--event-to-item (event-start event)))
(tab-number (tab-bar--key-to-number (nth 0 item))))
@@ -360,11 +362,11 @@ at the mouse-down event to the position at mouse-up event."
(defvar tab-bar-map
(let ((map (make-sparse-keymap)))
- (define-key map [down-mouse-1] 'tab-bar-mouse-select-tab)
+ (define-key map [down-mouse-1] 'tab-bar-mouse-down-1)
(define-key map [drag-mouse-1] 'tab-bar-mouse-move-tab)
- (define-key map [mouse-1] 'tab-bar-mouse-close-tab-from-button)
+ (define-key map [mouse-1] 'tab-bar-mouse-1)
(define-key map [down-mouse-2] 'tab-bar-mouse-close-tab)
- (define-key map [mouse-2] 'ignore)
+ (define-key map [mouse-2] 'ignore)
(define-key map [down-mouse-3] 'tab-bar-mouse-context-menu)
(define-key map [mouse-4] 'tab-previous)