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