Messages in this thread Patch in this message |  | | Subject | Re: <sigh> Coding Style doc: Let me try again | Date | Thu, 25 Jul 1996 16:40:55 -0500 | From | Alan Shutko <> |
| |
>>>>> "ADJ" == Arthur D Jerijian <celestra@ix.netcom.com> writes:
ADJ> I've noticed in the Documentation/CodingStyle document that the ADJ> LISP stuff required to getting Emacs to auto-indent C code is no ADJ> longer correct as of Emacs 19.31.
Yup. As of 19.30, it is using cc-mode instead of the old c-mode. This changes a lot of things, especially the old indenting engine.
I've put together some elisp to give the old indenting style. Here's a patch for the CodingStyle document with it. I've given it some trials and it does everything mentioned in the document.
--- /usr/src/linux/Documentation/CodingStyle Wed Jan 3 23:43:40 1996 +++ ./CodingStyle Thu Jul 25 16:34:35 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) + (setq c-file-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. A Semihemidemiquaver gives me a trill!
|  |