[BACK]Return to NetBSD.el CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / share / misc

File: [cvs.NetBSD.org] / src / share / misc / NetBSD.el (download)

Revision 1.6, Mon Feb 16 21:37:12 2009 UTC (11 years, 8 months ago) by uwe
Branch: MAIN
CVS Tags: yamt-pagecache-tag8, yamt-pagecache-base9, yamt-pagecache-base8, yamt-pagecache-base7, yamt-pagecache-base6, yamt-pagecache-base5, yamt-pagecache-base4, yamt-pagecache-base3, yamt-pagecache-base2, yamt-pagecache-base, yamt-pagecache, tls-maxphys-base, tls-maxphys, tls-earlyentropy-base, tls-earlyentropy, riastradh-xf86-video-intel-2-7-1-pre-2-21-15, riastradh-drm2-base3, riastradh-drm2-base2, riastradh-drm2-base1, riastradh-drm2-base, riastradh-drm2, prg-localcount2-base3, prg-localcount2-base2, prg-localcount2-base1, prg-localcount2-base, prg-localcount2, phil-wifi-base, phil-wifi-20200421, phil-wifi-20200411, phil-wifi-20200406, phil-wifi-20191119, phil-wifi-20190609, phil-wifi, pgoyette-localcount-base, pgoyette-localcount-20170426, pgoyette-localcount-20170320, pgoyette-localcount-20170107, pgoyette-localcount-20161104, pgoyette-localcount-20160806, pgoyette-localcount-20160726, pgoyette-localcount, pgoyette-compat-merge-20190127, pgoyette-compat-base, pgoyette-compat-20190127, pgoyette-compat-20190118, pgoyette-compat-1226, pgoyette-compat-1126, pgoyette-compat-1020, pgoyette-compat-0930, pgoyette-compat-0906, pgoyette-compat-0728, pgoyette-compat-0625, pgoyette-compat-0521, pgoyette-compat-0502, pgoyette-compat-0422, pgoyette-compat-0415, pgoyette-compat-0407, pgoyette-compat-0330, pgoyette-compat-0322, pgoyette-compat-0315, pgoyette-compat, perseant-stdc-iso10646-base, perseant-stdc-iso10646, netbsd-9-base, netbsd-9-1-RELEASE, netbsd-9-0-RELEASE, netbsd-9-0-RC2, netbsd-9-0-RC1, netbsd-9, netbsd-8-base, netbsd-8-2-RELEASE, netbsd-8-1-RELEASE, netbsd-8-1-RC1, netbsd-8-0-RELEASE, netbsd-8-0-RC2, netbsd-8-0-RC1, netbsd-8, netbsd-7-nhusb-base-20170116, netbsd-7-nhusb-base, netbsd-7-nhusb, netbsd-7-base, netbsd-7-2-RELEASE, netbsd-7-1-RELEASE, netbsd-7-1-RC2, netbsd-7-1-RC1, netbsd-7-1-2-RELEASE, netbsd-7-1-1-RELEASE, netbsd-7-1, netbsd-7-0-RELEASE, netbsd-7-0-RC3, netbsd-7-0-RC2, netbsd-7-0-RC1, netbsd-7-0-2-RELEASE, netbsd-7-0-1-RELEASE, netbsd-7-0, netbsd-7, netbsd-6-base, netbsd-6-1-RELEASE, netbsd-6-1-RC4, netbsd-6-1-RC3, netbsd-6-1-RC2, netbsd-6-1-RC1, netbsd-6-1-5-RELEASE, netbsd-6-1-4-RELEASE, netbsd-6-1-3-RELEASE, netbsd-6-1-2-RELEASE, netbsd-6-1-1-RELEASE, netbsd-6-1, netbsd-6-0-RELEASE, netbsd-6-0-RC2, netbsd-6-0-RC1, netbsd-6-0-6-RELEASE, netbsd-6-0-5-RELEASE, netbsd-6-0-4-RELEASE, netbsd-6-0-3-RELEASE, netbsd-6-0-2-RELEASE, netbsd-6-0-1-RELEASE, netbsd-6-0, netbsd-6, matt-premerge-20091211, matt-nb8-mediatek-base, matt-nb8-mediatek, matt-nb6-plus-nbase, matt-nb6-plus-base, matt-nb6-plus, matt-mips64-premerge-20101231, localcount-20160914, jym-xensuspend-nbase, jym-xensuspend-base, is-mlppp-base, is-mlppp, cherry-xenmp-base, cherry-xenmp, bouyer-socketcan-base1, bouyer-socketcan-base, bouyer-socketcan, bouyer-quota2-nbase, bouyer-quota2-base, bouyer-quota2, agc-symver-base, agc-symver, HEAD
Changes since 1.5: +5 -3 lines

Add c-backslash-max-column - its default value of 72 is less than what
we set for c-backslash-column, so macros with lines longer than 72
would be formatted icorrectly.

Fix brace-list-entry - it doesn't need extra indentation.  Pointed out
by roy@.  While here use '+ instead of 8 to express "full indentation
step".

XXX: Do we really want brace-list-open indented one step?  It might
work for one-liners, but we have lots of longer init lists that are
formatted with brace-list-open of 0.

