The Lumber Room

"Consign them to dust and damp by way of preserving them"

Multi-tty Emacs on Ubuntu

with 7 comments

“Multi-tty support” is a feature that is currently in Emacs CVS for what will eventually become Emacs 23. It lets different Emacs windows (“frames”) share the same session. This means that you’ll always have all your buffers, and Emacs starts faster. Emacs has had this “emacsclient” feature for a long time now, where you can edit new files in an Emacs instance that is running as “server”, but what is new is that you no longer have to hunt for where you had started Emacs first — you can simply edit in a new frame. For example, if you had originally started Emacs under X, and you log in remotely, you can reuse the running Emacs process by starting a new “frame” in the terminal. Instead of explaining better what it does, I’ll let you see for yourselves:

video by EnigmaCurry

Note that it is not necessary that all (or any) of them be in a terminal — you can have multiple GTK Emacs windows too. Also, note that every new window starts with the *scratch* buffer, not necessarily the same buffer as the one on top in other windows.

Multi-tty Emacs used to be maintained separately (which is why older posts have complicated instructions), but it has been merged into the main Emacs CVS branch for a long time now. This means that it is available on Ubuntu by simply installing the emacs-snapshot package (this has been true since 2007-09-02). On other distributions/platforms, use whatever it takes to get Emacs from CVS.

To use it, start one Emacs session, and, if you don’t have (server-start) in your .emacs already, do M-x server-start. Once done, you can either leave this Emacs window hanging around, or hide it, or whatever.
Now to start subsequent Emacs instances, use emacsclient -c. The “-c” stands for “-­-create-frame”, and means that a new Emacs “frame” is started instead of using the old one. (Emacs calls windows frames and what it calls “windows” is closer to “frames” in a web browser.)
Use emacsclient -t if you want to start it in the terminal.
It appears that you can quit each individual instance the normal way with C-x C-c; it is not necessary to use C-x 5 0 (that’s delete-frame).

Some things you can do to make life easier.

  • Put (server-start) in your .emacs if you haven’t done so already. Michael Olson suggests using (unless (string-equal "root" (getenv "USER")) (server-start)), but I don’t recall having ever needed that.
  • Automatically start an Emacs session at login and hide it, so that it runs like a “daemon” and you can simply use emacsclient -c consistently and forget about it. You can use screen -d -m emacs -nw, or use the more lightweight dtach: dtach -n /tmp/emacs emacs -nw
  • Do the above with some “name” for your emacs server. You can give your server a name by using (setq server-name "asdf") before (server-start), then you can can connect to it with emacsclient -s asdf -c (or -t). I don’t entirely see the utility of this; it might be so that you don’t start extra servers by mistake and always use the same one. There are scripts to do this.
  • You could probably combine all the above by writing a wrapper that checks if a server exists, connects to it if it does, else starts one, etc., and use that wrapper as your default system editor. That is what the wrapper script “ec” at EnigmaCurry does.

It would be nice if Emacs made this the default, though: Starting Emacs would by default work as multi-tty and share session with whatever previous Emacsen had been started, unless one explicitly told it not to do so.
Why not?

Sources: EnigmaCurry with old installation instructions, the wrapper script and the video, Mwolson’s post


Written by S

Sun, 2008-05-11 at 18:23:03

Posted in compknow

Tagged with

7 Responses

Subscribe to comments with RSS.

  1. This was the last feature left that XEmacs had that emacs didn’t. Finally I’ll be back to where I was in the 90s!


    Wed, 2008-05-14 at 15:24:26

  2. Interesting. So I guess that XEmacs is dead (or at least dying), after all.
    In my experience, GNU Emacs works better with everything, and it is easier to get help when your problem is not related to XEmacs.


    Wed, 2008-05-14 at 17:42:21

  3. […] Update: Emacsclient just got a lot more friendly. You no longer have to go find where the original emacs “server” was started — you can simply start up a new frame for your new buffer, wherever you want (all such Emacs “instances” share the same buffers). Read more about it. […]

  4. But only if you’re using Hardy! I installed the emacs-snapshot and got complaints about invalid option -t. Closer inspection revealed that on Gutsy (I haven’t had time to upgrade yet) emacs-snapshot is currently based on 2007-08-05… I’ll probably be upgraded to Hardy before the Gutsy repos pass 2007-09-02.


    Wed, 2008-05-14 at 23:08:46

  5. great post helped me out immensely


    Sun, 2010-12-19 at 21:25:03

  6. The video is private. Would it possible to allow the public to see it?

    Yesudeep Mangalapilly

    Thu, 2012-04-05 at 11:27:16

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s