Setting up and using emacs

My personal preference is to run just one copy of emacs all the time, as a server, and redefine the emacs command to talk to the running server. This is because it takes a second or two to start emacs, and I do a lot of editing; I would rather not wait for a second or two each time. I have a desktop icon which starts emacs when I click on it; then I just leave it running, typically for months at a time (ain't Linux great?).

Some useful resources:

If you have never used emacs before, type "control-H t" (the T can be lower- or upper-case) and you will be given a tutorial on the basics. All the keys and keystroke-sequences in emacs can be rebound to whatever you like. But I suggest you leave one key binding untouched: control-G is the abort key, useful if you are part of the way through some complex keystroke-sequence, or when emacs is expecting input to some interactyive question in the minibuffer at the bottom of its window, and don't want to continue that.

If you would like a printed reference card of the basics, look in /usr/share/emacs/21.2.93/etc/ (the 21.2.93 refers to the version of emacs you are using, and may differ on your machine).

Use the Help on the emacs toolbar for help. If you know vaguely what you are looking for, it can be quick and simple to do 'control-H A' (as in "help, apropos..") and then type a string, and emacs will look for all available internal commands that contain that string within their names. For example:

  control-H A calen
will find 93 commands about calendar operations. Click on the 'Command:' associated with any of them to get more details; emacs is a self-documenting editor!

If you find yourself doing some repetetive editing chore within emacs, such as converting all the /*...*/ coments to //-style comments in some C or C++ program, you may find it helpful to define a 'keyboard macro'. Start with 'contol-X (', then do some sequence of keystrokes such as:

  1. use 'control-S /*' to find the next opening comment delimiter
  2. delete the *, insert a / to convert that /* to //
  3. use 'control-S */' to find the closing comment delimiter
  4. delete it
and then end with 'control-X )' to end the storage of this sequence. Thereafter, the command 'control-X E' will repeat the sequence, and 'Esc 237 control-X E' will attempt to repeat it 237 times, but will give up when anything goes wrong such as failing to find another opening comment delimiter. If you really like your keyboard macro and want to keep it until you finally terminate emacs, you can always do 'Esc X name-last-kbd-macro' and give it a name such as 'modernise-comment', and then do 'Esc X modernise-comment' when you want to re-use it.

The Emacs Code Browser is a package that scans and analyses source code files in a variety of languages including C, C++ and Java, and displays windows that will permit you to move around the filespace, jump to functions, variables, classes, structures wherever they are defined, and so on. To start using ECB, you will need to stuff mentioned above. Then simply do this within emacs:

  Esc X ecb-activate
and to stop it, do this:
  Esc X ecb-deactivatedot-bashrc
You can also use the ecb-hide-ecb-windows and ecb-show-ecb-windows commands. Or use the ECB button on the toolbar for a menu.

My .emacs file, and the huge number of autoloadable extensions, are all written using Emacs LISP, alias elisp, a very extensive and powerful programming language. Emacs contains a compiler for it, which generates the *.elc files you could see in places such as /usr/share/eamcs/21.9.93/lisp/ as well as in the ~/lib/emacs/ you can download above. There is an online manual but in printed form it runs to over 500 pages; you can also buy it from bookshops.

Remember, emacs has a very long history and a huge community of users, mainly researchers. If there is something you wish you could do in emacs (split a window vertically, click on a URL to get taken to it wherever it resides on Planet Earth, decrypt a PGP-encoded email message, ...), then almost certainly somebody wanted this functionality before you did and it's already been provided; simply look for it!