mwolson.org Blog - /Tech

Fri, 31 Aug 2007

Emacs now has multi-tty in CVS HEAD

Now that multi-tty support has been merged into Emacs CVS HEAD, I have finally tried it out. Initial prognosis: this is the best damn thing to hit the Emacs source tree in years. A very short tutorial follows.

To make the most of multi-tty, you'll need add the line

(server-start)

to your ~/.emacs.d/init.el file (or ~/.emacs — this is just the new place for that file). What I do is something like the following, which only starts the server if I'm not root. This is needed if you are using sudo.

(unless (string-equal "root" (getenv "USER"))
  ;; Only start server mode if I'm not root
  (require 'server)
  (server-start))

The next step is to start a normal Emacs session. This will act as a server. In order to connect to this server, use emacsclient.

If you're connected to the server machine remotely via ssh and want to bring up Emacs in a terminal window, then do:

emacsclient -t

Emacs will load instantly, and you will then have access to all of your buffers and settings. When you are finished reveling in this new functionality and bragging to your vim-using co-workers about how Emacs now starts faster than vi does, with, hit C-x 5 0 to disconnect from the server, quit this particular Emacs client session, and get back to the command prompt.

One interesting possibility is to launch an Emacs "daemon" using screen when you start an X session, and then just connect to it by running emacsclient without any options when you want to get a nice graphical Emacs frame (or emacsclient -t for a terminal-only session).

Here is a very simplistic (and untested) script that will do just that.

#!/bin/sh
screen -d -m emacs -nw
Update
Removed nonworking test to see if the server has already been started, since it was incorrect, and I don't feel like fixing it.