forked from blastura/dot-emacs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
my-java.el
129 lines (111 loc) · 4.68 KB
/
my-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
;; Java
;; Time-stamp: "2008-11-08 14:24:39 anton
;; Flymake JDE
(require 'my-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 my-jde-mode-hook ()
(set-variable 'senator-minor-mode-hook nil)
(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 fill-column 80)
(setq c-basic-offset 4);; Tab indent 4 spaces
;;(c-set-offset 'inline-open 0)
(abbrev-mode nil)
(flymake-mode t)
(toggle-truncate-lines nil))
(add-hook 'jde-mode-hook 'my-jde-mode-hook)
(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 ":")))
;; 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 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)