Last active
August 29, 2015 14:18
-
-
Save xuchunyang/bd587c53a450f4aebf18 to your computer and use it in GitHub Desktop.
helm demo 02
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; elisp-helm-demo-02.el --- Write helm extensions demo 02 | |
;; Demo 01 --- with matched got highlighted with `helm-build-in-buffer-source' | |
(setq a-helm-source | |
(helm-build-in-buffer-source "*a helm source*" | |
:init (lambda () | |
(let ((text (buffer-string))) | |
(with-current-buffer (helm-candidate-buffer 'global) | |
(insert text)))) | |
:real-to-display (lambda (cand) (upcase cand)) ; Real displayed stuff | |
:action 'message)) | |
(helm :sources '(a-helm-source)) | |
;;; Demo 02 --- use `candidate-transformer' | |
(setq b-helm-source | |
'((name . "B helm source*") | |
(candidates . (lambda () (number-sequence 1 100))) | |
;; remove even numbers from candidates | |
(candidate-transformer . (lambda (candidates) | |
(seq-remove 'evenp candidates))) | |
(action . message))) | |
(helm :sources '(b-helm-source)) | |
;;; Demo 03 --- use `filtered-candidate-transformer' | |
(setq c-helm-source | |
'((name . "C helm sourcee") | |
(candidates . (lambda () (number-sequence 1 100))) | |
(filtered-candidate-transformer . | |
(lambda (candidates source) | |
(mapcar (lambda (x) | |
(+ (* x 10) | |
(string-to-number | |
helm-pattern))) | |
candidates))) | |
(action . message))) | |
(helm :sources '(c-helm-source)) | |
;;; Demo 04 --- use `display-to-real' | |
(setq d-helm-source | |
'((name . "D helm source") | |
(candidates . ;; (("one" . "1") ("two" . "2")) | |
("one" "two" "three") | |
) | |
(display-to-real . (lambda (sel-candidate) (concat ">|< " sel-candidate))) | |
(action . message))) | |
(helm :sources '(d-helm-source)) | |
;;; Demo 06 --- `real-to-display' | |
(setq f-helm-source | |
'((name . "F helm source") | |
(candidates . ("one" "two")) | |
(real-to-display . (lambda (sel-candidate) | |
(concat "<|> " sel-candidate))) | |
(action . message))) | |
(helm :sources '(f-helm-source)) | |
;;; Demo 05 --- use `filtered-one-by-one' | |
;; (setq e-helm-source | |
;; '((name . "E helm source") | |
;; (candidates . (("one" . "1") ("two" . "2"))) | |
;; (filter-one-by-one . (lambda (candidates) candidates)) | |
;; (action . message))) | |
;; (helm :sources '(e-helm-source)) | |
;;; Demo 07 --- Still use (Dispaly . Real) | |
(setq data `(,(cons "one" (list :number "1" :chinese "一")) | |
,(cons "two" (list :number "2" :chinese "二")) | |
,(cons "three" (list :number "3" :chinese "三")))) | |
(setq g-helm-source | |
`((name . "G helm source") | |
(candidates . data) | |
(action . ,(helm-make-actions | |
"Show number" (lambda (cand) | |
(message (plist-get cand :number))) | |
"Show Chinese" (lambda (cand) | |
(message (plist-get cand :chinese))))))) | |
(helm :sources '(g-helm-source)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment