gcv / julia-snail

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

ob-julia always uses the default `julia-snail-repl-buffer` for `completion-at-point` #150

Closed MasonProtter closed 3 months ago

MasonProtter commented 3 months ago
((nil . ((julia-snail-port . 10050)
         (julia-snail-repl-buffer . "*julia-scrap*"))))

in my .dir-locals.el so that I'm using a non-standard julia-snail-repl-buffer, then whenever I enter a src julia org block and attempt to do autocompletion, I get notified

Company: backend company-capf user-error: No Julia REPL buffer *julia* found; run julia-snail

evaluation and everything works totally fine, but I think somehow the julia-snail-repl-buffer isn't getting properly communicated to julia-snail-repl-completion-at-point something.

This problem appears to only be present in the ob-julia extension, not when editing .jl files, and I realize I was the one who implemented the ob-julia extension, but maybe someone familiar with how the completion system works can take a look and help me figure out what I did wrong.

gcv commented 3 months ago

That was a fun little problem to debug. :)

This happens because julia-snail-repl-buffer is a buffer-local variable, not a regular dynamic variable. (I'm not sure there's a good way to make it dynamic and still allow .dir-locals.el customization — maybe I don't fully understand the semantics here.) So it's correctly set in your org-mode file. Then, in julia-snail/ob-julia--module-at-point you use with-temp-buffer. Inside the temporary buffer, the buffer-local value of julia-snail-repl-buffer disappears (because the temporary buffer is probably not in the same directory as your original org file). Then you call julia-snail--cst-module-at, which expects julia-snail-repl-buffer to be set.

I think you can just save the value of julia-snail-repl-buffer outside with-temp-buffer, and rebind it inside. You can see me working around a similar problem here: https://github.com/gcv/julia-snail/blob/69d2a4c183925c820516fe860aed8964a78c9895/julia-snail.el#L1797-L1801

MasonProtter commented 3 months ago

Ahh, that makes sense!