gcv / julia-snail

An Emacs development environment for Julia
GNU General Public License v3.0
231 stars 21 forks source link

Question: Sending code to repl doesn't show plots, but evaluating code in the REPL does? #97

Closed johnabs closed 2 years ago

johnabs commented 2 years ago

Is this standard behavior?

Basically, when I have Gadfly.plot(sin,0,2pi) in the julia repl within vterm, it will open a new buffer and display the input. However, I want this to also work for code I send to the repl via the snail shortcuts. It looks like it tries to display it with the popup display eval results; however, this only really works for text, from what I can tell.

Am I doing something wacky here or missing a step in my config?

gcv commented 2 years ago

I think that the way Snail's built-in evaluation works (using eval in module context) interferes with the internal plot implementation in Gadfly (and Plots.jl). I found a comment in Gadfly.jl that says "rendering by plot [may be] suppressed with either trailing semi-colon or by calling it within a function" — and Snail effectively causes plot() to be called within a function when you use its Emacs commands.

Two workarounds:

  1. You can use the new double-prefix argument form of julia-snail-send-line or julia-snail-send-region (like C-u C-u C-c C-l). This will copy the relevant chunk of code to the REPL instead of using the Snail network connection. Because this runs code without module context, you may have to explicitly prefix the module name in front of your function calls.

  2. Wrap the call in display(), i.e. display(Gadfly.plot(sin, 0, 2pi)). This is a better approach for most (but not all) workflows IMNSHO, so I'll document it in the README.

gcv commented 2 years ago

Please reopen if I can help further.