Emacs helm with multiple sources

205 views Asked by At

I use helm for Emacs with several sources and wonder how I can extract the list of all entries that the user has marked with Ctrl+Space. As an example, execute the following in your *scratch* buffer

(require 'helm)

(defun helm-test-action (candidate)
  "Test."
  (interactive)
  (message (concat "candidate = " (prin1-to-string candidate) 
                   "\n, helm-marked-candidates = " (prin1-to-string (helm-marked-candidates)))))

(defun helm-test-case ()
  "Test."
  (interactive)
  (helm :sources (list (helm-build-sync-source "First Source"
                        :candidates '("one" "two" "three")
                        :action #'helm-test-action)
                       (helm-build-sync-source "Second Source"
                        :candidates '("four" "five")
                        :action #'helm-test-action))))

and then M-x helm-test-case.

When you mark, say, "one" and "four" with Ctrl+Space and press Enter, how do I retrieve the two marked entries from my action? It seems candidate is always the line on which the cursor has been placed and (helm-marked-candidates) yields the list of marked entries of the current source. How do I get the list of marked entries across all sources?

Thanks for your help,

HPF

1

There are 1 answers

0
HPF On

The answer is to use (helm-marked-candidates :all-sources t). This returns a list of all marked entries or, if none has been marked, the entry under the cursor when you hit enter.

It makes sense, of course, only if all your sources contain candidates of the same form and if the default action is the same for all sources. It seems this requirement isn't enforced though.

Regards,

HPF