I’d like to make a simple change to Emacs so that the next-buffer and previous-buffer commands (which I have bound to C-x <RIGHT> and C-x <LEFT> will skip over the *Messages* buffer.
I’m using Emacs 24 and the Emacs Starter Kit.
I’ve read the following related questions and answers, but they are not what I want:
- Buffer cycling in Emacs: avoiding scratch and Messages buffer
- Emacs disable *Messages* buffer
- Emacs Lisp Buffer out of focus function?
Here are some of the reasons why they don’t work:
- I’d like to keep it as simple as possible. Fewer configuration changes are better.
- I don’t want to kill or prevent
*Messages*altogether. (add-to-list 'ido-ignore-buffers "^\*Messages\*"helps with myC-x b(ido-switch-buffer) but does not change hownext-bufferandprevious-bufferbehave.
The simplest I can think of is defining an advice for both functions. Here it is for
next-buffer. Similarly would be forprevious-buffer. You can also define a configuration variable to enable/disable the behavior (or activating/deactivating the advice):Maybe you can compare buffers in some other way instead of its string name, but that will work. The code for previous buffer is almost the same. I don’t know either if there is a way of calling the original function without triggering the advice once inside the advice itself, but again, the code will work even if the name of the buffer is tested afterwards (will fail if you just have one buffer, and it is the messages buffer; some code can check if there is just one buffer and don’t call
next-bufferagain).If you want to use a standalone function that does the same thing: