Subject: Re: emacs and knf
To: Andrew Brown <atatat@atatdot.net>
From: Hauke Fath <hauke@Espresso.Rhein-Neckar.DE>
List: current-users
Date: 09/12/2000 22:33:38
At 16:11 Uhr +0200 12.9.2000, Andrew Brown wrote:
>i know someone must have done this before...
>
>does anyone out there have a emacs mode set up for editing c files
>more or less according to /usr/share/misc/style?

The following snippet from lib/xemacs/site-lisp/site-start.el works for me
(in the sense that diffing indented against original knf sources gave no
output):

--- snip -------------------------------------------------------------------
;; Verify against /usr/share/misc/style !

(defconst netbsd-knf-style
  '((c-auto-newline . nil)
    (c-tab-always-indent . nil)
    (c-recognize-knr-p . t)
    (c-basic-offset . 8)
    (c-comment-only-line-offset . 0)
    (c-cleanup-list . (brace-else-brace
		       empty-defun-braces
		       defun-close-semi
		       list-close-comma
		       scope-operator))
    (c-hanging-braces-alist . ((defun-open . (before after))
			       (defun-close . (before))
			       (class-open . (after))
			       (class-close . nil)
			       (inline-open . nil)
			       (inline-close . nil)
			       (block-open . (after))
			       (block-close . (before))
			       (substatement-open . nil)
			       (statement-case-open . nil)
			       (brace-list-open . nil)
			       (brace-list-close . nil)
			       (brace-list-intro . nil)
			       (brace-list-entry . nil)
			       ))
    (c-offsets-alist . ((knr-argdecl-intro . +)
			(arglist-cont-nonempty . 4)
			(knr-argdecl . 0)
			(block-open . -)
			(label . -)
			(statement-cont . 4)
			)))
  "NetBSD KNF Style")

(defun knf-c-mode-hook ()
  ;; Add style and set it for current buffer
  (c-add-style "NetBSD KNF" netbsd-knf-style t)
  ;; Offset customizations that are not in this style (??)
  (c-set-offset 'member-init-intro '++)
  ;; Other stuff
  (setq tab-width 8
	indent-tabs-mode t)
  (c-toggle-auto-hungry-state 1)
  ;;  (define-key c-mode-map "\C-m" 'newline-and-indent)
)

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

Don't ask me about details, it's been a while since I last looked at the
c-mode docs.  ;)

	hauke

--
"It's never straight up and down"     (DEVO)