From: Sascha Wildner Date: Sat, 3 Jan 2009 22:38:55 +0000 (+0100) Subject: Add a nice little C mode for Emacs. X-Git-Tag: v2.3.0~122 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/174c0cc7548488822ef97b377e22c4079347cf2e Add a nice little C mode for Emacs. Taken-from: FreeBSD (posted by DES to cvs-all some time ago) --- diff --git a/tools/tools/editing/dragonfly.el b/tools/tools/editing/dragonfly.el new file mode 100644 index 0000000000..12a3dbfc4d --- /dev/null +++ b/tools/tools/editing/dragonfly.el @@ -0,0 +1,34 @@ +;;; This function switches C-mode so that it indents stuff according to +;;; our style(9) which is equivalent to FreeBSD's. Tested with emacs-22.3. +;;; +;;; Use "M-x bsd" in a C mode buffer to activate it. +;;; +;;; To make this the default, use a line like this, but you can't easily +;;; switch back to default GNU style, since the old state isn't saved. +;;; +;;; (add-hook 'c-mode-common-hook 'bsd) +;;; +;;; As long as you don't have this in the c-mode hook you can edit GNU +;;; and BSD style C sources within one emacs session with no problem. +;;; +;;; Posted to FreeBSD's cvs-all by DES (<867ifoaulz.fsf@ds4.des.no>). + +(defun bsd () + (interactive) + (c-set-style "bsd") + + ;; Basic indent is 8 spaces + (setq c-basic-offset 8) + (setq tab-width 8) + + ;; Continuation lines are indented 4 spaces + (c-set-offset 'arglist-cont 4) + (c-set-offset 'arglist-cont-nonempty 4) + (c-set-offset 'statement-cont 4) + (c-set-offset 'cpp-macro-cont 8) + + ;; Labels are flush to the left + (c-set-offset 'label [0]) + + ;; Fill column + (setq fill-column 74)) diff --git a/tools/tools/editing/freebsd.el b/tools/tools/editing/freebsd.el deleted file mode 100644 index 63976b0d6b..0000000000 --- a/tools/tools/editing/freebsd.el +++ /dev/null @@ -1,40 +0,0 @@ -;;; This function switches C-mode so that it indents almost everything -;;; as specified in FreeBSD's style(9). Tested with emacs-19.34 and -;;; xemacs-20.4. -;;; -;;; Use "M-x bsd" in a C mode buffer to activate it. -;;; -;;; The only problem I found is top-level indenting: -;;; -;;; We want function definitions with the function name at the beginning -;;; of a second line after the return type specification in the first: -;;; > int -;;; > foo(int bla) -;;; But emacs c-mode can't treat this differently from other multiple-line -;;; toplevel constructs: -;;; > const char *const bar = -;;; > "sometext"; -;;; which means the second line must be indented by hand. -;;; -;;; To make this the default, use a line like this, but you can't easily -;;; switch back to default GNU style, since the old state isn't saved. -;;; (add-hook 'c-mode-common-hook 'bsd) -;;; As long as you don't have this in the c-mode hook you can edit GNU -;;; and BSD style C sources within one emacs session with no problem. -;;; -;;; Please report problems and additions directly to cracauer@freebsd.org - -(defun bsd () (interactive) - (c-set-style "bsd") - (setq indent-tabs-mode t) - ;; Use C-c C-s at points of source code so see which - ;; c-set-offset is in effect for this situation - (c-set-offset 'defun-block-intro 8) - (c-set-offset 'statement-block-intro 8) - (c-set-offset 'statement-case-intro 8) - (c-set-offset 'substatement-open 4) - (c-set-offset 'substatement 8) - (c-set-offset 'arglist-cont-nonempty 4) - (c-set-offset 'inclass 8) - (c-set-offset 'knr-argdecl-intro 8) - )