public
Last active

  • Download Gist
.emacs
Emacs Lisp
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
;; Anton Johansson
;; Time-stamp: "2008-11-08 18:34:02 anton"
 
;; Load paths
(add-to-list 'load-path (expand-file-name "~/.emacs.d"))
(add-to-list 'load-path (expand-file-name "~/.emacs.d/lisp"))
(add-to-list 'load-path (expand-file-name "~/.emacs.d/lisp-personal"))
(add-to-list 'load-path (expand-file-name "~/.emacs.d/lisp/yasnippet"))
(add-to-list 'load-path (expand-file-name "~/.emacs.d/lisp/color-theme-6.6.0"))
(add-to-list 'load-path (expand-file-name "~/.emacs.d/lisp/org-mode/lisp"))
 
;; JDE load paths
(add-to-list 'load-path (expand-file-name "~/.emacs.d/lisp/jde/lisp"))
(add-to-list 'load-path (expand-file-name "~/.emacs.d/lisp/elib"))
(add-to-list 'load-path (expand-file-name "~/.emacs.d/lisp/cedet/common"))
(add-to-list 'load-path (expand-file-name "~/.emacs.d/lisp/ecb"))
(add-to-list 'load-path (expand-file-name "~/.emacs.d/lisp/jdibug"))
 
;; Personal customizations
;;(require 'slime)
(require 'my-generic)
(require 'regex-tool)
(require 'my-ediff)
(require 'jdibug)
(require 'my-color)
(require 'my-html)
(require 'my-flymake)
(require 'my-latex)
(require 'my-irc)
(require 'my-org)
(require 'my-octave)
(require 'git)
(require 'my-java)
 
(load-file "~/.emacs.d/lisp/cedet/common/cedet.el")
(require 'my-cedet)
(make-directory "~/.emacs.d/semanticCache" t)
(setq semanticdb-default-save-directory "~/.emacs.d/semanticCache")
(require 'jde)
(require 'ecb-autoloads)
 
;; Javascript
(autoload 'js2-mode "js2" nil t)
 
;; File assosiation
(add-to-list 'auto-mode-alist '("\\.js$" . js2-mode))
(add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
 
;; Other customizations
(load "/Applications/Emacs.app/Contents/Resources/site-lisp/nxml/nxml-mode-20041004/rng-auto.el")
 
(require 'rst)
(add-to-list 'auto-mode-alist '("\\.rst$" . rst-mode))
 
(require 'yasnippet)
(yas/load-directory "~/.emacs.d/my-snippets")
(add-to-list 'yas/extra-mode-hooks
'rst-mode-hook)
 
(add-to-list 'yas/extra-mode-hooks
'nxml-mode-hook)
 
(add-hook 'yas/after-exit-snippet-hook
'(lambda ()
(indent-region yas/snippet-beg
yas/snippet-end)))
(set-variable 'yas/trigger-key "")
(yas/initialize)
 
;;Find-file-not-found-hooks
(add-hook 'find-file-not-found-hooks
'(lambda ()
(if (equal (file-name-extension (buffer-file-name)) "java")
(progn
(java-mode)
(insert-java-template)
(message "Inserted java template")))
 
(if (equal (file-name-extension (buffer-file-name)) "html")
(progn
(nxml-mode)
(insert-xhtml-template)
(message "Inserted xhtml template")))))
 
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(ecb-options-version "2.32"))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(flymake-errline ((((class color)) (:underline "OrangeRed"))))
'(flymake-warnline ((((class color)) (:underline "yellow"))))
'(ido-first-match-face ((t (:background "green"))) t))
flymake-java.el
Emacs Lisp
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
(require 'flymake)
(defconst ecj-jar-path "/Users/anton/.emacs.d/java/ecj.jar")
 
(defvar flymake-java-version "1.5")
 
;; To display current classpath from build.xml
;; <target name="show-classpath">
;; <property name="classpath" refid="project.classpath"/>
;; <echo message="classpath= ${classpath}"/>
;; </target>
 
(defun flymake-java-ecj-init ()
(let* ((temp-file (flymake-init-create-temp-buffer-copy
'flymake-ecj-create-temp-file))
(local-file (file-relative-name
temp-file
(file-name-directory buffer-file-name))))
(list "java" (list "-jar" ecj-jar-path "-Xemacs" "-d" "none"
;; "-warn:none"
;; "-warn:+over-ann,uselessTypeCheck" ;;,allJavadoc
"-source" flymake-java-version "-target" flymake-java-version "-proceedOnError"
"-classpath" (jde-build-classpath jde-global-classpath)
;; "-log" "c:/temp/foo.xml"
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 flymake-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 (abs (random))) (flymake-get-temp-dir)))))
(push '(".+\\.java$" flymake-java-ecj-init flymake-java-ecj-cleanup) flymake-allowed-file-name-masks)
(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)))))
 
(provide 'flymake-java)
my-java.el
Emacs Lisp
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
;; 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)
prj.el
Emacs Lisp
1
(set-variable 'jde-global-classpath (my-get-classpath))

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.