Since I do a lot of programming in Java, both for classes and my internships(so far, two have been primarily Java), I often need to look up javadoc. However, most of the time this information has been easily accessible, either through JDE or Eclipse. However, I recently started learning Clojure(I’ll cover my clojure setup in my next blog about emacs), and so neither of these tools were available to me. Searching for help online, I found the javadoc-help package.
Unfortunately, after trying it, I didn’t end up liking it very much. The search it uses, which pulls javadoc for each class that has as a substring the class you input, is far too wide. In most cases, I want an exact match on the class name I’m given - If I search for information on File, I don’t want to have to choose between it and FileFilter. Since this package didn’t work out, I wrote my own quick search function:
(defun java-describe (symbol-name) (interactive "MJava Class:") (let ((my-string (replace-regexp-in-string "^.*class-use/.*n" "" (shell-command-to-string (concat "find ~/.emacs.d/documentation/java/docs/api/ -name " symbol-name ".html")) ))) (string-match "^\(.*\)$" my-string) (browse-url (match-string 0 my-string)))) (global-set-key (kbd "C-h j") 'java-describe)
This function just finds the javadoc corresponding to the exact class name you specify, though you don’t specify package. If there are more than one class with the same name in different packages, it’ll choose one to show; I haven’t had an issue with this yet, although once it comes up I’ll probably allow adding part of the package name as well. For this to work, you need to the java API specification downloaded and extracted in the directory pointed to by this function - I just keep mine in ~/.emacs.d/documentation/java/.
WTF… what’s next… intellisense?
Thanks for very nice Emacs tips, but should the shell-command-to-string function call include the symbol-name parameter also?
Like this:
(shell-command-to-string (concat “find ~/.emacs.d/documentation/java/docs/api/ -name ” symbol-name “.html”))
Many moons ago I wrote something very similar myself but it seems I never published it someplace. Now I found this too: http://javadochelp.sourceforge.net/.