/tab-bar-lost-commands

Emacs: The "lost commands" of the tab bar

Primary LanguageEmacs LispGNU General Public License v3.0GPL-3.0

tab-bar-lost-commands.el

The “lost commands” of the Emacs tab bar.

That is, simple and convenient commands that help with common tab bar use-cases regarding the creation, selection and movement of tabs without the need to use prefix arguments (for reasons of ergonomics: in my own experience at least, frequently needing to type prefix arguments breaks my flow enough to be distracting).

Installation

If you use MELPA, an easy way to install this package is via package-install. Alternatively, download tab-bar-lost-commands.el, put it in your load-path and require it.

If you use both MELPA and use-package, you can use this, too:

(use-package tab-bar-lost-commands
  :ensure)

Commands

Table of available commands and their description.

CommandDescription
tab-bar-lost-commands-switch-to-first-tabSwitch to the first tab
tab-bar-lost-commands-switch-to-last-tabSwitch to the last tab
tab-bar-lost-commands-move-tab-backwardMove the current tab backward by one
tab-bar-lost-commands-move-tab-forwardMove the current tab forward by one
tab-bar-lost-commands-move-tab-firstMove the current tab to the first position
tab-bar-lost-commands-move-tab-lastMove the current tab to the last position
tab-bar-lost-commands-switch-to-or-create-tabLike tab-bar-switch-to-tab, but allow for the creation of a new, named tab on the fly

Recommended Keybindings

Note that this package doesn’t bind any keys by itself.

In my local configuration, to mimic my browser’s keyboard shortcuts for switching tabs, I use s-{ and s-} to switch to the previous or next tab (using pre-existing Emacs tab bar commands).

I then add the meta key to these bindings to make them switch to the first or last tab. Also, I add the control key to these bindings to make them move the current tab backward or forward by one. Lastly, I add both the control and the meta key to make them move the current tab to the first or last position.

I also rewrite C-x t <return> (“switch to tab by name”) to run an enhanced version of that command that allows for the creation of a new, named tab on the fly.

(use-package tab-bar
  :bind (("s-{" . tab-bar-switch-to-prev-tab)
         ("s-}" . tab-bar-switch-to-next-tab)))

(use-package tab-bar-lost-commands
  :ensure
  :bind (("M-s-{" . tab-bar-lost-commands-switch-to-first-tab)
         ("M-s-}" . tab-bar-lost-commands-switch-to-last-tab)
         ("C-s-{" . tab-bar-lost-commands-move-tab-backward)
         ("C-s-}" . tab-bar-lost-commands-move-tab-forward)
         ("C-M-s-{" . tab-bar-lost-commands-move-tab-first)
         ("C-M-s-}" . tab-bar-lost-commands-move-tab-last)
         :map tab-prefix-map
         ("<return>" . tab-bar-lost-commands-switch-to-or-create-tab)))