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

The *Ibuffer* buffer re-appears. How can I get it to behave more like a *Help* buffer, which is buried (dropped to the end of the "recently used" list) when you switch away from it (so it doesn't appear undesirably like this)?

I formerly used electric-buffer-list, which had the desired behavior.

1

If we type C-h m in an *Ibuffer* buffer, we see that there is more than one way to select/open a buffer. When I place my cursor on a file in an *Ibuffer* buffer and type C-h k and then press the enter key, I get a *Help* buffer that describes the function ibuffer-visit-buffer. If I were type type M-x find-function RET ibuffer-visit-buffer RET, then I could examine the function at issue, which looks like this:

(defun ibuffer-visit-buffer (&optional single)
  "Visit the buffer on this line.
If optional argument SINGLE is non-nil, then also ensure there is only
one window."
  (interactive "P")
  (let ((buf (ibuffer-current-buffer t)))
    (switch-to-buffer buf)
    (when single
      (delete-other-windows))))

I am guessing that the original poster is most interested in changing the behavior of ibuffer-visit-buffer so that the *Ibuffer* gets "burried". As such, we could just add the following statement (bury-buffer (current-buffer)) and redefine the function at issue, place it in our .emacs / init.el file, and restart Emacs:

(require 'ibuffer)

(defun ibuffer-visit-buffer (&optional single)
  "Visit the buffer on this line.
If optional argument SINGLE is non-nil, then also ensure there is only
one window."
  (interactive "P")
  (let ((buf (ibuffer-current-buffer t)))
    (bury-buffer (current-buffer))
    (switch-to-buffer buf)
    (when single
      (delete-other-windows))))

Note that we could just have easily killed the *Ibuffer* buffer by using (kill-buffer (current-buffer)), since generating a new *Ibuffer* buffer is virtually instantaneous .....

  • Thanks very much for your "teach them to fish" details. For some reason bury-buffer didn't work, but kill-buffer did. – Rick Mohr Nov 21 at 0:41

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.