Getting In and Out of Emacs, and Out of Trouble |
To start emacs, just type
A D V E R T I S E M E N T
To temporarily suspend emacs, type C-x C-z.1.
To revive it, just type fg, or better yet, %emacs (fg would only revive the most
recently suspended or ``backgrounded'' job, which might not be emacs).
To exit emacs just type C-x C-c.
Emacs is so useful that most people start up an emacs session
as soon as they log on to the machine, even though they may not need it right
away. They just want to have it ready when the need arises.2
If you find yourself in a jam while in emacs, say by having typed the
wrong thing, you can kill the current command by typing C-g.3
Remember this command!
Buffers
In a typical emacs session, you will be editing several ``files'' at
once. Some of these will be real files, while others will be temporary files4
which are created as the result of emacs commands.
For example, suppose I wish to edit the file WC.c. I type C-x C-f to load the
file, and then type WC.c. The screen will then look like this:
/* introductory C program */
/* implements (a subset of) the Unix wc command -- reports character,
word and line counts; in this version, the "file" is read from the
standard input, since we have not covered C file manipulation yet,
but of course a real file can be read by using the Unix `<' redirection
feature */
#define MaxLine 200
char Line[MaxLine]; /* one line from the file */
int NChars = 0, /* total number of characters in the file */
NWords = 0, /* total number of words in the file */
This looks just like regular vi, except for the bottom line, in which
emacs gives some general information, like the time of day. (Again, the
bottom line is in reverse video on the screen, but that doesn't show up here.)
Suppose this is my first emacs command. Then WC.c will be my first
buffer. Now suppose I type
in order to use emacs's built-in calendar facility.5
The screen would now look like this:
/* introductory C program */
/* implements (a subset of) the Unix wc command -- reports character,
word and line counts; in this version, the "file" is read from the
standard input, since we have not covered C file manipulation yet,
but of course a real file can be read by using the Unix `<' redirection
feature */
November 1992 December 1992 January 1993
S M Tu W Th F S S M Tu W Th F S S M Tu W Th F S
1 2 3 4 5 6 7 1 2 3 4 5 1 2
8 9 10 11 12 13 14 6 7 8 9 10 11 12 3 4 5 6 7 8 9
15 16 17 18 19 20 21 13 14 15 16 17 18 19 10 11 12 13 14 15 16
22 23 24 25 26 27 28 20 21 22 23 24 25 26 17 18 19 20 21 22 23
29 30 27 28 29 30 31 24 25 26 27 28 29 30
31
C-x < Calendar ? help/o other/c current Sun, Dec 6, 1992 C-x >
Loading calendar.elc...done
What has happened is that emacs has created a new buffer, for the
calendar, and displayed it along with my first buffer (for WC.c). The two
buffers are delineated on the screen by reverse-video lines at the bottom edge
of each buffer (which I have shown as long strings of asterisks here).
The calendar buffer is now a temporary file. I can edit it, e.g. delete
November, and if I desire to do so, save it to a permanent file.
Here are some commands dealing with buffers:
C-x o if two buffers appear together on the screen, move the cursor
to the other buffer
C-x 1 if two buffers appear together on the screen, expand the one
current containing the cursor to make that buffer fill the screen
C-x b display another buffer which is not currently displayed; emacs
is usually able to guess which buffer you want, and will ask you
to confirm that its guess is right; otherwise, specify the buffer
name yourself
C-x C-b list all buffers (note: this list itself will be a new buffer!)
C-x C-f read in a file and create a new buffer for it
C-x C-r read in a file and create a new buffer for it, but make the
buffer read-only (so that the file will not accidentally get
changed)
C-x k kill buffer; emacs will ask you to confirm that you mean
the one currently containing the cursor; otherwise, specify
which one
Again, remember that any buffer is a temporary file, and thus all editing
commands apply. For example, suppose I type C-x C-b to get a list of all
buffers. Again, this will create a new buffer, and suppose the list is so long
that it doesn't fit in one screen. Then I can use the usual editor scrolling
commands (for vi, C-f and C-b) to browse through the buffer.