LoginSignup
24

More than 5 years have passed since last update.

今いるgitレポジトリ内のファイルを一瞬で開くelisp

Last updated at Posted at 2012-04-30

自分で書いた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)

実行すると以下のようにそのレポジトリ内のファイルが一覧表示され,そこから絞り込んでファイルを開ける.

編集してコミットしてないファイルやトラックされていないファイルは分けて表示してくれる.便利.

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
24