2

I have a buffer foo.el with some invalid code

(bar)

If i run M-x eval-buffer, with debug on, it show this in backtrace buffer

Debugger entered--Lisp error: (void-function bar)
  (bar)
  eval-buffer()  ; Reading at buffer position 49
  call-interactively(eval-buffer nil nil)
  command-execute(eval-buffer)

I am trying to hyperlink

(bar)

to origial location which is foo.el at some position.

Here is what i have done so far.

(defun hyperlink-error-location ()
  "Hyperlink errors in backtrace."
  (interactive)
  (when (search-forward-regexp "Reading at buffer position " nil 'noerror)
    (goto-char (match-end 0))
    (let ((num (symbol-at-point)))
      (forward-line -1)
      (make-button (line-beginning-position) (line-end-position)
                   'action (lambda (x) 
                             (find-file "/path/to/file")
                             (goto-char num))))))

(add-hook 'debugger-mode-hook 'hyperlink-error-location)

However i need original buffer name foo.el in backtrace buffer. How can i get it?

Chillar Anand
  • 4,042
  • 1
  • 23
  • 52

2 Answers2

2

You can use the variable debugger-old-buffer to get the buffer where the debugger was entered.

Iqbal Ansari
  • 7,468
  • 1
  • 28
  • 31
0

Thanks to @Iqbal Ansari comment, i have added 1 second delay to hyperlinking and its working fine.

(defun hyperlink-error-location ()
  "Hyperlink errors in backtrace."
  (interactive)
  (when (search-forward-regexp "Reading at buffer position " nil 'noerror)
    (goto-char (match-end 0))
    (let ((num (symbol-at-point)))
      (forward-line -1)
      (make-button (line-beginning-position) (line-end-position)
                   'action (lambda (x)
                             (find-file (buffer-file-name debugger-old-buffer))
                             (goto-char num))))))

(defun debugger-timer ()
  "Timer to activate hyperlink-error-location"
  (setq debugger-timer
        (run-at-time
         (time-add (current-time) (seconds-to-time 1))
         nil 'hyperlink-error-location)))

(add-hook 'debugger-mode-hook 'debugger-timer)
Chillar Anand
  • 4,042
  • 1
  • 23
  • 52