Blog - /Tech
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
Posted by Tassilo Horn at Sat Sep 1 17:15:54 2007
Hey Michael,one question. Why do you think that this (unless (string-equal "root" (getenv "USER")) test is needed? If you start emacs as root it will load /root/.emacs and not /home/user/.emacs, or do I get something wrong? Or do you use a symlink so that root uses the same user-init-file?
Bye,
Tassilo
Posted by Tassilo Horn at Sat Sep 1 17:33:32 2007
Hm, and it doesn't work for me. Are you really sure that it does for you? AFAIK the variable server-process isn't shared between different emacs sessions, so the server will start every time you startup an emacs instance and that kills the last server.Currently I use a simple lockfile approach so that another instance doesn't start a new server.
I use a CVS emacs checked out this morning.
Posted by li lin at Sun Sep 2 10:28:24 2007
Hi, Michael. Since you maintain a deb package, I assume you are also using debian sid. I compiled the latest emacs cvs, but I got a reproducible segmentation fault which seems to be specific to debian. I start a server session with "emacs -nw", then if I launch a X frame emacsclient, the first time is ok, but the second time, the server session will crash with segmentation fault. However if I use "emacsclient -t", there will no problem.I talked to some people using Fedora, they do not have this problem. Do you have this problem?
Posted by Michael Olson at Sun Sep 2 12:34:17 2007
Tassilo: The check for USER=root is necessary if you are using sudo (or possibly su without the "-" after it). I know I've needed it in the past.As for the server-process stuff, you're probably right. I wrote that at least 2 years ago and haven't tested it much since then. I don't really need it now that multi-tty support is in, so I'm just going to remove that particular bit of code.
Posted by Michael Olson at Sun Sep 2 12:37:56 2007
li lin: Actually, I use Ubuntu gutsy, because I don't like what Debian did to the Emacs manual. I tried opening a couple of X emacsclient sessions in gutsy and didn't notice any segfaults, so it must be a Debian sid issue. Or, possibly, it could be that your version of emacsclient is the one that comes with the Emacs 22 debian package, rather than the Emacs that you just built.Posted by bojohan at Mon Sep 3 05:06:51 2007
A nicer way to check for rootness is(= 0 (user-uid))
Posted by cos at Mon Sep 3 05:52:34 2007
here's a fixed version that doesn't start the "server" if it's already running:Posted by Aaron Griffin at Thu Sep 6 18:43:50 2007
Hmmm"and bragging to your vim-using co-workers about how Emacs now starts faster than vi does"
From :h clientserver
When compiled with the | clientserver| option, Vim can act as a command server. It accepts messages from a client and executes them. At the same time, Vim can function as a client and send commands to a Vim server.
Posted by Michael Olson at Thu Sep 6 21:48:59 2007
Meh. The fact that it's a compile-time option makes it completely worthless. And I know of noone who actually uses that vim feature.Add a comment