]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/tab-line.el: Make tab closing commands work without mouse.
authorJuri Linkov <juri@linkov.net>
Tue, 27 May 2025 18:11:22 +0000 (21:11 +0300)
committerEshel Yaron <me@eshelyaron.com>
Sat, 7 Jun 2025 19:52:57 +0000 (21:52 +0200)
(tab-line--current-tab): New function.
(tab-line-close-tab, tab-line-close-other-tabs): Use it
when the 'event' arg doesn't originate from mouse.
Suggested by pinmacs <pinmacs@cas.cat>.

(cherry picked from commit b6d5f50bc2782829e896bfe1f9826afa6d904b48)

lisp/tab-line.el

index 49683eb5c874ba7f78790edcd7186cab74049c13..997db3ce7a0590edbea27056707ee884717b92b8 100644 (file)
@@ -1082,6 +1082,13 @@ This option is useful when `tab-line-tabs-function' has the value
   :group 'tab-line
   :version "27.1")
 
+(defun tab-line--current-tab ()
+  "Return the current tab in the tab line."
+  (seq-find (lambda (tab)
+              (eq (if (bufferp tab) tab (alist-get 'buffer tab))
+                  (current-buffer)))
+            (funcall tab-line-tabs-function)))
+
 (defun tab-line-close-tab (&optional event)
   "Close the selected tab.
 This command is usually invoked by clicking on the close button on the
@@ -1092,7 +1099,9 @@ sight of the tab line."
     (let* ((posnp (and (listp event)
                        (tab-line-event-start event)))
            (window (and posnp (posn-window posnp)))
-           (tab (tab-line--get-tab-property 'tab (car (posn-string posnp))))
+           (tab (if posnp
+                    (tab-line--get-tab-property 'tab (car (posn-string posnp)))
+                  (tab-line--current-tab)))
            (buffer (if (bufferp tab) tab (cdr (assq 'buffer tab))))
            (close-function (unless (bufferp tab) (cdr (assq 'close tab)))))
       (with-selected-window (or window (selected-window))
@@ -1118,7 +1127,9 @@ It preforms the same actions on the closed tabs as in `tab-line-close-tab'."
     (let* ((posnp (and (listp event)
                        (tab-line-event-start event)))
            (window (and posnp (posn-window posnp)))
-           (keep-tab (tab-line--get-tab-property 'tab (car (posn-string posnp)))))
+           (keep-tab (if posnp
+                         (tab-line--get-tab-property 'tab (car (posn-string posnp)))
+                       (tab-line--current-tab))))
       (with-selected-window (or window (selected-window))
         (dolist (tab (delete keep-tab (funcall tab-line-tabs-function)))
           (let ((buffer (if (bufferp tab) tab (cdr (assq 'buffer tab))))