Created
November 8, 2008 20:26
-
-
Save blastura/23129 to your computer and use it in GitHub Desktop.
my-java.el
This file contains 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
;; Java | |
;; Time-stamp: "2008-11-08 14:24:39 anton | |
(defun my-ant-find-build-file (dir) | |
"Find the next Ant build file upwards in the directory tree from DIR. | |
Returns nil if it cannot find a project file in DIR or an | |
ascendant directory. The parameter dir should be an empty string | |
if check should be performed on current dir. | |
TODO - name build.xml is hardcoded" | |
(let ((file (find "build.xml" (directory-files dir) :test 'string=))) | |
(if file | |
(setq file (expand-file-name file dir)) | |
(if (not (jde-root-dir-p dir)) | |
(setq file (jde-ant-find-build-file (concat dir "../"))))) | |
file)) | |
(defun my-get-classpath() | |
"To use in prj.el jde project files: (set-variable | |
'jde-global-classpath (get-cp)) will search for build.xml with | |
ant -find build.xml. Special target in build.xml must be defined: | |
<target name=\"print-classpath\"> | |
<property name=\"classpath\" refid=\"project.classpath\"/> | |
<echo message=\"-classpath-${classpath}-classpath-\"/> | |
</target> | |
Where project.classpath is the id of the tag path where classpath | |
is defined. | |
" | |
;; (message (concat "get-cp, dir is: "(pwd))) | |
;; (message (concat "get-cp, buildfile is: " (my-ant-find-build-file ""))) | |
(let* ((pattern "-classpath-") | |
(out-string (shell-command-to-string "ant -q -find build.xml print-classpath")) | |
(point-start (+ (length pattern) (string-match pattern out-string))) | |
(point-end (string-match pattern out-string point-start)) | |
(class-string (substring out-string point-start point-end))) | |
(split-string class-string ":"))) | |
;; Flymake | |
;;(set-variable 'flymake-no-changes-timeout 1.0) | |
(set-variable 'flymake-log-level 3) ;; Debug | |
(setq debug-on-error t) | |
;;(set-variable 'flymake-start-syntax-check-on-newline nil) | |
;; (defun flymake-java-ecj-init () | |
;; (let* ((temp-file (flymake-init-create-temp-buffer-copy | |
;; 'jde-ecj-create-temp-file)) | |
;; (local-file (file-relative-name | |
;; temp-file | |
;; (file-name-directory buffer-file-name)))) | |
;; ;; Change your ecj.jar location here | |
;; (list "java" (list "-jar" "/Users/anton/.emacs.d/java/ecj.jar" "-Xemacs" "-d" "/dev/null" | |
;; "-source" "1.5" "-target" "1.5" "-proceedOnError" | |
;; "-warn:+over-ann,uselessTypeCheck" ;;,allJavadoc | |
;; "-sourcepath" (car jde-sourcepath) "-classpath" | |
;; (jde-build-classpath jde-global-classpath) local-file)))) | |
;; (defun flymake-java-ecj-cleanup () | |
;; "Cleanup after `flymake-java-ecj-init' -- delete temp file and dirs." | |
;; (flymake-safe-delete-file flymake-temp-source-file-name) | |
;; (when flymake-temp-source-file-name | |
;; (flymake-safe-delete-directory (file-name-directory flymake-temp-source-file-name)))) | |
;; (defun jde-ecj-create-temp-file (file-name prefix) | |
;; "Create the file FILE-NAME in a unique directory in the temp directory." | |
;; (file-truename (expand-file-name (file-name-nondirectory file-name) | |
;; (expand-file-name (int-to-string (random)) (flymake-get-temp-dir))))) | |
;; (push '(".+\\.java$" flymake-java-ecj-init flymake-java-ecj-cleanup) flymake-allowed-file-name-masks) | |
;; (push '("\\(.*?\\):\\([0-9]+\\): error: \\(.*?\\)\n" 1 2 nil 2 3 (6 compilation-error-face)) compilation-error-regexp-alist) | |
;; (push '("\\(.*?\\):\\([0-9]+\\): warning: \\(.*?\\)\n" 1 2 nil 1 3 (6 compilation-warning-face)) compilation-error-regexp-alist) | |
;; ;; From http://www.credmp.org/2007/07/20/on-the-fly-syntax-checking-java-in-emacs/ | |
;; (defun my-flymake-display-err-minibuf () | |
;; "Displays the error/warning for the current line in the minibuffer" | |
;; (interactive) | |
;; (let* ((line-no (flymake-current-line-no)) | |
;; (line-err-info-list (nth 0 (flymake-find-err-info flymake-err-info line-no))) | |
;; (count (length line-err-info-list)) | |
;; ) | |
;; (while (> count 0) | |
;; (when line-err-info-list | |
;; (let* ((file (flymake-ler-file (nth (1- count) line-err-info-list))) | |
;; (full-file (flymake-ler-full-file (nth (1- count) line-err-info-list))) | |
;; (text (flymake-ler-text (nth (1- count) line-err-info-list))) | |
;; (line (flymake-ler-line (nth (1- count) line-err-info-list)))) | |
;; (message "[%s] %s" line text) | |
;; ) | |
;; ) | |
;; (setq count (1- count))))) | |
(require 'flymake-java) | |
(defun my-flymake-mode-hook () | |
(define-key (current-local-map) "\C-c\C-d" 'flymake-display-err-menu-for-current-line) | |
(define-key (current-local-map) "\C-c\C-p" 'flymake-goto-prev-error) | |
(define-key (current-local-map) "\C-c\C-n" 'flymake-goto-next-error) | |
(define-key (current-local-map) "\C-c\C-f" 'my-flymake-display-err-minibuf)) | |
(add-hook 'flymake-mode-hook 'my-flymake-mode-hook) | |
;;; | |
;;JDE | |
(defun my-jde-mode-hook () | |
(setq jde-enable-abbrev-mode nil) | |
(setq jde-gen-cflow-enable nil) | |
(local-set-key (kbd "C-<return>") 'jde-build) | |
(local-set-key "'" 'skeleton-pair-insert-maybe) | |
(local-set-key "\"" 'skeleton-pair-insert-maybe) | |
(local-set-key "[" 'skeleton-pair-insert-maybe) | |
(local-set-key "(" 'skeleton-pair-insert-maybe) | |
(local-set-key "{" 'skeleton-pair-insert-maybe) | |
(set-variable 'skeleton-pair t) | |
(setq c-basic-offset 4);; Tab indent 4 spaces | |
(abbrev-mode nil) | |
(flymake-mode t) | |
(toggle-truncate-lines nil)) | |
(add-hook 'jde-mode-hook 'my-jde-mode-hook) | |
(set-variable 'jde-jdk-registry (quote (("1.5" . "/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK")))) | |
(set-variable 'jde-complete-function (quote jde-complete-minibuf)) | |
(set-variable 'jde-build-function '(jde-ant-build)) | |
(set-variable 'jde-ant-read-target t) | |
(set-variable 'jde-ant-enable-find t) | |
(set-variable 'jde-ant-complete-target t) | |
(set-variable 'jde-sourcepath '("./src")) ;; . or ./src? | |
(set-variable 'jde-global-classpath '("./bin/prod" "./bin/test" "./bin")) | |
(set-variable 'jde-compile-option-directory "../bin") | |
;; Other java | |
(defun java-compile() | |
"comiles current buffer with javac" | |
(interactive) | |
(compile (concat "javac " (buffer-name)))) | |
(defalias 'javac 'java-compile) | |
(defun java-compile-all() | |
"comiles current buffer with javac" | |
(interactive) | |
(compile "javac *.java")) | |
(defalias 'javac-all 'java-compile-all) | |
(defun java-run() | |
"runs current buffer with java" | |
(interactive) | |
(shell-command | |
(concat "java " | |
(first (split-string (buffer-name) | |
".java"))))) | |
(defun insert-java-template() | |
"inserts standard java-class structure" | |
(interactive) | |
(java-mode) | |
(insert (concat "public class " (car (split-string (buffer-name) ".java")) " { \n" | |
"public "(car (split-string (buffer-name) ".java")) "() {\n" | |
"}\n" | |
"}\n")) | |
(mark-whole-buffer) | |
(indent-region (region-beginning) (region-end) nil) | |
;;(jdok-generate-javadoc-template) | |
(goto-line 1) | |
(insert (concat "/*\n" | |
" * @(#)" (buffer-name) "\n" | |
" * Time-stamp: \"" (format-time-string "%c") "\"\n" | |
" */\n\n"))) | |
(provide 'my-java) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment