1
0
Fork 0

documentation: update CodingStyle tips for Emacs users

Describe a setup that integrates better with Emacs' cc-mode and also fixes
up the alignment of continuation lines to really only use tabs.

Signed-off-by: Johannes Weiner <hannes@saeurebad.de>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Randy Dunlap <randy.dunlap@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
hifive-unleashed-5.1
Johannes Weiner 2008-07-25 01:45:51 -07:00 committed by Linus Torvalds
parent 197dcffc8b
commit a7f371e54f
1 changed files with 21 additions and 17 deletions

View File

@ -474,25 +474,29 @@ make a good program).
So, you can either get rid of GNU emacs, or change it to use saner So, you can either get rid of GNU emacs, or change it to use saner
values. To do the latter, you can stick the following in your .emacs file: values. To do the latter, you can stick the following in your .emacs file:
(defun linux-c-mode () (defun c-lineup-arglist-tabs-only (ignored)
"C mode with adjusted defaults for use with the Linux kernel." "Line up argument lists by tabs, not spaces"
(interactive) (let* ((anchor (c-langelem-pos c-syntactic-element))
(c-mode) (column (c-langelem-2nd-pos c-syntactic-element))
(c-set-style "K&R") (offset (- (1+ column) anchor))
(setq tab-width 8) (steps (floor offset c-basic-offset)))
(setq indent-tabs-mode t) (* (max steps 1)
(setq c-basic-offset 8)) c-basic-offset)))
This will define the M-x linux-c-mode command. When hacking on a (add-hook 'c-mode-hook
module, if you put the string -*- linux-c -*- somewhere on the first (lambda ()
two lines, this mode will be automatically invoked. Also, you may want (let ((filename (buffer-file-name)))
to add ;; Enable kernel mode for the appropriate files
(when (and filename
(string-match "~/src/linux-trees" filename))
(setq indent-tabs-mode t)
(c-set-style "linux")
(c-set-offset 'arglist-cont-nonempty
'(c-lineup-gcc-asm-reg
c-lineup-arglist-tabs-only))))))
(setq auto-mode-alist (cons '("/usr/src/linux.*/.*\\.[ch]$" . linux-c-mode) This will make emacs go better with the kernel coding style for C
auto-mode-alist)) files below ~/src/linux-trees.
to your .emacs file if you want to have linux-c-mode switched on
automagically when you edit source files under /usr/src/linux.
But even if you fail in getting emacs to do sane formatting, not But even if you fail in getting emacs to do sane formatting, not
everything is lost: use "indent". everything is lost: use "indent".