# Running code in repl whenever file is saved

**URL:** <https://discourse.julialang.org/t/running-code-in-repl-whenever-file-is-saved/125523>\
**Category:** General Usage\
**Tags:** revise\
**Created:** [February 4, 2025, 9:47am UTC](https://discourse.julialang.org/t/running-code-in-repl-whenever-file-is-saved/125523 "2025-02-04T09:47:53Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://avatars.discourse-cdn.com/v4/letter/a/258eb7/32.png) [@aris](https://discourse.julialang.org/u/aris)\
**Post date:** [February 4, 2025, 9:47am UTC](https://discourse.julialang.org/t/running-code-in-repl-whenever-file-is-saved/125523/1 "2025-02-04T09:47:53Z")

</div>

Hello everyone.

I’m aware or Revise.jl 's capabilities when it comes to editing code and having the changes immediately reflected in the repl.

I was wondering whether there would be a straightforward way to actually run some code whenever a file is saved.  
E.g., I’m editing a function `foo(x)`, and every time I save the file, I want `foo(3)` to be sent into the active repl I’m working on.

There’s things like [watchexec](https://github.com/watchexec/watchexec) and [neovim autocommands](https://neovim.io/doc/user/autocmd.html), and these can be used to run something like `julia filename.jl` in the shell every time `filename.jl` is saved, but I’m not sure how they could be used to run things directly into the repl.

Any advice would be appreciated!

---

<div class="post-metadata">

**Author:** ![klafyvel](https://avatars.discourse-cdn.com/v4/letter/k/a587f6/32.png) [@klafyvel](https://discourse.julialang.org/u/klafyvel)\
**Post date:** [February 4, 2025, 10:49am UTC](https://discourse.julialang.org/t/running-code-in-repl-whenever-file-is-saved/125523/2 "2025-02-04T10:49:10Z")

</div>

Hi! If you’re using NeoVim, I guess you could setup an AutoCmd to send the whole buffer on save to the repl using [vim-slime](https://github.com/jpalardy/vim-slime) or [nvim-smuggler](https://github.com/Klafyvel/nvim-smuggler).

---

<div class="post-metadata">

**Author:** ![aris](https://avatars.discourse-cdn.com/v4/letter/a/258eb7/32.png) [@aris](https://discourse.julialang.org/u/aris)\
**Post date:** [February 4, 2025, 10:55am UTC](https://discourse.julialang.org/t/running-code-in-repl-whenever-file-is-saved/125523/3 "2025-02-04T10:55:16Z")

</div>

Thank you for the tip @klafyvel.

I’m currently using [yeet](https://github.com/samharju/yeet.nvim) in neovim to yeet the line `include("filename.jl")` into the repl (yeet is very similar to slime).

Recently I was considering trying out the helix editor, so I wanted to see if we could have a solution which does depend on the editor.

Would it be reasonable for such a feature to be implemented directly into Revise.jl perhaps?

---

<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:** [February 4, 2025, 10:59am UTC](https://discourse.julialang.org/t/running-code-in-repl-whenever-file-is-saved/125523/4 "2025-02-04T10:59:47Z")

</div>

Does [`Revise.entr`](https://timholy.github.io/Revise.jl/stable/user_reference/#Revise.entr) help?

Assuming you have a source file `/tmp/foo.jl`:

```julia
foo(x) = 1

```

then you could do something like this in the REPL:

```julia-repl
julia> using Revise

julia> includet("/tmp/foo.jl")

julia> entr(["/tmp/foo.jl"]) do
         @show foo(3)
       end
foo(3) = 1
# (at this point, edit foo.jl and save it)
foo(3) = 2

```

---

<div class="post-metadata">

**Author:** ![aris](https://avatars.discourse-cdn.com/v4/letter/a/258eb7/32.png) [@aris](https://discourse.julialang.org/u/aris)\
**Post date:** [February 4, 2025, 11:05am UTC](https://discourse.julialang.org/t/running-code-in-repl-whenever-file-is-saved/125523/5 "2025-02-04T11:05:37Z")

</div>

> [@ffevotte](#):
>
> ```julia
> entr(["/tmp/foo.jl"]) do
> @show foo(3)
> end
> 
> ```

Exactly what I was looking for, thanks a lot!

---

<div class="post-metadata">

**Author:** ![aris](https://avatars.discourse-cdn.com/v4/letter/a/258eb7/32.png) [@aris](https://discourse.julialang.org/u/aris)\
**Post date:** [February 4, 2025, 11:31am UTC](https://discourse.julialang.org/t/running-code-in-repl-whenever-file-is-saved/125523/6 "2025-02-04T11:31:01Z")

</div>

After playing around a bit, I’m a bit curious about this.

Why does the `do` block above work fine but the following:

```julia
entr( () -> foo(3) , ["tmp/foo.jl"] )

```

does not work?

Nothing wrong with `do` blocks, I’m just wondering whether I’m missing something.

---

<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:** [February 4, 2025, 12:17pm UTC](https://discourse.julialang.org/t/running-code-in-repl-whenever-file-is-saved/125523/7 "2025-02-04T12:17:51Z")

</div>

> [@aris](#):
>
> `() -> foo(3)`

This computes `foo(3)` but does not display the result. That was the purpose of `@show` in my answer.

---

<div class="post-metadata">

**Author:** ![aris](https://avatars.discourse-cdn.com/v4/letter/a/258eb7/32.png) [@aris](https://discourse.julialang.org/u/aris)\
**Post date:** [February 4, 2025, 1:13pm UTC](https://discourse.julialang.org/t/running-code-in-repl-whenever-file-is-saved/125523/8 "2025-02-04T13:13:33Z")

</div>

> [@ffevotte](#):
>
> That was the purpose of `@show`

This one works fine though:

```julia
entr(["/tmp/foo.jl"]) do
   foo(3)
end

```

(as in, doesn’t throw any errors, unlike the one liner `entr( () -> foo(3) , ["tmp/foo.jl"] )` )

---

<div class="post-metadata">

**Author:** ![thofma](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thofma/32/1691_2.png) [@thofma](https://discourse.julialang.org/u/thofma)\
**Post date:** [February 4, 2025, 2:19pm UTC](https://discourse.julialang.org/t/running-code-in-repl-whenever-file-is-saved/125523/9 "2025-02-04T14:19:03Z")

</div>

One uses `"tmp/foo.jl"` and the other `"/tmp/foo.jl"`.

---

<div class="post-metadata">

**Author:** ![aris](https://avatars.discourse-cdn.com/v4/letter/a/258eb7/32.png) [@aris](https://discourse.julialang.org/u/aris)\
**Post date:** [February 4, 2025, 2:39pm UTC](https://discourse.julialang.org/t/running-code-in-repl-whenever-file-is-saved/125523/10 "2025-02-04T14:39:08Z")

</div>

Oh sorry, that was just a typo!

I was using `["test.jl"]` instead of `["/tmp/foo.jl"]`, so the typo wouldn’t matter.  
However, after playing around with it a bit more on a fresh repl session to confirm, I don’t get the same errors I was getting previously.  
Perhaps I did something weird while messing around with the foo function in the previous session which was causing the errors I was getting previously.  
Sorry for the confusion!
