4

My goal is to remotely write code. So far, I have been using ssh + screen + an editor (e.g. vim).

I understand using a local emacs (or vim), one can edit remote files. But once the local emacs is closed and I want to reopen it (or open it using another computer), I would need to reopen all the buffers again.

Is there a way to set up a emacs server on the remote machine and I could simply access it using a local emacs client? Which essentially simulate the screen behavior.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
guinny
  • 1,522
  • 10
  • 19
  • So in this scenario, you have files on remote machines X, Y, etc., and you have an emacs server on machine E, and you want to use the editor actually on machines A, B, ... that work by connecting to E to see the files on X and Y? – Daniel Lyons Nov 02 '18 at 15:42

3 Answers3

4

I think you might find your answer here;

http://www.gnu.org/software/emacs/manual/html_node/emacs/Emacs-Server.html

According to http://www.gnu.org/software/emacs/manual/html_node/emacs/emacsclient-Options.html#emacsclient-Options ;

An Emacs server usually uses an operating system feature called a “local socket” to listen for connections. Some operating systems, such as Microsoft Windows, do not support local sockets; in that case, Emacs uses TCP instead. When you start the Emacs server, Emacs creates a server file containing some TCP information that emacsclient needs for making the connection. By default, the server file is in ~/.emacs.d/server/. On Microsoft Windows, if emacsclient does not find the server file there, it looks in the .emacs.d/server/ subdirectory of the directory pointed to by the APPDATA environment variable. You can tell emacsclient to use a specific server file with the ‘-f’ or ‘--server-file’ option, or by setting the EMACS_SERVER_FILE environment variable.

Even if local sockets are available, you can tell Emacs to use TCP by setting the variable server-use-tcp to t. One advantage of TCP is that the server can accept connections from remote machines. For this to work, you must (i) set the variable server-host to the hostname or IP address of the machine on which the Emacs server runs, and (ii) provide emacsclient with the server file. (One convenient way to do the latter is to put the server file on a networked file system such as NFS.)

When the Emacs server is using TCP, the variable server-port determines the port number to listen on; the default value, nil, means to choose a random port when the server starts.

Of course, make sure to adjust your firewall settings on the server side, so that clients may connect to the machine running the emacs-server.

vyudh
  • 91
  • 4
  • thanks a lot for the reply. I tried this on both a redhat and an OSX machine, but neither leaves a server fiel in ~/.emacs.d/server, and both have their APPDATA unset. – guinny Oct 19 '12 at 18:38
  • Better than to adjust the firewall settings, one can use ssh to forward a port: – Rémi Oct 19 '12 at 19:24
  • @chaiy FWIW I just tried this on OSX with GNU Emacs and as long as you `(setq server-use-tcp t)` before `(server-start)` I get a file containing the server info at `~/.emacs.d/server/server`. I've never had a problem getting this far but I have never been able to get a remote client connected to the server unfortunately. – Randy Morris Oct 19 '12 at 22:22
  • @RandyMorris Thanks for trying this. I had a colleague trying this too. But he hasn't got the file either. Maybe it's different version of emacs? We tried both the macports one and the standalone one, but none seems to leave a server folder in .emacs.d... – guinny Oct 20 '12 at 13:05
  • I built emacs with homebrew, may be worth a try. – Randy Morris Oct 20 '12 at 14:25
1

I've attempted the method mentioned in the other post many times and have never had any success with it.

One nice thing that emacs is able to do is desktop-save-mode which will store all of your open buffers when you kill emacs and restore them when you open emacs again. By default it won't restore tramp buffers, but you can tweak the settings to allow this to happen. More information can be found in this Stack Overflow question.

Community
  • 1
  • 1
Randy Morris
  • 39,631
  • 8
  • 69
  • 76
  • thanks for the answer. But that would simply be almost the same as running a daemon at your local machine (if you never restart the computer). I am more looking for a solution where I can change the client computer. – guinny Oct 19 '12 at 18:35
0

You can login locally and then ssh to a remote machine. On the remote machine, you can have 'screen session, that you can join'. In this session, you have emacs running, with all buffers as you had left. You can also use the desktop-save in combination to this, in the case that remote machine need to be restarted, and you can lose your session. This is the most practical solution, I use. You can change the 'client computer' any time. You don't need to use local emacs client. You can also make multiple session for different projects and join screen session for a particular project on different terminal.

aartist
  • 3,145
  • 3
  • 33
  • 31
  • This is the setup I described as ssh+screen+editor, which I have been using too. But I have some troubles getting shell scrolling up and copy/paste across tabs to work. So I thought maybe editing remote files on your local machine might make this easier. – guinny Oct 19 '12 at 21:39