>>>>> "Paul" == Paul Kinnucan <[EMAIL PROTECTED]> writes:
Paul> At 06:39 PM 11/4/99 +0100, Jesper Nordenberg wrote:
>> Is there any way to get Emacs to parse the stack trace output by
>> the JVM? It would be quite nice to be able to goto the correct
>> Java source file and line number using next-error or something
>> similar.
>>
Paul> This would require some Lisp programming. There are a lot of
Paul> other features on my to-do list (e.g., the debugger, a new
Paul> project management architecture, method argument prompting,
Paul> etc.) that I regard as more important so I probably wouldn't
Paul> get to it for a long time, if ever. If anyone else wants to
Paul> take a stab at providing this feature, be my guest.
Actually this has struck me as an good idea for ages. Indeed
Im sure that I have a primitive cultural memory of JDE doing this at
one stage. I always figured that Id managed to break it in my
.emacs. In a way Im pleased to find that JDE never did it at all.
I realised that I'd already accomplished some of this task
already when I wrote a jump to sources function. Its very primitive,
and defines one function, which is
"phil-java-show-next-stacktrace-location", which jumps to the next
source location after point. So place the cursor before the opening
bracket in the stack trace and then call this function. Its also buggy
and will break on occasions (for instance if you attempt to view a
class which resolves into two different possible sources. It will ask
you which one you would like to view, but will also raise a "no such
buffer" error).
Anyway Ive included the code below in case you find it useful.
If I can find the time I may tidy it up so that its clean enough to go
into JDE, although I promise nothing. If anyone else wants to have a
go at improving this code, then Ive attached a copyleft so feel
free. Only please tell me so that I dont waste time duplicating
effort if I do actually get around to improving it.
Cheers
Phil
ps I think that a few people may already be using my jump to sources
function. The version given here is slightly different (it takes an
optional argument) but back-wards compatible with the previous
version.
;; Copyright (C) 1999 Phillip Lord
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;Totally hacky version which jumps to the source of the next reported
;;location in a stack trace.
(defun phil-java-show-next-stacktrace-location()
(interactive)
(re-search-forward "\\([A-Za-z0-9]*\\)\\([.]java\\)\\(:\\)\\([0-9]*\\)" )
(let((class (match-string 1))
(line (match-string 4)))
(phil-java-jump-to-sources class)
(set-buffer (concat class ".java" ))
(goto-line (string-to-number line))))
;;Support for auto open of source code. This is mostly a hack from
;;jde-help.el. Probably the two should be changed to use the
;;same methods over again...
(defun phil-java-jump-to-sources (&optional unqual-class)
"Displays source of the class whose name appears at point in the current
Java buffer."
(interactive)
(condition-case err
(let* ((unqualified-name
(or unqual-class
(read-from-minibuffer "Class: " (thing-at-point 'symbol))))
(class-names
;;expand the names into full names, or a list of names
(bsh-eval-r
(concat
"jde.util.JdeUtilities.getQualifiedName(\""
unqualified-name "\");"))))
;;Check return value of QualifiedName
(if (eq nil class-names)
(error "Cannot find %s" unqualified-name))
;;If the list is only one long
(if (eq 1 (length class-names))
;;then show it
(progn(other-window 1)
(jde-find-class-source (car class-names)))
;;else let the user choose
(phil-java-choose-sources class-names)))
(error
(message "%s" (error-message-string err)))))
(defun phil-java-choose-sources (new-imports)
"Prompts the user to select a source to show from a list of similarly
named candidates."
(let ((buf (get-buffer-create "*Select Show Sources*" )))
(setq phil-java-selected-sources new-imports)
(set-buffer buf)
(widget-insert "Several classes match the name you specified.\n")
(widget-insert "Select the ones you want to view.\n")
(widget-insert "Then click the OK button.\n" )
(let (i n) ;Iteration vars
(setq i 0)
(setq n (length new-imports))
(while (< i n)
(let* ((new-import
(nth i new-imports))
(args (list
;;widget of type checkbox
'checkbox
:value new-import
;;with a value equal to the importable file
:format "\n %[%v%] %t"
:tag new-import
;;When we activate this button we need to add to the
;;selected imports
:notify (lambda (widget &rest ignore)
(let ((value (widget-get widget ':tag)))
;;if the widgets value is already in the selected
imports
(if (find value phil-java-selected-sources)
;;then we need to remove it
(progn(setq phil-java-selected-sources
(delq value
phil-java-selected-sources))
(message "You have deselected: %s" value))
;;else we need to add it
(progn(setq phil-java-selected-sources
(nconc (list value)
phil-java-selected-sources))
(message "You have selected: %s"
value))))))))
(apply 'widget-create args)
(setq i (+ i 1)))))
;;Then insert the okay button
(widget-insert "\n")
(widget-create 'push-button
:notify (lambda (&rest ignore)
(let ((dialog-buffer
(current-buffer)))
(delete-window)
(kill-buffer dialog-buffer)
(if phil-java-selected-sources
(progn(other-window 1)
(mapcar 'jde-find-class-source
phil-java-selected-sources))
(message "No classes selected."))))
"Ok")
(use-local-map widget-keymap)
(widget-setup)
(pop-to-buffer buf)))
(define-key jde-mode-map "\C-c\C-v\C-y" 'phil-java-jump-to-sources)