# Emacsclient doesn't work with @edit

**URL:** <https://discourse.julialang.org/t/emacsclient-doesnt-work-with-edit/43673>\
**Category:** General Usage\
**Tags:** bug\
**Created:** [July 25, 2020, 5:03pm UTC](https://discourse.julialang.org/t/emacsclient-doesnt-work-with-edit/43673 "2020-07-25T17:03:49Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![NightMachinary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nightmachinary/32/14196_2.png) [@NightMachinary](https://discourse.julialang.org/u/NightMachinary)\
**Post date:** [July 25, 2020, 5:03pm UTC](https://discourse.julialang.org/t/emacsclient-doesnt-work-with-edit/43673/1 "2020-07-25T17:03:49Z")

</div>

I have tried setting `EDITOR` and `VISUAL` to `emacsclient -t`, and to point to this wrapper:

```julia
#!/usr/bin/env dash

emacsclient -t "$@"

```

But they don’t work. I get this error when I try `@edit someFunc()`:

```julia
emacsclient: could not get terminal name
emacsclient: error executing alternate editor ""

```

Using `EDITOR=emacsclient VISUAL=emacsclient` partially works; The file will be opened if I have an emacs client already (in that client), but not in the Julia REPL.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [July 26, 2020, 4:45am UTC](https://discourse.julialang.org/t/emacsclient-doesnt-work-with-edit/43673/2 "2020-07-26T04:45:55Z")

</div>

OS, Julia version?

---

<div class="post-metadata">

**Author:** ![NightMachinary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nightmachinary/32/14196_2.png) [@NightMachinary](https://discourse.julialang.org/u/NightMachinary)\
**Post date:** [July 26, 2020, 8:39am UTC](https://discourse.julialang.org/t/emacsclient-doesnt-work-with-edit/43673/3 "2020-07-26T08:39:30Z")

</div>

julia version 1.4.1  
GNU Emacs 26.3  
macOS 10.15

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [July 26, 2020, 12:59pm UTC](https://discourse.julialang.org/t/emacsclient-doesnt-work-with-edit/43673/4 "2020-07-26T12:59:29Z")

</div>

> [@NightMachinary](#):
>
> The file will be opened if I have an emacs client already (in that client), but not in the Julia REPL.

Sorry, I don’t understand this. Do you mean that running Julia from Emacs works?

In any case, `EDITOR=emacsclient` should be all you need, I would debug this further from there. In particular, I am not sure what you are looking for with `-t`, that would block your REPL even if it worked, but I don’t think that Julia provides a tty to these calls, which is why you get the error.

---

<div class="post-metadata">

**Author:** ![rfourquet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rfourquet/32/3610_2.png) [@rfourquet](https://discourse.julialang.org/u/rfourquet)\
**Post date:** [July 26, 2020, 1:43pm UTC](https://discourse.julialang.org/t/emacsclient-doesnt-work-with-edit/43673/5 "2020-07-26T13:43:44Z")

</div>

There was a bug in Julia 1.4, which has been fixed on master; you can benefit from the fix on 1.4 by putting the following in your startup.jl:

```julia
using InteractiveUtils
InteractiveUtils.define_editor([
    "vim", "vi", "nvim", "mvim", "nano",
    r"\bemacs\b.*\s(-nw|--no-window-system)\b",
    r"\bemacsclient\b.\s*-(-?nw|t|-?tty)\b"], wait=true) do cmd, path, line
        `$cmd +$line $path`
    end

```

---

<div class="post-metadata">

**Author:** ![NightMachinary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nightmachinary/32/14196_2.png) [@NightMachinary](https://discourse.julialang.org/u/NightMachinary)\
**Post date:** [July 26, 2020, 3:13pm UTC](https://discourse.julialang.org/t/emacsclient-doesnt-work-with-edit/43673/6 "2020-07-26T15:13:32Z")

</div>

This makes me think that what I see is actually the intended behavior. I thought that edit should open an emacsclient in the Julia REPL. Most tools I have seen do it like that.

Current behavior: Julia makes any open emacsclient (e.g., on another terminal) open the file, and doesn’t do anything in the repl itself. If I use vim, however, vim opens in the REPL (i.e., the REPL is hidden and vim is shown).

---

<div class="post-metadata">

**Author:** ![rfourquet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rfourquet/32/3610_2.png) [@rfourquet](https://discourse.julialang.org/u/rfourquet)\
**Post date:** [July 26, 2020, 3:15pm UTC](https://discourse.julialang.org/t/emacsclient-doesnt-work-with-edit/43673/7 "2020-07-26T15:15:25Z")

</div>

Emacs can be opened in the REPL like vim, for example with `ENV["JULIA_EDITOR"] = "emacsclient -nw"`.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [July 26, 2020, 6:21pm UTC](https://discourse.julialang.org/t/emacsclient-doesnt-work-with-edit/43673/8 "2020-07-26T18:21:46Z")

</div>

> [@NightMachinary](#):
>
> Julia makes any open emacsclient (e.g., on another terminal) open the file

That’s kind of the intention of `emacsclient`. That other `emacs` is not a client but a server, started with `(server-start)` in your init file. This is not Julia-specific, but how `emacsclient` works. See

[https://www.emacswiki.org/emacs/EmacsClient](https://www.emacswiki.org/emacs/EmacsClient)

---

<div class="post-metadata">

**Author:** ![NightMachinary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nightmachinary/32/14196_2.png) [@NightMachinary](https://discourse.julialang.org/u/NightMachinary)\
**Post date:** [July 31, 2020, 3:26pm UTC](https://discourse.julialang.org/t/emacsclient-doesnt-work-with-edit/43673/9 "2020-07-31T15:26:38Z")

</div>

I am not sure I understand. Other terminal apps successfully open an emacs frame when they want to edit something. Julia opens a new buffer in an existing frame. I, myself, use bash scripts to open new frames with emacsclient, ala `emacsclient -t +LINE_NUMBER PATH`, and it opens a new frame.
