From 02c3523cdf46591e147840a70488e11cf09fb06f Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Tue, 27 May 2025 21:11:22 +0300 Subject: [PATCH] * lisp/tab-line.el: Make tab closing commands work without mouse. (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 . (cherry picked from commit b6d5f50bc2782829e896bfe1f9826afa6d904b48) --- lisp/tab-line.el | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lisp/tab-line.el b/lisp/tab-line.el index 49683eb5c87..997db3ce7a0 100644 --- a/lisp/tab-line.el +++ b/lisp/tab-line.el @@ -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)))) -- 2.39.5