0

Emacs-27.1 ships with a new tab-bar-mode minor mode. This puts a tab bar at the top of each Emacs frame. Each tab in the tab bar can display multiple windows.

Emacs (and various packages) has many commands that open a buffer in a new window in the current frame.

How do I take an existing Emacs command that opens a buffer new window in the current frame and instead make it open a buffer in a new tab?

For instance, I often call the Magit function magit-status. This function opens a new window to show the Magit status buffer. Instead of opening a new window, I'd like to open a new tab to show the Magit status buffer.

What are my options for opening buffers in new tabs instead of new windows?

I can imagine two general approaches:

  1. Change some Emacs variable that makes all new windows open in new tabs. This would be an easy way to have all commands open buffers in new tabs, although quite heavy-handed.

    Is there an Emacs variable I can set that will do this?

  2. Create a function like open-in-new-tab that modifies any function given as an argument to open a buffer in a new tab instead of a new window.

    For instance, if I want magit-status to open in a new tab, I would have to call it like (open-in-new-tab 'magit-status). I could create a command for this, and bind it to some key.

    How would I write this open-in-new-tab function? (I'm somewhat new to Elisp.)

    I imagine this open-in-new-tab function would be similar to a function for modifying a command to open a buffer in a new frame instead of a new window.

2
  • There appears to be two variables that determine whether new buffers will be shown in a new window or a new frame: pop-up-windows and pop-up-frames. However, there doesn't appear to be anything like a pop-up-tabs variable. – illabout Oct 16 '20 at 14:08
  • Here is a simple way to define a function for running another function and opening up a buffer in a new frame. I imagine this would only need to be modified slightly to work for a new tab instead of a new frame. – illabout Oct 16 '20 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.