3

How to move to previous or next buffer in a fixed & arbitrary order? I am using C-<left> and C-<right> but they move in a variable order, depending on the last viewed buffer, but if I want to switch back and forth between the two last files I worked in, with C-x b RET, then C-<left> and C-<right> would be always setting the two last viewed files in the ring, making it pointless.

When moving with next/previous, the idea is to have different alternatives: a manually sorted ring, last viewed ring, and other sorts (alphabetical, size, etc.). This by preserving or integrating the option of moving back and forth between the two last viewed the way C-x b RET does.

Individually sorting buffers is maybe too much, but is kind of important, since the typical tab system of ordinary editors allow for manually sorting the tabs.

Hopefully the sorting work for picking the buffers with ido-mode too.

Need to install a library or not necessary?

  • The buffer-list and buried-buffer-list cannot reliably be controlled in terms of ordering all buffers -- i.e., the list will change outside of your control. So, consider using something to organize those buffers first and then select a particular buffer. Alternatively, consider setting a value of buffers in a particular order and recording/embedding that list in the frame-parameter -- updating as needed. Then, you can access buffers from that recorded/embedded list that will be frame-local. You can programmatically alter or sort that list. See frame-bufs by Alp Aker for some idea. – lawlist May 15 '16 at 3:24
  • It looks like Austin Clements' library magic-buffer-list will do the alphabetic sort that you want out-of-the-box with a little customization of the default sorting: raw.githubusercontent.com/aclements/.emacs.d/master/lisp/… There is a previous and next function. Read through the library to understand how to set the defaults to your liking. You can then prevent the buffer list buffer from appearing if you don't want to see it. Word search forwards and backwards in the source code to see the interactive functions meant to be called by the user interactively. – lawlist May 15 '16 at 6:21
  • Do you know if these will work for ido-mode too? – mikl May 15 '16 at 12:26
  • Like suggested in that post? – Nsukami _ May 15 '16 at 13:01
  • Here is an example of how to sort buffers alphabetically and select a buffer using ido. You can modify it to remove uninteresting buffers, and/or select a particular starting location. (defun ido-alpha-switch-buffer () (interactive) (let* ( (string-buffer-list (mapcar (lambda (x) (buffer-name x)) (buffer-list))) (buffer-list-alphabetized (sort string-buffer-list #'(lambda (e1 e2) (string-lessp e1 e2)))) (buffer (ido-completing-read "Select Buffer: " buffer-list-alphabetized)) ) (unless (minibufferp buffer) (switch-to-buffer buffer)))) – lawlist May 15 '16 at 17:26
1

You can sort the buffers you access in multiple ways, if you use Icicles.

When you use any command, such as C-x b, that accesses a buffer by name, you can use C-, to choose a different sort order for the buffer-name candidates.

By default, these buffer-name sort orders are available, to choose from:

by last display time
*...* last 
by buffer size
by major mode name 
by mode-line mode name
by file/process name 

Besides those sort orders, which are specific to buffer-name completion, the following general sort orders are also available for buffer-name completion:

alphabetical
by 2nd parts alphabetically
by flx score
by last display time
by last use as input
by previous use alphabetically
case insensitive
extra candidates first 
special candidates first

Finally, you can define your own sort orders. And you can make any given sort order the default one for a given command or for all buffer-name completion (see user option icicle-buffer-sort).

See Icicles - Buffer-Name Input for more information.

1

The built-in bs library has support for defining one or more configurations that you can use to cycle between buffers. The commands bs-cycle-next and bs-cycle-previous move back and forth between the buffers defined by the current configuration (bs-current-configuration). Configurations can define a subset of buffers, as well as a sort order.

You might be able to customize this library to meet your needs.

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.