anything-project.elでSymfony2
anything-project.elにSymfony2用のプロジェクトを定義してみた。
(ap:add-project :name 'symfony2 :look-for 'ap:symfony2-root-detector :grep-extensions '("\\.php" "\\.twig" "\\.yml") :exclude-regexp '("/cache/" "/logs/")) (defun ap:symfony2-root-detector (files) (ap:all-files-exist '("app" "bin" "src" "vendor" "web") files))
使ってみて、M-x anything-project-grepした時にcacheディレクトリなどが対象になって少し困ったので、ap:add-project-exという関数の追加とap:build-grep-commandを上書きして:grep-ignore-dirsというキーワード引数で除外するディレクトリを定義できるようにした。*1
最終的に以下のような感じ。
(require 'anything-project) (defun* ap:add-project-ex (&key name look-for (include-regexp ".*") (exclude-regexp nil) (exclude-directory-regexp nil) (grep-extensions nil) (grep-ignore-dirs nil)) (ap:add-project :name name :look-for look-for :include-regexp include-regexp :exclude-regexp exclude-regexp :exclude-directory-regexp exclude-directory-regexp :grep-extensions grep-extensions) (nconc (cdr (assq name ap:projects)) (list (cons :grep-ignore-dirs grep-ignore-dirs)))) (defun ap:get-grep-extra-options (key) (let ((grep-ignore-dirs (ap:get-project-data key :grep-ignore-dirs))) (mapconcat 'identity (mapcar (lambda (dir) (concat "--ignore-dir=" dir)) grep-ignore-dirs) " "))) (defun ap:build-grep-command (key) (let ((grep-extensions (ap:get-grep-extensions key)) (ack-command (ap:get-ack-command)) (grep-extra-options (ap:get-grep-extra-options key)) (xargs-command (ap:get-xargs-command)) (egrep-command (ap:get-egrep-command))) (concat ack-command " -afG " grep-extensions " " grep-extra-options " | " xargs-command " " egrep-command " -Hin " "%s"))) ;; PHP Symfony2 (ap:add-project-ex :name 'symfony2 :look-for 'ap:symfony2-root-detector :grep-extensions '("\\.php" "\\.twig" "\\.yml") :grep-ignore-dirs '("cache" "logs") ; これを新たに追加 :exclude-regexp '("/cache/" "/logs/")) (defun ap:symfony2-root-detector (files) (ap:all-files-exist '("app" "bin" "src" "vendor" "web") files))
そしてsymfony2.elが欲しくなってきた。
*1:emacs lisp知識不足でdefunしたけどdefadviceで出来るものなのかな?