non-Jedi / eglot-jl

Wrapper for using Julia LanguageServer.jl with emacs eglot
Creative Commons Zero v1.0 Universal
62 stars 11 forks source link

Help wanted with eglot not finding julia? #18

Closed ablaom closed 4 years ago

ablaom commented 4 years ago

Have successfully installed the MELPA elglot-jl packages and run eglot-jl-init.

Then a I open a .jl buffer (putting me into julia-mode). Running eglot gives this:

[eglot] Sorry, couldn't guess for `emacs-lisp-mode'!
Enter program to execute (or <host>:<port>): 

What should be my response? Note that I am a julia developer who needs to run multiple versions of julia. Previously, using julia-repl I controlled this with an JULIA_PATH env variable.

My .bashrc has stuff like this:

# so .emacs.d/lisp/init.el loads correct julia executable we define aliases:
alias je6="export JULIA_PATH=\"/Applications/Julia-0.6.app/Contents/Resources/julia/bin/julia\""
alias je7="export JULIA_PATH=\"/Applications/Julia-0.7.app/Contents/Resources/julia/bin/julia\""
alias je1="export JULIA_PATH=\"/Applications/Julia-1.0.app/Contents/Resources/julia/bin/julia\""
alias je11="export JULIA_PATH=\"/Applications/Julia-1.1.app/Contents/Resources/julia/bin/julia\""
alias je12="export JULIA_PATH=\"/Applications/Julia-1.2.app/Contents/Resources/julia/bin/julia\""
alias je13="export JULIA_PATH=\"/Applications/Julia-1.3.app/Contents/Resources/julia/bin/julia\""
alias je14="export JULIA_PATH=\"/Applications/Julia-1.4.app/Contents/Resources/julia/bin/julia\""
alias je15="export JULIA_PATH=\"/Applications/Julia-1.5.app/Contents/Resources/julia/bin/julia\

On issue #17 I saw reference to eglot-jl-julia-command but this command does not to exist in my installation. There is only eglot-jl-init.

non-Jedi commented 4 years ago

Then a I open a .jl buffer (putting me into julia-mode). Running eglot gives this:

This looks like you're invoking eglot from a buffer in emacs-lisp-mode. Are you sure that julia-mode is active in the buffer?

eglot-jl-julia-command is a variable rather than a function. But in this case, it's irrelevant--it's not the julia installation failing to be detected but eglot failing to use the julia language server.

ablaom commented 4 years ago

Thanks for that!

Sorry, the message (from a julia buffer is much the same):

[eglot] Sorry, couldn't guess for `julia-mode'!
Enter program to execute (or <host>:<port>): 
non-Jedi commented 4 years ago

Could you confirm that you've actually run eglot-jl-int in this emacs session? If so, what's the content of the eglot-server-programs variable?

ablaom commented 4 years ago

You were right, I hadn't realised I needed to redo elgot-jl-init. There was a problem with running eglot but an informative message explained I needed julia in PATH (which it isn't by default in a Mac install of julia).

After adding a version of julia to my PATH, and running the two commands again, I seem to have got things working!

Two questions:

  1. How do I switch julia versions. With julia-repl mode, the solution is the following code in my emacs init.el:

    (julia-repl-set-executable (getenv "JULIA_PATH"))

    and I switch the JULIA_PATH between emacs sessions when I need to. Can I do something similar with eglot? Or maybe there is a better solution that does not require me to restart emacs?

  2. Do I still need julia-repl to interact with the REPL from emacs, or does eglot provide this? What is the relationship between eglot-jl and julia-repl?

ffevotte commented 4 years ago
  1. How do I switch julia versions.

Something like this should work and fit your previous way of doing things:

(setq eglot-jl-julia-command (getenv "JULIA_PATH"))
  1. Do I still need julia-repl to interact with the REPL from emacs, or does eglot provide this? What is the relationship between eglot-jl and julia-repl?

I don't think there's any relationship between eglot-jl and julia-repl. AFAIK eglot-jl handles interactions between emacs and the Julia LSP language server. So you still need an other package to provide REPL interaction if you want it.

ablaom commented 4 years ago

Thanks @ffevotte and @non-Jedi for your help!

non-Jedi commented 4 years ago

Or maybe there is a better solution that does not require me to restart emacs?

Note that for either julia-repl or eglot-jl, you can switch the location of the julia executable without restarting julia:

For julia-repl:

(julia-repl-set-executable "/path/to/julia/executable")

Or for eglot-jl

(setq eglot-jl-julia-command "/path/to/julia/executable")

You could create interactive functions in emacs doing both of these and mirroring your jeX bash aliases if you wanted.

Alternatively you can do this interactively for eglot-jl by invoking M-x customize-option (probably there's also a customizable variable used for this purpose by julia-repl as well).

ablaom commented 4 years ago

I'm still having some problems. Be great if someone can help out.

I have this in my init.el:

(setq eglot-jl-julia-command (getenv "JULIA_PATH"))

Then if I do M-x eglot-jl-init and M-x eglot everything works and I don't need to enter anything interactively. But it seems I have to do both of these every session, which is a pain. So I added these lines to my init.el:

(add-hook 'julia-mode-hook 'eglot-jl-ini)
(add-hook 'julia-mode-hook 'eglot-ensure)

But then booting up an emacs session with julia file gives the "[eglot] Couldn't guess for `julia-mode'!" error:

File mode specification error: (void-function eglot-jl-ini)
Error in post-command-hook (#[0 "\303\304\301\242\305#\210\300\306!\205r\211q\210
?\205\307\310\311 \")\207" [#<buffer MLJ.jl> (#0) eglot--managed-mode remove-hook post-command-hook nil buffer-live-p apply eglot--connect eglot--guess-contact] 4]): (error "[eglot] Couldn't guess for `julia-mode'!")
non-Jedi commented 4 years ago

Looks like you've got a typo: eglot-jl-ini instead of eglot-jl-init. ;)

ablaom commented 4 years ago

Thanks! All good now.