Commit a7f371e5 authored by Johannes Weiner's avatar Johannes Weiner Committed by Linus Torvalds

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: default avatarJohannes Weiner <hannes@saeurebad.de>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Randy Dunlap <randy.dunlap@oracle.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 197dcffc
...@@ -474,25 +474,29 @@ make a good program). ...@@ -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
(setq auto-mode-alist (cons '("/usr/src/linux.*/.*\\.[ch]$" . linux-c-mode) (string-match "~/src/linux-trees" filename))
auto-mode-alist)) (setq indent-tabs-mode t)
(c-set-style "linux")
to your .emacs file if you want to have linux-c-mode switched on (c-set-offset 'arglist-cont-nonempty
automagically when you edit source files under /usr/src/linux. '(c-lineup-gcc-asm-reg
c-lineup-arglist-tabs-only))))))
This will make emacs go better with the kernel coding style for C
files below ~/src/linux-trees.
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".
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment