# Emacs and Julia: how to

**URL:** <https://discourse.julialang.org/t/emacs-and-julia-how-to/123623>\
**Category:** Tooling\
**Tags:** emacs\
**Created:** [December 9, 2024, 3:05pm UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623 "2024-12-09T15:05:54Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [December 9, 2024, 3:05pm UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/1 "2024-12-09T15:05:54Z")

</div>

Could someone knowledgeable in these matters list all the possible options? I understand there is julia-snail, julia-ts-mode, … But how do they fit together? What is hot and what is not?

Many thanks!

---

<div class="post-metadata">

**Author:** ![mihalybaci](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mihalybaci/32/13528_2.png) [@mihalybaci](https://discourse.julialang.org/u/mihalybaci)\
**Post date:** [December 9, 2024, 4:10pm UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/2 "2024-12-09T16:10:53Z")

</div>

Maybe a good start here?

> [@Current emacs recommendations?](https://discourse.julialang.org/t/current-emacs-recommendations/109008):
>
> For some reason I don’t understand, I thought I might try out emacs again 16 years after I decided I hate it. I like using hot keys and shortcuts more now, so maybe that’s it. When I looked at the emacs page, I learned that there are different “flavors” (GNU emacs, Xemacs, etc.). What do folks use and is there really a noticeable difference? Does the julia emacs extension even work with other versions? Aside from the Julia extension, are there any others that make learning (especially!) or usi…

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [December 9, 2024, 4:36pm UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/3 "2024-12-09T16:36:48Z")

</div>

This is a good illustration of my point. Several things are mentioned in that thread, with very little indication on how they fit together.

[GitHub - JuliaEditorSupport/julia-emacs: Julia support in Emacs.](https://github.com/JuliaEditorSupport/julia-emacs) sounds like the “official” (endorsed?) way of using Julia with Emacs, and curiously there is no mention of LSP or julia-repl…

Again, it would be nice to see how these things fit together. (Diagram?)

---

<div class="post-metadata">

**Author:** ![linwaytin](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@linwaytin](https://discourse.julialang.org/u/linwaytin)\
**Post date:** [December 9, 2024, 5:05pm UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/4 "2024-12-09T17:05:08Z")

</div>

I would suggest using `julia-mode`, instead of `julia-ts-mode`. The `julia-ts-mode` relies on Julia’s tree-sitter grammar which is not mature enough, in my opinion.

`Julia-snail` is good and it also provides completion for the juila code, and it also provides elementary org-babel support. If you like to develop code with an REPL (i.e. sending some code to the REPL to execute), this might be the best option in Emacs.

I also recommend `julia-vterm` and its sibling `ob-julia-vterm`, if you use `org-babel`. In my opinion, this is probably the best org-babel package for Julia so far. Org-mode has built-in julia babel support but the quality is not good, IMO.

---

<div class="post-metadata">

**Author:** ![hexaeder](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hexaeder/32/24403_2.png) [@hexaeder](https://discourse.julialang.org/u/hexaeder)\
**Post date:** [December 9, 2024, 5:05pm UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/5 "2024-12-09T17:05:19Z")

</div>

At a basic level, emacs is just a text editor. `julia-mode` is the major mode for editing julia files, this mainly means syntax highlighting. `julia-ts-mode` is a replacement for that, which uses a tree sitter grammar rather than regex for parsing and syntax highlighting.  
So far there are no “interactive” features yet.

On top of that there is [`julia-repl`](https://github.com/tpapp/julia-repl), which defines how to launch a repl, shortcuts for activating environments, changing directories and so on. Also “sending” selections of your buffer o the repl (similar to `shift+enter` in vs code).  
On top of that, you could use [lsp-julia](https://github.com/gdkrmr/lsp-julia) as an minor mode integrating with the julia lsp server through `lsp-mode` or [`eglot-jl`](https://github.com/non-Jedi/eglot-jl) to integrate with julia lsp server through `eglot-mode`.

I have no personal experience with `julia-snail`, but afaik this is more of an alternative approach to `julia-repl`, which launches a repl and a helper process in that repl. Your editor directly interacts with the running julia process you use for interactive work rather than a completely different julia process (LSP approach).

---

<div class="post-metadata">

**Author:** ![g-gundam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/g-gundam/32/47593_2.png) [@g-gundam](https://discourse.julialang.org/u/g-gundam)\
**Post date:** [December 9, 2024, 5:56pm UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/6 "2024-12-09T17:56:45Z")

</div>

## Using julia-snail and multiple REPLs

One feature that I really like about [julia-snail](https://github.com/gcv/julia-snail?tab=readme-ov-file#multiple-repls) is its ability to run more than one Julia REPL at a time. To make this work, you have to add a `.dir-locals.el` file (which I leave out of version control) that tells julia-snail what port to use to communicate with the Julia process. Every julia-snail REPL needs its own port if you intend to run multiple REPLs. Here’s what that typically looks like for me.

```elisp
((julia-mode . ((julia-snail-port . 10013)
                (julia-snail-repl-buffer . "*julia CryptoMarketData*")
                (julia-snail-extra-args . ("--project=~/src/github.com/g-gundam/CryptoMarketData.jl"
                                           "-e 'cd(\"..\")'"
                                           "-i"))
                )))

```

I put a `.dir-locals.el` file that looks like this at the root of every Julia project I work on. If you frequently move between 2 or more Julia projects in a session, this can be a huge help.

## Reloading .dir-locals.el

To force Emacs to reload `.dir-locals.el`, I found a little interactive function that’ll do just that. This may come in handy while you figure things out.

```elisp
;; force reload .dir-locals.el
;; https://emacs.stackexchange.com/a/13096/37580
(defun i/dir-locals-reload ()
  "Reload .dir-locals.el for the current buffer."
  (interactive)
  (let ((enable-local-variables :all))
    (hack-dir-local-variables-non-file-buffer)))

```

`M-x i/dir-locals-reload`

## Put .dir-locals.el in .gitignore

That port you specify for julia-snail is specific to your system, and I don’t think it’s relevant to anyone else who clones your repo. That’s why I choose to exclude `.dir-locals.el` from version control.

---

<div class="post-metadata">

**Author:** ![g-gundam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/g-gundam/32/47593_2.png) [@g-gundam](https://discourse.julialang.org/u/g-gundam)\
**Post date:** [December 9, 2024, 6:21pm UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/7 "2024-12-09T18:21:29Z")

</div>

> [@linwaytin](#):
>
> I also recommend `julia-vterm` and its sibling `ob-julia-vterm`

I had no idea those existed. At a quick glance, it looks like it improves the org-mode experience for Julia code blocks significantly. I will definitely be trying these out.

> **[GitHub - shg/ob-julia-vterm.el: Org-babel support for Julia code blocks using...](https://github.com/shg/ob-julia-vterm.el)**
>
> Org-babel support for Julia code blocks using julia-vterm

> **[GitHub - shg/julia-vterm.el: A simple vterm-based mode for an inferior Julia...](https://github.com/shg/julia-vterm.el)**
>
> A simple vterm-based mode for an inferior Julia REPL process in Emacs

---

<div class="post-metadata">

**Author:** ![cstjean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstjean/32/1444_2.png) [@cstjean](https://discourse.julialang.org/u/cstjean)\
**Post date:** [December 9, 2024, 9:20pm UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/8 "2024-12-09T21:20:11Z")

</div>

If you’re brand new to Emacs, I would start with just julia-mode (i.e. julia-emacs), while working in the REPL, while you’re getting comfortable. If you configure `JULIA_EDITOR` to `emacs-client`, then `@edit` and `Ctrl-q` works great in the REPL.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [December 9, 2024, 9:24pm UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/9 "2024-12-09T21:24:10Z")

</div>

Thanks!

I just mostly want to find out what the path forward is. Does one go with julia-mode + julia-repl-mode? Or julia-snail? Or julia-ts-mode? And where does lsp-mode come into it? Is it compatible with all the preceding?

Edit: And, there is also ESS-Julia, and eglot…  
Edit 2: Further, there is lsp-julia.

---

<div class="post-metadata">

**Author:** ![g-gundam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/g-gundam/32/47593_2.png) [@g-gundam](https://discourse.julialang.org/u/g-gundam)\
**Post date:** [December 9, 2024, 10:06pm UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/10 "2024-12-09T22:06:21Z")

</div>

This might help you understand what choices you have. I tried to summarize this thread’s contents visually, and I added a little extra info for `julia-snail` and `eglot` since I had a little extra knowledge on those topics that I haven’t posted in this thread.

 ![image](https://global.discourse-cdn.com/julialang/original/3X/2/b/2b99a91cdaaea55d79ad4bc8fb35dfdd8304c938.png)

You can input the following code at [nomnoml](https://nomnoml.com/) to edit it.

```julia-auto
[<start>] -> [<choice> syntax]
[<start>] -> [<choice> repl]
[<start>] -> [<choice> lsp]
[<choice> syntax] -> [julia-mode]
[<choice> syntax] -> [julia-ts-mode]
[<choice> repl] -> [julia-repl]
[<choice> repl] -> [julia-snail]
  [julia-snail] -> [<choice> terminal]
    [<choice> terminal] -> [eat]
    [<choice> terminal] -> [vterm]
[<choice> repl] -> [julia-vterm] -> [ob-julia-vterm]
  [julia-vterm] -> [vterm]
[<choice> lsp] -> [lsp-mode] -> [lsp-julia]
[<choice> lsp] -> [eglot] -> [eglot-jl]
  [eglot] -> [breadcrumb]
[<choice> lsp] -> [lsp-bridge]

```

# MELPA Package Repository

Every package mentioned should be available here.  
[https://melpa.org/#/](https://melpa.org/#/)

---

<div class="post-metadata">

**Author:** ![g-gundam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/g-gundam/32/47593_2.png) [@g-gundam](https://discourse.julialang.org/u/g-gundam)\
**Post date:** [December 9, 2024, 10:17pm UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/11 "2024-12-09T22:17:47Z")

</div>

> [@PetrKryslUCSD](#):
>
> I just mostly want to find out what the path forward is.

Everyone is going to have a different preference, but my own is:

- Syntax: julia-mode
  - I’ve heard julia-ts-mode can crash Emacs, and that’s unacceptable to me. Maybe its bugs have been cleaned up, but I’ll let someone else find out.

- REPL: julia-snail
  - I need the ability to run multiple independent Julia REPLs in a single Emacs session.

- LSP: I don’t know. I use eglot, but I’m not totally sold on it. I think lsp-mode deserves to be given a solid try. I’ve heard there’s a third option too. lsp-bridge? There’s a lot I don’t know about on the LSP front.

---

<div class="post-metadata">

**Author:** ![greatpet](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@greatpet](https://discourse.julialang.org/u/greatpet)\
**Post date:** [December 9, 2024, 11:41pm UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/12 "2024-12-09T23:41:24Z")

</div>

julia-snail also has lightweight code completion and navigation features without the heavy LSP dependence. For example, there are shortcuts `Ctrl-Alt-i` for completion and `Alt-.` for finding definition.

---

<div class="post-metadata">

**Author:** ![linwaytin](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@linwaytin](https://discourse.julialang.org/u/linwaytin)\
**Post date:** [December 10, 2024, 12:24am UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/13 "2024-12-10T00:24:43Z")

</div>

I sometimes use LSP through eglot. It takes like 1~2 minutes to start up. Otherwise it is good. Indeed, `julia-snail` gives some functionalities of LSP, but not all of them. It all depends on what you want.

---

<div class="post-metadata">

**Author:** ![g-gundam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/g-gundam/32/47593_2.png) [@g-gundam](https://discourse.julialang.org/u/g-gundam)\
**Post date:** [December 10, 2024, 3:50pm UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/14 "2024-12-10T15:50:18Z")

</div>

## Fun Fact

One of the maintainers of [emacs-libvterm](https://github.com/akermu/emacs-libvterm) is the same person who gave a talk about Julia and Emacs at EmacsConf 2024 a few days ago.

- [EmacsConf - 2024 - talks - Exploring shared philosophies in Julia and Emacs](https://emacsconf.org/2024/talks/julia/)

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [December 11, 2024, 4:27pm UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/15 "2024-12-11T16:27:56Z")

</div>

Sorry, what does ctrl-q do? I thought it was for fixing terminal problems…?

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [December 11, 2024, 4:28pm UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/16 "2024-12-11T16:28:25Z")

</div>

I am now using vterm. It works well.

---

<div class="post-metadata">

**Author:** ![gcv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gcv/32/11086_2.png) [@gcv](https://discourse.julialang.org/u/gcv)\
**Post date:** [December 11, 2024, 6:34pm UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/17 "2024-12-11T18:34:20Z")

</div>

One thing to note about julia-snail: its REPL integration is module-aware. So when you tell it to update a function definition, it’ll do so in the right place. AFAIK no other Julia REPL integration does this. (Revise users probably don’t care about this very much.) That was the main reason I wrote Snail. That, and LSP didn’t exist when I started.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [December 11, 2024, 6:43pm UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/18 "2024-12-11T18:43:23Z")

</div>

I have to admit I have no idea how to use eglot. I installed eglot-jl, but I get nothing: no completions, no information. I can’t even find which keybindings I should be using. The commands such as eglot-find-definition give me  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/c/3/c30802e4c2409d0b64fae2d7ee520ad89aacf15a.png)

---

<div class="post-metadata">

**Author:** ![linwaytin](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@linwaytin](https://discourse.julialang.org/u/linwaytin)\
**Post date:** [December 11, 2024, 8:26pm UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/19 "2024-12-11T20:26:37Z")

</div>

> [@g-gundam](#):
>
> One of the maintainers of [emacs-libvterm](https://github.com/akermu/emacs-libvterm) is the same person who gave a talk about Julia

Interesting. `vterm` is arguably the best terminal emulator in Emacs ecosystem. I really hope they can integrate this terminal emulator into Emacs core.

---

<div class="post-metadata">

**Author:** ![linwaytin](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@linwaytin](https://discourse.julialang.org/u/linwaytin)\
**Post date:** [December 11, 2024, 8:34pm UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/20 "2024-12-11T20:34:47Z")

</div>

Hi, you need to run `eglot-jl-init` once in your Emacs session. Then you can run `eglot` in a julia buffer, as described in the github page. The error you got I think is because the language server does not really start.

The julia LSP needs long time to start (see the bottom of `eglot-jl` github page). I set `eglot-connet-timeout` to 180, in order to start up the julia LSP. Yes, it takes like 2 mins on my machine to start…

[Next page](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623.md?page=2)
