* lisp/tab-line.el: Add context menu bound to down-mouse-3 like on tab bar.
* lisp/tab-line.el: Bind tab-line down-mouse-3 to tab-line-context-menu. (tab-line-tab-map): Rebind tab-line-select-tab from mouse-1 to down-mouse-1. Bind down-mouse-3 to tab-line-tab-context-menu. (tab-line-add-map): Rebind tab-line-new-tab from mouse-1 to down-mouse-1. (tab-line-left-map, tab-line-right-map): Rebind mouse-1 to down-mouse-1. (tab-line-tab-context-menu, tab-line-context-menu): New functions. (tab-line-hscroll-right, tab-line-hscroll-left) (tab-line-new-tab, tab-line-select-tab) (tab-line-switch-to-prev-tab, tab-line-switch-to-next-tab) (tab-line-close-tab): Rename event args to 'event'.
This commit is contained in:
parent
6d65d50f71
commit
3d1f51382f
1 changed files with 41 additions and 22 deletions
|
|
@ -123,16 +123,17 @@ function `tab-line-tab-face-group'."
|
|||
|
||||
(defvar tab-line-tab-map
|
||||
(let ((map (make-sparse-keymap)))
|
||||
(define-key map [tab-line mouse-1] 'tab-line-select-tab)
|
||||
(define-key map [tab-line down-mouse-1] 'tab-line-select-tab)
|
||||
(define-key map [tab-line mouse-2] 'tab-line-close-tab)
|
||||
(define-key map [tab-line down-mouse-3] 'tab-line-tab-context-menu)
|
||||
(define-key map "\C-m" 'tab-line-select-tab)
|
||||
map)
|
||||
"Local keymap for `tab-line-mode' window tabs.")
|
||||
|
||||
(defvar tab-line-add-map
|
||||
(let ((map (make-sparse-keymap)))
|
||||
(define-key map [tab-line mouse-1] 'tab-line-new-tab)
|
||||
(define-key map [tab-line mouse-2] 'tab-line-new-tab)
|
||||
(define-key map [tab-line down-mouse-1] 'tab-line-new-tab)
|
||||
(define-key map [tab-line down-mouse-2] 'tab-line-new-tab)
|
||||
(define-key map "\C-m" 'tab-line-new-tab)
|
||||
map)
|
||||
"Local keymap to add `tab-line-mode' window tabs.")
|
||||
|
|
@ -146,16 +147,16 @@ function `tab-line-tab-face-group'."
|
|||
|
||||
(defvar tab-line-left-map
|
||||
(let ((map (make-sparse-keymap)))
|
||||
(define-key map [tab-line mouse-1] 'tab-line-hscroll-left)
|
||||
(define-key map [tab-line mouse-2] 'tab-line-hscroll-left)
|
||||
(define-key map [tab-line down-mouse-1] 'tab-line-hscroll-left)
|
||||
(define-key map [tab-line down-mouse-2] 'tab-line-hscroll-left)
|
||||
(define-key map "\C-m" 'tab-line-new-tab)
|
||||
map)
|
||||
"Local keymap to scroll `tab-line-mode' window tabs to the left.")
|
||||
|
||||
(defvar tab-line-right-map
|
||||
(let ((map (make-sparse-keymap)))
|
||||
(define-key map [tab-line mouse-1] 'tab-line-hscroll-right)
|
||||
(define-key map [tab-line mouse-2] 'tab-line-hscroll-right)
|
||||
(define-key map [tab-line down-mouse-1] 'tab-line-hscroll-right)
|
||||
(define-key map [tab-line down-mouse-2] 'tab-line-hscroll-right)
|
||||
(define-key map "\C-m" 'tab-line-new-tab)
|
||||
map)
|
||||
"Local keymap to scroll `tab-line-mode' window tabs to the right.")
|
||||
|
|
@ -666,20 +667,20 @@ the selected tab visible."
|
|||
(when window
|
||||
(force-mode-line-update t))))
|
||||
|
||||
(defun tab-line-hscroll-right (&optional arg mouse-event)
|
||||
(defun tab-line-hscroll-right (&optional arg event)
|
||||
(interactive (list current-prefix-arg last-nonmenu-event))
|
||||
(let ((window (and (listp mouse-event) (posn-window (event-start mouse-event)))))
|
||||
(let ((window (and (listp event) (posn-window (event-start event)))))
|
||||
(tab-line-hscroll arg window)
|
||||
(force-mode-line-update window)))
|
||||
|
||||
(defun tab-line-hscroll-left (&optional arg mouse-event)
|
||||
(defun tab-line-hscroll-left (&optional arg event)
|
||||
(interactive (list current-prefix-arg last-nonmenu-event))
|
||||
(let ((window (and (listp mouse-event) (posn-window (event-start mouse-event)))))
|
||||
(let ((window (and (listp event) (posn-window (event-start event)))))
|
||||
(tab-line-hscroll (- (or arg 1)) window)
|
||||
(force-mode-line-update window)))
|
||||
|
||||
|
||||
(defun tab-line-new-tab (&optional mouse-event)
|
||||
(defun tab-line-new-tab (&optional 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
|
||||
|
|
@ -688,20 +689,20 @@ corresponding to the switched buffer."
|
|||
(if (functionp tab-line-new-tab-choice)
|
||||
(funcall tab-line-new-tab-choice)
|
||||
(let ((tab-line-tabs-buffer-groups mouse-buffer-menu-mode-groups))
|
||||
(if (and (listp mouse-event)
|
||||
(if (and (listp event)
|
||||
(display-popup-menus-p)
|
||||
(not tty-menu-open-use-tmm))
|
||||
(mouse-buffer-menu mouse-event) ; like (buffer-menu-open)
|
||||
(mouse-buffer-menu event) ; like (buffer-menu-open)
|
||||
;; tty menu doesn't support mouse clicks, so use tmm
|
||||
(tmm-prompt (mouse-buffer-menu-keymap))))))
|
||||
|
||||
(defun tab-line-select-tab (&optional e)
|
||||
(defun tab-line-select-tab (&optional event)
|
||||
"Switch to the selected tab.
|
||||
This command maintains the original order of prev/next buffers.
|
||||
So for example, switching to a previous tab is equivalent to
|
||||
using the `previous-buffer' command."
|
||||
(interactive "e")
|
||||
(let* ((posnp (event-start e))
|
||||
(let* ((posnp (event-start event))
|
||||
(tab (get-pos-property 1 'tab (car (posn-string posnp))))
|
||||
(buffer (if (bufferp tab) tab (cdr (assq 'buffer tab)))))
|
||||
(if buffer
|
||||
|
|
@ -743,12 +744,12 @@ when `tab-line-tabs-function' is `tab-line-tabs-window-buffers'."
|
|||
:group 'tab-line
|
||||
:version "28.1")
|
||||
|
||||
(defun tab-line-switch-to-prev-tab (&optional mouse-event)
|
||||
(defun tab-line-switch-to-prev-tab (&optional event)
|
||||
"Switch to the previous tab.
|
||||
Its effect is the same as using the `previous-buffer' command
|
||||
(\\[previous-buffer])."
|
||||
(interactive (list last-nonmenu-event))
|
||||
(let ((window (and (listp mouse-event) (posn-window (event-start mouse-event)))))
|
||||
(let ((window (and (listp event) (posn-window (event-start event)))))
|
||||
(if (eq tab-line-tabs-function #'tab-line-tabs-window-buffers)
|
||||
(switch-to-prev-buffer window)
|
||||
(with-selected-window (or window (selected-window))
|
||||
|
|
@ -767,12 +768,12 @@ Its effect is the same as using the `previous-buffer' command
|
|||
(when (bufferp buffer)
|
||||
(switch-to-buffer buffer)))))))
|
||||
|
||||
(defun tab-line-switch-to-next-tab (&optional mouse-event)
|
||||
(defun tab-line-switch-to-next-tab (&optional event)
|
||||
"Switch to the next tab.
|
||||
Its effect is the same as using the `next-buffer' command
|
||||
(\\[next-buffer])."
|
||||
(interactive (list last-nonmenu-event))
|
||||
(let ((window (and (listp mouse-event) (posn-window (event-start mouse-event)))))
|
||||
(let ((window (and (listp event) (posn-window (event-start event)))))
|
||||
(if (eq tab-line-tabs-function #'tab-line-tabs-window-buffers)
|
||||
(switch-to-next-buffer window)
|
||||
(with-selected-window (or window (selected-window))
|
||||
|
|
@ -806,13 +807,13 @@ This option is useful when `tab-line-tabs-function' has the value
|
|||
:group 'tab-line
|
||||
:version "27.1")
|
||||
|
||||
(defun tab-line-close-tab (&optional mouse-event)
|
||||
(defun tab-line-close-tab (&optional 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 (list last-nonmenu-event))
|
||||
(let* ((posnp (and (listp mouse-event) (event-start mouse-event)))
|
||||
(let* ((posnp (and (listp event) (event-start event)))
|
||||
(window (and posnp (posn-window posnp)))
|
||||
(tab (get-pos-property 1 'tab (car (posn-string posnp))))
|
||||
(buffer (if (bufferp tab) tab (cdr (assq 'buffer tab))))
|
||||
|
|
@ -832,6 +833,22 @@ from the tab line."
|
|||
(funcall tab-line-close-tab-function tab)))
|
||||
(force-mode-line-update))))
|
||||
|
||||
(defun tab-line-tab-context-menu (&optional event)
|
||||
"Pop up context menu for the tab."
|
||||
(interactive "e")
|
||||
(let ((menu (make-sparse-keymap (propertize "Context Menu" 'hide t))))
|
||||
(define-key-after menu [close]
|
||||
'(menu-item "Close" tab-line-close-tab :help "Close the tab"))
|
||||
(popup-menu menu event)))
|
||||
|
||||
(defun tab-line-context-menu (&optional event)
|
||||
"Pop up context menu for the tab line."
|
||||
(interactive "e")
|
||||
(let ((menu (make-sparse-keymap (propertize "Context Menu" 'hide t))))
|
||||
(define-key-after menu [close]
|
||||
'(menu-item "New tab" tab-line-new-tab :help "Create a new tab"))
|
||||
(popup-menu menu event)))
|
||||
|
||||
|
||||
;;;###autoload
|
||||
(define-minor-mode tab-line-mode
|
||||
|
|
@ -865,6 +882,8 @@ from the tab line."
|
|||
:version "27.1")
|
||||
|
||||
|
||||
(global-set-key [tab-line down-mouse-3] 'tab-line-context-menu)
|
||||
|
||||
(global-set-key [tab-line mouse-4] 'tab-line-hscroll-left)
|
||||
(global-set-key [tab-line mouse-5] 'tab-line-hscroll-right)
|
||||
(global-set-key [tab-line wheel-up] 'tab-line-hscroll-left)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue