自分で書いたelispの中で一番重宝しているもの.
以下のコードを適当なところ(init.elなど)に貼れば,C-;
でそのプロジェクト内のファイルをanything絞りこみして開ける.
anything-git-project.el
(defun anything-c-sources-git-project-for (pwd)
(loop for elt in
'(("Modified files (%s)" . "--modified")
("Untracked files (%s)" . "--others --exclude-standard")
("All controlled files in this project (%s)" . ""))
collect
`((name . ,(format (car elt) pwd))
(init . (lambda ()
(unless (and ,(string= (cdr elt) "") ;update candidate buffer every time except for that of all project files
(anything-candidate-buffer))
(with-current-buffer
(anything-candidate-buffer 'global)
(insert
(shell-command-to-string
,(format "git ls-files $(git rev-parse --show-cdup) %s"
(cdr elt))))))))
(candidates-in-buffer)
(type . file))))
(defun anything-git-project ()
(interactive)
(let* ((pwd default-directory)
(sources (anything-c-sources-git-project-for pwd)))
(anything-other-buffer sources
(format "*Anything git project in %s*" pwd))))
(define-key global-map (kbd "C-;") 'anything-git-project)
実行すると以下のようにそのレポジトリ内のファイルが一覧表示され,そこから絞り込んでファイルを開ける.
編集してコミットしてないファイルやトラックされていないファイルは分けて表示してくれる.便利.