2

I had a set of buffers open that I want to keep.

Then I started a search with M-x rgrep (SPC f g on Spacemacs).

While browsing results with n and p, each file containing a result is opened in a new buffer.

After I'm done with the search and browsing, I'm left with dozens of buffers open that I no longer want.

They are in the same project as I have the buffers I want to keep, so I can't just M-x projectile-kill-buffers.

Is there any other way?

agentofuser
  • 501
  • 3
  • 11
  • (1) From the `buffer-list`, save a new list of open interesting buffers [without a leading space] to a variable of your choice; (2) Do your stuff such as `regrep`, etc.; (3) `mapc` down the current `buffer-list` and if a buffer is interesting and not a `memq` of the saved list in step number 1 above [previously saved to variable of your choice], then kill that buffer. Add additional tests as needed; e.b., a file-visiting buffer. `buffer-list` is a function. – lawlist May 31 '18 at 22:43
  • Do you want the separate buffers to begin with? Maybe looking at having n/p reuse the same buffer would fit your needs? – glucas Jun 01 '18 at 11:59
  • @glucas good point. I guess in an ideal scenario n/p would reuse the same buffer, and I could optionally use N/P for "open in its own buffer" (taking inspiration from Vimium's f/F for "open link"/"open link in new tab"). – agentofuser Jun 01 '18 at 12:36

1 Answers1

2

Since you don't want to kill all windows of a certain mode, or all of the buffers in a certain directory I recommend using ibuffer you can sort the list of windows by view time s v and then kill all the buffers you wish from the top of the list.

n and p in rgrep open the files at pointer for viewing in a window, you can use arrow keys instead to just walk through the list without opening in a window.

manandearth
  • 2,068
  • 1
  • 11
  • 23
  • This works! I'm wondering if there's a more general solution, like "enter command X to start a new buffer 'scope'/'bubble', run whichever sequence of buffer-opening commands you want, then enter command Y to close said set of buffers". I'll accept this in a few days if that doesn't turn up though. Thanks! – agentofuser Jun 01 '18 at 12:40