The Emacs buffers menu shows two columns: One with the buffer name, and one with the filename, with full path. The paths in our projects can become very long, spanning more than one screen. So I would like to not show them in the buffers menu. How can I achieve this? Bonus: use a tooltip for the path instead.

  • Not an answer to your specific question (hence a comment) but have you looked at Ibuffer? – terdon Apr 5 '13 at 16:08
  • No, I did not know lbuffer so far. I also just found buffer-menu+, which can en- and disable the columns displayed in the menu. – Arne Apr 5 '13 at 17:21
  • Cool, why don't you post it as an answer? – terdon Apr 5 '13 at 17:41
  • I think it is not the right choice. It seems there is buffer-menu (that's just a buffer displaying a buffer list), buffers-menu (that's the one you get with Ctrl+Left Mouse Button), buffer-menu+ (that's a better buffer displaying a buffer list), and your lbuffer (that's again a buffer displaying a buffer list). And then there is msb-mode, which I haven't tried yet. – Arne Apr 5 '13 at 17:45

Since Emacs comes with sources, I just took the liberty to adjust the mouse-buffer-menu. I put this in my init.el to override the default implementation that creates the mouse-buffer-menu-alist. This one does away with the filename and only shows the buffer name. For my needs this is enough:

(defun mouse-buffer-menu-alist (buffers)
  (let (tail
    (maxlen 0)
    (setq buffers
      (sort buffers
        (function (lambda (elt1 elt2)
                (string< (buffer-name elt1) (buffer-name elt2))))))
    (setq tail buffers)
    (while tail
      (or (eq ?\s (aref (buffer-name (car tail)) 0))
      (setq maxlen
        (max maxlen
             (length (buffer-name (car tail))))))
      (setq tail (cdr tail)))
    (setq tail buffers)
    (while tail
      (let ((elt (car tail)))
    (if (/= (aref (buffer-name elt) 0) ?\s)
        (setq head
             (format "%%-%ds  %%s%%s" maxlen)
             (buffer-name elt)
             (if (buffer-modified-p elt) "*" " ")
             (with-current-buffer elt
               (if buffer-read-only "%" " "))
      (setq tail (cdr tail)))
    ;; Compensate for the reversal that the above loop does.
    (nreverse head)))
| improve this answer | |
  • PS: This function is taken from the Emacs23 source. For Emacs24 it might look a bit different. – Arne Apr 8 '13 at 12:31
  • This seems to work fine with Emacs 24, thanks! – kcbanner Aug 4 '13 at 1:54
  • Thanks for steering me in the right direction. Incidentally, if you don't like having subgroups in the menu (this was my case, because I don't like selecting a buffer to be a two-step process), you can set the mouse-buffer-menu-mode-mult variable to a large number in .emacs init file. See comments in mouse.el source file. – Colin Mar 5 '15 at 14:24

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.