Home | History | Annotate | Line # | Download | only in misc
NetBSD.el revision 1.3
      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 ;; NOTE: whitespace-cleanup has the following control knobs.  By
     59 ;; default these are all true.
     60 ;(setq whitespace-check-leading-whitespace nil)
     61 ;(setq whitespace-check-trailing-whitespace nil)
     62 ;(setq whitespace-check-spacetab-whitespace nil)
     63 ;(setq whitespace-check-indent-whitespace nil)
     64 ;(setq whitespace-check-ateol-whitespace nil)
     65 
     66 ;; XXX - whitespace.el is badly behaved on blank buffers, so we handle
     67 ;; those buffers ourselves.
     68 (defun knf-nonblank-buffer-p ()
     69   (if (whitespace-buffer-search "[^ \t\n]")
     70       t
     71     (progn
     72       (delete-region (point-min) (point-max))
     73       nil)))
     74 
     75 (defun knf-write-contents-hook ()
     76   (if (and (string-equal c-indentation-style "netbsd knf")
     77 	   (require 'whitespace nil t)
     78 	   (knf-nonblank-buffer-p))
     79       (whitespace-cleanup))
     80   nil	;; XXX - make sure we return nil or the file will not be written.
     81 )
     82 
     83 (defun knf-c-mode-hook ()
     84   ;; Add style and set it for current buffer
     85   (c-add-style "NetBSD KNF" netbsd-knf-style t)
     86   ;; useful, but not necessary for the mode
     87   ;; give syntactic information in message buffer
     88   ;;(setq c-echo-syntactic-information-p t)
     89   ;; automatic newlines after special characters
     90   (setq c-toggle-auto-state 1)
     91   ;; delete all connected whitespace when pressing delete
     92   (setq c-toggle-hungry-state 1)
     93   ;; auto-indent new lines
     94   (define-key c-mode-base-map "\C-m" 'newline-and-indent)
     95   ;; cleanup whitespace when saving
     96   (add-hook 'write-contents-hooks 'knf-write-contents-hook)
     97 )
     98 
     99 (add-hook 'c-mode-hook 'knf-c-mode-hook)
    100