0

In my current setup, not having customised it, helm-mini shows me all the buffers in a single list, it then shows the recent files and a section to "Create buffer".

I am wondering if it's possible to have multiple lists of buffers with different filters. Namely, I would like to have a section showing normal buffers, a section showing temporary buffers (normally starting and ending with *), and a section for orphan buffers (not connected to a file).

2 Answers 2

1

Based on @jagrg answer, I managed to come up with this

 (defclass tohiko/helm-source-file-buffers (helm-source-buffers) ((candidate-transformer :initform (lambda (buffers) (cl-loop for buf in buffers when (with-current-buffer buf buffer-file-name) collect buf)))) ) (defclass tohiko/helm-source-nonfile-buffers (helm-source-buffers) ((candidate-transformer :initform (lambda (buffers) (cl-loop for buf in buffers unless (with-current-buffer buf buffer-file-name) collect buf)))) ) (setq tohiko/helm-source-file-buffers-list (helm-make-source "File Buffers" 'tohiko/helm-source-file-buffers)) (setq tohiko/helm-source-nonfile-buffers-list (helm-make-source "Non-file Buffers" 'tohiko/helm-source-nonfile-buffers)) (setq helm-mini-default-sources '(tohiko/helm-source-file-buffers-list tohiko/helm-source-nonfile-buffers-list helm-source-recentf helm-source-buffer-not-found)) 

Although I am a beginner, so I am not sure if I am defining the class correctly. Also, I am using helm-make-source rather than helm-build-in-buffer-source, as @jagrg suggested, I am not sure what the difference is.

Finally, while this view does show new buffers that are not saved, I haven't figured out how to separate them into their own list.

2
  • DId you manage to come up with a solution? Commented Feb 18 at 7:57
  • 1
    Yes, switched to vertico/consult. Commented Feb 24 at 14:30
1

I think you would have to write your own sections, which in helm terms is called sources, and either add them to the helm-mini-default-sources variable or create your own custom command. Filtering is usually done in the candidate-transformer or filtered-candidate-transformer slots. See helm-source-in-buffer for more information.

I'm not sure I understand how you're distinguishing temporary from orphan buffers, maybe you can explain in the comments, but for file buffers and non-file buffers you could try:

(setq tohiko/helm-source-file-buffers (helm-build-in-buffer-source "File Buffers" :data 'helm-buffer-list :candidate-transformer (lambda (buffers) (cl-loop for buf in buffers when (with-current-buffer buf buffer-file-name) collect buf)) :action (lambda (buffer) (switch-to-buffer buffer)))) (setq tohiko/helm-source-nonfile-buffers (helm-build-in-buffer-source "Non-file Buffers" :data 'helm-buffer-list :candidate-transformer (lambda (buffers) (cl-loop for buf in buffers unless (with-current-buffer buf buffer-file-name) collect buf)) :filtered-candidate-transformer 'helm-skip-boring-buffers :action (lambda (buffer) (switch-to-buffer buffer)))) (setq helm-mini-default-sources '(tohiko/helm-source-file-buffers tohiko/helm-source-nonfile-buffers helm-source-buffer-not-found)) 
5
  • Thanks! I didn't know about helm sources. I mean by orpahn buffers those that get created when I input a new name buffer in helm-mini. Using your code, these buffers do not appear in either section. In the default helm-mini, they just appear in different color. Commented Feb 4, 2019 at 8:32
  • I see. I added helm-source-buffer-not-found to helm-mini-default-sources. See if that works for you. Commented Feb 4, 2019 at 10:05
  • Mmm... I don't think that's the problem. Right now, if I input a name of a new buffer, it shows up in the "Create buffer" section (or the helm-source-buffer-not-found source). But then if I do create the buffer and open helm-mini again, the buffer does not show up in any section. Commented Feb 4, 2019 at 11:31
  • Changing (mapcar 'buffer-name (buffer-list)) to 'helm-buffer-list should fix the issue, although I'm not why the previous method didn't work. Commented Feb 4, 2019 at 15:26
  • Your solution looks great, and is a much better approach indeed. Commented Feb 4, 2019 at 16:10

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.