上に向かって build.xml ファイルをば。
どうもです。
東京に帰ってきたのが,先週の金曜日の夜。
ほいで,世間ではオリンピックが話題になっているようですが,
ワタシの話題は,5歳?の姪っ子にいわれた,「whitypig なんでそんなに白髪があるぅ?」
でして,早速白髪染めを購入したわけで。
実家滞在記は機会があれば書きます。
Windows7 使いやすいぞー。オレも欲しくなったぞ−。けどフォントサイズ周りが微妙。
smart-compile.el は便利ですね。
便利で,お世話になってます。ありがとうございます。
ワタシは,C-cC-c に割り当てて使ってます。
java でコードを書いている時,書き捨てのプログラムの時は,java foo.java で
うれしいです。
ただ,ソースディレクトリの階層が多段で,カレントディレクトリに build.xml がないが,
プロジェクトのトップディレクトリにはある。
このような場合には,自分でコンパイルコマンドを作成する必要があると,
ワタシは理解しているわけでして。
つまり,
C-cC-c
java some.java
ant -emacs -f
この時点で, ん? はて? build.xml ファイルはどこにござんしょ?
となるわけで,
ant -emacs -f ../../build.xml
適当にこのくらいか? と試してみて,「アウチッ!」となるわけです。
build.xml ファイルをルートディレクトリまでのぼって探します。
というわけで,改造しました。
カレントディレクトリに build.xml をおいて,そっから
トップディレクトリの build.xml を使う,みたいなパターンも考えたのですが,
build.xml を複数用意するのは,あまり慣習的ではないみたい? なので棄却。
--- smart-compile.el.orig 2010/02/22 12:43:26 1.1 +++ smart-compile.el 2010/02/22 14:00:50 @@ -138,15 +138,15 @@ (setq smart-compile-check-makefile nil))) ;; ant ? (from smart-compile+.el by William XWL) - ((and smart-compile-check-makefile - (file-readable-p "build.xml")) - (if (y-or-n-p "build.xml is found. Try 'ant'? ") - (progn - (set (make-local-variable 'compile-command) "ant ") - (call-interactively 'compile) - (setq not-yet nil) - ) - (setq smart-compile-check-makefile nil))) + ((when smart-compile-check-makefile + (let ((location (smart-compile-search-ant-file))) + (if (and location (y-or-n-p "build.xml is found. Try 'ant'? ")) + (progn + (set (make-local-variable 'compile-command) (concat "ant -emacs -f " location)) + (call-interactively 'compile) + (setq not-yet nil) + ) + (setq smart-compile-check-makefile nil))))) ) ;; compile @@ -214,6 +214,28 @@ )) arg) +(defun smart-compile-search-ant-file () + "Search for build.xml and return the location if found or nil." + (let ((location nil) (neet-to-loop t) (found nil) (prev-dir nil) (dir-org nil)) + (setq dir-org (substring (pwd) 10)) + (while (and neet-to-loop (not found)) + (cond + ((file-readable-p "build.xml") + (setq neet-to-loop nil) + (setq found t) + (setq location (concat location "build.xml"))) + (t + (setq prev-dir (substring (pwd) 10)) + (cd "..") + (setq location (concat "../" location)) + (when (string-equal prev-dir (substring (pwd) 10)) + ;; we were in the root directory. + (setq neet-to-loop nil) + (setq location nil))))) + ;; now, we go back to the original directory. + (cd dir-org) + location)) + (provide 'smart-compile) ;;; smart-compile.el ends here
ちなみに,
です。
ワタシの環境は,WindowsXP,Meadow3 です。
簡単に試したところうまくいっている様です。
というか,Eclipse 使えよっていう。
まとめ
これで,build.xml は2階上の住人なのか? はたまた3階上の住人なのか?
などと悩まなくて済みそうです。