diff options
author | Johannes Weiner <hannes@saeurebad.de> | 2008-07-25 04:45:51 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-07-25 13:53:29 -0400 |
commit | a7f371e54fac49ff62bb640d4a7276fca01527e8 (patch) | |
tree | d18489939fe84cbd706c0ac242fabd0732858eb2 /Documentation/CodingStyle | |
parent | 197dcffc8ba0ea943fee86e28e99cd9575799772 (diff) |
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>
Diffstat (limited to 'Documentation/CodingStyle')
-rw-r--r-- | Documentation/CodingStyle | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/Documentation/CodingStyle b/Documentation/CodingStyle index 6caa14615578..1875e502f872 100644 --- a/Documentation/CodingStyle +++ b/Documentation/CodingStyle | |||
@@ -474,25 +474,29 @@ make a good program). | |||
474 | So, you can either get rid of GNU emacs, or change it to use saner | 474 | So, you can either get rid of GNU emacs, or change it to use saner |
475 | values. To do the latter, you can stick the following in your .emacs file: | 475 | values. To do the latter, you can stick the following in your .emacs file: |
476 | 476 | ||
477 | (defun linux-c-mode () | 477 | (defun c-lineup-arglist-tabs-only (ignored) |
478 | "C mode with adjusted defaults for use with the Linux kernel." | 478 | "Line up argument lists by tabs, not spaces" |
479 | (interactive) | 479 | (let* ((anchor (c-langelem-pos c-syntactic-element)) |
480 | (c-mode) | 480 | (column (c-langelem-2nd-pos c-syntactic-element)) |
481 | (c-set-style "K&R") | 481 | (offset (- (1+ column) anchor)) |
482 | (setq tab-width 8) | 482 | (steps (floor offset c-basic-offset))) |
483 | (setq indent-tabs-mode t) | 483 | (* (max steps 1) |
484 | (setq c-basic-offset 8)) | 484 | c-basic-offset))) |
485 | 485 | ||
486 | This will define the M-x linux-c-mode command. When hacking on a | 486 | (add-hook 'c-mode-hook |
487 | module, if you put the string -*- linux-c -*- somewhere on the first | 487 | (lambda () |
488 | two lines, this mode will be automatically invoked. Also, you may want | 488 | (let ((filename (buffer-file-name))) |
489 | to add | 489 | ;; Enable kernel mode for the appropriate files |
490 | 490 | (when (and filename | |
491 | (setq auto-mode-alist (cons '("/usr/src/linux.*/.*\\.[ch]$" . linux-c-mode) | 491 | (string-match "~/src/linux-trees" filename)) |
492 | auto-mode-alist)) | 492 | (setq indent-tabs-mode t) |
493 | 493 | (c-set-style "linux") | |
494 | to your .emacs file if you want to have linux-c-mode switched on | 494 | (c-set-offset 'arglist-cont-nonempty |
495 | automagically when you edit source files under /usr/src/linux. | 495 | '(c-lineup-gcc-asm-reg |
496 | c-lineup-arglist-tabs-only)))))) | ||
497 | |||
498 | This will make emacs go better with the kernel coding style for C | ||
499 | files below ~/src/linux-trees. | ||
496 | 500 | ||
497 | But even if you fail in getting emacs to do sane formatting, not | 501 | But even if you fail in getting emacs to do sane formatting, not |
498 | everything is lost: use "indent". | 502 | everything is lost: use "indent". |