Differences between revisions 3 and 4
Revision 3 as of 2010-05-27 12:01:55
Size: 1464
Comment: Emacs directory-specific variables
Revision 4 as of 2010-05-27 12:08:38
Size: 1162
Comment: Delete non-GNU formatting specific customization from .emacs. Let's leave the required settings and leave the rest to the user, who might have different customizations.
Deletions are marked like this. Additions are marked like this.
Line 14: Line 14:
;; Return as C-j, newline and indent
 (define-key c-mode-map [return] 'newline-and-indent)
Line 19: Line 16:
;; auto format when you type {
;; Backspace will delete the most space
Line 25: Line 18:
;; Show the function where the cursor is in.

The formatting rules for GCC are described in http://gcc.gnu.org/contribute.html and in http://gcc.gnu.org/codingconventions.html.

If you use Emacs, you can use M-x c-set-style and type 'gnu' for the style. And also, you can configure like this in your ~/.emacs file:

;; This line is not actually needed, it is on by default.
(setq-default indent-tabs-mode t)

(add-hook 'c-mode-hook 'linux-c-mode)
(defun linux-c-mode()
;; set gnu style.
 (c-set-style "gnu")
;; TAB offset set to 2
 (setq c-basic-offset 2)

Alternatively, on Emacs 23.1 or later, you can use directory-specific variables. Create a file .dir-locals.el in some directory between root and GCC sources with following contents:

((c-mode . ((c-file-style . "GNU")
            (c-basic-offset . 2)
            (indent-tabs-mode t))))

If you use Vim, you can use the following settings:

$ cat ~/.vim/after/ftplugin/c.vim
GNU Coding Standards
setlocal cindent
setlocal cinoptions=>4,n-2,{2,^-2,:2,=2,g0,h2,p5,t0,+2,(0,u0,w1,m1
setlocal shiftwidth=2
setlocal softtabstop=2
setlocal textwidth=79
setlocal fo-=ro fo+=cql

None: FormattingCodeForGCC (last edited 2016-01-18 17:39:08 by ManuelLopezIbanez)