1

When I run $ emacs file1 file2 file3 file4 in a Unix shell, this is the result (using C-x Left and C-x Right to switch buffers):

file4 file3 file1 file2 *BufferList* *scratch* 

The starting buffer is file4, and *Buffer List* has this order:

file4
file3
*scratch*
file1
file2

I disable the *scratch* buffer because it interrupts the middle of the list. (I never use it anyway.) When disabled, the result is different:

file1 file4 file3 file2 *BufferList*

The starting buffer is still file4 (which is no longer the "left-most" file in the list), and *Buffer List* has this order:

file4
file3
file1
file2

(These are both with the *Messages* buffer disabled. When re-enabled, the behavior is similar to the first example, but *Messages* is shoved in between file3 and file1 in the file switching list, which is the reason I disabled it in the first place.)

How is this still the default behavior? The file switching list and Buffer List do not match, and the files are out of order for both. Have there been no bug reports on this yet? I cannot find anything about this issue, which has existed for me on multiple emacs installations across a variety of Linux distributions over the years.

More importantly, is there anything I can do in my .emacs file that can alter the order of files opened in one command? I'd like it to be in order: 1, 2, 3, 4. Additionally, I would like file1 to be the starting buffer upon opening emacs instead of file4.

9
  • If you mean the value returned by function buffer-list then say that explicitly. If that's not what you mean then specify clearly what you mean by the order of "the Buffer List". Do you mean the order you see when you do C-x C-b? Do you see the same thing if you start Emacs with emacs -Q (no init file)? If not, bisect your init file to find the culprit. There's no buffer *Buffer List* by default, so either your init file is opening that or you're doing so interactively (e.g. with C-x C-b). Please clarify the question.
    – Drew
    Commented Apr 2 at 19:39
  • The C-x C-b command opens the very same *Buffer List* in a little pop-up display. It is a default "buffer" when opening multiple files (use C-x Left and C-x Right to find it). And yes, using emacs -Q will have all the behavior seen above with the addition of that annoying *Buffer List* pop-up display. I have no idea what your buffer-list command is; that doesn't seem to exist in emacs.
    – Ness
    Commented Apr 2 at 20:27
  • I played around with the *Buffer List* for the first time (I never use it beyond closing individual files), and apparently the left/right order changes constantly with no discernible pattern. This...is horrible. Am I able to change that behavior as well?
    – Ness
    Commented Apr 2 at 20:42
  • Function buffer-list is not a command. M-: (buffer-list) shows you the current list of buffers, in canonical order. C-x C-b provides interactive manipulation of buffers, and you can sort the list by columns (up/down) - C-h m for info. Your question isn't clear, so far. Provide a step-by-step recipe from emacs -Q, saying, at each step, what you do, what you see, and what you expected to see instead.
    – Drew
    Commented Apr 2 at 20:53
  • old.reddit.com/r/emacs/comments/192vl7j/… may (or may not) help.
    – phils
    Commented Apr 3 at 2:51

1 Answer 1

2

The list of commands to replicate is simple: emacs -Q one two three four. The buffer list that appears will show vertically: "four three scratch messages one two". The current buffer above it is four. Then use C-x Right to cycle through the rest in this order: three, messages, one, two. bufferlist, scratch, and back to four. I just did it on both my work PC (Debian) and my home PC (WSL). The emacs version is 27.1 build 1 and apparently cannot be upgraded further.

I can replicate that in Emacs 27.2 and Emacs 28.2.

In Emacs 29.3 I get a split with four in the selected window and the *Buffer List* in the other window (listing from top to bottom: four, three, two, one, *scratch*, *Messages*).

Using C-x <right> repeatedly then cycles through three, two, one (in that order) then *Messages*, *Buffer List*, and lastly *scratch* (which is different to what's displayed in the buffer list).

Notwithstanding the last bit (and it's not clear whether that's a problem for you), it seems to me that your complaint was resolved in Emacs 29.

If this is a significant issue for you, my best suggestion is that you figure out how to update to Emacs 29 on your system. You can always compile from source if no package for your OS is available. The latest stable release at the time of writing is 29.3.

Failing that, https://old.reddit.com/r/emacs/comments/192vl7j/reordering_the_split_window_when_opening_two_files/ may help, but you will most likely need to examine the equivalent code in startup.el for your version of Emacs and figure out whether the suggestions in that discussion are applicable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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