Skip to content

Instantly share code, notes, and snippets.

@podhmo
Created August 17, 2010 02:52
Show Gist options
  • Save podhmo/528214 to your computer and use it in GitHub Desktop.
Save podhmo/528214 to your computer and use it in GitHub Desktop.
;;; .elと入力した時、\\.elとして扱われるようにしたい。
(defun insert-result (s)
(insert (format "\n;;result:%s" s)))
(defun glob-to-regexp (str)
(loop for (pat . rep) in '(("\\." . "\\\\.") ("\\*" . ".*"))
do (setq str (replace-regexp-in-string pat rep str))
finally return str))
;; foobar.el -> foobar\\.el
(insert-result (glob-to-regexp "foobar.el"))
;;result:foobar\.el
(defun anything-compile-source--glob (source)
"anything (plugin) for input with glob pattern"
(if (assoc 'glob source)
(append source
'((match (lambda (candidate)
(string-match (glob-to-regexp anything-pattern) candidate)))))
source))
;; anything source for test
(setq *base-source*
`((name . "foo")
(candidates . ("foobarael" "foobar.el" "foobar*el"))
(action . message)
(glob)))
;;; compute-matchesでは\\.elとして扱われる。
(let ((anything-pattern ".el"))
(insert-result
(anything-compute-matches
(anything-compile-source--glob *base-source*))))
;;result:(foobar.el)
;;; anythingを呼び出して利用すると\\.elであるはずなのに.elとして扱われる?
(let ((anything-compile-source-functions
(cons 'anything-compile-source--glob
anything-compile-source-functions)))
(insert-result
(anything `(,*base-source*) ".el" ":" nil nil "*FOO*")))
;;result:foobarael
(insert-result
(anything `(,(anything-compile-source--glob *base-source*))
".el" ":" nil nil "*FOO*"))
;;result:foobarael
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment