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