1 ;; c-style.el --- sets c-style control variables.
2 ;; Copyright (C) 1992-1993 Free Software Foundation, Inc.
4 ;; This file is part of XEmacs.
6 ;; XEmacs is free software; you can redistribute it and/or modify it
7 ;; under the terms of the GNU General Public License as published by
8 ;; the Free Software Foundation; either version 2, or (at your option)
11 ;; XEmacs is distributed in the hope that it will be useful, but
12 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ;; General Public License for more details.
16 ;; You should have received a copy of the GNU General Public License
17 ;; along with XEmacs; see the file COPYING. If not, write to the
18 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 ;; Boston, MA 02111-1307, USA.
22 ;; c-style|Daniel LaLiberte|liberte@cs.uiuc.edu
23 ;; |sets c-style control variables
24 ;; |Thu Feb 27 13:42:57 CST 1992|Version: 2.1|~/as-is/c-src-doc.el.Z
26 ;;; Synched up with: Not in FSF.
28 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
30 ;;; There are several ways to call set-c-style described below.
31 ;;; None of these methods reindent your program - they only affect
34 ;;; - Just call set-c-style in your c-mode-hook.
35 ;;; Without style argument, default-c-style will be used.
36 ;;; With style argument, this will set the style for every
37 ;;; c-mode buffer the same.
39 ;;; - Call set-c-style from the Local Variables list.
40 ;;; e.g. "eval:(set-c-style 'C++)"
42 ;;; - Call set-c-style interactively. It prompts for the style name
43 ;;; with completion using default-c-style.
45 ;;; For convenience, put one of the following in your .emacs:
46 ;;; (autoload 'set-c-style "c-style" nil t)
47 ;;; or (load "c-style")
48 ;;; =====================================================
50 (defvar default-c-style 'GNU
51 "*The default value of c-style. Set this in your .emacs.")
53 ;; The following predefined styles are all I know about.
54 ;; If you learn of another style that has a "big" following, please
55 ;; send me the parameters.
60 (c-continued-statement-offset 2)
67 (c-continued-statement-offset 8)
74 (c-continued-statement-offset 5)
81 (c-continued-statement-offset 4)
89 (c-continued-statement-offset 4)
97 (c-continued-statement-offset 8)
98 (c-continued-brace-offset -8)
100 (c-brace-imaginary-offset 0)
104 (c-tab-always-indent t))
106 ;; From Jozsef A Toth <jtoth+@pitt.edu>
107 ;; Is this really the Whitesmith style?
110 (c-brace-imaginary-offset 2) ;;; ????
112 (c-continued-statement-offset 2)
122 (c-continued-statement-offset 4)
126 (c-brace-imaginary-offset 0))
128 ;; From Joan Eslinger <wombat@kilimanjaro.key.amdahl.com>
131 (c-continued-statement-offset 4)
135 (c-brace-imaginary-offset 4)
136 (c-continued-brace-offset -4))
140 "The buffer local c-mode indentation style.")
142 ;; Add style name to mode line. Assumes minor-mode-alist is not buffer local.
143 ;; Thanks to Joan Eslinger.
145 (defvar c-style-name nil
146 "The style name for a c-mode indentation style.
147 This is to be set by set-c-style, and used by the mode line.")
149 (or (assq 'c-style-name minor-mode-alist)
150 (setq minor-mode-alist
152 (append minor-mode-alist
153 ;; use undocumented feature
154 '((c-style-name c-style-name))))))
156 (defun set-c-style (&optional style)
157 "Set up the c-mode style variables from STYLE if it is given, or
158 default-c-style otherwise. It makes the c indentation style variables
163 (let ((c-styles (mapcar 'car c-style-alist))) ; for completion
166 (let ((style-string ; Get style name with completion.
168 (format "Set c-mode indentation style to (default %s): "
171 (function (lambda (arg) (memq arg c-styles)))
173 (if (string-equal "" style-string)
175 (intern style-string))
178 ;; If style is nil, use default-c-style.
179 (setq style (or style default-c-style))
181 (make-local-variable 'c-style)
182 (if (memq style c-styles)
184 (error "Undefined c style: %s" style)
186 (message "c-style: %s" c-style)
188 ;; Set the c-style-name
189 (make-local-variable 'c-style-name)
190 (setq c-style-name (format " %s" c-style))
192 ;; Finally, set the indentation style variables making each one local.
193 (mapcar (function (lambda (c-style-pair)
194 (make-local-variable (car c-style-pair))
195 (set (car c-style-pair)
196 (car (cdr c-style-pair)))))
197 (cdr (assq c-style c-style-alist)))