Re: <sigh> Coding Style doc: Let me try again

Alan Shutko (ats@shep1.wustl.edu)
Thu, 25 Jul 1996 16:45:07 -0500


Ooops, nuke that last one. I forgot to save after making a last
change.

--- /usr/src/linux/Documentation/CodingStyle Wed Jan 3 23:43:40 1996
+++ ./CodingStyle Thu Jul 25 16:43:05 1996
@@ -1,4 +1,4 @@
-
+]
Linux kernel coding style

This is a short document describing the preferred coding style for the
@@ -177,7 +177,10 @@
make a good program).

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 one of the following in your
+.emacs file.
+
+* Emacs < 19.30

(defun linux-c-mode ()
"C mode with adjusted defaults for use with the Linux kernel."
@@ -191,6 +194,49 @@
(setq c-continued-statement-offset 8)
(setq indent-tabs-mode nil)
(setq tab-width 8))
+
+* Emacs >= 19.30
+
+(defconst linux-c-style
+ '((c-basic-offset . 8)
+ (c-comment-only-line-offset . 0)
+ (c-offsets-alist
+ (statement-block-intro . +)
+ (knr-argdecl-intro . 0)
+ (substatement-open . 0)
+ (label . 0)
+ (statement-cont . +))
+ (c-hanging-braces-alist . ((brace-list-open)
+ (substatement-open after)
+ (block-close . c-snug-do-while)))
+ (c-cleanup-list . ((brace-else-brace)))))
+
+(defun linux-c-mode ()
+ "C mode with Linux kernel indentation."
+ (interactive)
+ (c-mode)
+ (set-c-style "linux"))
+
+
+(defun c-snug-if-or-do (syntax pos)
+ "Dynamically calculate brace hanginess for do-while statements.
+ Using this function, `else' clauses that end a `if-else' block will
+ remain on the same line as the brace that closes that block.
+
+ See `c-hanging-braces-alist' for how to utilize this function as an
+ ACTION associated with `block-close' syntax."
+ (save-excursion
+ (let (langelem)
+ (if (and (eq syntax 'block-close)
+ (setq langelem (assq 'block-close c-syntactic-context))
+ (progn (goto-char (cdr langelem))
+ (if (= (following-char) ?{)
+ (forward-sexp -1))
+ (looking-at "\\<if\\|do\\>[^_]")))
+ '(before)
+ '(before after)))))
+
+(add-hook 'c-mode-common-hook '(lambda () (c-add-style "Linux" linux-c-style)))

This will define the M-x linux-c-mode command. When hacking on a
module, if you put the string -*- linux-c -*- somewhere on the first

--
Alan Shutko <ats@hubert.wustl.edu> - The Few, the Proud, the Remaining.
Sign on bank: We can loan you enough money to get you completely out of debt.