Going to the Top and Bottom of iBuffer

I use iBuffer a lot. That’s probably because I get a little OCD about stray buffers eating up memory for no reason. With my new 16 GB laptop, buffers eating up memory isn’t much of a problem but it’s too late for me to reform my ways.

I especially like to clean up after I upgrade my packages. That process always leaves a Compile-Log buffer at the top of the iBuffer list and a Packages buffer at the bottom. Of course, when I navigate to the head or tail of the buffer I end up in the wrong place—not at the head or tail of the list.

If that seems a little familiar it’s probably because Magnar Sveen had similar problem with dired and solved it with a bit of Elisp. So I shamelessly ripped off Sveen’s code and made a few trivial changes so it does the same thing for iBuffer that Sveen’s did for dired. If you’re having the same problem, the code is below. It’s almost embarrassing to post it because it’s such a rip off but Emacsers who don’t have the wherewithal to figure out which key map to use or who don’t know Elisp may find it useful.

;; Stolen from Magnar's code to do the same thing for dired
;; http://whattheemacsd.com/setup-dired.el-02.html
(defun ibuffer-back-to-top ()
  (interactive)
  (beginning-of-buffer)
  (next-line 3))

(defun ibuffer-jump-to-bottom ()
  (interactive)
  (end-of-buffer)
  (next-line -2))

(eval-after-load 'ibuffer
  '(progn
     (define-key ibuffer-mode-map
       (vector 'remap 'end-of-buffer) 'ibuffer-jump-to-bottom)
     (define-key ibuffer-mode-map
       (vector 'remap 'beginning-of-buffer) 'ibuffer-back-to-top)))
This entry was posted in General and tagged . Bookmark the permalink.