Key Bindings · Compiling · Debugging · Controlling Windows · Emacs Manual
For more information, see Chap. 23 in H. Hahn,
Harley Hahn's Student Guide to UNIX, 2nd edition, McGraw-Hill,
1996; Appendix F summarizes most of the emacs
commands. For a
complete guide, see
Learning GNU Emacs by Debra Cameron and Bill Rosenblatt (O'Reilly &
Associates, Sebastopol, CA, 1991, ISBN 0-937175-84-6). The full emacs manual
also available online.
C-a beginning-of-line C-e end-of-line C-n next-line C-p previous-line C-k kill-line C-o open-line
ESC f forward-word ESC b backward-word ESC d kill-word ESC DEL backward-kill-word
C-f forward-char C-b backward-char C-d delete-char DEL delete-backward-char C-q quoted-insert C-t transpose-chars
C-@ set-mark-command C-w kill-region (between cursor and mark) C-y yank (i.e., insert text last killed)
C-l recenter C-v scroll-up (forward) ESC-v scroll-down (backward) ESC < beginning-of-buffer ESC > end-of-buffer
C-s isearch-forward C-r isearch-backward
C-x C-f find-file C-x C-r find-file-read-only C-x C-w write-file
C-x 1 delete-other-windows C-x 2 split-window-vertically C-x 4 f find-file-other-window C-x o other-window
ESC ! shell-command ESC x compile compile ("make -k" is default) C-x ` next-error (used after "compile" to find/edit errors)
C-x C-c save-buffers-kill-emacs C-u universal-argument C-x C-z suspend-emacs (resume by typing "fg" to unix)
C-g keyboard-quit C-h help-command C-h t help-with-tutorial C-h b describe-bindings (complete list of emacs commands)
ESC-x compile
If this is the first time you have issued this command since entering emacs,
the minibuffer at the bottom of the screen appears filled with make -k
.
If you're not using make -k
erase the minibuffer line (using
DEL
, for example) and type in the compiler command of your choice,
e.g., lcc -g -A encode.c
. This command is remembered for
subsequent executions of ESC-x compile
. When you type RETURN
,
if there are unsaved buffers, you will be given the opportunity to save each
one. The screen then splits into two windows, and the output from the
compilation command appears in one of the two windows. If there are parse
errors, use the following command.
C-x `
Each time this command is given after a compilation that found errors,
another line of parse errors is located. The compilation window is scrolled up,
so that the topmost line displays the a new parse error. The other window
changes buffers, if necessary, and displays the source line associated with the
error.Note that if your program consists of several files, this command locates
the file and loads it into the buffer. The cursor is placed at the line
containing the error. You may edit the file to correct the source of the error
and repeat the command again to find additional errors. When you have done the
most you can with this batch of parse errors, give the ESC-x compile
command again.
ESC-x gdb
The minibuffer at the bottom of the screen prompts you for the name of your
executable file. Unless you compiled with the -o
option to name
the output file, the name of your executable file is a.out
. When
you type in the file name followed by RETURN
, the screen splits
into two windows (or remain split if it is split already). One window is used
for interactive input and output to gdb. The other will eventually display your
program files for you to examine and edit. Sometimes the screen doesn't divide
immediately after ESC-x gdb
, but gdb
takes over the
whole window where it was executed from; the screen divides the first time you
run the program and it stops because of a breakpoint or an error caught by the
debugger. So, if the window doesn't split and you want to follow the behaviour
of the running program, just type break main
before you run it the
first time. When execution reaches main
, the window splits as
described above, an arrow points to the current position in the code, which is
the first line of main.
The cursor initially is placed after the gdb
prompt (gdb)
.
Whenever you want to issue a command to gdb, position the cursor at the end of
the buffer, i.e., after the (gdb)
, and type the command as usual.
The command ESC->
gets you to the end of the buffer. To
examine previous input or output to gdb
, use the usual emacs
commands to move around the buffer.
Whenever your program, which was running under gdb
, stops
because of a breakpoint an interrupt, etc., the source code associated with the
current locus of execution is displayed automatically in the other window. A
marker,
=>
, points to the specific line. If you use the frame
command to change frames, the source for the new frame is displayed and the
marker is placed accordingly.
When you find an error, you may change the source code and save the file.
However, before recompiling, give gdb
the command kill
to cancel your running program. Otherwise, when the compiler runs the linker to
link your program you'll get the error `text file busy' and a new executable
file will not be written.
After recompiling a program, you should reload the symbol table and the executable, otherwise you'll be running the previous program. To do so, execute
(gdb) exec-file program-name (gdb) symbol-file program-name
The symbol-file
command will request confirmation before
reloading the symbol table; just answer yes
.
ESC-x gdb-break
gdb
breakpoint at the source line on which the cursor
appears.C-x 1
C-x 4f
C-x 4f
command prompts for the file name.C-x o