2012/06/20: Attaching to a running emacs

I'm sometimes amazed how little I know about programs I'm using on a daily basis.

It is more than a decade ago that I added

(server-start)
to my .emacs. One of the first applications was to add export EDITOR=emacsclient to my .emacs_bash so that programs startet within my emacs shell can use the surrunding emacs as their editor of choice.

Version 23 of emacs is also out for a while, and as early as November 2008 wrote my first script using emacsclient -e, whichs asks the server emacs to evaluate an expression (presumably with a side effect). I used it, so that hot keys from my window manager could talk to my jabber client to set my presence state.

It is even much longer ago that I startet using screen(1). I can't remember anymore logging into a remote machine and not typing screen -x as first command (OK, after a reboot, it is a simple screen again).

But it was only recently that I became really aware of the -c option of emacsclient. This, essentially, is the emacs way of saying screen -x. Typing

emacsclient -c
provides you with a new (graphical) frame for the running emacs server. In particular you have access to all the buffers and all their unsafed changes, all the processes (shell, ...) controlled by that emacs, and so on. For a terminal version there is also the -t option, also aliases as -nw which, well, provides you with a similar experience as emacs -nw, but still providing a new frame for the running emacs server. Since this is a new frame, you can get rid of it with
delete-frame
which, in the default setting, is bound to C-x 5 0.