crea `display-buffer` buffer aperto in una nuova scheda

Nov 11 2020

La display-bufferfunzione sembra essere usata abbastanza pesantemente all'interno di Emacs. Ha molte opzioni per determinare dove aprire un nuovo buffer (una nuova finestra, un nuovo frame, una finestra esistente, ecc.).

Emacs ha introdotto un concetto di schede in 27.1. Tuttavia, non sembra esserci un modo semplice per dire display-bufferche vuoi che i nuovi buffer si aprano in una scheda, invece che solo in una nuova finestra.

C'è un modo per configurare display-bufferper aprire tutti i buffer in una scheda nuova (o esistente?)?


La soluzione di NickD suggerisce di utilizzare una funzione come display-buffer-in-tab.

Sono stato in grado di farlo funzionare impostando display-buffer-base-actioncome segue:

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

Tuttavia, questo non sembra funzionare bene con funzioni come helpe magit-status. Tendono ad aprire troppe schede ogni volta che vengono eseguiti.

Possono essere necessarie impostazioni più specifiche per comando o per nuovo buffer.

Risposte

2 NickD Nov 11 2020 at 19:04

C'è display-buffer-in-new-tab. La sua stringa di documentazione dice:

display-buffer-in-new-tab is a compiled Lisp function in ‘tab-bar.el’.

(display-buffer-in-new-tab BUFFER ALIST)

Display BUFFER in a new tab.
ALIST is an association list of action symbols and values.  See
Info node ‘(elisp) Buffer Display Action Alists’ for details of
such alists.

Like ‘display-buffer-in-tab’, but always creates a new tab unconditionally,
without checking if a suitable tab already exists.

If ALIST contains a ‘tab-name’ entry, it creates a new tab with that name
and displays BUFFER in a new tab.  The ‘tab-name’ entry can be a function,
then it is called with two arguments: BUFFER and ALIST, and should return
the tab name.  When a ‘tab-name’ entry is omitted, create a new tab without
an explicit name.

This is an action function for buffer display, see Info
node ‘(elisp) Buffer Display Action Functions’.  It should be
called only by ‘display-buffer’ or a function directly or
indirectly called by the latter.

Non testato.

EDIT: l'ho trovato usando il sistema di aiuto di Emacs. Non lo uso tab-bar-modee non lo sapevo in anticipo, ma farlo C-h f display-buffer-TABmi mostra un buffer di completamento. Scansionandolo rapidamente, ho trovato display-buffer-in-tabe display-buffer-in-new-tab. Ho scelto quest'ultimo e ho ottenuto la doc string che ho incollato sopra.

Se il completamento del buffer è troppo lungo per eseguire la scansione facilmente a occhio, è possibile passare al buffer con C-x oe poi basta cercare ad esempio per tabnel buffer utilizzando C-s.

Imparare a usare Helpe anche imparare a cercare nei manuali con Infoè un ottimo investimento del tuo tempo.