aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuri Linkov2021-09-15 09:30:11 +0300
committerJuri Linkov2021-09-15 09:30:11 +0300
commitb172049717ee2dd55e389bfa96d33a1850fe41ef (patch)
treeeef2d21f12d316ca9f51f192594b70b5327d9978
parentcc52f6d995ac73c66701f788852e9a8e82eea6f7 (diff)
downloademacs-b172049717ee2dd55e389bfa96d33a1850fe41ef.tar.gz
emacs-b172049717ee2dd55e389bfa96d33a1850fe41ef.zip
* lisp/tab-bar.el (tab-bar-close-other-tabs): Add arg ‘tab-number’.
(tab-bar-mouse-context-menu): Bind menu-item "Close other tabs" to tab-bar-close-other-tabs with arg ‘tab-number’.
-rw-r--r--lisp/tab-bar.el27
1 files changed, 21 insertions, 6 deletions
diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el
index 89af3069024..d6173d9ca42 100644
--- a/lisp/tab-bar.el
+++ b/lisp/tab-bar.el
@@ -316,7 +316,12 @@ that closes only when clicked on the close button."
316 (define-key-after menu [close] 316 (define-key-after menu [close]
317 `(menu-item "Close" (lambda () (interactive) 317 `(menu-item "Close" (lambda () (interactive)
318 (tab-bar-close-tab ,tab-number)) 318 (tab-bar-close-tab ,tab-number))
319 :help "Close the tab")))) 319 :help "Close the tab"))
320 (define-key-after menu [close-other]
321 `(menu-item "Close other tabs"
322 (lambda () (interactive)
323 (tab-bar-close-other-tabs ,tab-number))
324 :help "Close all other tabs"))))
320 325
321 (popup-menu menu event))) 326 (popup-menu menu event)))
322 327
@@ -1405,15 +1410,25 @@ for the last tab on a frame is determined by
1405 (funcall tab-bar-tabs-function))))) 1410 (funcall tab-bar-tabs-function)))))
1406 (tab-bar-close-tab (1+ (tab-bar--tab-index-by-name name)))) 1411 (tab-bar-close-tab (1+ (tab-bar--tab-index-by-name name))))
1407 1412
1408(defun tab-bar-close-other-tabs () 1413(defun tab-bar-close-other-tabs (&optional tab-number)
1409 "Close all tabs on the selected frame, except the selected one." 1414 "Close all tabs on the selected frame, except TAB-NUMBER.
1415TAB-NUMBER counts from 1 and defaults to the current tab."
1410 (interactive) 1416 (interactive)
1411 (let* ((tabs (funcall tab-bar-tabs-function)) 1417 (let* ((tabs (funcall tab-bar-tabs-function))
1412 (current-tab (tab-bar--current-tab-find tabs)) 1418 (current-index (tab-bar--current-tab-index tabs))
1419 (keep-index (if (integerp tab-number)
1420 (1- (max 0 (min tab-number (length tabs))))
1421 current-index))
1422 (keep-tab (nth keep-index tabs))
1413 (index 0)) 1423 (index 0))
1414 (when current-tab 1424
1425 (when keep-tab
1426 (unless (eq keep-index current-index)
1427 (tab-bar-select-tab (1+ keep-index))
1428 (setq tabs (funcall tab-bar-tabs-function)))
1429
1415 (dolist (tab tabs) 1430 (dolist (tab tabs)
1416 (unless (or (eq tab current-tab) 1431 (unless (or (eq tab keep-tab)
1417 (run-hook-with-args-until-success 1432 (run-hook-with-args-until-success
1418 'tab-bar-tab-prevent-close-functions tab 1433 'tab-bar-tab-prevent-close-functions tab
1419 ;; `last-tab-p' logically can't ever be true 1434 ;; `last-tab-p' logically can't ever be true