Building Multi-TTY Emacs from CVS on Ubuntu Gutsy Gibbon

October 21, 2007 at 06:25 PM | categories: emacs, linux | View Comments

(Historical note May 2008: The build instructions below, while they should still work, are unnecessary as Multi-TTY has been merged into the main Emacs 23 branch and is available in ubuntu repositories: apt-get install emacs-snapshot)

Last spring I wrote an article about Multi-TTY Emacs. I had promised that I would update instructions for building it on Ubuntu, but since then I have been mainly using Gentoo on my laptop and never got around to updating it. Sorry :)

I switched to Ubuntu Gutsy Gibbon yesterday. I also got Multi-TTY Emacs running, and here's the video to prove it (If this is too small to see, download the original ogg theora version) :

Building CVS Emacs the old fashioned way

For those of you that want the easy way out, I've prebuilt an emacs CVS package that includes the Multi-TTY patch. I've tested that the package works on both Gutsy as well as Feisty.

For those of you that would like to learn how this is done, here's my recipe:

Install all the dependencies

sudo apt-get install build-essential cvs texinfo libx11-dev libxpm-dev libjpeg-dev \
libpng-dev libgif-dev libtiff-dev libgtk2.0-dev checkinstall

Check out the Emacs code from CVS

cvs -z3 -d:pserver:anonymous@cvs.savannah.gnu.org:/cvsroot/emacs co emacs

Compile the source

cd emacs
./configure --with-gtk --prefix=/usr/local
make bootstrap
make

Checkinstall will build a basic emacs package for us with a minimum of fuss. We don't want to automatically install this package though for reasons we'll see below

sudo checkinstall -D --install=no

Checkinstall will ask you to change some values. I changed the maintainer email and the version number.

Checkinstall is great, and works for 99% percent of the packages that I've tried it with. Emacs is a bit different though -- the package that checkinstall creates doesn't include everything that emacs requires, like all the .el files in the lisp folder among other things. So we have to edit the package a bit. For the following code, we'll assume the .deb file that checkinstall creates is just called "emacs_cvs-10202007-1_i386.deb", so adjust for whatever checkinstall called your .deb file:

Extract the data from the .deb

dpkg-deb -x emacs_cvs-10202007-1_i386.deb emacs_cvs-10202007-1_i386 
#Or whatever your .deb is called

Extract the control information from the .deb

dpkg-deb -e emacs_cvs-10202007-1_i386.deb emacs_cvs-10202007-1_i386/DEBIAN

Now we need to add some of the files that checkinstall left out of the package

