Emacs as Your IDE

This is a no-frills listing towards using Emacs as a development environment. C-x means CTRL-x. M-x means ALT-x (or ESC and then x).

You can press the TAB key almost anywhere for autocompletion. Wherever you input text, use M-p and M-n to traverse up and down the history list.

C-u is the numeric-prefix operator. To go up by 10 lines, for example, one would say C-u 10 C-p.

Stuck!

File Handling

Editing

Search/Replace


[XKCD pays tribute to Emacs]

Navigation

Vertical Copy

Sometimes you will need to copy a vertical patch of data, e.g. one column in a table. First press C-<space> where you want to start copying. Then go to the end of the column and press C-x r k. To paste the column press C-x r y. (If you don't want to delete original column, just press C-_ there once to restore it and then press C-x r y at target.)

Registers

Symbol Lookup

Assuming CODEDIR to be the top-level source directory, first update your ~/.bashrc like so:
alias mktags='cd $CODEDIR && etags `find $CODEDIR -name "*.[h|c]"` && cd -'

Then run:

source ~/.bashrc
mktags

When Emacs asks for the TAGS file, specify $CODEDIR/TAGS.

Re-run mktags when the codebase has changed drastically.

Compilation and Debugging

To change the default string for M-x compile, edit your ~/.emacs file:
(setq compile-command "gmake -f Makefile.gnu all")

Comparing Two Files

Keyboard Macros

Example: Add 'extern' before all function protoypes in a file.

Go to the first prototype, and say:

    C-x (
    C-a
    extern<SPACE>
    C-n
    C-x )
Then say C-u 50 C-x e to replace 50 prototypes.

Perforce CVS Integration

Get p4.el and then follow these steps.
$ emacs -batch -f batch-byte-compile p4.el

Put the p4.el in some directory, say /home/foo/bar. Then edit your ~/.emacs as follows:

(setq load-path (cons "/home/foo/bar" load-path))
(load-library "p4")

You should see a P4 menu in Emacs, and you can do CVS operations from within Emacs now.

Symbol Lookup with cscope

Download cscope program, and xcscope.el and cscope-indexer from an OSS repository. Save the xcscope.el onto some directory in Emacs' load-path. Edit your ~/.emacs as follows:
(require 'xcscope)
To add a directory ~/foo to your load-path, use the following directive in .emacs file, making sure it appears before the "require xcscope" directive:
(setq load-path (cons "~/foo" load-path))

Place cscope-indexer in your $PATH. You can then use these keystrokes while browsing C source code:

File Operations

Operations such as move, copy, delete etc. are available in the directory editor: M-x dired

Calculations

More Help

Nervous Breakdown

Get therapy from a psychiatrist: M-x doctor
This file last modified: 11/Feb/2008
Back home