emacs-diffs
[Top][All Lists]
Advanced

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

emacs-28 81e3697 2/2: * lisp/tab-bar.el: Add a new tab on [mouse-1] inst


From: Juri Linkov
Subject: emacs-28 81e3697 2/2: * lisp/tab-bar.el: Add a new tab on [mouse-1] instead of [down-mouse-1]
Date: Sun, 17 Oct 2021 13:27:47 -0400 (EDT)

branch: emacs-28
commit 81e3697600e5c792cf2ee99bd0d2818807e62108
Author: Juri Linkov <juri@linkov.net>
Commit: Juri Linkov <juri@linkov.net>

    * 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).
---
 lisp/tab-bar.el | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el
index 8738e38..9fb363d 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)



reply via email to

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