;; $NetBSD: NetBSD.el,v 1.6 2009/02/16 21:37:12 uwe Exp $

(defconst netbsd-knf-style
  '(
   ;; (c-auto-newline . nil)
   ;; default indentation level
   (c-basic-offset . 8)
   ;; in which column to add backslashes when macroizing a region
   (c-backslash-column . 78)
   (c-backslash-max-column . 78)
   ;; automatically compact brace-else(if)-brace on one line and
   ;; semi-colon after closing struct brace
   (c-cleanup-list . (brace-else-brace
		      brace-elseif-brace
		      defun-close-semi))
   ;; do not indent lines containing only start-of-comment more than default
   (c-comment-only-line-offset . 0)
   ;; start new lines after braces
   ;; default is: before and after (for all other cases)
   (c-hanging-braces-alist . ((defun-open . (before after))
			      (defun-close . (before after))
			      (block-open . (after))
			      (block-close . c-snug-do-while)
			      (substatement-open . after)
			      (statement-case-open . nil)
			      (brace-list-open . after)
			      (brace-list-close . nil)
			      ))
   ;; where to put newlines around colons
   (c-hanging-colons-alist . (quote ((label after)
				     (case-label after))))
   ;; indent comments syntactically
   (c-indent-comments-syntactically-p . t)
   ;; no spaces needed before a label
   ;; (c-label-minimum-indentation . 0)
   ;; define offsets for some code parts
   (c-offsets-alist . ((arglist-cont-nonempty . 4)
		       (block-open        . 0)
;;		       (block-open        . -)
		       (brace-list-open   . +)
		       (brace-list-intro  . +)
		       (brace-list-entry  . 0)
		       (brace-list-close  . 0)
		       (knr-argdecl       . 0)
		       (knr-argdecl-intro . +)
		       (label             . -)
		       (member-init-intro . ++)
		       (statement-cont    . 4)
		       (substatement-open . 0)
		       (case-label        . 0)))
   ;; XXX: undocumented. Recognize KNR style?
   (c-recognize-knr-p . t)
   ;; indent line when pressing tab, instead of a plain tab character
   (c-tab-always-indent . t)
   ;; use TABs for indentation, not spaces
   (indent-tabs-mode . t)
   ;; set default tab width to 8
   (tab-width . 8)
  )
  "NetBSD KNF Style")

(eval-when-compile (require 'whitespace nil t))

(defcustom netbsd-knf-whitespace-check nil
  "Enable NetBSD KNF whitespace cleanup when saving the buffer.
See also:
  `whitespace-auto-cleanup',
  `whitespace-abort-on-error',
  `whitespace-check-leading-whitespace',
  `whitespace-check-trailing-whitespace',
  `whitespace-check-spacetab-whitespace',
  `whitespace-check-indent-whitespace',
  `whitespace-check-ateol-whitespace'.
NOTES:
1) `whitespace-check-spacetab-whitespace' will replace any RE-match of
   \" +\\t\" with single '\\t' and hence may break tabbing.
2) Both `whitespace-check-spacetab-whitespace' and
   `whitespace-check-indent-whitespace' may alter strings."
  :type 'boolean
  :group 'netbsd-knf)

(defun netbsd-knf-whitespace-cleanup ()
  ;; XXX - emacs 21.4 whitespace.el was badly behaved on blank
  ;; buffers.  This was fixed in 22.1.  I don't know about other
  ;; versions, so these conditions may need to be more restrictive.
  (cond ((> emacs-major-version 21)
	 (whitespace-cleanup-internal))
	(t ;; default
	 (if (save-excursion
	       (goto-char (point-min))
	       (re-search-forward "[^ \t\n]" nil t))
	     (whitespace-cleanup)
	   (delete-region (point-min) (point-max))))))

(defun netbsd-knf-write-contents-hook ()
  (if (and (string-equal c-indentation-style "netbsd knf")
	   (require 'whitespace nil t))
      (if netbsd-knf-whitespace-check
	  (if whitespace-auto-cleanup
	      (netbsd-knf-whitespace-cleanup)
	    (if (and (whitespace-buffer) whitespace-abort-on-error)
		(error (concat "Abort write due to whitespaces in "
			       buffer-file-name)))))
    (remove-hook 'write-contents-hook 'netbsd-knf-write-contents-hook))
  nil)

(defun netbsd-knf-c-mode-hook ()
  ;; Add style and set it for current buffer
  (c-add-style "NetBSD KNF" netbsd-knf-style t)
  ;; useful, but not necessary for the mode
  ;; give syntactic information in message buffer
  ;;(setq c-echo-syntactic-information-p t)
  ;; automatic newlines after special characters
  (setq c-toggle-auto-state 1)
  ;; delete all connected whitespace when pressing delete
  (setq c-toggle-hungry-state 1)
  ;; auto-indent new lines
  (define-key c-mode-base-map "\C-m" 'newline-and-indent)
  ;; check/cleanup whitespace when saving
  (add-hook 'write-contents-hooks 'netbsd-knf-write-contents-hook))

(add-hook 'c-mode-hook 'netbsd-knf-c-mode-hook)