\documentstyle[twocolumn]{article}

\newcommand {\caret} {{\tt \^{ }}}
\newcommand {\bs} {$\backslash$}
\newcommand {\ARG} {{\it ARG}}
\newcommand {\myskip} {\bigskip}
\newcommand {\bul} {$\bullet$}
\newcommand {\key} [2] {
    \par\noindent%
    \hbox to 3.25 true in{{\tt #1}\hfil\parbox[t]{2.5 true in}{#2\strut}}\par}
\newcommand {\bkey} [2] {
    \par\hangindent0.75 true in\hangafter1\noindent{\tt #1}~ #2}
\newcommand {\nodesc} [1] {\par\noindent{\tt #1}}
\newcommand {\block} [1] {\par\myskip\noindent{\bf #1}\par\smallskip}

\headheight 0pt
\headsep 0pt
\topskip 0pt
%\footskip 0pt
%\textheight 9.75 true in
\advance\oddsidemargin-0.5in
\advance\evensidemargin-0.5in
\textwidth 6.75 true in
%\pagestyle{empty}

\begin{document}
% \setcounter{page}{78}
\small
\hbadness=10000
\begin{center}\bf
GNU Emacs \\
Quick Reference Guide \\
for CS61A
\end{center}

\vspace{0.5em}

\noindent Bullets (\bul) mark a suggested starting set of commands.
Daggers
(\dag) denote key bindings that are not standard in GNU Emacs. \ARG{}
denotes the prefix numeric argument (entered with {\tt C-u} or {\tt
M-}{\it digit}).  The notation `{\tt C-$x$}' means ``control-$x$'',
the result of holding down the control key while typing $x$.  `{\tt
M-$x$}' means ``meta-$x$'', the result of holding down the `{\tt
Meta}', {\tt Alt}, or $\diamond$ key (depending on keyboard) while
typing $x$.  If you are not using a window system or have a keyboard
without these keys, the sequence of two characters {\tt ESC~$x$} is
equivalent.  The notation `{\tt C-M-$x$}' is equivalent to holding
down both control and meta keys while typing $x$, or of typing the two
characters {\tt ESC~C-$x$}.

\section*{Cursor motion.}

\key{C-f}{Forward character.\bul}
\key{C-b}{Backward character.\bul}
\key{M-f}{Forward word.\bul}
\key{M-b}{Backward word.\bul}
\key{C-e}{Forward to end of line.\bul}
\key{C-a}{Backward to start of line.\bul}
\key{C-M-f}{Forward S-expression.\bul}
\key{C-M-b}{Backward S-expression.\bul}
\key{M-e}{Forward sentence.}
\key{M-[}{Forward paragraph.}
\key{M-a}{Backward sentence.}
\key{M-]}{Backward paragraph.}

\myskip

\key{C-n}{Next line.\bul}
\key{C-p}{Previous line.\bul}
\key{M-<}{Beginning of buffer.\bul}
\key{M->}{End of buffer.\bul}
\key{C-v}{Scroll text up one screen (or \ARG{} lines).\bul}
\key{M-v}{Scroll text  down (or \ARG{} lines).\bul}
\key{M-g}{Go to line number \ARG.\dag}
\bkey{M-x what-line}{Display line number.}
\key{C-M-v}{Scroll other window up one screen (or \ARG{} lines).}

\section*{Marking regions of text}

\key{C-@}{Set mark at point.\bul}
\key{C-x C-x}{Exchange mark and point.\bul}
\key{C-SPC}{Same as {\tt C-@}.}
\key{M-@}{Set mark after end of next word.}
\key{M-h}{Set mark and point around current paragraph.}
\key{C-x h}{Set mark and point around current buffer.}

\section*{Deletion and yanking}

\key{DEL}{Delete character before cursor.\bul}
\key{M-DEL}{Delete word before cursor and add to kill buffer.\bul}
\key{C-d}{Delete character at cursor.\bul}
\key{M-d}{Delete word at and after cursor and add to kill buffer.\bul}
\key{C-k}{Delete to end of line and add to kill buffer.\bul}
\key{C-w}{Delete current region, and add to kill buffer.\bul}
\key{M-w}{Copy current region to kill buffer without deleting.\bul}
\key{M-\bs}{Delete surrounding blanks and tabs.}
\key{M-SPC}{Delete all but one surrounding blank.}
\key{C-x C-o}{Delete all but one surrounding blank line.}
\key{C-M-w}{Cause next command, if a kill, to append to previous kill buffer, instead of new one.}

\myskip

\key{C-y}{Insert text from kill buffer at point.\bul}
\key{C-u C-y}{Insert text from kill buffer at point without moving point.}
\key{M-y}{Replace preceding {\tt C-y} text with next most recent kill buffer.}
\key{M-w}{Copy region to kill buffer, no deletion.}

\section*{Indentation}

\key{TAB}{Indent according to mode.\bul}
\key{LFD}{Same as RET TAB.}
\key{M-;}{Indent and start comment.}
\key{M-LFD}{Continue comment on next line.}
\key{C-x TAB}{Indent region rigidly by \ARG.}
\key{C-M-\bs}{Indent region according to mode.\bul}

\section*{Search}

\key{C-s}{Search forward.\bul}
\key{C-s C-s}{Same as {\tt C-s} with last string.\bul}
\key{C-r}{Search backward.\bul}
\key{C-r C-r}{Same as {\tt C-r} with last string.\bul}
\key{C-u C-s}{Search forward for regular expression.}
\bkey{M-x occur}{Display lines matching a regular expression.}
\key{M-x grep}{Display results of UNIX {\tt grep} utility.}
\nodesc{M-x count-matches}

\myskip\noindent
The following subcommands are valid during a search.

\smallskip
\key{RET}{End search.\bul}
\key{DEL}{Undo effect of last search character typed.\bul}
\key{C-g}{Abort search.\bul}
\key{C-s}{Search for next match forward.\bul}
\key{C-r}{Search for next match backward.\bul}
\key{C-q}{Quote next character.}
\key{C-w}{Extend search string with next word.}
\key{LFD}{Extend search string with rest of line.}

\section*{Replacement}

\key{M-\%}{Query replace.\bul}
\nodesc{M-x delete-matching-lines}
\nodesc{M-x delete-non-matching-lines}

\myskip\noindent
During a query-replacement, the following are valid responses to prompts.

\smallskip
\key{SPC}{Make replacement and go to next.\bul}
\key{DEL}{Skip replacement and go to next.\bul}
\key{RET}{End replacement.\bul}
\key{!}{Replace all remaining instances without asking.\bul}
\key{C-r}{Enter recursive edit; return with {\tt C-M-c}.}

\section*{Regular expressions}

\key{.}{Match any character.\bul}
\key{\^{ }}{Match at start of line.\bul}
\key{\$}{Match at end of line.\bul}
\key{[...]}{Match any character in the `...'.\bul}
\key{[\^{ }...]}{Match any character except those in `...'.\bul}
\key{*}{Match 0 or more of pattern to left.\bul}
\key{+}{Match 1 or more of pattern to left.}
\key{?}{Match 0 or 1 of pattern to left.}
\key{\bs$c$}{Quotes $c$, except for the following.}
\key{\bs b}{Match at beginning or end of word.}
\key{\bs B}{Match except at beginning or end of word.}
\key{\bs$|$}{Match either pattern to left or right.}
\key{\bs(...\bs)}{Grouping.}
\key{\bs$n$}{Match copy of whatever matched $n^{\mbox{th}}$ group.}

\section*{Miscellaneous editing}

\key{C-o}{Insert newline after cursor.}
\key{C-t}{Transpose characters.}
\key{M-t}{Transpose words.}
\key{C-x C-t}{Transpose lines.}
\key{M-u}{Convert whole word to upper case.}
\key{M-l}{Convert whole word to lower case.}
\key{M-c}{Capitalize word.}

\section*{Files}

\key{C-x C-f}{Find file; load if needed.\bul}
\key{C-x 4 C-f}{Find file in other window.\bul}
\key{C-x C-s}{Save file.\bul}
\key{C-x C-w}{Write to explicitly-named file.}
\key{C-x i}{Insert file at cursor.}
\bkey{M-x recover-file}{Recover file after disaster from auto-save file.}
\bkey{M-x revert-buffer}{Throw away changes to buffer and restore from file.}

\section*{Buffers and windows}

\key{C-x o}{Put cursor in other window.\bul}
\key{C-x 1}{Grow current window to full screen.\bul}
\key{C-x 2}{Split current window vertically.\bul}
\key{C-x b}{Put named buffer in window.\bul}
\key{C-x 0}{Remove current window.}
\key{C-x 3}{Split current window horizontally.}
\key{C-x C-b}{List all buffers.}
\key{C-x k}{Delete buffer.}

\section*{Shells}

\bkey{M-x shell}{Run UNIX shell in a buffer.\bul}
\key{M-$|$}{Execute single shell command on region.  With \ARG{},
replaces region.}

\myskip\noindent
Commands active in shell buffers:

\smallskip

\key{RET}{Send current line to shell.\bul}
\key{TAB}{Complete preceding file name.\bul}
\key{C-c C-c}{Send interrupt to shell.\bul}
\key{C-c C-u}{Erase current input line.\bul}
\key{C-c C-z}{Send stop signal to shell.\bul}
\key{C-c C-d}{Send EOF to shell.}


\section*{Scheme}
\bkey{M-x run-scheme}{Run Scheme interpreter in buffer {\tt *scheme*}.\bul}
\key{C-c~C-z}{Put the cursor in buffer {\tt *scheme*}.\bul}
\key{C-c~C-e}{Send definition to {\tt *scheme*}.}
\key{C-c~M-e}{Same as {\tt C-c~C-e~C-c~C-z}.}
\key{C-c~C-l}{Load file into {\tt *scheme*}.}
\key{C-c~M-l}{Same as {\tt C-c~C-l~C-c~C-z}.\bul$\dag$}
\key{C-c~C-r}{Send current region to {\tt *scheme*}.}
\key{C-c~M-r}{Same as {\tt C-c~C-r~C-c~C-z}.}
\key{M-C-q}{Indent Scheme expression.\bul}
\key{M-C-\bs}{Indent current region.}
\key{TAB}{Indent the current line.\bul}
\key{LFD}{Same as {\tt RET}~{\tt TAB}.}


\section*{Compilation, debugging, and tags}

\bkey{M-x compile}{Execute command (by default, {\tt make}) asynchronously.}
\key{C-x `}{Position to next error or next line found by {\tt M-x grep} 
command.}
\bkey{M-x kill-compiler}{Stop active {\tt compile}.}

\myskip

\bkey{M-x visit-tags-table}{Specify file containing tags produced by
{\tt etags}.}
\key{M-.}{Display source for given tag.}
\key{C-u M-.}{Find next alternate definition for last tag.}
\key{C-x 4 .}{Display source for tag in other window.}
\nodesc{M-x tags-search}
\bkey{M-x tags-query-replace}{Look for pattern in all files
named in tags table.}
\bkey{M-x tags-apropos}{Display matching tags.}

\myskip
\key{M-x gdb}{Run GNU debugger on file.}

\myskip
\noindent Commands valid in {\tt gdb} mode.

\smallskip
\key{C-c C-s}{Step.}
\key{C-c C-n}{Next.}
\key{C-c <}{Up stack.}
\key{C-c >}{Down stack.}
\key{C-c C-r}{Finish.}
\key{C-x SPC}{In any source file, sets a break point.}
\key{C-c C-i}{Stepi.}

\section*{Help and documentation}

\bkey{M-x manual-entry}{UNIX man page for given topic.}
\key{C-h a}{Look up names of matching Emacs commands.\bul}
\key{C-h b}{Display key bindings.\bul}
\key{C-h f}{Help for {\tt M-x} function.\bul}
\key{C-h C-h}{Help for {\tt C-h}.\bul}
\key{C-h i}{Run info browser.\bul}
\key{C-h k}{Help for key.\bul}
\key{C-h m}{Help for current mode.}
\key{C-h t}{Tutorial.}
\key{C-h w}{Key containing function.}

\myskip\noindent
Inside an *info* buffer (result of {\tt C-h i}), the following are defined.

\smallskip

\key{m}{Select menu item.\bul}
\key{l}{Go to last-visited node.\bul}
\key{?}{Get help for browser.\bul}
\key{u}{Go to node's parent.\bul}
\key{n}{Go to next node in sequence.\bul}
\key{q}{Leave browser.\bul}
\key{.}{Go to top of node.}
\key{d}{Go to top-level node.}

\section*{Mouse commands}
Left, middle, and right buttons are {\tt LB}, {\tt MB}, and {\tt RB}.

\key{LB}{Put cursor at mouse. Dragging marks region.\bul}
\key{MB}{Paste text from window-system cut buffer at mouse.\bul}
\key{RB}{Extend region to pointer and copy into cut and kill buffers. Clicking
twice deletes region.\bul}
\key{C-LB}{Select a buffer.}

\end{document}
