Emacs is very hard to characterize. It is usually thought of as an extensible text editor. It is actually much, much, more. It can be used as an email client, an appointment book, or a file manager. More importantly for our biostats department, it can be used as
Emacs is cool as an editor, because it has
begin
and end
codes within LaTeX, or the color of quoted strings in C++. The feedback from such highlighting prevents many common typos.Sure, there are other editors which can accomplish these tasks for particular languages or applications. The classification of Emacs goes from cool to kewl, though, because it provides a single interface with a single (albeit strange) set of keyboard shortcuts and mouse clicks to learn. It is also extensible. When I used to program Stata very heavily, I yearned for an editor which would format and highlight for me... so I wrote a mode to handle Stata coding.
Emacs runs on pretty much any flavor of Unix (including GNU/Linux and Mac OS X), on the classic Mac OS, and on pretty much all types of MS Windows which still get used. Here are locations for getting Emacs for yourself, regardless of what OS you like. Note to folks using R at Hopkins: To use the subprocesses, such as R, you will need to use Emacs on the biostat server itself.
It's gonna be pretty hard to learn Emacs without starting up the application. To fire up emacs on our system,
You will be greeted by a window which looks like this:
Before you start, there are some things to note:
Come back to this page when you're finished. It'll take, oh, about a half hour.
Don't even think of skipping the tutorial!
As you can see, Emacs could very well be an acronym for Excessive Meta and Control Sequences. Don't get too worried. The strength of emacs is its ability to quickly edit without forever grabbing the mouse.
Note:The page up, page down, and arrow keys function as expected for moving around. They are generally easier to use than the Emacs scrollbar, especially if you don't have a three-button mouse.
There are many ways to get help when using Emacs. As you'll note, they all begin with C-h
(Control-h):
C-h i
(short for Info)h
. This will take you on a guided tour of Info.C-s
to search for what you want to know.C-h a
(short for Apropos)*Apropos*
buffer which contains all the functions containing the word you typed. So... if, say, searching is what you'd like to do, typingC-h a<RET>search
C-h b
(short for Bindings)C-h w
(short for Where)undo
, and get the key sequence to which the function is bound.C-h k
(short for Key)C-/
). Emacs will open up a second window with an explanation of the function used by the key. This help is invaluable if a key does not seem to be behaving properly (often a key's purpose will be changed depending on the mode).C-h f
(short for Function)
Emacs will sense that you are working on a LaTeX file if you 'find' (i.e. open) any file whose extension is .tex
, .TeX
, .ltx
, .sty
, .cls
, .clo
, or .bbl
. Once you have something like this open, you'll notice a couple of things happen:
C-c
key sequences.xdvi
to preview it, and then running it off to the printer.
Emacs will also correctly recognize the file extension .bib
for BibTeX files. What are BibTeX files? BibTeX is the automatic bibliography generator for LaTeX, and is invaluable when writing papers.
If you wanna typeset mathematically interesting things, you need to learn to use LaTeX. If you're going to use LaTeX on the Unix server, you should learn Emacs - it'll save immense amounts of time.
Emacs will divine your overwhelming urge to work in R whenever you open any file which has an extension of .s
, .S
, or .q
. It will figure that you are wanting R if a file has an extension of .R
. If you wish to start working in S (or R) without having a specific file that you want to edit, simply typing M-x S
will start S, and M-x R
will start R. Both of these modes allow you to work in S (or R) with the usual context-sensitive highlighting.
By now, you will have guessed that Emacs will detect SAS files (program files, that is), and will help you edit them with nice context-sensitive highlighting. I'm working on getting ESS (Emacs Speaks Statistics) to correctly run SAS from within Emacs, but at this point (Friday, July 28, 2000), it is not quite functional yet. Don't expect too much from the SAS mode as yet.
Emacs will even understand the need to work on Stata programs if you open any file which has an extension of .ado
, .lbl
, or .do
. The Stata mode is not as slick as those above, since it is merely a device to edit Stata files. It is not integrated into a networked version of Stata. (Possibly because we don't have a networked version of Stata.) Still - it is useful for editing Stata programs.
This is frowned upon by Emacs purists, even though there is a case to be made for both the mouse and the keyboard. For those who really want to grab the mouse, here are some tips for using a three-button mouse (along with the keyboard equivalents):
C-space
C-Mouse Button 2
(control-middle-button). The keyboard is simpler: C-w
(for wipe).
M-w
.C-y
. Emacs keeps a very large kill ring, and successive C-y
s will pull out earlier kills. You can also go to the Edit menu to see what is on the kill ring.I will probably lose my membership in the True Emacs Lovers Club, since I have even mentioned that a mouse can be used. I personally use the mouse very little, because I find remembering bindings to 3 mouse buttons harder than remembering keyboard shortcuts.
This is the easiest way to start customizing! One of the wonderful things about Unix is the simplicity with which you can use others' outrageously complex code as though it were your own. To get other folks' customizations for free, just go to their home directories, and copy their .emacs
file. There could be some things which don't quite work, but hey, you can't have lost anything!
For those of you who want to give it a shot, here is a link to my .emacs file. Open it, copy it, and put it into your home directory. Of course, if you are here in the biostat department, you should be able to just cp
it to your home by typing
cp /home1/biostats/brising/.emacs ~/.emacs
Emacs would not be called an extensible editor if it did not have some mechanism for customizations. For most folks, the customizations can be rather intimidating, since everything in Emacs is written in a variant of LISP, known as Elisp. Lisp is wonderful if you understand it, but Lots of Irritating Single Parentheses if you don't.
Luckily, there are some reasonable methods for simple customization which don't involve Elisp. Unfortunately, some of them require knowledge of something equally strange - using flags in Unix commands
As you (might) know, Unix commands typically have a series of flags which can be set by the user to cause a command to run differently than its default. Here are some of some of the ones I find useful. Note: the first of these - the one which changes the color of the Emacs window is very useful.
bg
flag will change the background color of the Emacs window.fg
flag will change the foreground color of the Emacs window. Hmm... I bet there is a way to do this in Unix, also.font
flag sets, uh, the default font for the pretty text characters.geometry
flag sets the size of a default Emacs window.
If you get sick of having to type all the durn command line flags when you just want to start Emacs easily, consider making an alias for the command line in your .cshrc
file. Here is an example which
niceemacs foo.tex
would start up Emacs editing the file foo.tex
.
alias niceemacs 'emacs -bg LightYellow -fg Black -i -font 8x13 -geometry 90x36 \!* &'
Now, wasn't that fun? (You can copy this and paste it to the bottom of your .cshrc
file, if you like).
.emacs
FileEmacs, just like other unix applications has initialization files. When Emacs starts, it first races off to see if there is a site-wide (for us: department-wide) start file from which it should pick up customizations. There is such a file, of course, so that each individual user don't have to waste time getting LaTeX to run when (s)he wants it to.
After Emacs has run through the site-wide initialization file, it looks for a .emacs
file in the user's home directory. This, also, is typical behavior for a Unix application. Any other tweaking you'd like to do, you can put in this file.
The most common customization that people need is that of the color of the window, and the color of the fonts in the context-sensitive highlighting. The order in which the customizations are made is important! Get a background color you like, and then get font colors.
Customizations can be done on the fly from within Emacs by typing M-x customize
. A menu with various groups will be presented, and changes can be made by clicking on options(!) using the middle mouse button in Unix (or its equivalent when using an X-server to hook up to Athena).
If this seems complex, try the command M-x customize-apropos
, and then entering an appropriate word. Emacs will then bring up a customize buffer containing those items in the customize window containing the word.
Now you should be happily on your way to using Emacs. If you do get unnecessarily worried, remember
C-x C-c
with the best of them. If you're not in the computer lab, but need access to a reference sheet, go here to get PDF or Postscript files for version 20, or go here to find something for the browser (which is for version 19).M-x yow
It will make you feel better.M-x doctor
.