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?

3
  • 2
    You can use the variable debugger-old-buffer, but I am not sure your hook will work since the mode-hook is called before the debugger buffer is setup Commented Sep 11, 2015 at 8:31
  • 1
    Modify the backtrace function instead: emacs.stackexchange.com/questions/7852/…
    – wasamasa
    Commented Sep 11, 2015 at 9:15
  • Converted the comment to an answer Commented Sep 11, 2015 at 12:08

2 Answers 2

2

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

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.