Skip to content

Instantly share code, notes, and snippets.

@mrowe
Created August 2, 2012 01:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrowe/3232191 to your computer and use it in GitHub Desktop.
Save mrowe/3232191 to your computer and use it in GitHub Desktop.
Anything source to search files in current GIT project (http://www.emacswiki.org/emacs/AnythingSources#toc64)
(defvar anything-c-source-git-project-files-cache nil "(path signature cached-buffer)")
(defvar anything-c-source-git-project-files
'((name . "Files from Current GIT Project")
(init . (lambda ()
(let* ((git-top-dir (magit-get-top-dir (if (buffer-file-name)
(file-name-directory (buffer-file-name))
default-directory)))
(top-dir (if git-top-dir
(file-truename git-top-dir)
default-directory))
(default-directory top-dir)
(signature (magit-rev-parse "HEAD")))
(unless (and anything-c-source-git-project-files-cache
(third anything-c-source-git-project-files-cache)
(equal (first anything-c-source-git-project-files-cache) top-dir)
(equal (second anything-c-source-git-project-files-cache) signature))
(if (third anything-c-source-git-project-files-cache)
(kill-buffer (third anything-c-source-git-project-files-cache)))
(setq anything-c-source-git-project-files-cache
(list top-dir
signature
(anything-candidate-buffer 'global)))
(with-current-buffer (third anything-c-source-git-project-files-cache)
(dolist (filename (mapcar (lambda (file) (concat default-directory file))
(magit-git-lines "ls-files")))
(insert filename)
(newline))))
(anything-candidate-buffer (third anything-c-source-git-project-files-cache)))))
(type . file)
(candidates-in-buffer)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment