Software Engineering on Unix
Emacs can be used as a unified environment for software development
under UNIX. If things are set up properly, you can use it for
everything.
We'll assume you're using Emacs 20. On Athena this is now the default.
Some places are still using Emacs 19, but not many. Emacs 21 was
released recently, but it takes a while for a new version to take
hold.
Key bindings
- C-x means to hold down control and press the x key
- M-x means to hold down the meta (or alt or compose) key
and press the x key.
- M-x can also be done by pressing ESCAPE then
pressing the x key.
- C-x C-y means to hold down control and press the x key
then let go then hold down control and press the y key
- M-C-x means to hold down control and alt keys and press the x key
Buffers and files and windows
- C-x C-f
- open file in a new buffer
- C-x C-w
- write file out with a different name
- C-x C-s
- save buffer under current name
- C-x b
- switch to buffer
- C-x k
- kill current buffer
- C-g
- cancel
- C-_
- undo
C-x 2
split current window
C-x o
switch to other window
C-x 1
make current window only window
C-x 0
remove current window
C-x 5 2
make another X window
C-x 5 0
delete the current X window
.emacs file and elisp
Regions
- Used to select regions of text on which to perform an operation
- Select with C-SPACE then move to end
- Also select with mouse button 1 and drag
Editing C code in c-mode
M-x compile
- In c-mode, M-x compile runs make for you
- To make C-c C-v do a compile in c-mode:
;; Use C-c C-v in c-mode to do a compile
(defun my-save-and-compile ()
(interactive "")
(save-buffer 0)
(compile "make -k"))
(define-key c-mode-map "\C-c\C-v" 'my-save-and-compile)
If global-map is used instead of c-mode-map
then applies to makefile and other modes.
- Middle button over an error goes to it in the source
- M-n goes to next error with:
(define-key c-mode-map "\M-n" 'next-error)
Tags
- Keeps track of what is defined where
- Generate TAGS file with:
etags *.[ch]
- To go to where a function is defined, do M-.
over the function call
- To do a query replace over all files,
do M-x tags-query-replace
- To search for something across all files, M-x tags-search
- To go to next occurance of search string, M-,
Faces and colorization
- List faces with M-x list-faces-display
- (set-face-foreground 'face "color")
- (set-face-background 'face "color")
- Highlight active region with:
(transient-mark-mode 1)
- Use font-lock minor mode to enable syntax hilighting
M-x font-lock-mode
or
(global-font-lock-mode 1)
- Update hilighting with C-=
- Example of setting C coloring for font lock mode:
(new-face 'font-lock-comment-face "gray")
(new-face 'font-lock-variable-name-face "skyblue")
(new-face 'font-lock-keyword-face "burlywood")
(new-face 'font-lock-function-name-face "deepskyblue")
(new-face 'font-lock-preprocessor-face "burlywood")
(new-face 'font-lock-string-face "violet red")
(new-face 'font-lock-doc-string-face "green")
(new-face 'font-lock-type-face "lightsalmon")
Adding filename to mode mappings
Using the shell within emacs
- Start shell with M-x shell
- For command line history, use M-p and M-n
- Particularly useful for things like sqlplus and other badly written programs.
Using GDB within emacs
- Start with M-x gdb
- For command line history, use M-p and M-n
- Some other commands:
- C-c TAB
- step one statement
- C-x C-a C-b
- in c file will set a break point at that line
Obtaining more documentation
- M-x info enters info mode
- Clicking with middle mouse button follows hyperlinks
- Provides documentation for lots of GNU software
- Menus on toolbar provides access to info and features
- C-h m provides help with the current mode
File management with dired
- Use C-x C-f to open up a directory rather than a file
- f descends into subdirs and opens files
- o opens files in other windows
- d marks files for deletion
- u unmarks marked files
- x deletes marked files
- C copies files
- R renames files
Using RCS and CVS from inside Emacs
- C-x v v does the next logical command.
- If the file is not under version control, add it or start an rcs file for it.
- If the file is not up to date, update it.
- If the file is has unchecked in changes, check them in.
- C-x v = diff with most recent version.
Prepared by
Erik Nygren (nygren@mit.edu)
and
Mike Whitson (mwhitson@mit.edu)