I'm a huge fan of multi-tty emacs. It allows you to run terminal based emacsclients, kind of like how XEmacs does. For years I used XEmacs because it had this feature, but last year I heard about the multi-tty project, and it was so nice to switch back into Emacs from XEmacs.
I have a great setup now where I have long running Emacs servers, one per project that I'm working on, which are mostly Ruby on Rails projects. Each of these servers runs for a long time in the background, so I can setup all the terminals and shells that I need, and get things organized just how I like them. Then, I can connect to these Emacs servers with a text based emacsclient.
I start my Emacs servers with screen, this allows me to disconnect the Emacs server from the tty, so that I can logoff of a machine and still leave the Emacs server running. This is fantastic for web development work, because I can have these Emacs servers running on my web servers, all across the planet, connect to them when I need to do work, and have everything setup just like I like it.
I found the following script somewhere on the net, and it works great for starting up the Emacs server with screen:
#!/bin/bash
# Usage: preload-emacs <name> [<waitp>]
#
# Preloads the Emacs instance called NAME in a detached screen
# session. Does nothing if the instance is already running. If WAITP
# is non-empty, the function waits until the server starts up and
# creates its socket; otherwise it returns immediately.
name="$1"
waitp="$2"
screendir="/var/run/screen/S-$USER"
serverdir="/tmp/emacs$UID"
emacs=/usr/sness/emacs/bin/emacs
if [ -z "$name" ]; then
echo "Usage: preload_emacs <name> [<waitp>]" <&2
exit 1
fi
if [ ! -e "$screendir"/*."$name" ]; then
if [ -e "$serverdir/$name" ]; then
# Delete leftover socket (for the wait option)
rm "$serverdir/$name"
fi
screen -dmS "$name" "$emacs" -nw --eval "(setq server-name \"$name\")" -f server-start
fi
if [ ! -z "$waitp" ]; then
while [ ! -e "$serverdir/$name" ]; do sleep 0.1; done
fi
I have this aliased to the letter "e":
alias e='/home/sness/bin/preload-emacs sness'
o when I want to start up a server I can just type "e snessnet" to start an Emacs server with a name of "snessnet". Mmmm, less keystrokes...
To connect to these Emacs servers, I use emacsclient, and alias it to "ec":
alias ec='/usr/sness/emacs/bin/emacsclient -s sness'
So that I can type "ec snessnet" to connect to the snessnet Emacs server.
I have a whole bunch of these Emacs servers running at once on my development box, right now I have 9 different Emacs servers running, each of them for a different project that I'm working on. To look at all the current servers that are running, I have an alias setup:
we='ps auwwx | grep emacs | grep SCREEN | cut -d "\"" -f 2'
Which allows me to just type "we" to find out the names of all the currently running Emacs servers. Really really sweet.
What is extra sweet is that multi-tty emacs is in the process of getting merged into the main Emacs codebase, so that by the time Emacs 23 is out, it should be in the mainline codebase.
2 comments:
Awesome! This was extremely useful to me. I've made my own customization that will create the server on the fly if it doesn't already exist.
Thanks again
Hi, as the previous comment said your post is awesome and very useful! But I have a little question: When I open a new emacsclient as
emacsclient -c -s nano
(nano is the server name, and -c is for open in a new frame)
the client is showing the icon bar...
I don't like that...
In my .emacs I had:
(tool-bar-mode -1)
(menu-bar-mode -1)
(scroll-bar-mode -1)
Do you know a workaround for this?
Thanks !
Post a Comment