1;;; This function switches C-mode so that it indents almost everything 2;;; as specified in FreeBSD's style(9). Tested with emacs-19.34 and 3;;; xemacs-20.4. 4;;; 5;;; Use "M-x bsd" in a C mode buffer to activate it. 6;;; 7;;; The only problem I found is top-level indenting: 8;;; 9;;; We want function definitions with the function name at the beginning 10;;; of a second line after the return type specification in the first: 11;;; > int 12;;; > foo(int bla) 13;;; But emacs c-mode can't treat this differently from other multiple-line 14;;; toplevel constructs: 15;;; > const char *const bar = 16;;; > "sometext"; 17;;; which means the second line must be indented by hand. 18;;; 19;;; To make this the default, use a line like this, but you can't easily 20;;; switch back to default GNU style, since the old state isn't saved. 21;;; (add-hook 'c-mode-common-hook 'bsd) 22;;; As long as you don't have this in the c-mode hook you can edit GNU 23;;; and BSD style C sources within one emacs session with no problem. 24;;; 25;;; Please report problems and additions directly to cracauer@freebsd.org 26 27(defun bsd () (interactive) 28 (c-set-style "bsd") 29 (setq indent-tabs-mode t) 30 ;; Use C-c C-s at points of source code so see which 31 ;; c-set-offset is in effect for this situation 32 (c-set-offset 'defun-block-intro 8) 33 (c-set-offset 'statement-block-intro 8) 34 (c-set-offset 'statement-case-intro 8) 35 (c-set-offset 'substatement-open 4) 36 (c-set-offset 'substatement 8) 37 (c-set-offset 'arglist-cont-nonempty 4) 38 (c-set-offset 'inclass 8) 39 (c-set-offset 'knr-argdecl-intro 8) 40 ) 41