Last active
December 19, 2015 16:09
-
-
Save tungd/5981446 to your computer and use it in GitHub Desktop.
Use `grizzl` as backend for `ido` (WIP)
This file contains hidden or 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
;; Testing: `grizzl-ubiquitous` | |
(setq completing-read-function 'completing-read-grizzl) | |
(defun ->choices (coll pred) | |
"TODO: more consistence handle of `pred`" | |
(cond | |
((eq coll obarray) ;; obarray | |
smex-ido-cache) | |
((functionp coll) ;; function | |
(coll)) | |
((and (listp coll) (consp (first coll))) ;; alist | |
(mapcar #'car coll)) | |
((listp coll) coll) ;; list of strings | |
)) | |
(defun completing-read-grizzl (prompt coll &optional pred | |
require-match initial-input | |
hist def inherit-input-method) | |
(let* ((items (->choices coll pred)) | |
(index (grizzl-make-index items))) | |
(grizzl-completing-read prompt index))) |
This file contains hidden or 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
(defun ido-grizzl (items &optional do-full) | |
;; TODO: Making the index everytime is totally wrong | |
(let* ((*index* (grizzl-make-index items :case-sensitive ido-case-fold)) | |
(*result* (grizzl-search ido-text *index*))) | |
(grizzl-result-strings *result* *index*))) | |
(defadvice ido-set-matches-1 (around ido-use-grizzl) | |
"An advice using `grizzl' for IDO matching." | |
(setq ad-return-value (ido-grizzl (ad-get-arg 0)))) | |
(ad-enable-advice 'ido-set-matches-1 'around 'ido-use-grizzl) | |
(ad-activate 'ido-set-matches-1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment