TFM


by Jesse Zbikowski - Newspeak Staff

First off, I'd like to hope that all of you out there are disciples of GNU Emacs. For you misguided heathens who occasionally use "pico" or haven't got any pictures of Richard Stallman on your fridge, Emacs is easily the most important piece of software running in user space. It will handle your email and your news, help you write, compile, and debug programs, and entertain, amaze, and inform you. Emacs is based on Lisp, a language given to computer science as a gift from the gods. Unfortunately most people aren't interested in learning Lisp just to edit their email messages, which is why GNU Emacs is sometimes said to stand for "Generally Not Used, Except by Middle-Aged Computer Scientists." Alas. (You don't have to know Lisp to use Emacs. You don't have to be crazy, either, but both help.)

When GNU Emacs 19 came out, it added tremendous support for X Window System users. In this article we'll take a look at some of the things you can do with Emacs under X.

Since virtually every login session involves the use of Emacs, it's a good idea to start an Emacs window every time you start X. You can do this by putting the line

emacs &

in your ~/.X11Startup file. Emacs has loads of command-line switches for customizing the appearance of your window. Here are some you may want to try:

-name string Specifies the title to give your Emacs window (I recommend "Praise Emacs!")

-font fontname Specifies the font to use. Type "xlsfonts" for the list of fonts installed on your machine. Note that you can only use fixed-width fonts, such as "12x24kana".

-fg color -bg color Specifies the color to use for your text and background, respectively. Check out the file /usr/lib/X11/rgb.txt for color names.

-i Tell Emacs to use the k00l GNU bitmap when you iconify it.

Now that you've started one Emacs, you can use it to do all your editing. There's no need to start up another. "But," you say, "I use (elm, trn) to read my (email, news). They start up a new Emacs window every time I want to send a message!" Yes indeed! But with GNU Emacs, you can make those programs connect with your existing Emacs window instead of starting a new one. All you have to do is start an "emacs server" in your main Emacs window, and tell your shell to have programs use an "emacs client" for editing. Here's how.

a) Add this line to your ~/.emacs file (you do have a .emacs file, right?)

(if window-system

(server-start))

2) If you use tcsh for your shell, add this to the end of your .tcshrc:

if($?DISPLAY) then

setenv EDITOR emacsclient

else

setenv EDITOR emacs

endif

If you use the Z-shell (like me), that would be

if [[ -n $DISPLAY ]] then

EDITOR=emacsclient

else

EDITOR=emacs

fi

export EDITOR

Now you're all set! When you finish the message, do a "C-x #" (not "C-x C-c" !). Not only do you save time and system load waiting for a new Emacs window, but you can also use the same kill ring and registers for inserting text.

Another interesting feature of Emacs under X is support for syntax-highlighting of source code. You can make comments in orange, literal strings red, keywords in another color. Highlighting is available for many Emacs programming modes (C mode, Perl mode, Scheme and Lisp modes); you just have to turn it on. You can do this with "M-x font-lock-mode" inside of Emacs ("M-x font-lock-mode" again to turn it off.) Or you can set up your .emacs file to start font-lock anytime you visit a file; try changing the piece of Lisp code above to this.

(if window-system

(progn

(server-start)

(add-hook 'find-file-hooks 'turn-on-font-lock)))

You can customize the colors Emacs uses by using set-face-foreground; experiment with these lines (between the server-start and the add-hook):

(set-face-foreground 'bold "pink")

(set-face-foreground 'highlight "LimeGreen")

"M-x list-faces-display" shows the different types of faces (bold, highlight, etc); /usr/lib/X11/rgb.txt has the colors available. The default colors look pretty good on the color displays in the CCC, but in the Zoo some are hard to see.

Well, hopefully this has given you a few things to play around with next time you log on to a workstation console. Email questions and suggestions to zed@wpi.edu; flames automatically forwarded to /dev/null. Until next time, happy gweeping, and RTFM.

die;



WPI Community Newspeak This Issue
Give feedback: newspeak@wpi.wpi.edu
Maintained by: Troy Thompson