Skip to content

Instantly share code, notes, and snippets.

@tungd
Last active December 19, 2015 16:09
Show Gist options
  • Save tungd/5981446 to your computer and use it in GitHub Desktop.
Save tungd/5981446 to your computer and use it in GitHub Desktop.
Use `grizzl` as backend for `ido` (WIP)
;; 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)))
(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