An update Java development environment
As a pre-cursor to my promised larger articles, a post about Emacs and some of the development tweaks I did last week.
The last weeks there has been quite some chatter about development setups. Most notably Sacha Chua figured out that she could be more productive in Emacs then in Eclipse in her current project, read about it here, here and here.
Sometimes it just takes another person to bring back a thought about some feature or another that you go “damn, how could I have forgotten that one?”. Sacha’s posts and the emacswiki have fine-tuned my development process a little more.
Here are the changes I made, first the file-cache usage. I didn’t know about this one and I found it really usefull. It requires the usage of ido-mode though, so it might not be for everyone.
(defun file-cache-ido-find-file (file) "Using ido, interactively open file from file cache'. First select a file, matched using ido-switch-buffer against the contents in `file-cache-alist'. If the file exist in more than one directory, select directory. Lastly the file is opened." (interactive (list (file-cache-ido-read "File: " (mapcar (lambda (x) (car x)) file-cache-alist)))) (let* ((record (assoc file file-cache-alist))) (find-file (expand-file-name file (if (= (length record) 2) (car (cdr record)) (file-cache-ido-read (format "Find %s in dir: " file) (cdr record))))))) (defun file-cache-ido-read (prompt choices) (let ((ido-make-buffer-list-hook (lambda () (setq ido-temp-list choices)))) (ido-read-buffer prompt))) (require 'filecache) (require 'ido) (ido-mode t) (global-set-key (kbd "ESC ESC f") 'file-cache-ido-find-file)
This sets up file-cache and adds a hook to ido for finding a file using file-cache. Pressing ESC ESC f will popup a prompt in the echo area for a name, just type the filename, without directory, and ido will list all files matching without looking if it is in the current directory or not.
I use this a lot with Java projects, using the JDEE mode. In order to adjust the file-cache to the current JDEE project, add the following to your .emacs file.
;; Prevent subversion files form polluting the cache (add-to-list 'file-cache-filter-regexps "\\.svn-base$") ;; global variable to keep track of current project (defvar credmp/current-jde-project nil) ;; small function to re-create the cache when the project changes (defun credmp/update-cache () (if (not (string= jde-current-project credmp/current-jde-project)) (progn (file-cache-clear-cache) (file-cache-add-directory-using-find (substring jde-current-project 0 (- (length jde-current-project) 6)))) ) (setq credmp/current-jde-project jde-current-project) ) ;; add the hook... (add-hook 'jde-project-hooks 'credmp/update-cache)
One a-ha erlebniss (as the germans call it) was Etags, a usefull TAGS file generating program, which basically creates an index of symbols from your source tree.
In order to use etags you need 2 things, a TAGS file and etags support in Emacs. Generating a TAGS file is easy, if you are on Linux or Mac OS X. How it is done on Windows, I don’t know ![]()
The shell command to execute:
$ find . -name '*.java' | etags -
And the necessary elisp to use it:
(require 'etags)
Now you can use M-. to jump to a TAG. For in-depth info on TAGS please see section 33 Maintaining of your GNU Emacs manual (C-h i and then m Emacs).
It is quite nice to see our Emacs community so active in enhancing our day to day lives! Keep bringing it!