Define function to easy navigate to Java source file from Java exception.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Thu, 23 Feb 2017 09:59:25 +0200
changeset 1497 9a881de3da24
parent 1496 4b336f352950
child 1498 e8ad022540d4
Define function to easy navigate to Java source file from Java exception.
.emacs-my
log4-hi-mode.el
--- a/.emacs-my	Thu Feb 23 08:19:21 2017 +0200
+++ b/.emacs-my	Thu Feb 23 09:59:25 2017 +0200
@@ -3199,6 +3199,37 @@
 (when (and (featurep 'semantic) (featurep 'company))
   (add-hook 'java-mode-hook #'my/company-java-setup))
 
+(defvar my/java-exeption-dirs nil
+  "List of dirs to look by `my/java-exeption'.")
+
+(defun my/java-exeption ()
+  "Look at current line if it like Java exaption and try find file using `my/java-exeption-dirs'"
+  (interactive)
+  (save-excursion
+    (let ( path file line end )
+      (forward-line 1)
+      (backward-char 1)
+      (setq end (point))
+      (forward-line 0)
+      (if (not (re-search-forward "^\\s-+at \\([a-zA-Z0-9.$]+\\)(\\([^.]+\\)\\.java:\\([1-9][0-9]*\\))" end t))
+          (message "Current line doesn't look like Java exeption or lack necessary information...")
+        (setq file (match-string 2))
+        (setq line (match-string 3))
+        (setq path (match-string 1))
+        (setq path (replace-regexp-in-string (concat "\\." file ".*") "" path))
+        (setq path (replace-regexp-in-string "\\." "/" path))
+        (setq path (cl-some (lambda (dir)
+                              (let ((full-path (format "%s/%s/%s.java" dir path file)))
+                                (when (file-exists-p full-path) full-path)))
+                            my/java-exeption-dirs))
+        (if (not path)
+            (message "Can't find file %s.java" file)
+          (find-file-other-window path)
+          (goto-line (string-to-int line)))))))
+
+(my--eval-after-load log4-hi-mode
+  (define-key log4-hi-mode-map [C-return] #'my/java-exeption))
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 (message "Pascal")
 
--- a/log4-hi-mode.el	Thu Feb 23 08:19:21 2017 +0200
+++ b/log4-hi-mode.el	Thu Feb 23 09:59:25 2017 +0200
@@ -39,10 +39,13 @@
 (defvar log4-hi-func t
   "Mark to use hilighting of function names in stacktraces. Currently only Java supported.")
 
+(defvar log4-hi-mode-map (make-sparse-keymap)
+  "Keymap for `log4-hi-mode'.")
+
 ;;;###autoload
 (define-minor-mode log4-hi-mode
   "Highlight standard elements in log4* like log-files."
-  nil " log4-hi" nil
+  nil " log4-hi" log4-hi-mode-map
   :global nil
   (catch 'exit
     (when log4-hi-mode