2

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.

Is there any way to invoke Emacs from the command line and have it open multiple files in separate tabs?

For instance, I want to run a command like the following:

$ emacs --some-flag file1.txt file2.txt file3.txt

Emacs should open file1.txt, file2.txt, and file3.txt in separate tabs (instead of separate buffers). Is there some way to get this to work?


Vim has a -p flag that allows it to open files into separate tabs instead of just separate buffers.

illabout
  • 285
  • 2
  • 14

2 Answers2

3

Having just read on the Emacs Stack Exchange Make display-buffer open buffer in new tab and applying it to your situation, I suggest you put in your .emacs file:

(setq display-buffer-base-action '(display-buffer-in-tab))

save it and then call from the command line without any additional flag:

$ emacs --some-flag file1.txt file2.txt file3.txt
halloleo
  • 1,215
  • 9
  • 23
  • Oh, that's a smart idea. However, I don't actually want to use Emacs with `display-buffer-base-action` turned on all the time. Is there some way to set it to only be active while processing the files from the command line? – illabout Nov 12 '20 at 09:14
0

Based on halloleo's answer:

emacs --eval "(setq display-buffer-base-action '(display-buffer-in-tab))" file1.txt file2.txt file3.txt

This is probably not something to remember, so maybe you want to have a shell-alias for it:

alias emacstabs='emacs --eval "(setq display-buffer-base-action \'(display-buffer-in-tab))"'
Kaligule
  • 319
  • 3
  • 10