Difference between revisions of "C-mode"

From WikEmacs
Jump to navigation Jump to search
(moved all markup to CC-mode and added redirection)
 
Line 1: Line 1:
{{Infobox major-mode
+
#REDIRECT [[CC-mode]]
|title = C
 
|library = cc-mode
 
|command = c-mode
 
|builtin = yes
 
|auto activates = *.c *.h *.xbm *.xpm *.y *.yacc *.lex *.i *.m
 
}}
 
 
 
'''c-mode''' is the default [[major mode]] for editing [[C]] source files. It's major features are customizable indentation and font-locking (coloring of code).
 
 
 
<!-----DONT REMOVE ANYTHING FROM THIS TEMPLATE ------------------------------>
 
<!-----FEW MONTHS, YEARS FROM NOW, MAYBE WE CAN DELETE STUFF. NOT NOW ------------------>
 
<!-----YOU DON"T WANT WIKEMACS TO BE ANOTHER EMACSWIKI RIGHT ------------------>
 
<!-----PLEASE BE PATIENT AND CO-OPERATE FOR GREATER GOOD ------------------>
 
 
 
 
 
 
 
<!------------------------------------------------------------------------->
 
 
 
= Basic setup =
 
 
 
c-mode is bundled with Emacs by default. No additional setup is required.
 
 
 
= Helpful keybindings =
 
 
 
; {{Keys|C-M-a}}
 
: Go to the beginning of the current function. If you are between 2 functions, go the start of the previous one.
 
 
 
; {{Keys|C-M-e}}
 
: Go to the end of the current function. If you are between 2 functions, go to the end of the next one.
 
 
 
; {{Keys|C-M-h}}
 
: Mark current function
 
 
 
; {{Keys|M-a}}
 
: Go to beginning of current statement (or next one).
 
 
 
; {{Keys|M-e}}
 
: Go to end of current statement (or previous one).
 
<!------------------------------------------------------------------------->
 
 
 
= Common Customization =
 
<!-- Customization common to all platforms goes here -->
 
 
 
== Style ==
 
Any mode based on {{ModeLink|cc-mode}} provides automatic indentation. The default style is <code>gnu</code>. 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:
 
; <code>gnu</code>
 
: The default style for GNU projects
 
; <code>k&r</code>
 
: What Kernighan and Ritchie, the authors of C used in their book
 
; <code>bsd</code>
 
: What BSD developers use, aka “Allman style” after Eric Allman.
 
; <code>whitesmith</code>
 
: Popularized by the examples that came with Whitesmiths C, an early commercial C compiler.
 
; <code>stroustrup</code>
 
: What Stroustrup, the author of C++ used in his book
 
; <code>ellemtel</code>
 
: Popular C++ coding standards as defined by “Programming in C++, Rules and Recommendations,” Erik Nyquist and Mats Henricson, Ellemtel
 
; <code>linux</code>
 
: What the Linux developers use for kernel development
 
; <code>python</code>
 
: What Python developers use for extension modules
 
; <code>java</code>
 
: The default style for java-mode (see below)
 
; <code>user</code>
 
: When you want to define your own style
 
 
 
You can look the [http://cc-mode.sourceforge.net/html-manual/Built_002din-Styles.html#Built_002din-Styles cc-mode documentation] for a complete list of builtin style.
 
For visual example of each style you can look the [http://en.wikipedia.org/wiki/Indent_style Wikipedia article on indenting style].
 
 
 
* The default style is set via the variable {{Variable|c-default-style}}
 
* Use {{CommandKeys|C-c .|c-set-style}} to change the indentation style of the current buffer.
 
* The amount of space use to indent is set via the variable {{Variable|c-basic-offset}}.
 
 
 
To set the default style to K&R and use 4 spaces, add this to your {{EmacsConfigFile}}:
 
 
 
<source lang="lisp">
 
; set k&r style
 
(setq c-default-style "k&r")
 
; indent with 4 spaces
 
(setq c-basic-offset 4)
 
</source>
 
 
 
 
 
<!------------------------------------------------------------------------->
 
 
 
= [[GNU/Linux]] =
 
<!-- Customization/Notes specific to GNU/Linux goes here -->
 
 
 
 
 
<!------------------------------------------------------------------------->
 
 
 
= [[OS X]] =
 
<!-- Customization/Notes specific to OS X goes here -->
 
 
 
 
 
<!------------------------------------------------------------------------->
 
 
 
= [[Windows]] =
 
<!-- Customization/Notes specific to Windows goes here -->
 
 
 
 
 
 
 
<!------------------------------------------------------------------------->
 
 
 
= [[Emacs-24]] =
 
<!-- Customization/Notes specific to Emacs-24 -->
 
<!-- Recent revision should come first. This way important information stays at top  -->
 
 
 
 
 
 
 
<!------------------------------------------------------------------------->
 
 
 
= [[Emacs-23]] =
 
<!-- Customization/Notes specific to Emacs-22 -->
 
 
 
 
 
<!------------------------------------------------------------------------->
 
 
 
= Recommended Reading =
 
<!-- Only internal links. DO NOT insert EXTERNAL LINKS -->
 
 
 
<!------------------------------------------------------------------------->
 
 
 
= Project Pages =
 
* [http://cc-mode.sourceforge.net/ cc-mode]
 
 
 
<!------------------------------------------------------------------------->
 
 
 
= Tutorial Pages =
 
<!-- ;[http://wiki.bazaar.canonical.com/EmacsTips Emacs as commit message editor]  -->
 
<!-- :Tips for setting up Emacs as Bazaar commit editor. -->
 
 
 
<!------------------------------------------------------------------------->
 
<!-- Add categories based on user-level (beginner etc), user-role (programming, emacs contributor etc), platform (windows, linux etc) or work flow (text editing, document authoring etc)  -->
 
 
 
Nice visual preview of different cc mode styles: http://davidha.wordpress.com/2009/05/15/emacs-cc-modes-built-in-styles-gallery/
 
 
 
[[Category:Programming]]
 

Latest revision as of 11:27, 20 April 2012

Redirect to: