4

I want to implement automatic tab management. Every file I open needs to go into a tab. The tab into which any given buffer goes is determined by root directory of the VC repo the file belongs to.

The mechanism used by tabbar.el was tabbar-buffer-groups-function where I could use a function like

(defun my/find-vc-root ()
  "Retuns the repository root as per [vc]."
  (vc-call-backend (vc-responsible-backend default-directory)
           'root default-directory))

I do see tab-bar-new-tab-group in the code but I can't wrap my head around how it is to be used.

alephnull
  • 75
  • 4
  • FYI useful to see this: https://github.com/ema2159/centaur-tabs – Ian Apr 20 '21 at 06:45
  • Emacs tab-line is similar to tabbar.el. I use `tab-line-tabs-buffer-group-function` in tab-line to do what `tabbar-buffer-groups-function` did ([details](https://amitp.blogspot.com/2020/06/emacs-prettier-tab-line.html)). Emacs also has tab-bar but it works differently from tabbar.el, so I would suggest trying tab-line first to make it easier to move from tabbar.el. – amitp Apr 23 '21 at 02:39

1 Answers1

2

Tab groups don't create new tabs. You can implement automatic tab management at different levels, it depends on your needs.

  1. If you want only C-x C-f to open a file in a new tab, then you can just rebind this key with (define-key ctl-x-map "\C-f" 'find-file-other-tab)

  2. If you want every opened file to go to a new tab, this implies that you need to rely on the file-visiting hook:

(add-hook 'find-file-hook
          (lambda ()
            (let ((tab-bar-new-tab-choice (buffer-name)))
              (tab-bar-new-tab))))
  1. If you want that even displaying a visited file should switch to its tab, this is possible with:
(push '((lambda (b _a) (buffer-local-value 'buffer-file-name (get-buffer b)))
        .
        (display-buffer-in-tab (tab-name . (lambda (b _a) (buffer-name b)))))
      display-buffer-alist)
alephnull
  • 75
  • 4
link0ff
  • 1,081
  • 5
  • 14
  • Thank you. #3 is very interesting. As for #1 and #2 I feel that tab-bar-groups solve this problem if I could just figure it out :) – alephnull Apr 20 '21 at 02:48
  • 1
    Tab groups don't create new tabs. The package tabbar.el corresponds to the per-window tab-line.el in core Emacs where every file buffer gets own tab automatically. However, for per-frame tab-bar.el you need to create every tab explicitly after visiting a file with the solutions in the answer. – link0ff Apr 20 '21 at 05:36