Reference :

C in Emacs

GNU Emacs has a special mode called c-mode for editing C source files. When you visit a .c or a .h file, Emacs automatically puts you in c-mode. One of the nice features of c-mode is automatic indentation. Type TAB at the beginning of a line to position the point (a.k.a. cursor) at the right indentation for that line. As usual, you can do C-h m to find out more about the current mode.

GNU Emacs also has a function for compiling source files. The Emacs function compile can help you compile C files. If you have errors in your C files, C-x ` will take you to the position in you C files where the first error occured. You’ll also see a message describing the error. Subsequent C-x ` commands take you to the next errors. To learn more about compile, type C-h C-f compile.

Emacs can find function definitions. For example, say you are developing a program that consists of several .c files. You remember that you need to change a function called foo(). Where is foo()? Assuming that you have run an indexing program called etags on your program files, all you have to do it to type M-. foo. Emacs will open the file containing the definition of foo(), and Emacs will put the point (a.k.a. cursor) at the beginning of the definition.

Finally GNU Emacs has a mode for debugging programs. M-x gdb starts the GNU debugger gdb in a buffer. For more information on this mode, type C-h C-f gdb. See section Debugging.

See section `Introduction’ in Introduction to Gnu Emacs, for more information about the Gnu Emacs editor.