Created
July 25, 2012 21:21
-
-
Save skeeto/3178747 to your computer and use it in GitHub Desktop.
Automatically open .class files in Emacs with javap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(add-to-list 'file-name-handler-alist '("\\.class$" . javap-handler)) | |
(defun javap-handler (op &rest args) | |
"Handle .class files by putting the output of javap in the buffer." | |
(cond | |
((eq op 'get-file-buffer) | |
(let ((file (car args))) | |
(with-current-buffer (create-file-buffer file) | |
(call-process "javap" nil (current-buffer) nil "-verbose" | |
"-classpath" (file-name-directory file) | |
(file-name-sans-extension (file-name-nondirectory file))) | |
(setq buffer-file-name file) | |
(setq buffer-read-only t) | |
(set-buffer-modified-p nil) | |
(goto-char (point-min)) | |
(java-mode) | |
(current-buffer)))) | |
((javap-handler-real op args)))) | |
(defun javap-handler-real (operation args) | |
"Run the real handler without the javap handler installed." | |
(let ((inhibit-file-name-handlers | |
(cons 'javap-handler | |
(and (eq inhibit-file-name-operation operation) | |
inhibit-file-name-handlers))) | |
(inhibit-file-name-operation operation)) | |
(apply operation args))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment