|Auto-activates for||*.c *.h *.xbm *.xpm *.y *.yacc *.lex *.i *.m|
c-mode is bundled with Emacs by default. No additional setup is required.
- Go to the beginning of the current function. If you are between 2 functions, go the start of the previous one.
- Go to the end of the current function. If you are between 2 functions, go to the end of the next one.
- Mark current function
- Go to beginning of current statement (or next one).
- Go to end of current statement (or previous one).
Any mode based on cc-mode provides automatic indentation. The default style is
gnu. It is the one recommended by the Free Software Foundation for GNU projects but you can use a different one.
Here is a basic list of predefined styles:
- The default style for GNU projects
- What Kernighan and Ritchie, the authors of C used in their book
- What BSD developers use, aka “Allman style” after Eric Allman.
- Popularized by the examples that came with Whitesmiths C, an early commercial C compiler.
- What Stroustrup, the author of C++ used in his book
- Popular C++ coding standards as defined by “Programming in C++, Rules and Recommendations,” Erik Nyquist and Mats Henricson, Ellemtel
- What the Linux developers use for kernel development
- What Python developers use for extension modules
- The default style for java-mode (see below)
- When you want to define your own style
- The default style is set via the variable
- Use [C-c .] (or M-x c-set-style) to change the indentation style of the current buffer.
- The amount of space use to indent is set via the variable .
To set the default style to K&R and use 4 spaces, add this to your Emacs configuration file:
; set k&r style (setq c-default-style "k&r") ; indent with 4 spaces (setq c-basic-offset 4)
Nice visual preview of different cc mode styles: http://davidha.wordpress.com/2009/05/15/emacs-cc-modes-built-in-styles-gallery/