gregsexton / ob-ipython

org-babel integration with Jupyter for evaluation of (Python by default) code blocks
738 stars 108 forks source link

Making error traceback link to file #75

Open rhymer opened 8 years ago

rhymer commented 8 years ago

Is it possible to make error traceback clickable and brings you to the line where error occurs? Thanks.

gregsexton commented 8 years ago

That would be awesome.

garaud commented 8 years ago

Hi, we, @tlentali and I, would like to help.

If I understand, you want to have a clickable line to your org file, inside the source block, when a traceback occurs?

Is it easy to identify the source block BEGIN_SRC in the file? I think it's possible to parse the lineno from the traceback. If you know the source block which posts the snippet of code, you can get the right line.

Thank you. Cheers, Damien

rhymer commented 8 years ago

There are two possible cases:

Like you've pointed out, if we know which source block contains the error, it should be easy to get to the right line. The hard part is knowing what ipython-input-12-a4e4c76b432d corresponds to. Any idea?

nnicandro commented 6 years ago

You can get the lines of a src block using something like (assuming point is somewhere inside the src-block)

(let* ((src-block (org-element-at-point))
       (src (org-element-property :value src-block))
  (split-string src))

See the org-element API for more info.

With regards to figuring out how to know which source block the error occurs in, we can use the org-babel-current-src-block-location marker since it is set before the call to org-babel-execute:ipython. We can copy this marker and pass it along to ob-ipython--eval to have the source block location available when an error happens.