Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Johannes Weiner and committed by
Linus Torvalds
a7f371e5 197dcffc

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