|
CSE 341, Sp '07: Emacs Hints
|
|
As the quarter progresses I'll accumlate here what kinds of
commands I'm using frequently. If I did something quickly in section
and you couldn't follow it, look here.
This is not an introduction to emacs, see the Unix and Emacs tutorial for that.
Useful key commands
Note: C-xo means hit the control key and x
at the same time, then hit o (without the control key);
C-xC-f means hit control - x and then control -
f. M-x is Meta - x, Meta is usually the
Alt key on the lab machines.
- Moving between buffers
- C-xb switch buffers
- C-xo switch windows
- C-x1 make the current buffer the only window
- C-x2 make a new window horizontally below
- C-x3 make a new window horizontally besides
- C-x4b switch to a buffer in a new window (same as
doing C-x2 followed by C-xb)
- Moving around inside a buffer and editing
- C-/ undos the previous action. Emacs' undo-ring is
very long and quite handy.
- C-hh gives you help at any time. C-hk,
followed by a key sequence, tells you what command the sequence is
bound to. C-hb creates a buffer with a list of all key bindings
for the buffer you were in. C-hf lets you type in a
function and get documentation, if any, on that function.
- Arrow keys move the cursor, Meta-arrow keys move by words
- C-n and C-p move the cursor down and up ("next"
and "previous"); C-b, C-f move the cursor left and
right ("back" and "forward"). Meta moves by words; in the sml
command shell Meta up and down goes through the command history
- C-e C-a move to the end and beginning of the
current line, respectively. Same as Home and End.
- C-d is the same as the delete key. Meta with
C-d, delete or backspace kills a word. C-k kills
the rest of the line (and puts it in the kill-buffer, see below).
- C-space sets a mark. C-w kills the text
between the point and the mark and saves it in the kill-buffer.
M-w saves the text between the point and the mark but
doesn't kill it. C-y yanks text from the kill buffer. If
the previous command was a yank, M-y replaces the just
yanked text with the previous contents of the kill-buffer. This is
pretty handy as you can copy multiple things and paste them around in
a different order.
- C-t transposes the letters around a point, M-t
transposes words. M-u, M-l, M-c convert
the word following the point to upper case, lower case, and
capitalized, respectively.
- Using SML.
- M-x then run-sml fires up an SML command shell.
- The following all is used from an sml file, not the command
shell. See below for getting the default
emacs bindings set up. See also the SML REP
loop document for more tricks here.
- C-cC-b reads the whole file into SML. The SML
use command is what actually reads it in; it's read in
through a temporary file, so the line numbers reported for errors are
correct.
- C-cC-f sends the current function to sml. Note that
line numbers reported for errors aren't correct.
- The SML mode you edit your file in is reasonably smart about
indenting. If you hit the tab key on a line, emacs will indent that
line. Sometimes you have to hit tab after entering text as that
changes you things are indented. Try typing something like fun
x = <return> if <tab> null x <return> then
<tab> 0 <return> else <tab> hd x <return>
Emacs Setup
Emacs gets its defaults from the .emacs file in your home
directory. This file is just an emacs Lisp program that gets run on
startup. Emacs Lisp is very similar to the Scheme language that we
will study later on this quarter. After making a change to your
.emacs file, to get the change to apply you can put the point
in the thing you just typed, then do CM-x, which sends the
current function to emacs (much like C-cC-f sends a function
to SML).
In addition to the changes mentioned in the Unix and Emacs Tutorial, put in the
following. Note that ; is used to start a comment; the rest
of the line is ignored.
;; Set up C-cC-f.
(add-hook 'sml-mode-hook (lambda () (local-set-key "\C-c\C-f"
'sml-send-function-and-go)))
;; I don't know why this isn't standard in emacs: M-g lets you type a
line number to goto in. Handy for moving to errors that SML reports
(global-set-key "\M-g" 'goto-line)
;; bind M-` (the backtick key, a backwards single quote) to
;; next-error, which sometimes can go to compile error messages. It
;; seems to be somewhat flakey with SML, but if you put the point on
;; an error message and then hit M-`, you'll jump to the error in the
;; source file. Sometimes you have to hit it twice, and sometimes it
;; doesn't work.
(global-set-key "\M-`" 'next-error)
Matt Cary, March 2005