Skip to content

Instantly share code, notes, and snippets.

@xuchunyang
Created April 4, 2015 12:12
Show Gist options
  • Save xuchunyang/7c595f69acc4728de211 to your computer and use it in GitHub Desktop.
Save xuchunyang/7c595f69acc4728de211 to your computer and use it in GitHub Desktop.
helm demo 02
;;; Demo 1
;;; `candidates' is a real list
(setq simple-helm-source
'((name . "A simple source")
(candidates . (1 2 3 4))
(action . (lambda (candidate) (message "%s" candidate)))))
(helm :sources '(simple-helm-source))
;;; Demo 2
;; `candidates' is variable name
(setq some-candidates ; a list with (Display . Real)
'(("one" . "1")
("two" . "2")
("three" . "3")
("four" . "4")
("five" . "5")))
(setq medium-helm-source
'((name . "Big source")
(header-name . (lambda (name) (concat name " - " (buffer-name))))
(candidates . some-candidates)
(action . (lambda (candidate) (message "%s" candidate)))))
(helm :sources '(medium-helm-source) :buffer "*big helm*")
;;; Demo 3
;;; `candidates' is a function
(setq another-helm-source
'((name . "another source")
(candidates . (lambda () (number-sequence 1 10)))))
(helm :sources '(another-helm-source))
;;; Demo 4 --- More than one Marked candidates
(setq data '(("John" . "john@email.com")
("Jim" . "jim@email.com")
("Jane" . "jane@email.com")
("Jill" . "jill@email.com")))
(setq some-helm-source
`((name . "HELM at the Emacs")
(candidates . ,data)
(action . (lambda (candidate)
(helm-marked-candidates)))))
(helm :sources '(some-helm-source))
;;; Demo 5 --- More than one action
(setq some-helm-source
'((name . "HELM at the Emacs")
(candidates . data)
(action . (("show email address" .
(lambda (candidate)
(message "selected: %s" (helm-marked-candidates))))
("send email" .
(lambda (candidate)
(message "selected: %s" (helm-marked-candidates))))))))
(helm :sources '(some-helm-source))
;;; Demo 6 --- Actions when there is no match
(defun some-action (arg)
(message "%s\n%s" (helm-get-selection) (helm-marked-candidates)))
(defun default-action (candidate)
(browse-url
(format
"http://www.google.com/search?q=%s"
(url-hexify-string helm-pattern))))
(setq source1 '((name . "HELM")
(candidates . (1 2 3 4))
(action . (("open" . some-action)))))
(setq fallback-source '((name . "fallback")
(dummy)
(action . (("Google" . default-action)))))
(helm :sources '(source1 fallback-source))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment