# 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:** 2

<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, 8:39pm UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/21 "2024-12-11T20:39:24Z")

</div>

Do you put it in your init.el?

---

<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:40pm UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/22 "2024-12-11T20:40:45Z")

</div>

@gcv Snail is great! Thanks a lot.

I am wondering if Snail can check variable/function names and underline them if the definition is not found, like `eglot`. This is probably the main reason I need eglot, even though the startup time is long. Really hope this can be done with Snail.

---

<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:41pm UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/23 "2024-12-11T20:41:55Z")

</div>

@PetrKryslUCSD Yes, I put `(setq eglot-connet-timeout 180)` in my init.el.

---

<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, 8:42pm UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/24 "2024-12-11T20:42:15Z")

</div>

No, I mean eglot-jl-init…

---

<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:46pm UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/25 "2024-12-11T20:46:38Z")

</div>

@PetrKryslUCSD Yes, I also put `(eglot-jl-init)` in my init file.

---

<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, 10:40pm UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/26 "2024-12-11T22:40:05Z")

</div>

It can be done, but should really happen after Snail switches from CSTParser to tree-sitter or JuliaSyntax. I added [a ticket for your feature request](https://github.com/gcv/julia-snail/issues/168). It’ll definitely take me a while to find time to work on it.

---

<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 12, 2024, 2:27am UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/27 "2024-12-12T02:27:58Z")

</div>

Julia Snail is very nice indeed!

---

<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 12, 2024, 4:56am UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/28 "2024-12-12T04:56:17Z")

</div>

```julia
julia> methods(sin)
# 14 methods for generic function "sin" from Base:
  [1] sin(::Irrational{:π})
     @ Base.MathConstants mathconstants.jl:126
  [2] sin(::Missing)
     @ Base.Math math.jl:1580
  [3] sin(a::Float16)
     @ Base.Math math.jl:1558
  [4] sin(x::BigFloat)
     @ Base.MPFR mpfr.jl:801

```

See those numbers? If you have JULIA\_EDITOR configured (eg. to emacs-client), and press `2` then `Ctrl-q`, it opens the editor on that line of that file, and grants you five extra lives. It’s the Konami-code of the Julia REPL.

---

<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 12, 2024, 8:56am UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/29 "2024-12-12T08:56:14Z")

</div>

> C-q

I had no idea this existed. I ran into 2 little problems that were easily solved.

1. It used the environment variable `VISUAL` instead of `EDITOR` for me.
2. I had my `VISUAL` set to `emacsclient -f` so that it would open a new Emacs frame instead of reusing an existing one, and the way julia invoked it didn’t work. I had to change `VISUAL` back to just `emacsclient`, and then it worked.

PS: Where is this C-q feature documented?

UPDATE: 2024-12-12: I missed that you used the `JULIA_EDITOR` environment variable. I’d like to keep the value of `VISUAL` to `emacsclient -f`, so it’s nice that I can use `JULIA_EDITOR` in a Julia-specific way.

---

<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 12, 2024, 9:50am UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/30 "2024-12-12T09:50:41Z")

</div>

`C-q` [documentation here](https://docs.julialang.org/en/v1/stdlib/REPL/#Key-bindings):

> ^Q  
> Write a number in REPL and press `^Q` to open editor at corresponding stackframe or method

It works great for opening source files at a numbered location in a stack trace, when you encounter errors.

---

<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 12, 2024, 10:01am UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/31 "2024-12-12T10:01:31Z")

</div>

Skimming through the list of keybindings, you can tell the Julia REPL was designed by an Emacs user. It’s funny seeing words like [kill and yank](https://www.emacswiki.org/emacs/KillingAndYanking) used outside of Emacs.

---

<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 13, 2024, 4:03pm UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/32 "2024-12-13T16:03:12Z")

</div>

Update concerning a Julia REPL in Emacs 29.1.4 running in WSL 2:

1. Julia Snail is very nice indeed. I did not get to use the remote capability, so I can’t comment. I’m not sure how I feel about the ability to evaluate code within a module. Maybe I’m just not used to it.  
Unfortunately, clicking on errors in the `*julia* error` buffer only works at the top.  
Error links such as the one on line 6 open a dialogue asking for a path.  

2. julia-repl is great! I like that everything is in the command window, and the links to errors are clickable.

---

<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 13, 2024, 5:30pm UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/33 "2024-12-13T17:30:50Z")

</div>

Thank you, @gcv, for saving us from [this](https://discourse.julialang.org/t/how-do-you-use-the-develop-command/123767). I’m thankful that I can move between multiple Julia projects with ease using a single Emacs instance.

---

<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 17, 2024, 11:50pm UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/34 "2024-12-17T23:50:59Z")

</div>

> [@gcv](#):
>
> 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.)

My first thought was that practically everyone uses Revise now. However, I just discovered a case where this module-aware feature is still useful.

Apparently, Revise doesn’t notice when I modify a macro in a module. I modified a few other random things in the module to verify Revise was otherwise working, and it was. However, changes to a macro were never picked up. I needed to `julia-snail-send-dwim` while my cursor was in the macro code to get the REPL to get the latest macro code.

---

<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 18, 2024, 12:41am UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/35 "2024-12-18T00:41:41Z")

</div>

That’d be this issue, maybe? [Changes to macros are ignored · Issue #20 · timholy/Revise.jl](https://github.com/timholy/Revise.jl/issues/20)

---

<div class="post-metadata">

### Author: ![Mark\_Nahabedian](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mark_nahabedian/32/16562_2.png) [@Mark\_Nahabedian](https://discourse.julialang.org/u/Mark_Nahabedian)
#### Post date: [January 10, 2025, 7:39pm UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/36 "2025-01-10T19:39:21Z")

</div>

I run my Julia REPLs in _shell_ buffers. If you give `Meta-x shell` a numeric argument it will prompt you for a new buffer name. I typically have a shell buffer for each project I’m currently wrking on.

---

<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: [January 10, 2025, 9:20pm UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/37 "2025-01-10T21:20:34Z")

</div>

That’s a clever way to do it. Do you also have a way to send Julia code to these various shell buffers? (I did a little investigation before posting, and I found the `comint-send-string` function which could be used for this, but it seems like you’d have to write your own interactive function that wraps it …unless I missed something which is very possible.)

---

<div class="post-metadata">

### Author: ![Mark\_Nahabedian](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mark_nahabedian/32/16562_2.png) [@Mark\_Nahabedian](https://discourse.julialang.org/u/Mark_Nahabedian)
#### Post date: [January 11, 2025, 12:31am UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/38 "2025-01-11T00:31:09Z")

</div>

Nothing clever, just Meta-w from one buffer and Ctrl-y in the other.

---

<div class="post-metadata">

### Author: ![ffevotte](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffevotte/32/6587_2.png) [@ffevotte](https://discourse.julialang.org/u/ffevotte)
#### Post date: [January 13, 2025, 9:37am UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/39 "2025-01-13T09:37:11Z")

</div>

> [@g-gundam](#):
>
> Do you also have a way to send Julia code to these various shell buffers?

Maybe you could give [`isend`](https://melpa.org/#/isend-mode) a try; it’s purpose is exactly this: send code from a buffer to a terminal. In a way that’s configurable enough to work the same for multiple types of interpreters (`shell`, `[i]python`, `julia`…) and multiple types of terminals (`ansi-term`, `vterm`…). It does not have specific code for `shell` but I just tested and it seems to work.

Disclaimer: I’m the author of this library

---

<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: [January 13, 2025, 10:22am UTC](https://discourse.julialang.org/t/emacs-and-julia-how-to/123623/40 "2025-01-13T10:22:58Z")

</div>

Long time `julia-repl` user here, I just wanted to add that it is totally possible to use [multiple repls in `julia-repl`](https://github.com/tpapp/julia-repl?tab=readme-ov-file#executable-suffix)!

The idea is that you can define a repl suffix, and the code gets send to the repl buffer with the corresponding suffix. Thus it is possible to have `*julia-project1*` and `*julia-project2*` repls. And since emacs is emacs you can obviously automate this by defining function advice, using project load hooks and so on.

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

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