> * In message <[EMAIL PROTECTED]>
> * On the subject of "Re: feature request: java exception handling"
> * Sent on Fri, 19 Jan 2001 06:55:53 GMT
> * Honorable Paul Kinnucan <[EMAIL PROTECTED]> writes:
>
<jde-stack doesn't work with packages>

I added a workaround for the `jde-class-source' bug.
Please try the appended code.

> >Code:
> >-----------------------------

I would really appreciate it if you included in you reply only those
parts of my message that you were actually referring to in your reply.
Please see "Zen & The art of the Internet", the section on "Netiquette".
Thanks.

-- 
Sam Steingold (http://www.podval.org/~sds)
Support Israel's right to defend herself! <http://www.i-charity.com/go/israel>
Read what the Arab leaders say to their people on <http://www.memri.org/>
The early worm gets caught by the bird.

;;; jde-stack.el --- Jump to source from Java stack trace
;;; Copyright (C) 2001 Sam Steingold <[EMAIL PROTECTED]>
;;; based on some code Copyright (C) 1999 Phillip Lord <[EMAIL PROTECTED]>

;; This code is not a part of GNU Emacs, but it is distributed under
;; the same conditions.

;; 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.

;;; Commentary:
;;
;; This package provides the ability to jump from stack traces to the
;; relevant part of the java source. There is one main entry point
;; which is a mouse-2 click on the stack trace, which will jump to the
;; source suggested at this point. This should also work in other
;; buffers (for instance log files), by calling directly the function
;; `jde-stack-show-at-point'. Following this entry point two functions
;; `jde-stack-show-next' and `jde-stack-show-prev' allow cycling
;; backwards and forwards through the stack trace. Error messages are
;; given when the end of the stack is reached.

(require 'jde)
(require 'compile)

(defvar jde-stack-current-marker (cons (make-marker) (make-marker))
  "The location of the last stack shown.
A cons of two markers, location of the error and the location in the code.")

(defun jde-stack-current-marker (&optional next)
  "Update the `cdr' of `jde-stack-current-marker' from its `car'.
Here goes all the error message parsing."
  (let ((here (car jde-stack-current-marker))
        (there (cdr jde-stack-current-marker))
        package class line file buf file-name)
    (save-excursion
      (set-buffer (marker-buffer here))
      (goto-char here)
      (forward-line (or next 0))
      (re-search-forward
       (eval-when-compile
        (concat "\\([a-zA-Z0-9_.]+\\.\\)?" ; package
                "\\([a-zA-Z0-9_]+\\)" ; class
                "\\.<?[a-zA-Z0-9_]+>?" ; method
                "(\\([a-zA-Z0-9_]+\\)\\.java:" ; java file = public class
                "\\([0-9]+\\))"))) ; line number
      (setq package (or (match-string 1) "")
            class (match-string 2)
            file-name (match-string 3)
            line (car (read-from-string (match-string 4)))
            file (jde-class-source (concat package file-name))
            buf (if file (find-file-noselect file)
                    (error "jde-class-source cannot find source for %s%s (%s)"
                           package class file-name)))
      (set-buffer buf) (goto-line line)
      (set-marker there (point) buf)))
  jde-stack-current-marker)

(defun jde-stack-goto (&optional next)
  "Display the current stack using `compilation-goto-locus'."
  (compilation-goto-locus (jde-stack-current-marker next)))

(defun jde-stack-show-at-mouse (event)
  "Jump to the stack position at the mouse click.
Click anywhere on the line with the stack reference."
  (interactive "e")
  (set-marker (car jde-stack-current-marker)
              (posn-point (event-start event))
              (window-buffer (posn-window (event-start event))))
  (jde-stack-goto))

(defun jde-stack-show-at-point ()
  "Jump to the stack position on this current line.
The point should be anywhere on the line with the stack reference."
  (interactive)
  (set-marker (car jde-stack-current-marker) (point) (current-buffer))
  (jde-stack-goto))

(defun jde-stack-next ()
  "Jump to the next stack postion (next line)."
  (interactive)
  (jde-stack-goto 1))

(defun jde-stack-prev ()
  "Jump to the previous stack postion (previous line)."
  (interactive)
  (jde-stack-goto -1))

(add-hook
 'jde-run-mode-hook
 (lambda ()
   (define-key (current-local-map) "\C-c\C-v\C-[" 'jde-stack-prev)
   (define-key (current-local-map) "\C-c\C-v\C-]" 'jde-stack-next)
   (define-key (current-local-map) [mouse-2] 'jde-stack-show-at-mouse)))

(define-key jde-mode-map "\C-c\C-v\C-[" 'jde-stack-prev)
(define-key jde-mode-map "\C-c\C-v\C-]" 'jde-stack-next)

(provide 'jde-stack)
;;; jde-stack.el ends here

Reply via email to