NetBSD.el revision 1.6 1 1.6 uwe ;; $NetBSD: NetBSD.el,v 1.6 2009/02/16 21:37:12 uwe Exp $
2 1.4 christos
3 1.1 wiz (defconst netbsd-knf-style
4 1.1 wiz '(
5 1.1 wiz ;; (c-auto-newline . nil)
6 1.1 wiz ;; default indentation level
7 1.1 wiz (c-basic-offset . 8)
8 1.1 wiz ;; in which column to add backslashes when macroizing a region
9 1.1 wiz (c-backslash-column . 78)
10 1.6 uwe (c-backslash-max-column . 78)
11 1.1 wiz ;; automatically compact brace-else(if)-brace on one line and
12 1.1 wiz ;; semi-colon after closing struct brace
13 1.1 wiz (c-cleanup-list . (brace-else-brace
14 1.1 wiz brace-elseif-brace
15 1.1 wiz defun-close-semi))
16 1.1 wiz ;; do not indent lines containing only start-of-comment more than default
17 1.1 wiz (c-comment-only-line-offset . 0)
18 1.1 wiz ;; start new lines after braces
19 1.1 wiz ;; default is: before and after (for all other cases)
20 1.1 wiz (c-hanging-braces-alist . ((defun-open . (before after))
21 1.1 wiz (defun-close . (before after))
22 1.1 wiz (block-open . (after))
23 1.1 wiz (block-close . c-snug-do-while)
24 1.1 wiz (substatement-open . after)
25 1.1 wiz (statement-case-open . nil)
26 1.1 wiz (brace-list-open . after)
27 1.1 wiz (brace-list-close . nil)
28 1.1 wiz ))
29 1.1 wiz ;; where to put newlines around colons
30 1.1 wiz (c-hanging-colons-alist . (quote ((label after)
31 1.1 wiz (case-label after))))
32 1.1 wiz ;; indent comments syntactically
33 1.1 wiz (c-indent-comments-syntactically-p . t)
34 1.1 wiz ;; no spaces needed before a label
35 1.1 wiz ;; (c-label-minimum-indentation . 0)
36 1.1 wiz ;; define offsets for some code parts
37 1.1 wiz (c-offsets-alist . ((arglist-cont-nonempty . 4)
38 1.1 wiz (block-open . 0)
39 1.1 wiz ;; (block-open . -)
40 1.6 uwe (brace-list-open . +)
41 1.6 uwe (brace-list-intro . +)
42 1.6 uwe (brace-list-entry . 0)
43 1.1 wiz (brace-list-close . 0)
44 1.1 wiz (knr-argdecl . 0)
45 1.1 wiz (knr-argdecl-intro . +)
46 1.1 wiz (label . -)
47 1.1 wiz (member-init-intro . ++)
48 1.1 wiz (statement-cont . 4)
49 1.1 wiz (substatement-open . 0)
50 1.1 wiz (case-label . 0)))
51 1.1 wiz ;; XXX: undocumented. Recognize KNR style?
52 1.1 wiz (c-recognize-knr-p . t)
53 1.1 wiz ;; indent line when pressing tab, instead of a plain tab character
54 1.1 wiz (c-tab-always-indent . t)
55 1.1 wiz ;; use TABs for indentation, not spaces
56 1.1 wiz (indent-tabs-mode . t)
57 1.1 wiz ;; set default tab width to 8
58 1.1 wiz (tab-width . 8)
59 1.1 wiz )
60 1.1 wiz "NetBSD KNF Style")
61 1.1 wiz
62 1.5 christos (eval-when-compile (require 'whitespace nil t))
63 1.5 christos
64 1.5 christos (defcustom netbsd-knf-whitespace-check nil
65 1.5 christos "Enable NetBSD KNF whitespace cleanup when saving the buffer.
66 1.5 christos See also:
67 1.5 christos `whitespace-auto-cleanup',
68 1.5 christos `whitespace-abort-on-error',
69 1.5 christos `whitespace-check-leading-whitespace',
70 1.5 christos `whitespace-check-trailing-whitespace',
71 1.5 christos `whitespace-check-spacetab-whitespace',
72 1.5 christos `whitespace-check-indent-whitespace',
73 1.5 christos `whitespace-check-ateol-whitespace'.
74 1.5 christos NOTES:
75 1.5 christos 1) `whitespace-check-spacetab-whitespace' will replace any RE-match of
76 1.5 christos \" +\\t\" with single '\\t' and hence may break tabbing.
77 1.5 christos 2) Both `whitespace-check-spacetab-whitespace' and
78 1.5 christos `whitespace-check-indent-whitespace' may alter strings."
79 1.5 christos :type 'boolean
80 1.5 christos :group 'netbsd-knf)
81 1.5 christos
82 1.5 christos (defun netbsd-knf-whitespace-cleanup ()
83 1.5 christos ;; XXX - emacs 21.4 whitespace.el was badly behaved on blank
84 1.5 christos ;; buffers. This was fixed in 22.1. I don't know about other
85 1.5 christos ;; versions, so these conditions may need to be more restrictive.
86 1.5 christos (cond ((> emacs-major-version 21)
87 1.5 christos (whitespace-cleanup-internal))
88 1.5 christos (t ;; default
89 1.5 christos (if (save-excursion
90 1.5 christos (goto-char (point-min))
91 1.5 christos (re-search-forward "[^ \t\n]" nil t))
92 1.5 christos (whitespace-cleanup)
93 1.5 christos (delete-region (point-min) (point-max))))))
94 1.5 christos
95 1.5 christos (defun netbsd-knf-write-contents-hook ()
96 1.2 christos (if (and (string-equal c-indentation-style "netbsd knf")
97 1.4 christos (require 'whitespace nil t))
98 1.5 christos (if netbsd-knf-whitespace-check
99 1.5 christos (if whitespace-auto-cleanup
100 1.5 christos (netbsd-knf-whitespace-cleanup)
101 1.5 christos (if (and (whitespace-buffer) whitespace-abort-on-error)
102 1.5 christos (error (concat "Abort write due to whitespaces in "
103 1.5 christos buffer-file-name)))))
104 1.5 christos (remove-hook 'write-contents-hook 'netbsd-knf-write-contents-hook))
105 1.5 christos nil)
106 1.2 christos
107 1.5 christos (defun netbsd-knf-c-mode-hook ()
108 1.1 wiz ;; Add style and set it for current buffer
109 1.1 wiz (c-add-style "NetBSD KNF" netbsd-knf-style t)
110 1.1 wiz ;; useful, but not necessary for the mode
111 1.1 wiz ;; give syntactic information in message buffer
112 1.1 wiz ;;(setq c-echo-syntactic-information-p t)
113 1.1 wiz ;; automatic newlines after special characters
114 1.1 wiz (setq c-toggle-auto-state 1)
115 1.1 wiz ;; delete all connected whitespace when pressing delete
116 1.1 wiz (setq c-toggle-hungry-state 1)
117 1.1 wiz ;; auto-indent new lines
118 1.1 wiz (define-key c-mode-base-map "\C-m" 'newline-and-indent)
119 1.5 christos ;; check/cleanup whitespace when saving
120 1.5 christos (add-hook 'write-contents-hooks 'netbsd-knf-write-contents-hook))
121 1.1 wiz
122 1.5 christos (add-hook 'c-mode-hook 'netbsd-knf-c-mode-hook)
123