3

I'd like to customize helm-mini in such a way that its helm-source-buffers-list would be decomposed in two parts:

  1. One source corresponding to buffers visiting a file (i.e. something like (remove-if-not #'buffer-file-name (buffer-list))

  2. Another corresponding to the complement of (1) (i.e. (remove-if #'buffer-file-name (buffer-list))

I looked at tutorials like this one which gives me an idea of how I could probably do it:

http://kitchingroup.cheme.cmu.edu/blog/2015/01/24/Anatomy-of-a-helm-source/

but I'm too new to Helm to imagine that whatever solution I will come up with will make complete sense or be minimal enough.. so I'd appreciate any help.

3

Short answer: Create your own helm buffer sources and modify the helm-mini-default-sources variable to use them.


The helm-mini command uses helm-mini-default-sources as its helm sources, so you can choose which sources to use and their order when showing in helm buffer. You cannot customize the helm-source-buffers-list variable itself, except choosing to use it or not. You need to create your own buffer list source to replace helm-source-buffers-list, for example,

(setq helm-mini-default-sources '(my-file-buffers
                                  my-other-buffers
                                  helm-source-recentf
                                  helm-source-buffer-not-found))

here, you need to create two new sources: my-file-buffers and my-other-buffers.

Usually, you should use the helm-source-buffers class to make these two sources, but you cannot use them in one and the same helm command (see closed issue https://github.com/emacs-helm/helm/issues/1034), so you also need to create your own helm buffer source class, it's easy if you use helm-source-buffers as a reference.

PS. helm wiki includes a section on Developping using helm: https://github.com/emacs-helm/helm/wiki#developpingusinghelmframework, it can be considered the official documentation of helm.

  • Thanks a lot, this puts me on the right path. I'm not sure about the "create your own helm buffer source class" part though.. could you be a bit more explicit? – cjauvin Jun 26 '15 at 15:02
  • helm source class is used to create helm source, so you need to create that class first since the helm-source-buffers class doesn't work, something like (defclass my-helm-source-buffers (helm-source-sync helm-type-buffer) ... ), it should be helpful if you know EIEIO. – xuchunyang Jun 26 '15 at 15:05
  • So if my understanding is correct, I should have to redefine the helm-source-buffers class so that it doesn't make use of helm-buffers-list-cache for its initial list of candidates, as you mention in the GH issue? – cjauvin Jun 26 '15 at 15:38
3

With the help of @xuchunyang's excellent answer and after an epic struggle with ELisp, this is the solution I came up with, and which seems to work:

;; This decomposes helm-source-buffers-list in two parts/sources:
;; (1) Files: file-visiting buffers
;; (2) Buffers non-file-visiting buffers

(defclass my-helm-source-file-buffers-class (helm-source-buffers)
  ((candidates :initform
               (lambda ()
                 (mapcar 'buffer-name
                         (cl-remove-if-not #'buffer-file-name (buffer-list)))))))

(defclass my-helm-source-nonfile-buffers-class (helm-source-buffers)
   ((candidates :initform
               (lambda ()
                 (mapcar 'buffer-name
                         (cl-remove-if #'buffer-file-name (buffer-list)))))))

;; Use the decomposition for helm-mini

(setq my-helm-source-file-buffers-list
      (helm-make-source "Files" 'my-helm-source-file-buffers-class)
      my-helm-source-nonfile-buffers-list
      (helm-make-source "Buffers" 'my-helm-source-nonfile-buffers-class))

(setq helm-mini-default-sources '(my-helm-source-file-buffers-list
                                  my-helm-source-nonfile-buffers-list
                                  helm-source-recentf
                                  helm-source-buffer-not-found))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.