0

I am trying to put all (opened) org files in a list so I could add them to helm-projectile-switch-to-file lists.

I was able to get to this code:

  (->> (buffer-list)
       (--select (with-current-buffer it
                   (derived-mode-p 'org-mode)))
       (mapc #'kill-buffer))

but this kills the buffers instead of putting them in an aggregated list.

Drew
  • 29,895
  • 7
  • 74
  • 104
SFbay007
  • 1,917
  • 1
  • 20
  • 39

1 Answers1

1

If you don't want to kill the buffers, I suggest not applying kill-buffer to each element. Other than that, you pretty much got everything done already. Here's a version that does not require any external libraries:

(seq-filter '(lambda (buffer)                                                                                                                                                            
               (with-current-buffer buffer
                 (derived-mode-p 'org-mode)))
            (buffer-list))
Thomas
  • 17,016
  • 4
  • 46
  • 70
  • Thank you Thomas. I tried applying this to helm-projectile list: (add-to-list helm-source-projectile-buffers-list '(lambda (buffer) (with-current-buffer buffer (derived-mode-p 'org-mode))) (buffer-list)) but that gave errors. I don't know how to correctly add the list of open org-files to the helm-projectile-switch-to-buffer list. – SFbay007 Jan 31 '20 at 08:40
  • It looks like you forgot the `(seq-filter ` part at the beginning. But also, `add-to-list` is only for adding a single element. Try `(setq helm-source-projectile-buffers-list (append helm-source-projectile-buffers-list (seq-filter...)))` instead. – Thomas Jan 31 '20 at 08:44
  • I still don't see org-files that are open listed along other project files when calling helm-projectile-switch-to-buffer. – SFbay007 Jan 31 '20 at 09:06
  • Sorry, can't help you with that - the above code gets you the list of buffers you're after, but I have no experience with helm-projectile. – Thomas Jan 31 '20 at 09:37