- Clone into a folder of your choice (~/.emacs.d/git for example)
- With use-package, configure it like this (with suggested key bindings):
(use-package intuitive-tab-line
:load-path "git/intuitive-tab-line-mode"
:custom
(tab-line-tabs-function 'intuitive-tab-line-buffers-list)
(tab-line-switch-cycling t)
:config
(global-tab-line-mode 1)
(recentf-mode 1)
(setq
tab-line-new-button-show nil ;; do not show add-new button
tab-line-close-button-show nil ;; do not show close button
tab-line-separator " " ;; delimitation between tabs
))
(global-set-key (kbd "C-<prior>") 'tab-line-switch-to-prev-tab)
(global-set-key (kbd "C-<iso-lefttab>") 'tab-line-switch-to-prev-tab)
(global-set-key (kbd "C-<next>") 'tab-line-switch-to-next-tab)
(global-set-key (kbd "C-<tab>") 'tab-line-switch-to-next-tab)
(global-set-key (kbd "C-S-<prior>") 'intuitive-tab-line-shift-tab-left)
(global-set-key (kbd "C-S-<next>") 'intuitive-tab-line-shift-tab-right)
(global-set-key (kbd "C-S-t") 'recentf-open-most-recent-file)
Make Emacs tabs behave intuitively (similar to how tabs behave in a browser).
I know many don’t feel this way, but I like using tabs. And more than this, I like the simplicity of having one buffer per tab.
I tried doing things The Emacs Way (TM) of having buffers managed invisibly in the background, but I could never get a good mental model for this. I needed a visual representation of what buffers were open and their order.
What I wanted was:
- For any buffer manually opened by the user to be represented by its own tab.
- For their order to persist (until manually changed).
Put simply, I want Emacs tabs to work like a browser would.
So using tab-line-mode
I have created my own custom tab-line-tabs-function
: a simple list to manage the tab/buffers I wanted displayed. I then created a set of functions to manipulate that list to get the functionality I was after.
The various functions should more or less be self-explanatory. Please note I use tab-line-switch-to-next-tab
and tab-line-switch-to-prev-tab
to cycle between tabs.
Tested with Emacs 28.1.
kill-this-buffer
will generally work just fine, but will sometimes cause a previously dropped buffer to get a tab again. This can be prevented by instead usingintuitive-tab-line-drop-tab
with a non-nilkill
argument.- You can define which buffers you would like get their own tab and which you would like to remain tabless by editing
intuitive-tab-line-add-current-buffer-to-tab
. - You can manually add a buffer that would normally not be added with
intuitive-tab-line-manually-add-current-buffer-to-tab
. - You can remove the tab for a buffer, without killing the buffer with
intuitive-tab-line-drop-tab
. The next time you visit the buffer, it will be given a tab again. - You can change the order of the tabs with
intuitive-tab-line-shift-tab-left
andintuitive-tab-line-shift-tab-right
. - You can set a ‘default’ tab with
intuitive-tab-line-set-default-tab
and go to the default tab withintuitive-tab-line-goto-default-tab
. - You can remove all tabs and leave only your
initial-buffer-choice
open withintuitive-tab-line-load-initial-buffer-only
.
As I say, this has been a goal of mine ever since I started using Emacs. It was a lot of confusing work to get it to work, but work it does and it is enormously gratifying. Very open to feedback and criticism, but do keep in mind I’m not a programmer and trying my best.