Übersicht Letzte Änderungen Neuigkeiten Suchen ElispSektion KurzAnleitung Impressum
Kamerun: Erlangung der Unabhängigkeit 1960

BufferMenuSorting

BufferMenu has various options to sort the listing of buffers. According to the EmacsManual.

The buffers are listed in the order that they were current; the buffers that were current most recently come first.

What the manual fails to mention is that you can change the sorting with ‘M-x Buffer-menu-sort’.

‘M-2 M-x Buffer-menu-sort’
Sort by buffer name.
‘M-3 M-x Buffer-menu-sort’
Sort by buffer size (ascending).
‘M-4 M-x Buffer-menu-sort’
Sort by buffer mode name.
‘M-5 M-x Buffer-menu-sort’
Sort by buffer file name.
‘M-x Buffer-menu-sort’
Sort by display time (default).

If you hit the S key (bound to tabulated-list-sort) in the Buffer Menu, the Buffer Menu is sorted by column. Unfortunately, there’s no command I found for returning tabulated-list-sort-key variable to its default nil value – except to kill-buffer then buffer-menu to bring it back.

Sort by Buffer Name

If your buffer list becomes too disorganized, you can sort it using this function:

  (defun sort-buffers ()
    "Put the buffer list in alphabetical order."
    (interactive)
    (dolist (buff (buffer-list-sorted)) (bury-buffer buff))
    (when (interactive-p) (list-buffers))
    )
  
  (defun buffer-list-sorted ()
    (sort (buffer-list) 
  	(function
  	 (lambda
  	   (a b) (string<
  		  (downcase (buffer-name a))
  		  (downcase (buffer-name b))
  		  )))))

and bind it with

  (global-set-key "\M-b"    'sort-buffers)

An extension like this became obsolete with Emacs 22.

To permanently customize the default listing order of buffer menu, set ‘Buffer-menu-sort-column’. For example, use the following to automatically sort by column Mode.

   (setq Buffer-menu-sort-column 4)

You can easily sort on any column, in both directions, if you use BufferMenuPlus. If you instead use the vanilla BufferMenu, you can still sort the list in a couple of ways. – DrewAdams


CategoryBufferSwitching