11
  1. M-x ibuffer
  2. Select a buffer
  3. Kill that buffer

After the buffer is killed, the ibuffer buffer re-appears, but it still shows the buffer name killed in step 3.

Is it possible to have ibuffer auto-refresh the list of buffers?

  • If you press Ctrl-x Ctrl-b again in ibuffer, it makes autorefresh. – ofenerci Aug 30 '17 at 7:59
  • @ofenerci For me (v25.2.2) C-x C-b opens an additional window *Buffer List* with the current list of buffers, but the *Ibuffer* is left unchanged – user2740 Jan 25 at 14:08
12

Running the command ibuffer-auto-mode in an Ibuffer buffer makes it refresh the display after each interactive command.

There doesn't appear to be a direct way of activating it automatically. You can put this in your init file:

(add-hook 'ibuffer-mode-hook (lambda () (ibuffer-auto-mode 1)))
  • This accepted solution breaks the selection in other buffer. When I enable that hook, if I do a selection on any buffer, then invoke ibuffer, the selection is lost. – nephewtom Jun 23 '17 at 18:10
7

The right way to do it is to introduce support in ibuffer for auto-revert-mode. This can be achieved by defining buffer-stale-function for those those buffers. Arguably, since buffer-menu supports that feature, it'd be good to have it upstream for ibuffer too, but that doesn't seem to be the case for now.

Anyway, here's a way to do it:

(defun my-ibuffer-stale-p (&optional noconfirm)
  ;; let's reuse the variable that's used for 'ibuffer-auto-mode
  (frame-or-buffer-changed-p 'ibuffer-auto-buffers-changed))

(defun my-ibuffer-auto-revert-setup ()
  (set (make-local-variable 'buffer-stale-function)
       'my-ibuffer-stale-p)
  (set (make-local-variable 'auto-revert-verbose) nil)
  (auto-revert-mode 1))

(add-hook 'ibuffer-mode-hook 'my-ibuffer-auto-revert-setup)

Note: in general, one would need to define a value for revert-buffer-function, but ibuffer already does that (it's set to ibuffer-update)

  • 1
    Is there a reason to prefer this method over ibuffer-auto-mode? – nispio Oct 15 '14 at 2:35
  • Well auto-revert-mode uses timers, and ibuffer-auto-mode uses post-command-hook, so there's an obvious difference; but offhand I couldn't say if one was preferable to the other. – phils Oct 15 '14 at 2:45
  • 3
    @nispio I guess I tend to prefer generic solutions to ad-hoc ones. So in that sense, making ibuffer buffers behave like others when it comes to refreshing outdated content feels cleaner to me. Also, I generally dislike abusing post-command-hook that way: it's really overkill when you happen to do something completely unrelated in the buffer. Finally, if some kind of keystroke is required for content to be refreshed, it might as well be g, which is the explicit way of updating content. But granted, it's probably a philosophical issue :) – Sigma Oct 15 '14 at 2:57
  • 1
    When I use this method, I keep getting a message Reverting buffer `*Ibuffer*'. The message is intrusive because it keeps interrupting me when I am working in the minibuffer. The message appears whether the ibuffer buffer is visible or not. – nispio Oct 15 '14 at 3:31
  • 1
    @nispio (setq auto-revert-verbose nil), potentially locally – Sigma Oct 15 '14 at 3:34

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.