timwoj · 2022-06-29 18:55
I frequently will open Emacs with a large number of files, such as something like `emacs $(grep -r something *)`. From there I'll work on a file, close it, and work on the next one. Is there a way to tell Emacs to send all of the special buffers such as scratch, Messages, lsp buffers (for clangd), etc to the end of the buffer list? Right now, as I'm working on files, those are interspersed through out the list of buffers, so I have to skip over them as I encounter them. It's not a big deal, but it's rather annoying.
Along the same lines, is it possible to keep lsp-mode from opening buffers for clangd unless an error or something occurs that I actually need to know about?
EDIT: I dig all of the ibuffer stuff. That'll come in handy. I'm not sure I was clear in what I meant in the description though, so I'll step through exactly what I'm seeing.
1. From a terminal run emacs and pass it 4 files to open.
2. Window opens split horizontally with two buffers showing, one of the first file in the list and the second is the buffer list.
3. `C-x 1` cuts the window down to just the first file buffer showing.
4. `C-x k` kills the first file buffer, but now instead of being on the second file buffer, I'm on the `*scratch*` buffer.
5. `C-x k` kills the scratch buffer and now I'm on on the second file. Another `C-x k` kills that file buffer, but now I'm on the `*Messages*` buffer.
This is what I mean by shoving all of the special buffers to the end of the list. I want to be able to open a bunch of files and edit/kill their buffers in sequence, without any of those other buffers getting in the way of the editing.
hcalves · 2022-06-29 19:39
I don't have an answer for the specific question of moving special buffers to the \*end\* of the list, but the default buffer list (C-x C-b) has this binding:
T Toggle whether the menu displays only file buffers.
Extension_Try_6870 · 2022-06-29 19:55
I found this: https://www.emacswiki.org/emacs/IbufferMode#h5o-3
StrangeAstronomer · 2022-06-29 21:44
After >35 years with emacs, I did not know that!
StrangeAstronomer · 2022-06-29 21:48
I change buffer-list to initially only display files:
(defun bh:buffer-menu (&optional arg)
"runs buffer-menu but with the sense of C-u inverted (ie files only unless C-u is given)"
(interactive "P")
(setq arg (not arg))
(buffer-menu arg))
(global-set-key (kbd "C-x C-b") 'bh:buffer-menu)
If I want all buffers, then it's `C-u C-x C-b` or use the 'T' toggle as noted by u/hcalves
xtifr · 2022-06-29 22:20
Use `ibuffer` instead of `list-buffers` for maximum control over how the buffers are displayed and sorted. It has a crazy number of options. Many people bind `ibuffer` to `C-x C-b`.
FrozenOnPluto · 2022-06-29 23:58
Also see 'filetree', which can also be a buffer list handler which suppresses showing the \*special\* type buffers.
purplug · 2022-06-30 00:34
Have you considered something like persp-mode? There's several variations of it, but being able to separate buffers into groups could help with this issue.
For example, I create a new perspective named "Session" after Emacs finishes initializing so all the random special buffers, like messages or other log buffers, go into the default perspective. Then I have a wrapper around opening a new project to create a new perspective there.
Works really well for me and I also often kill a buffer to go to the previous one.
timwoj · 2022-06-30 03:30
I wonder if it would be possible to set that up automatically, maybe using `emacs-startup-hook`.
purplug · 2022-06-30 10:06
It is automatic. I forgot to mention that
github-alphapapa · 2022-07-01 05:45
You could write a simple function to iterate over the buffer list and `bury-buffer` any special buffer.
kamui78 · 2022-07-02 15:07
I use the consult-buffer from the consult package and filter the buffers I don't want to see with the following configuration:
(use-package consult
:ensure t
:config
(setq consult-buffer-filter
'(
"\\` "
"\\`\\*Completions\\*\\'"
"\\`\\*Backtrace\\*\\'"
"\\`\\*Messages\\*\\'"
"\\`\\*XELB-DEBUG\\*\\'"
"magit*"
"\\`\\*Org Preview LaTeX Output\\*\\'"
"\\`\\*Flymake log\\*\\'"
"\\`\\*Semantic SymRef\\*\\'"
"\\`\\*tramp/.*\\*\\'"
)))