Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
;; 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))
(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)
;; 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)
(set-variable 'jde-global-classpath (my-get-classpath))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.