5

I'm running a TCP server locally, and I'm trying to open a file from a remote host on my local Emacs through emacsclient. The reason for this is that I have emacspeak running locally which gives me speech, and I want to use this for commands that use the $EDITOR variable, like editing crontab, or kubectl edit and so on.

This question already exists on StackOverflow and has an answer, but at the time the question was asked, this feature was not yet introduced. This feature is introduced in Emacs 26.0.50, according to the relevant issue.

So, here is what I've set:

  • server-auth-key is set to a key I generated with server-generate-key
  • server-host is set to my local computer's hostname
  • server-port is set to 1990
  • server-use-tcp is set to t

I copied and pasted the local ~/.emacs.d/server/server into the remote host's ~/.emacs.d/server/server, and then ran the following command:

$ emacsclient -f server test

This gave me the following output:

emacsclient: connected to remote socket at 10.156.54.246

And then nothing. Nothing pops up on my local Emacs.

Running the same command locally works.

I investigated further and doing a telnet to the host mentioned in the output of emacsclient on port 1990 doesn't work either.

It looks like I'm not setting the value of server-host correctly. I've set it to my hostname, but that doesn't seem to be working.

How should I set my server-host? What should I set it to?

6
  • This isn't what the Emacs server is designed for. You're better off doing SSH tunneling with X forwarding for that.
    – wasamasa
    Jul 27, 2018 at 18:37
  • 1
    Possible duplicate of How do I use emacsclient to connect to a remote emacs instance?
    – wasamasa
    Jul 28, 2018 at 9:35
  • I suggest you try M-x trace-function RET server-execute RET to try and start investigating what the local Emacs does. Note that you're probably going to have to add some code somewhere because emacsclient will provide names of files that are on the remote machine and which your local Emacs will hence need to access over Tramp. E.g. you may need to set $EDITOR to a script that does emacsclient -f server "/ssh:my.remote.host:$1".
    – Stefan
    Jul 28, 2018 at 16:09
  • @wasamasa Check out this link helpfully provided in the answer debbugs.gnu.org/cgi/bugreport.cgi?bug=26591 Jul 29, 2018 at 7:40
  • @stefan Wow, great workaround for my emacsclient not yet having the --tramp option which seems to be introduced in Emacs 26.0.50. I'll try this and let you know. Jul 29, 2018 at 7:43

1 Answer 1

3

This should work with a fairly recent emacsclient, as long as you pass in a prefix that lets the server emacs find remote files over tramp:

--tramp=/ssh:remote:

I can’t remember if the feature made it in time for 26.1 or not, but it was committed in May 2017. See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=26591 for details. No changes should be necessary on the server side, so 25.3 should be sufficient.

5
  • Perfect, I'm glad you sent me the link to the issue tracker because I didn't know where I was to point people to when they said it's not possible, even though I was seeing a mention of it in info files and Emacs news. So, to clarify, my server version is 26.1, and my client version is 25.3 (i.e. the emacsclient on the remote machine is 25.3). Hence, it doesn't have support for the --tramp option. Maybe that's the problem? Jul 29, 2018 at 7:35
  • Surprisingly enough, this made it into Emacs 26.1. I've checked the Emacs info manual here and it mentions this command-line option, along with a usage example in (info "(emacs) emacsclient Options").
    – wasamasa
    Jul 29, 2018 at 7:45
  • @ParhamDoustdar Yes, it’s the emacsclient that needs to be 26.1 or newer. You can maybe just copy over the binary from the newer installation. Or you can use the string manipulating shell script hack outlined by Stefan. That should work with older emacsclients. Jul 29, 2018 at 8:49
  • Your answer will definitely help me in the future, but for now, my problem seems to be one step before I get to the emacsclient bit: apparently, I'm setting the server-host variable incorrectly. Can you tell me how you set yours up? Jul 29, 2018 at 13:43
  • @ParhamDoustdar I must admit it's been a while since I dabbled with this, and I'm currently on vacation and can't test. With that caveat, this is what I remember: I do not set the server-host variable. I have the emacs server listen on the default localhost, and arrange for the remote machine to have an ssh tunnel back to my desktop machine. I.e. I log on to the remote machine with ssh -R 11111:localhost:11111 remote.machine. Then on the remote machine, I can connect to localhost port 11111 and have the connection forwarded to port 11111 on my desktop. Jul 29, 2018 at 16:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.