1 1.1 wiz (defconst netbsd-knf-style 2 1.1 wiz '( 3 1.1 wiz ;; (c-auto-newline . nil) 4 1.1 wiz ;; default indentation level 5 1.1 wiz (c-basic-offset . 8) 6 1.1 wiz ;; in which column to add backslashes when macroizing a region 7 1.1 wiz (c-backslash-column . 78) 8 1.1 wiz ;; automatically compact brace-else(if)-brace on one line and 9 1.1 wiz ;; semi-colon after closing struct brace 10 1.1 wiz (c-cleanup-list . (brace-else-brace 11 1.1 wiz brace-elseif-brace 12 1.1 wiz defun-close-semi)) 13 1.1 wiz ;; do not indent lines containing only start-of-comment more than default 14 1.1 wiz (c-comment-only-line-offset . 0) 15 1.1 wiz ;; start new lines after braces 16 1.1 wiz ;; default is: before and after (for all other cases) 17 1.1 wiz (c-hanging-braces-alist . ((defun-open . (before after)) 18 1.1 wiz (defun-close . (before after)) 19 1.1 wiz (block-open . (after)) 20 1.1 wiz (block-close . c-snug-do-while) 21 1.1 wiz (substatement-open . after) 22 1.1 wiz (statement-case-open . nil) 23 1.1 wiz (brace-list-open . after) 24 1.1 wiz (brace-list-close . nil) 25 1.1 wiz )) 26 1.1 wiz ;; where to put newlines around colons 27 1.1 wiz (c-hanging-colons-alist . (quote ((label after) 28 1.1 wiz (case-label after)))) 29 1.1 wiz ;; indent comments syntactically 30 1.1 wiz (c-indent-comments-syntactically-p . t) 31 1.1 wiz ;; no spaces needed before a label 32 1.1 wiz ;; (c-label-minimum-indentation . 0) 33 1.1 wiz ;; define offsets for some code parts 34 1.1 wiz (c-offsets-alist . ((arglist-cont-nonempty . 4) 35 1.1 wiz (block-open . 0) 36 1.1 wiz ;; (block-open . -) 37 1.1 wiz (brace-list-entry . 8) 38 1.1 wiz (brace-list-open . 8) 39 1.1 wiz (brace-list-close . 0) 40 1.1 wiz (knr-argdecl . 0) 41 1.1 wiz (knr-argdecl-intro . +) 42 1.1 wiz (label . -) 43 1.1 wiz (member-init-intro . ++) 44 1.1 wiz (statement-cont . 4) 45 1.1 wiz (substatement-open . 0) 46 1.1 wiz (case-label . 0))) 47 1.1 wiz ;; XXX: undocumented. Recognize KNR style? 48 1.1 wiz (c-recognize-knr-p . t) 49 1.1 wiz ;; indent line when pressing tab, instead of a plain tab character 50 1.1 wiz (c-tab-always-indent . t) 51 1.1 wiz ;; use TABs for indentation, not spaces 52 1.1 wiz (indent-tabs-mode . t) 53 1.1 wiz ;; set default tab width to 8 54 1.1 wiz (tab-width . 8) 55 1.1 wiz ) 56 1.1 wiz "NetBSD KNF Style") 57 1.1 wiz 58 1.2 christos (defun knf-write-contents-hook () 59 1.2 christos (if (and (string-equal c-indentation-style "netbsd knf") 60 1.2 christos (require 'whitespace nil t)) 61 1.2 christos (whitespace-cleanup)) 62 1.2 christos nil ;; XXX - make sure we return nil or the file will not be written. 63 1.2 christos ) 64 1.2 christos 65 1.1 wiz (defun knf-c-mode-hook () 66 1.1 wiz ;; Add style and set it for current buffer 67 1.1 wiz (c-add-style "NetBSD KNF" netbsd-knf-style t) 68 1.1 wiz ;; useful, but not necessary for the mode 69 1.1 wiz ;; give syntactic information in message buffer 70 1.1 wiz ;;(setq c-echo-syntactic-information-p t) 71 1.1 wiz ;; automatic newlines after special characters 72 1.1 wiz (setq c-toggle-auto-state 1) 73 1.1 wiz ;; delete all connected whitespace when pressing delete 74 1.1 wiz (setq c-toggle-hungry-state 1) 75 1.1 wiz ;; auto-indent new lines 76 1.1 wiz (define-key c-mode-base-map "\C-m" 'newline-and-indent) 77 1.2 christos ;; cleanup whitespace when saving 78 1.2 christos (add-hook 'write-contents-hooks 'knf-write-contents-hook) 79 1.1 wiz ) 80 1.1 wiz 81 1.1 wiz (add-hook 'c-mode-hook 'knf-c-mode-hook) 82