Created
August 20, 2015 19:32
-
-
Save ctanis/9bb4610eda3b3f34e8af to your computer and use it in GitHub Desktop.
Here's my emacs/flymake setup for java with and without a dominating build.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require 'flymake) | |
;; flymake requires something like this in the build.xml: | |
;; <target name="check-syntax" depends="init" description="check for errors"> | |
;; <javac destdir="${build}" | |
;; classpathref="project.class.path" | |
;; includeantruntime="false"> | |
;; <src path="${CHK_SOURCES}" /> | |
;; <compilerarg value="-Xlint" /> | |
;; </javac> | |
;; </target> | |
(defun flymake-fixed-get-ant-cmdline (source base-dir) | |
(list "ant" | |
(list "-file" | |
(concat base-dir "/" "build.xml") | |
;; scan the whole directory. fix this?? | |
(concat "-DCHK_SOURCES=" (file-name-directory source)) | |
"check-syntax"))) | |
(defun my-java-flymake-init () | |
"flymake using build.xml if there is one, otherwise javac with lint" | |
(if (locate-dominating-file default-directory "build.xml") | |
(flymake-simple-make-init-impl 'flymake-create-temp-with-folder-structure | |
t nil "build.xml" 'flymake-fixed-get-ant-cmdline) | |
(list "javac" (list "-Xlint:unchecked" | |
(flymake-init-create-temp-buffer-copy | |
'flymake-create-temp-with-folder-structure))))) | |
(add-to-list 'flymake-allowed-file-name-masks | |
'("\\.java$" my-java-flymake-init flymake-simple-cleanup)) | |
;; choose an appropriate compile-command | |
(add-hook 'java-mode-hook | |
(lambda () | |
(add-hook 'java-mode-hook 'flymake-mode-on) | |
(if (locate-dominating-file default-directory "build.xml") | |
(set (make-local-variable 'compile-command) | |
"ant -s build.xml -e ") | |
(if buffer-file-name | |
(set (make-local-variable 'compile-command) | |
(concat "javac -Xlint " (file-name-nondirectory buffer-file-name))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment