unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Java: Jump to file from stacktrace
@ 2021-04-18 14:51 Anand Tamariya
  2021-04-19  6:15 ` Anand Tamariya
  2021-04-19 12:41 ` Eli Zaretskii
  0 siblings, 2 replies; 4+ messages in thread
From: Anand Tamariya @ 2021-04-18 14:51 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1973 bytes --]

If you need to jump into a file from stacktrace in a log, use the patch in
compile.el . Then with an appropriate find-file function, you can easily
jump to the location.

(defun gud-compilation-find-file (_marker filename _directory &rest
_formats)
  "Find a buffer for file FILENAME."
  (ede-find-file filename))

(setq next-error-function 'compilation-next-error-function
          compilation-locs (make-hash-table :test 'equal :weakness 'value)
          compilation-find-file 'gud-compilation-find-file)


diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el
index 6b39dcd3d5..a21be665f5 100644
--- a/lisp/progmodes/compile.el
+++ b/lisp/progmodes/compile.el
@@ -802,6 +802,7 @@ compilation-disable-input
 ;; value is a FILE-STRUCTURE as described above, with the car eq to the
hash
 ;; key.  This holds the tree seen from root, for storing new nodes.
 (defvar compilation-locs ())
+(make-variable-buffer-local 'compilation-locs)

 (defvar compilation-debug nil
   "Set this to t before creating a *compilation* buffer.
@@ -2586,7 +2587,7 @@ compilation-next-error-function
       (with-current-buffer
           (if (bufferp (caar (compilation--loc->file-struct loc)))
               (caar (compilation--loc->file-struct loc))
-            (apply #'compilation-find-file
+            (apply compilation-find-file
                    marker
                    (caar (compilation--loc->file-struct loc))
                    (cadr (car (compilation--loc->file-struct loc)))
@@ -2869,6 +2870,10 @@ compilation-goto-locus-delete-o
   (remove-hook 'pre-command-hook
               #'compilation-goto-locus-delete-o))
 ^L
+(defvar compilation-find-file #'compilation-find-file
+  "Function to find a file in compilation buffer.")
+(make-variable-buffer-local 'compilation-find-file)
+
 (defun compilation-find-file (marker filename directory &rest formats)
   "Find a buffer for file FILENAME.
 If FILENAME is not found at all, ask the user where to find it.

[-- Attachment #2: Type: text/html, Size: 2388 bytes --]

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: Java: Jump to file from stacktrace
  2021-04-18 14:51 Java: Jump to file from stacktrace Anand Tamariya
@ 2021-04-19  6:15 ` Anand Tamariya
  2021-04-19 12:41 ` Eli Zaretskii
  1 sibling, 0 replies; 4+ messages in thread
From: Anand Tamariya @ 2021-04-19  6:15 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 2248 bytes --]

Additionally, one can use next-error and previous-error to quickly locate
the stacktrace in the log file.

On Sun, Apr 18, 2021 at 8:21 PM Anand Tamariya <atamariya@gmail.com> wrote:

> If you need to jump into a file from stacktrace in a log, use the patch in
> compile.el . Then with an appropriate find-file function, you can easily
> jump to the location.
>
> (defun gud-compilation-find-file (_marker filename _directory &rest
> _formats)
>   "Find a buffer for file FILENAME."
>   (ede-find-file filename))
>
> (setq next-error-function 'compilation-next-error-function
>           compilation-locs (make-hash-table :test 'equal :weakness 'value)
>           compilation-find-file 'gud-compilation-find-file)
>
>
> diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el
> index 6b39dcd3d5..a21be665f5 100644
> --- a/lisp/progmodes/compile.el
> +++ b/lisp/progmodes/compile.el
> @@ -802,6 +802,7 @@ compilation-disable-input
>  ;; value is a FILE-STRUCTURE as described above, with the car eq to the
> hash
>  ;; key.  This holds the tree seen from root, for storing new nodes.
>  (defvar compilation-locs ())
> +(make-variable-buffer-local 'compilation-locs)
>
>  (defvar compilation-debug nil
>    "Set this to t before creating a *compilation* buffer.
> @@ -2586,7 +2587,7 @@ compilation-next-error-function
>        (with-current-buffer
>            (if (bufferp (caar (compilation--loc->file-struct loc)))
>                (caar (compilation--loc->file-struct loc))
> -            (apply #'compilation-find-file
> +            (apply compilation-find-file
>                     marker
>                     (caar (compilation--loc->file-struct loc))
>                     (cadr (car (compilation--loc->file-struct loc)))
> @@ -2869,6 +2870,10 @@ compilation-goto-locus-delete-o
>    (remove-hook 'pre-command-hook
>                #'compilation-goto-locus-delete-o))
>  ^L
> +(defvar compilation-find-file #'compilation-find-file
> +  "Function to find a file in compilation buffer.")
> +(make-variable-buffer-local 'compilation-find-file)
> +
>  (defun compilation-find-file (marker filename directory &rest formats)
>    "Find a buffer for file FILENAME.
>  If FILENAME is not found at all, ask the user where to find it.
>

[-- Attachment #2: Type: text/html, Size: 2851 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Java: Jump to file from stacktrace
  2021-04-18 14:51 Java: Jump to file from stacktrace Anand Tamariya
  2021-04-19  6:15 ` Anand Tamariya
@ 2021-04-19 12:41 ` Eli Zaretskii
  2021-04-19 13:47   ` Anand Tamariya
  1 sibling, 1 reply; 4+ messages in thread
From: Eli Zaretskii @ 2021-04-19 12:41 UTC (permalink / raw)
  To: Anand Tamariya; +Cc: emacs-devel

> From: Anand Tamariya <atamariya@gmail.com>
> Date: Sun, 18 Apr 2021 20:21:31 +0530
> 
> If you need to jump into a file from stacktrace in a log, use the patch in compile.el . Then with an appropriate
> find-file function, you can easily jump to the location.
> 
> (defun gud-compilation-find-file (_marker filename _directory &rest _formats)
>   "Find a buffer for file FILENAME."
>   (ede-find-file filename))
> 
> (setq next-error-function 'compilation-next-error-function
>           compilation-locs (make-hash-table :test 'equal :weakness 'value)
>           compilation-find-file 'gud-compilation-find-file)

Thanks, but could you please describe the scenario where this feature
would be useful?  I'm not sure I understand that, especially what kind
of "log" is supposed to include a stacktrace, and what do GUD and EDE
have to do with this?



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Java: Jump to file from stacktrace
  2021-04-19 12:41 ` Eli Zaretskii
@ 2021-04-19 13:47   ` Anand Tamariya
  0 siblings, 0 replies; 4+ messages in thread
From: Anand Tamariya @ 2021-04-19 13:47 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 962 bytes --]

> Thanks, but could you please describe the scenario where this feature
> would be useful?  I'm not sure I understand that, especially what kind
> of "log" is supposed to include a stacktrace, and what do GUD and EDE
> have to do with this?
>
Java applications typically log execution steps in a log file. This
includes exceptions as well (a sample
<https://preview.redd.it/74g3ys4g4yt61.png?width=939&format=png&auto=webp&s=c976e31ffd54d1087fa13211dc39ed3fadc4c66a>).
The log files are usually collected after reproducing the error scenario
and analyzed. So these can be large. next-error command can take one
straight to the stacktrace location. Using the file and line number, one
can figure out possible causes of errors. If one could click on it and
reach the destination, it's even better.

I'm using this for jumping into code while running debug sessions with GUD.
EDE just has a handy API for finding file by name. That's why I used that
as an example.

[-- Attachment #2: Type: text/html, Size: 1272 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-04-19 13:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-18 14:51 Java: Jump to file from stacktrace Anand Tamariya
2021-04-19  6:15 ` Anand Tamariya
2021-04-19 12:41 ` Eli Zaretskii
2021-04-19 13:47   ` Anand Tamariya

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).