Emacs and the Modern Desktop

I’ve been using GNU Emacs, an over-featured text editor for Unix-like systems, off and on since 1989. It has a somewhat primitive interface (at least for those who, like me, are accustomed to a mouse and menu-driven interface), and several quirks that are indicative of its pre-Mac and pre-Windows origin (for example, to find a string in a file, you use CTRL+S for “search” instead of CTRL+F for “find”, and the cursor is mysteriously called “point” in all the documentation). But it can’t be beat for the breadth of file editing tasks it handles well; from DNS Zone Files to Apache configuration files to shell scripts to Windows INI files to XML to source code for just about any programming language you care to name (even Ada!), it can syntax-highlight them all, and in many cases provide additional commands that make editing easier.

Its versatility and power – not to mention its essential “Free as in Speech” nature – has allowed it to survive over the years and function well as both a terminal application and a GUI application on many different platforms. But as the graphical capabilities of Linux workstations have evolved, especially in the last five years or so, Emacs hasn’t kept up. It has always been the odd window out on my desktop, with jagged fonts worthy of a early-to-mid-90’s Sun workstation and a Motif-ish scrollbar to match.

Fortunately, a few changes have been made on the “bleeding edge” that allows Emacs to use the same text rendering techniques that most other Linux desktop applications have been using for years, and a fellow named Alexandre Vassalotti has made Ubuntu packages of Emacs with this new feature, making installation a snap.

One problem I had with this tutorial is that he relies on setting the default font for text using X Resources. Since the new “pretty Emacs” is an alpha version, there’s always the possibility of something not working correctly, and so I keep both the new version and a “stable” version installed. Unfortunately, the older version uses a different naming convention for fonts, and since the X Resource Database setting affects both versions, his configuration suggestion doesn’t work for me.

I set the default font programmatically through the initialization file (“.emacs”), which is written in a programming language called Emacs Lisp. I accomplish this by setting an element in a List data structure called “default-frame-alist”, and I needed to find a way to set that element based on what version of Emacs was running. In Java, this would look something like:

AlistElement fontspec;
if(Emacs.getVersion().indexOf(“23”) > 0)
{
     // Use new-style font name
     fontspec = new AlistElement(“font”, “Liberation Mono-10”);
}
else
{
     fontspec = new AlistElement(“font”, “7x13”);
}

defaultFontAlist.add(fontspec);

After shaking off some cobwebs (if you use Emacs enough to want to customize it, you can’t help but pick up a little bit of Lisp along the way), I figured out the the “if/else” part, but how to manipulate the alist (which is called an “Association List,” similar to a Java Map) was a bit tougher. But I stumbled upon someone who had a similar problem of adding things to an alist, and he suggested using the lisp push function. So my final Lisp code looked like this:

(if (not (eq (string-match "23" (emacs-version)) nil))
     (push '(font . "Liberation Mono-8") default-frame-alist)
     (push '(font . "7x13") default-frame-alist))
Advertisements

No comments yet

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com 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

%d bloggers like this: