1

I configured Emacs so I can use tabs similarly to a browser :

  (use-package intuitive-tab-line
    :vc (:url "https://github.com/thread314/intuitive-tab-line-mode")
    :defer 0
    :init
    (define-prefix-command 'intuitive-tab)
    (define-key Commands (kbd "i") 'intuitive-tab)
    :config
    (global-tab-line-mode 1)
    :custom
    (tab-line-tabs-function 'intuitive-tab-line-buffers-list)
    (tab-line-switch-cycling t)
    (tab-line-new-button-show nil)    ;; do not show add-new button
    (tab-line-close-button-show nil)  ;; do not show close button
    :bind 
    ("C-<prior>" . tab-line-switch-to-prev-tab)
    ("C-<iso-lefttab>" . tab-line-switch-to-prev-tab)
    ("C-<next>" . tab-line-switch-to-next-tab)
    ("C-<tab>" . tab-line-switch-to-next-tab)
    ("C-S-<prior>" . intuitive-tab-line-shift-tab-left)
    ("C-S-<next>" . intuitive-tab-line-shift-tab-right)
    (:map intuitive-tab
    ("a" . intuitive-tab-line-manually-add-current-buffer-to-tab)
    ("d" . intuitive-tab-line-drop-tab))
    )

However there is a functionality that I can't manage to replicate. On Firefox I can go to the third tab by pressing control + 3, to the nth tab by pressing control + n (with n <0 & >9). How could I associate each tab with a key binding?

1 Answer 1

3

In Emacs, there are two built-in modes for tabs:

tab-bar-mode creates tabs at (or near) the top of the frame. These tabs each hold a "window-configuration", which may be a single window displaying one buffer or a collection of windows holding various buffers.

The other built-in tab mode is tab-line-mode. Based on the name of the package you configured in your code, I guess it has something to do with that mode.

tab-line-mode creates a line of tabs at the top of each window. It is automatically updated whenever you change buffers in a window, so that you have a visual indication of which buffers have been shown in that window. This allows you to click on a tab to switch to a buffer. Maybe it's because of the automatically-updating nature of these tabs, but there is no feature in tab-line-mode to switch to a tab based on its number.

However, there is such a feature included with tab-bar-mode. Here is how you can enable it.

(tab-bar-mode 1)
(setopt tab-bar-tab-hints t)
(setopt tab-bar-select-tab-modifiers '(control))

This will display a number for each tab and allow you to select the 3rd tab by pressing C-3. Keep in mind that that also prevents you from using Ctrl plus a number to enter a numeric argument. But you have the option of changing the modifier(s) to something else if that becomes an annoyance.

With tab-bar-mode, much like in Firefox, the tabs are not created automatically. It is up to you to create a new tab when you want one. You can do that using C-x t 2. And there are several other commands for manipulating tabs, which you can find under the C-x t prefix.

6
  • Thanks for the answer. Unfortunately, I struggle to understand how tab-bar-mode works. Maybe a new function could allow using this functionality on tab-line-mode Commented Nov 23 at 21:03
  • It's certainly possible to write a function to add numbers to the tab-line tabs. But with tab-line-mode adding and changing tabs so often, I think it would be less useful than you might hope. What is it about tab-bar-mode that you find hard to understand? Commented Nov 23 at 21:48
  • When I put the snippet you provided plus mine I have two levels of tabs. When I only put yours, commenting mine, either I see not tab at all, either all buffers open in the same tab. Commented Nov 23 at 23:59
  • The two levels of tabs is because you have both tab-line-mode and tab-bar-mode enabled. If you want to create a new tab-bar tab, use C-x t 2 (similar to how C-x 2 creates a new window). If you see no tab at all, it's because you (or a package you installed) have changed the value of tab-bar-show. Make sure it is set to t (the default). Commented Nov 24 at 0:43
  • Thank you @mmarshall540 for the explanations. Is it not possible to automatically open a new tab when I open a new buffer? Commented Nov 24 at 9:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.