Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
    
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

1 Answer 1

up vote 1 down vote accepted

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)
    head)
    (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
          (cons
           (cons
            (format
             (format "%%-%ds  %%s%%s" maxlen)
             (buffer-name elt)
             (if (buffer-modified-p elt) "*" " ")
             (with-current-buffer elt
               (if buffer-read-only "%" " "))
                     )
            elt)
           head))))
      (setq tail (cdr tail)))
    ;; Compensate for the reversal that the above loop does.
    (nreverse head)))
share|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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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