emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 30deac8: * lisp/tab-line.el: Bind mouse commands to


From: Juri Linkov
Subject: [Emacs-diffs] master 30deac8: * lisp/tab-line.el: Bind mouse commands to [tab-line].
Date: Sun, 20 Oct 2019 18:37:47 -0400 (EDT)

branch: master
commit 30deac84c4168a6315a08a0dd85f6dde9b9df439
Author: Juri Linkov <address@hidden>
Commit: Juri Linkov <address@hidden>

    * lisp/tab-line.el: Bind mouse commands to [tab-line].
    
    * lisp/tab-line.el: Bind mouse-4/mouse-5, wheel-up/wheel-down
    globally to [tab-line].
    (tab-line-tab-map): Remove local bindings of mouse-4/mouse-5.
    (tab-line-new-tab, tab-line-switch-to-prev-tab)
    (tab-line-switch-to-next-tab, tab-line-close-tab):
    Turn commands into mouse-free (can be used without mouse).
---
 etc/NEWS         |  2 +-
 lisp/tab-line.el | 43 +++++++++++++++++++++++++------------------
 2 files changed, 26 insertions(+), 19 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index d9a9fd8..d0e369e 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2184,7 +2184,7 @@ the previous window-local tab is the same as typing 'C-x 
<LEFT>'
 ('next-buffer').  Both commands support a numeric prefix argument as
 a repeat count.  Clicking on the plus icon adds a new buffer to the
 window-local tab line of buffers.  Using the mouse wheel on the tab
-line scrolls tabs that display the window buffers.
+line scrolls tabs.
 
 ** fileloop.el lets one setup multifile operations like search&replace.
 
diff --git a/lisp/tab-line.el b/lisp/tab-line.el
index 5f2dd3e..58f648c 100644
--- a/lisp/tab-line.el
+++ b/lisp/tab-line.el
@@ -94,8 +94,6 @@
   (let ((map (make-sparse-keymap)))
     (define-key map [tab-line mouse-1] 'tab-line-select-tab)
     (define-key map [tab-line mouse-2] 'tab-line-close-tab)
-    (define-key map [tab-line mouse-4] 'tab-line-switch-to-prev-tab)
-    (define-key map [tab-line mouse-5] 'tab-line-switch-to-next-tab)
     (define-key map "\C-m" 'tab-line-select-tab)
     map)
   "Local keymap for `tab-line-mode' window tabs.")
@@ -262,16 +260,16 @@ variable `tab-line-tabs-function'."
                                tab-line-new-button))))))
 
 
-(defun tab-line-new-tab (&optional e)
+(defun tab-line-new-tab (&optional mouse-event)
   "Add a new tab to the tab line.
 Usually is invoked by clicking on the plus-shaped button.
 But any switching to other buffer also adds a new tab
 corresponding to the switched buffer."
-  (interactive "e")
+  (interactive (list last-nonmenu-event))
   (if (functionp tab-line-new-tab-choice)
       (funcall tab-line-new-tab-choice)
-    (if window-system                   ; (display-popup-menus-p)
-        (mouse-buffer-menu e)           ; like (buffer-menu-open)
+    (if (and (listp mouse-event) window-system) ; (display-popup-menus-p)
+        (mouse-buffer-menu mouse-event) ; like (buffer-menu-open)
       ;; tty menu doesn't support mouse clicks, so use tmm
       (tmm-prompt (mouse-buffer-menu-keymap)))))
 
@@ -302,19 +300,21 @@ using the `previous-buffer' command."
       (with-selected-window window
         (switch-to-buffer buffer))))))
 
-(defun tab-line-switch-to-prev-tab (&optional e)
+(defun tab-line-switch-to-prev-tab (&optional mouse-event)
   "Switch to the previous tab.
 Its effect is the same as using the `previous-buffer' command
 (\\[previous-buffer])."
-  (interactive "e")
-  (switch-to-prev-buffer (posn-window (event-start e))))
+  (interactive (list last-nonmenu-event))
+  (switch-to-prev-buffer
+   (and (listp mouse-event) (posn-window (event-start mouse-event)))))
 
-(defun tab-line-switch-to-next-tab (&optional e)
+(defun tab-line-switch-to-next-tab (&optional mouse-event)
   "Switch to the next tab.
 Its effect is the same as using the `next-buffer' command
 (\\[next-buffer])."
-  (interactive "e")
-  (switch-to-next-buffer (posn-window (event-start e))))
+  (interactive (list last-nonmenu-event))
+  (switch-to-next-buffer
+   (and (listp mouse-event) (posn-window (event-start mouse-event)))))
 
 (defcustom tab-line-close-tab-action 'bury-buffer
   "Defines what to do on closing the tab.
@@ -326,16 +326,17 @@ If `kill-buffer', kills the tab's buffer."
   :group 'tab-line
   :version "27.1")
 
-(defun tab-line-close-tab (&optional e)
+(defun tab-line-close-tab (&optional mouse-event)
   "Close the selected tab.
 Usually is invoked by clicking on the close button on the right side
 of the tab.  This command buries the buffer, so it goes out of sight
 from the tab line."
-  (interactive "e")
-  (let* ((posnp (event-start e))
-         (window (posn-window posnp))
-         (buffer (get-pos-property 1 'tab (car (posn-string posnp)))))
-    (with-selected-window window
+  (interactive (list last-nonmenu-event))
+  (let* ((posnp (and (listp mouse-event) (event-start mouse-event)))
+         (window (and posnp (posn-window posnp)))
+         (buffer (or (get-pos-property 1 'tab (car (posn-string posnp)))
+                     (current-buffer))))
+    (with-selected-window (or window (selected-window))
       (cond
        ((eq tab-line-close-tab-action 'kill-buffer)
         (kill-buffer buffer))
@@ -358,5 +359,11 @@ from the tab line."
                                   '(:eval (tab-line-format)))))
 
 
+(global-set-key [tab-line mouse-4] 'tab-line-switch-to-prev-tab)
+(global-set-key [tab-line mouse-5] 'tab-line-switch-to-next-tab)
+(global-set-key [tab-line wheel-up] 'tab-line-switch-to-prev-tab)
+(global-set-key [tab-line wheel-down] 'tab-line-switch-to-next-tab)
+
+
 (provide 'tab-line)
 ;;; tab-line.el ends here



reply via email to

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