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