cp -a lisp/* emacs_cvs-10202007-1_i386/usr/local/share/emacs/23.0.50/site-lisp/
mkdir emacs_cvs-10202007-1_i386/usr/local/share/emacs/23.0.50/lisp
mkdir -p emacs_cvs-10202007-1_i386/usr/local/libexec/emacs/23.0.50/i686-pc-linux-gnu
cp -a etc emacs_cvs-10202007-1_i386/usr/local/share/emacs/23.0.50/
mkdir emacs_cvs-10202007-1_i386/etc
ln -s ../usr/local/share/emacs/23.0.50/etc/termcap.src emacs_cvs-10202007-1_i386/etc/termcap

Rebuild the modified package

dpkg-deb -b emacs_cvs-10202007-1_i386 emacs_modified.deb

To totally revolutionize the way you use Emacs, remember to check out my earlier post on Multi-TTY Emacs.

Read and Post Comments

Multi-TTY Emacs on Gentoo and Ubuntu

May 24, 2007 at 01:59 PM | categories: emacs, linux | View Comments

(Historical note Sep 2008: The 'ec' script below is no longer (or shortly will not be) required, as there is now a patch that enables emacs as a frameless daemon)

(Historical note May 2008: This post is now over a year old. Multi-TTY Emacs is now part of the main Emacs CVS tree. Most of this post is still applicable, but the build instructions are very much out of date and for the most part are unnecessary as the multi-tty patch has now made it into most distros. It should just be an 'apt-get install emacs-snapshot' away)

Multi-TTY Emacs is one of the most useful peices of software I've seen in a long time. Emacsclient, the underlying interface for multi-tty, has been around for a while. It allows someone to connect to a long running Emacs session and it avoids the long startup time Emacs usually has. However, it only works in a graphical environment. Multi-TTY Emacs allows us to do the same from either a graphical environment or from a simple terminal (tty).

Here's a typical use case: I'm at home and I'm using Emacs from within X-windows. I'm using the wonderful IRC client, ERC, and asking a question in #python, #emacs, #gentoo etc. but no one seems to be paying any attention and no one is answering my question right away. Oh well, it's time for me to head off to class or work. I leave Emacs running at home but since I forgot to enable chat logs, it's rather difficult for me to connect remotely and find out if anyone has responded to my question. With Multi-TTY, I can ssh into my home computer and bring up Emacs in a text console and check my ERC buffer even though I originally started Emacs graphically from X-Windows. Neat.

Emacs Multi-TTY
You can also see a video of it in action

Multi-TTY is contained in the CVS version (23) of Emacs. Version 23 is still a (tiny) bit rough around the edges, so don't blame me if while using it it deletes all your files and destroys your life in general. It won't, but caveat emptor. I am now running multi-tty on Gentoo and Ubuntu Feisty Fawn. Here's how:

Gentoo

On my laptop I run Gentoo Linux. Getting the latest version of Emacs on Gentoo was a breeze! :

  • Setup Layman
  • Add the emacs overlay: sudo layman -a emacs
  • Add the following USE flags for app-editors/emacs-cvs: sudo flagedit app-editors/emacs-cvs X Xaw3d alsa gif gzip-el jpeg lesstif png sound spell tiff toolkit-scroll-bars xpm -gtk -hesiod -motif -source.
  • GTK support is explicitly turned off as it causes problems with multi-TTY. This is no biggie for me as I always have (menu-bar-mode -1) and (tool-bar-mode -1) set.
  • Emerge: sudo emerge emacs-cvs -va
  • Tell the system to use the new emacs: sudo eselect emacs set emacs-23-multi-tty

Ubuntu

Ubuntu was much more difficult to setup correctly because the repositories don't have the CVS version yet (emacs-snapshot is 22). So, I've compiled it from source myself and once I clean up my instructions I will publish a HOWTO as well as my .deb package.

Update: See my new Ubuntu specific post for build instructions

Usage

Connecting to an already running emacs session is quite easy:

  • In the main emacs session run M-x server-start
  • Now just run emacsclient -c and you should see a new window pop up that has all the exact same buffers. If you are on a non-graphical terminal you'll likewise get the same emacs session albeit in text mode.

I found some excellent tips from sness.net for making this even easier. Here are my variations on his methods:

Make a new file somewhere in your path called preload_emacs:

#!/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.
# Visit http://www.enigmacurry.com
# based on http://emacslife.blogspot.com/2007/05/multi-tty-emacs.html


name="$1"
waitp="$2"
screendir="/var/run/screen/S-$USER"
serverdir="/tmp/emacs$UID"
emacs=/usr/bin/emacs

if [ -z "$name" ]; then
    echo "Usage: preload_emacs <name> [<waitp>]"
    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 "emacs-$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

Running preload_emacs -s ryan will now create an emacs server named 'ryan'. It loaded emacs in a screen session so that it will be able to be a long running process (Emacs apparently cannot run without an interface, hence we run it in a screen session to hide it away out of sight.)

To connect, we run emacsclient -c -s ryan. Typing plain old emacs here will load an entirely new Emacs session, which isn't really what we want. To make it a bit easier I created a shell script called "ec" that will load an emacsclient with these settings automatically:

#!/bin/bash -l
SERVERNAME=ryan
#Attempt to connect to an existing server
emacsclient -c -s $SERVERNAME $*
if [ $? -ne 0 ]
 then
 #Start a new emacs server and connect
 preload_emacs $SERVERNAME 0
 emacsclient -c -s $SERVERNAME $*
fi

Now when I type ec it will automatically attempt to connect to an already running emacs server named ryan. If it is not running, it will transparently create the server and then connect to it.

If you make "ec" your system's default editor, you'll now be able to use a lightning quick version of emacs for all your editing needs!

Read and Post Comments

Emacs movement keys

May 13, 2005 at 12:45 AM | categories: emacs, linux | View Comments

Emacs
whoa. I just realized something cool in Emacs... hold down control and use the arrow keys and you can move around by words and paragraphs.

... I guess I should have RTFM years ago huh? ... I'm such a dolt.

  • Ryan
Read and Post Comments

« Previous Page