forked from blastura/dot-emacs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aj-java.el
198 lines (169 loc) · 7.46 KB
/
aj-java.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
;; Java
;; Time-stamp: "2008-11-08 14:24:39 anton
;; Java maven project settings ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; (when (string-match "Emacs 23" (emacs-version))
;; (jde-project-file-version "1.0")
;; (jde-set-variables
;; '(jde-build-function (quote (jde-mvn-build)))
;; '(jde-compile-option-command-line-args
;; (quote ("-Xlint:all" "-Xlint:-serial"))))
;; (with-pom nil
;; (jde-mvn-set-jde-variables :include-dependency-sources t))
;; ;; Map C-c C-v C-t to run current test
;; (define-key jde-mode-map [remap jde-jdb-menu-debug-applet]
;; 'jde-mvn-build-run-test))
;; End java maven project settings ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Flymake JDE
(require 'aj-flymake-java)
;; Start eclipse compiler server
;; ================================
;; (require 'jde-eclipse-compiler-server)
;; (set-variable 'jde-ecj-command-line-args '("-d" "none" "-1.6"))
;; (set-variable 'jde-compiler '(("eclipse java compiler server" "/Users/anton/.emacs.d/java/ecj.jar")))
;; (push '(".+\\.java$" jde-ecj-flymake-init jde-ecj-flymake-cleanup) flymake-allowed-file-name-masks)
;; ==============================
;; End eclipse compiler server
;; JDE
(setenv "JAVA_HOME" "/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home")
;;(setenv "JAVA_HOME" "/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Home")
(custom-set-variables
'(jde-jdk-registry (quote (("1.6" . "/System/Library/Frameworks/JavaVM.framework/Versions/1.6"))))
'(jde-jdk (quote ("1.6"))))
(set-variable 'jde-jdk-doc-url "/System/Library/Frameworks/JavaVM.framework/Versions/1.6/docs/api/allclasses-noframe.html")
(set-variable 'jde-complete-function '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" ".")) ;; Used in eg find Class at symbol
(set-variable 'jde-global-classpath '("./bin/main" "./bin/test" "./bin"))
(defun aj-jde-mode-hook ()
;;(set-variable 'senator-minor-mode-hook nil)
;; WARNING can't be set in mode-hook
;;(semantic-tag-folding-mode t)
(setq jde-enable-abbrev-mode nil)
(setq jde-gen-cflow-enable nil)
(local-set-key (kbd "C-<return>") 'jde-build)
(local-set-key (kbd "M-j") 'hippie-expand)
(local-set-key (kbd "C-j") 'c-indent-new-comment-line)
(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 fill-column 80)
(setq c-basic-offset 4) ;; Tab indent 4 spaces
;;(c-set-offset 'inline-open 0)
(abbrev-mode nil)
(flymake-mode t)
;;(flyspell-prog-mode)
(toggle-truncate-lines nil))
(add-hook 'jde-mode-hook 'aj-jde-mode-hook)
(defun aj-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 aj-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: " (aj-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 ":")))
;; 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()
"TODO: interactive args.
Runs current buffer with java"
(interactive)
(shell-command
(concat "java "
(first (split-string (buffer-name)
".java")))))
;; (defun aj-maven-quickstart-prj (groupId artifactId)
;; (interactive "sgroupId: \ns artifactId: ")
;; ;; mvn archetype:generate -B
;; ;; -DarchetypeGroupId=org.apache.maven.archetypes
;; ;; -DarchetypeArtifactId=maven-archetype-quickstart
;; ;; -DarchetypeVersion=1.0
;; ;; -DgroupId=com.company
;; ;; -DartifactId=project
;; ;; -Dversion=1.0
;; ;; -Dpackage=1.5
;; (shell-command (concat "mvn -B archetype:generate"
;; " -DarchetypeGroupId=antonj.se"
;; " -DarchetypeArtifactId=aj-quickstart"
;; " -DarchetypeVersion=1.0"
;; ;;" -DarchetypeCatalog=local"
;; " -Dversion=1.0"
;; " -Dpackage=1.5"
;; " -DgroupId=" groupId
;; " -DartifactId=" artifactId))
;; ;;(shell-command "")
;; )
(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")))
;; complete
;; From http://blog.tuxicity.se/?p=137
(defun jde-complete-ido ()
"Custom method completion for JDE using ido-mode and yasnippet."
(interactive)
(let ((completion-list '()) (variable-at-point (jde-parse-java-variable-at-point)))
(dolist (element (jde-complete-find-completion-for-pair variable-at-point nil) nil)
(add-to-list 'completion-list (cdr element)))
(if completion-list
(let ((choise (ido-completing-read "> " completion-list nil nil (car (cdr variable-at-point)))) (method))
(unless (string-match "^.*()$" choise)
(setq method (replace-regexp-in-string ")" "})"(replace-regexp-in-string ", " "}, ${" (replace-regexp-in-string "(" "(${" choise)))))
(delete-region (point) (re-search-backward "\\." (line-beginning-position)))
(insert ".")
(if method
(yas/expand-snippet method (point) (point))
(insert choise)))
(message "No completions at this point"))))
(setq jde-complete-function 'jde-complete-ido)
(provide 'aj-java)