1

When I used vanilla Emacs,

C-xC-bT

showed me the list of files I had open, with special buffers filtered out.

Recently I switched to Emacs Prelude, which uses ibuffer, and I'm not sure why the letter T trick won't work.

  • ibuffer is not list-buffers. See C-h f ibuffer for info about how to use it to filter. – Drew Nov 22 '17 at 16:53
3

TL;DR

Emacs Prelude binds C-xC-b to ibuffer. What T does in the *Buffer List* buffer, /v does in the *Ibuffer* buffer. This filter was only added in Emacs 26, however, so before that you have to emulate it: /fRET will filter by buffers associated with a file, but this does not exclude all special buffers, such as Magit buffers. You can then, for example, filter the list further by excluding starred buffers: /n^\*RET/!.

Type ? in *Ibuffer* for a listing of ibuffer commands and their key bindings.

In order to backport /v to Emacs versions prior to 26, rather than emulating it with more complex filter combinations, you can write something like

(with-eval-after-load 'ibuffer
  (define-ibuffer-filter my-visiting-file
      "Limit current view to buffers that are visiting a file."
    (:description "visiting a file"
     :reader nil)
    (buffer-file-name buf))

  (define-key ibuffer-mode-map (kbd "/ v") #'ibuffer-filter-by-my-visiting-file))

When I used vanilla Emacs, C-xC-bT showed me the list of files I had open, with special buffers filtered out.

Indeed, this is because C-hkC-xC-b (or M-xdescribe-keyRETC-xC-b) reveals the key is bound to the list-buffers command by default:

C-x C-b runs the command list-buffers (found in global-map), which is
an interactive compiled Lisp function in ‘buff-menu.el’.

It is bound to C-x C-b, <menu-bar> <buffer> <list-all-buffers>.

(list-buffers &optional ARG)

Display a list of existing buffers.
The list is displayed in a buffer named "*Buffer List*".
See ‘buffer-menu’ for a description of the Buffer Menu.

By default, all buffers are listed except those whose names start
with a space (which are for internal use).  With prefix argument
ARG, show only buffers that are visiting files.

The *Buffer List* buffer has Buffer-menu-mode enabled, under which C-hkT reveals:

T runs the command Buffer-menu-toggle-files-only (found in
Buffer-menu-mode-map), which is an interactive compiled Lisp function
in ‘buff-menu.el’.

It is bound to T, <menu-bar> <Buffer-menu-mode> <tf>.

(Buffer-menu-toggle-files-only ARG)

Toggle whether the current buffer-menu displays only file buffers.
With a positive ARG, display only file buffers.  With zero or
negative ARG, display other buffers as well.

You can read more about this buffer list and menu in the Emacs Manual under (emacs) List Buffers and (emacs) Several Buffers and in the docstrings of C-hfbuffer-menuRET (or M-xdescribe-functionRETbuffer-menuRET) and C-hfBuffer-menu-modeRET.


Recently I switched to Emacs Prelude, which uses ibuffer

Indeed, as mentioned in its documentation under Global Keymap, Prelude rebinds the default list-buffers binding to the more featureful ibuffer.

I'm not sure why the letter T trick won't work.

Although ibuffer provides a superset of buffer-menu functionality, the two are mostly, if not completely, disjoint modes, with many different keybindings. In the *Ibuffer* buffer, C-hkT reveals:

T runs the command ibuffer-do-toggle-read-only (found in
ibuffer-mode-map), which is an interactive compiled Lisp function in
‘ibuffer.el’.

It is bound to T.

(ibuffer-do-toggle-read-only &optional ARG)

Toggle read only status in marked buffers.
If optional ARG is a non-negative integer, make buffers read only.
If ARG is a negative integer or 0, make buffers writable.
Otherwise, toggle read only status.

In order to find the functionality you are looking for, as well as other ibuffer features, I recommend typing ? (or C-hm or M-xdescribe-modeRET) in the *Ibuffer* buffer and reading through the mode's description.

Here you may spot that /v is bound to ibuffer-filter-by-visiting-file:

/ v runs the command ibuffer-filter-by-visiting-file (found in
ibuffer-mode-map), which is an interactive autoloaded compiled Lisp
function in ‘ibuf-ext.el’.

It is bound to / v, <menu-bar> <view> <filter>
<filter-by-visiting-file>.

(ibuffer-filter-by-visiting-file QUALIFIER)

Limit current view to buffers that are visiting a file.

which is analogous to T under *Buffer List*, and /* is bound to ibuffer-filter-by-starred-name:

/ * runs the command ibuffer-filter-by-starred-name (found in
ibuffer-mode-map), which is an interactive autoloaded compiled Lisp
function in ‘ibuf-ext.el’.

It is bound to / *, <menu-bar> <view> <filter>
<filter-by-starred-name>.

(ibuffer-filter-by-starred-name QUALIFIER)

Limit current view to buffers with name beginning and ending
with *, along with an optional suffix of the form digits or
<digits>.

which is not too divorced from the inverse operation (you can precisely invert a filter via /!).


In general, I recommend giving default bindings a chance to grow on you, but if your muscle memory is too strong and/or you don't like ibuffer's default bindings too much, you can emulate the behaviour under *Buffer List* by rebinding T to ibuffer-filter-by-visiting-file:

(with-eval-after-load 'ibuffer
  (define-key ibuffer-mode-map "T" #'ibuffer-filter-by-visiting-file))

or equivalently, if you prefer named and documented hooks to anonymous eval-after-load forms:

(defun my-ibuffer-setup-bindings ()
  "Customise `ibuffer' key bindings."
  (define-key ibuffer-mode-map "T" #'ibuffer-filter-by-visiting-file))

(add-hook 'ibuffer-load-hook #'my-ibuffer-setup-bindings)
  • damn that was a long answer – american-ninja-warrior Nov 23 '17 at 12:44
  • perhaps a one line summary at the top would help, like a TLDR – american-ninja-warrior Nov 23 '17 at 12:45
  • @joshsverns Done. – Basil Nov 23 '17 at 14:45
  • this solution did not work – american-ninja-warrior Dec 1 '17 at 19:24
  • @joshsverns Please elaborate, perhaps by updating your answer with what you have tried, what you expected and the behaviour you are actually witnessing. It "did not work" does help anyone help you. – Basil Dec 1 '17 at 19:28

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.