Using Emacs on Unix

I use GNU Emacs under Unix, and find it a productive work environment. Emacs is a rich environment, and requires some investment in time and energy to get started. However, I believe the effort is worth it.

I have put together these notes as a ``crash start'' guide to using Emacs. You will find out the bare-basics of what is needed to get work done. There is a 2-page reference card on Emacs available. The resource center may be able to supply you with a copy, or you can print your own. On Unix, type

% lpr /usr/local/common/lib/emacs/19.34/etc/refcard.ps

Basic Concepts

Think of GNU Emacs as a ``shell'' rather than an editor. A shell is a program that lets you access all the relevant parts of the operating system. On the Macintosh, the ``Finder'' is a shell. Unix gives you a choice of shell, such as csh, sh, ksh, bash, etc. These shells are all much the same. Emacs is much more sophisticated.

When you login to Unix, the first thing you should do it run emacs. You will have no need to exit from emacs until you finish your session.

When emacs starts up, you will see the window is split into three regions: the main editing window, a ``mode line'' and an ``minibuffer window'' (used for displaying informational messages and reading command arguments).

The main window can be split vertically and/or horizontally. This is useful as it lets you edit your files and look at the output of Prolog at the same time.

Each window can display a ``buffer'' -- usually a file, or the output of another program (like prolog). You can have more buffers than there are windows. Commands are available for selecting which buffer to display in a window.

Emacs keys

Emacs understands 8-bit key codes, which are generated like this: The notation C-x is shorthand for CONTROL-x (hold down CONTROL and press x).

The notation M-x is shorthand for META-x (press ESC and then press x).

Editing files

To open a file (or create a new file, or show an already opened file in the window), use C-x C-f.

To save a file, press C-x C-s.

You should be able use the arrow keys to move around. Typing an ordinary character will insert that character. The reference card gives you some more movement commands.

To select a region of text, press C-spc (i.e. CONTROL-SPACE), and move the cursor to the other end of the region.

You can delete a region with C-w, and put it back somewhere else with C-y

Running Prolog

Type M-x run-prolog RET. Split the screen into two windows with C-x 2. Open the file containing your Prolog program with C-x C-f filename.pl RET.

You can now move between Prolog and your source file with C-x o.

You can load a section of your program into Prolog by placing the mark at one end of the region (C-spc) and moving the cursor to the other end. Then press M-C-x (i.e. press ESC, then CONTROL-x).

To load the whole file into Prolog, select the whole buffer with C-x h, then press M-C-x.

To interrupt Prolog (if it gets into a loop), switch to the *prolog* window with C-x o if necessary, and type C-c C-c.

If something goes wrong

The UNDO key is C-_ (i.e. hold down CONTROL and SHIFT together, and type the minus (-) key. You can undo the last 20,000 or so changes to a file by repeatedly typing this key. The undo sequence stops when you make an editing change. You can undo your undos if you need to.

The key C-g is used to interrupt Emacs and return to the normal editing state. You can use it to stop Emacs asking you to enter something in the minibuffer, for example.

Quitting Emacs

Type C-x C-c. You will be asked to save any files first, and told ``there are subprocesses running. Kill them?'', to which you can respond yes RET.

Using Emacs with NCSA Telnet 2.6

The NCSA Telnet Session menu should look like this:

   Session
+-------------+
| Backspace   | NO tick mark
|*Delete      | ticked
+-------------+
| Local echo  | NO tick mark
| Wrap mode   | doesn't matter
|*Emacs arrows| ticked
| Map PgUp/...| NO tick mark
| ...         | (irrelevant)
+-------------+
| Set screen  | do this manually (hold down OPTION
|       size  | and resize window with the mouse)
+-------------+
| Setup keys..| ALL entries MUST be blank!!!
| ...         |
+-------------+
A set of function key bindings is available for use with NCSA Telnet 2.6 on the Macintoshes in the lab. To use them, type M-x load-file RET ~j-hamer/Emacs/NCSA-telnet.el RET. Press the HELP key on the middle keypad for a description of the key bindings.

You can load these bindings automatically by placing the following line in your ~/.emacs file:

(load-file "/users/staff/j-hamer/Emacs/NCSA-telnet.el")

Learning more about GNU Emacs

Emacs has extensive on-line documentation. Type C-h i to bring up the ``info mode'' browser -- a hypertext system similar to the WWW (but with only local links). Select topics by moving the cursor on top of the link, and press RETURN. Scroll to the next page with SPACE. Scroll back with DELETE. Move back ``up'' with `u'. Quit with `q'.