Adding to Justin's answer:
I have the following in my slime config which is supposed to jump to a file and line from a clojure stack trace.
Unfortunately I must admit that it doesn't actually work for me at the moment - the function isn't able to find the correct file - but as far as I can tell, that should be fixable by changing how project-root
is defined or by changing the structure of my projects on the filesystem (I just haven't had the time or inclination to look into it).
It does bring up a good point though, in most functinality like this it's a bit tricky to figure out the project root in a generic and portable fashion. In this case we rely on a src
directory, but that's probably not appropriate for your python projects.
So following on from where Justin left off, you should be able to take some tips from the function below and parse the file name and line numbers from the test case error, create a link to the line number, and use the compilation-parse-errors-filename-function
and propertize
to make the line in the gud
buffer a link.
If you do get it to work, please add an answer to your own question. I think a lot of people would find it useful.
(defun slime-jump-to-trace (&optional on)
"Jump to the file/line that the current stack trace line references.
Only works with files in your project root's src/, not in dependencies."
(interactive)
(save-excursion
(beginning-of-line)
(search-forward-regexp "[0-9]: \\([^$(]+\\).*?\\([0-9]*\\))")
(let ((line (string-to-number (match-string 2)))
(ns-path (split-string (match-string 1) "\\."))
(project-root (locate-dominating-file default-directory "src/")))
(find-file (format "%s/src/%s.clj" project-root
(mapconcat 'identity ns-path "/")))
(goto-line line))))
I should also mention that I copied this function from somewhere on the web, but I can't remember the URL. It seems to be from Phil Hagelberg's (technomancy) excellent Emacs starter kit.