Emacsclient doesn't work with @edit

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

#!/usr/bin/env dash

emacsclient -t "$@"

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

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.

OS, Julia version?

julia version 1.4.1
GNU Emacs 26.3
macOS 10.15

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.

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:

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
2 Likes

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).

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

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

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.