Skip to content

Instantly share code, notes, and snippets.

@jamescherti
Last active July 5, 2024 12:31
Show Gist options
  • Save jamescherti/21436157fa3764022c95f00dfe2ae828 to your computer and use it in GitHub Desktop.
Save jamescherti/21436157fa3764022c95f00dfe2ae828 to your computer and use it in GitHub Desktop.
Emacs: Move to the next tab when the current tab is closed. (similar to Firefox.)
;; Description: Emacs: Move to the next tab when the current tab
;; is closed. (similar to Firefox.)
;; Gits URL: https://gist.github.com/jamescherti/21436157fa3764022c95f00dfe2ae828
;; License: MIT
;; Author: James Cherti
(defun my-tab-bar-close-tab-advice (orig-fun &rest args)
"Advice around `tab-bar-close-tab' to move to the next tab when closed.
ORIG-FUN is the original `tab-bar-close-tab` function. ARGS are the arguments
passed to `tab-bar-close-tab`."
(let ((current-tab (tab-bar--current-tab-index)))
(apply orig-fun args)
(when (< current-tab (length (tab-bar-tabs)))
(tab-bar-select-tab (+ current-tab 1)))))
(advice-add 'tab-bar-close-tab :around #'my-tab-bar-close-tab-advice)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment