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.3 christos ;; NOTE: whitespace-cleanup has the following control knobs. By 59 1.3 christos ;; default these are all true. 60 1.3 christos ;(setq whitespace-check-leading-whitespace nil) 61 1.3 christos ;(setq whitespace-check-trailing-whitespace nil) 62 1.3 christos ;(setq whitespace-check-spacetab-whitespace nil) 63 1.3 christos ;(setq whitespace-check-indent-whitespace nil) 64 1.3 christos ;(setq whitespace-check-ateol-whitespace nil) 65 1.3 christos 66 1.3 christos ;; XXX - whitespace.el is badly behaved on blank buffers, so we handle 67 1.3 christos ;; those buffers ourselves. 68 1.3 christos (defun knf-nonblank-buffer-p () 69 1.3 christos (if (whitespace-buffer-search "[^ \t\n]") 70 1.3 christos t 71 1.3 christos (progn 72 1.3 christos (delete-region (point-min) (point-max)) 73 1.3 christos nil))) 74 1.3 christos 75 1.2 christos (defun knf-write-contents-hook () 76 1.2 christos (if (and (string-equal c-indentation-style "netbsd knf") 77 1.3 christos (require 'whitespace nil t) 78 1.3 christos (knf-nonblank-buffer-p)) 79 1.2 christos (whitespace-cleanup)) 80 1.2 christos nil ;; XXX - make sure we return nil or the file will not be written. 81 1.2 christos ) 82 1.2 christos 83 1.1 wiz (defun knf-c-mode-hook () 84 1.1 wiz ;; Add style and set it for current buffer 85 1.1 wiz (c-add-style "NetBSD KNF" netbsd-knf-style t) 86 1.1 wiz ;; useful, but not necessary for the mode 87 1.1 wiz ;; give syntactic information in message buffer 88 1.1 wiz ;;(setq c-echo-syntactic-information-p t) 89 1.1 wiz ;; automatic newlines after special characters 90 1.1 wiz (setq c-toggle-auto-state 1) 91 1.1 wiz ;; delete all connected whitespace when pressing delete 92 1.1 wiz (setq c-toggle-hungry-state 1) 93 1.1 wiz ;; auto-indent new lines 94 1.1 wiz (define-key c-mode-base-map "\C-m" 'newline-and-indent) 95 1.2 christos ;; cleanup whitespace when saving 96 1.2 christos (add-hook 'write-contents-hooks 'knf-write-contents-hook) 97 1.1 wiz ) 98 1.1 wiz 99 1.1 wiz (add-hook 'c-mode-hook 'knf-c-mode-hook) 100