18

It's well known that emacs can be used as a terminal emulator (while itself is running in a terminal emulator), thus making it a valid alternative to more traditional terminal-in-a-terminal approaches, such as tmux or screen. However, there's one thing that could be done easily with the latter and I've found no alternative in emacs' term for this one so far.

Both tmux and screen can detach from a terminal and all tasks ran in their windows continue to run in background. It's done using C-b, d in tmux and C-a, d in screen by default. Later, I can return (reattach) to the terminal I've detached from by running something like tmux attach or screen -r. Also, sessions run in both of these terminal multiplexers are persistent - i.e. if I'm connected to some remote terminal and connection fails, I can reconnect and reattach to the terminal without losing any of my work - it really helps in case of faulty network link that occasionally breaks ssh connections.

Is there something like that available for emacs? Basically, I'd want to be able to:

  • Detach from emacs and leave it running in background with all the sub-processes ran in term buffers intact.
  • Reattach to it later and find all my processes running.
  • Automatic detachment of emacs from terminal on receiving a SIGHUP.
GreyCat
  • 16,622
  • 18
  • 74
  • 112
  • Minimally, you could run emacs inside screen/tmux to do that. – Thomas Sep 03 '12 at 05:19
  • 1
    Well, that's exactly the opposite of what I'm trying to do. I want to use emacs' keymappings and windowing features *instead* of very close alternatives that screen/tmux provide. – GreyCat Sep 03 '12 at 08:52
  • But with an Emacs running inside screen you *get* both its keymappings and windowing features?! But I guess you would have to detach the complete Emacs instance, and thus keep multiple Emacs-in-screen instances around, while what you seem to be looking for is a single running instance from which you can detach certain processes while keeping the actual Emacs running, right? – Thomas Sep 03 '12 at 14:20

1 Answers1

24

Use emacs daemon:

$ emacs --daemon

Then simply launch a new frame, equivalent for screen -x:

$ emacsclient -t
Yno
  • 786
  • 4
  • 9
  • Thanks! It really looks like a solution :) I believe it is SIGHUP-resistant, isn't it? – GreyCat Sep 03 '12 at 22:04
  • Unfortunately it doesn't set up your windows the way you had them before (although as far as I've seen screen doesn't either; though tmux does.) – echristopherson Jan 18 '13 at 07:48
  • You can, however, save your window configurations with emacs, then just restore them. See: http://www.emacswiki.org/emacs/SessionManagement – Justin Abrahms Feb 18 '13 at 18:49
  • You can also start multiple Emacs servers, name them, and select a server to connect to by name. I have this in my per-project startup: "(set-variable 'server-name ) (server-start)" and then I can connect remotely via: ssh -Y lukstafi@workstation -f emacsclient -s --eval '"(make-frame-on-display \"$DISPLAY\")"' – lukstafi Jul 06 '20 at 14:37