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