annotate lisp/cc-mode/cc-styles.el @ 165:5a88923fcbfe r20-3b9

Import from CVS: tag r20-3b9
author cvs
date Mon, 13 Aug 2007 09:44:42 +0200
parents
children 85ec50267440
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
1 ;;; cc-styles.el --- support for styles in CC Mode
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
2
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985,87,92,93,94,95,96,97 Free Software Foundation, Inc.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
4
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
5 ;; Authors: 1992-1997 Barry A. Warsaw
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
6 ;; 1987 Dave Detlefs and Stewart Clamen
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
7 ;; 1985 Richard M. Stallman
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
8 ;; Maintainer: cc-mode-help@python.org
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
9 ;; Created: 22-Apr-1997 (split from cc-mode.el)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
10 ;; Version: 5.11
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
11 ;; Keywords: c languages oop
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
12
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
13 ;; This file is part of GNU Emacs.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
14
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
15 ;; GNU Emacs is free software; you can redistribute it and/or modify
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
16 ;; it under the terms of the GNU General Public License as published by
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
17 ;; the Free Software Foundation; either version 2, or (at your option)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
18 ;; any later version.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
19
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
20 ;; GNU Emacs is distributed in the hope that it will be useful,
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
23 ;; GNU General Public License for more details.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
24
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
25 ;; You should have received a copy of the GNU General Public License
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
26 ;; along with GNU Emacs; see the file COPYING. If not, write to the
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
28 ;; Boston, MA 02111-1307, USA.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
29
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
30 (eval-when-compile
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
31 (load-file "./cc-align.el"))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
32
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
33
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
34 (defconst c-style-alist
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
35 '(("gnu"
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
36 (c-basic-offset . 2)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
37 (c-comment-only-line-offset . (0 . 0))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
38 (c-offsets-alist . ((statement-block-intro . +)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
39 (knr-argdecl-intro . 5)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
40 (substatement-open . +)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
41 (label . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
42 (statement-case-open . +)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
43 (statement-cont . +)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
44 (arglist-intro . c-lineup-arglist-intro-after-paren)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
45 (arglist-close . c-lineup-arglist)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
46 ))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
47 (c-special-indent-hook . c-gnu-impose-minimum)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
48 )
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
49 ("k&r"
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
50 (c-basic-offset . 5)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
51 (c-comment-only-line-offset . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
52 (c-offsets-alist . ((statement-block-intro . +)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
53 (knr-argdecl-intro . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
54 (substatement-open . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
55 (label . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
56 (statement-cont . +)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
57 ))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
58 )
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
59 ("bsd"
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
60 (c-basic-offset . 4)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
61 (c-comment-only-line-offset . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
62 (c-offsets-alist . ((statement-block-intro . +)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
63 (knr-argdecl-intro . +)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
64 (substatement-open . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
65 (label . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
66 (statement-cont . +)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
67 ))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
68 )
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
69 ("stroustrup"
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
70 (c-basic-offset . 4)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
71 (c-comment-only-line-offset . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
72 (c-offsets-alist . ((statement-block-intro . +)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
73 (substatement-open . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
74 (label . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
75 (statement-cont . +)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
76 ))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
77 )
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
78 ("whitesmith"
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
79 (c-basic-offset . 4)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
80 (c-comment-only-line-offset . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
81 (c-offsets-alist . ((statement-block-intro . +)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
82 (knr-argdecl-intro . +)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
83 (substatement-open . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
84 (label . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
85 (statement-cont . +)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
86 ))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
87
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
88 )
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
89 ("ellemtel"
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
90 (c-basic-offset . 3)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
91 (c-comment-only-line-offset . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
92 (c-hanging-braces-alist . ((substatement-open before after)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
93 (c-offsets-alist . ((topmost-intro . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
94 (topmost-intro-cont . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
95 (substatement . +)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
96 (substatement-open . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
97 (case-label . +)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
98 (access-label . -)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
99 (inclass . ++)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
100 (inline-open . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
101 ))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
102 )
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
103 ("linux"
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
104 (c-basic-offset . 8)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
105 (c-comment-only-line-offset . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
106 (c-hanging-braces-alist . ((brace-list-open)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
107 (substatement-open after)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
108 (block-close . c-snug-do-while)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
109 (c-cleanup-list . (brace-else-brace))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
110 (c-offsets-alist . ((statement-block-intro . +)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
111 (knr-argdecl-intro . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
112 (substatement-open . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
113 (label . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
114 (statement-cont . +)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
115 ))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
116 )
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
117 ("python"
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
118 (indent-tabs-mode . t)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
119 (fill-column . 72)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
120 (c-basic-offset . 8)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
121 (c-offsets-alist . ((substatement-open . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
122 ))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
123 (c-hanging-braces-alist . ((brace-list-open)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
124 (brace-list-intro)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
125 (brace-list-close)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
126 (substatement-open after)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
127 (block-close . c-snug-do-while)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
128 ))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
129 )
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
130 ("java"
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
131 (c-basic-offset . 2)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
132 (c-comment-only-line-offset . (0 . 0))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
133 (c-offsets-alist . ((topmost-intro-cont . +)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
134 (statement-block-intro . +)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
135 (knr-argdecl-intro . 5)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
136 (substatement-open . +)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
137 (label . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
138 (statement-case-open . +)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
139 (statement-cont . +)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
140 (arglist-intro . c-lineup-arglist-intro-after-paren)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
141 (arglist-close . c-lineup-arglist)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
142 (access-label . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
143 (inher-cont . c-lineup-java-inher)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
144 (func-decl-cont . c-lineup-java-throws)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
145 ))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
146
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
147 )
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
148 )
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
149 "Styles of indentation.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
150 Elements of this alist are of the form:
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
151
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
152 (STYLE-STRING [BASE-STYLE] (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
153
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
154 where STYLE-STRING is a short descriptive string used to select a
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
155 style, VARIABLE is any Emacs variable, and VALUE is the intended value
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
156 for that variable when using the selected style.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
157
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
158 Optional BASE-STYLE if present, is a string and must follow
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
159 STYLE-STRING. BASE-STYLE names a style that this style inherits from.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
160 By default, all styles inherit from the \"cc-mode\" style, which is
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
161 computed at run time. Style loops generate errors.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
162
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
163 Two variables are treated specially. When VARIABLE is
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
164 `c-offsets-alist', the VALUE is a list containing elements of the
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
165 form:
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
166
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
167 (SYNTACTIC-SYMBOL . OFFSET)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
168
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
169 as described in `c-offsets-alist'. These are passed directly to
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
170 `c-set-offset' so there is no need to set every syntactic symbol in
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
171 your style, only those that are different from the default.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
172
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
173 When VARIABLE is `c-special-indent-hook', its VALUE is added to
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
174 `c-special-indent-hook' using `add-hook'. If VALUE is a list, each
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
175 element of the list is added with `add-hook'.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
176
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
177 Do not change this variable directly. Use the function `c-add-style'
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
178 to add new styles or modify existing styles (it is not a good idea to
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
179 modify existing styles -- you should create a new style that inherits
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
180 the existing style.")
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
181
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
182
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
183 ;; Functions that manipulate styles
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
184 (defun c-set-style-1 (conscell)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
185 ;; Set the style for one variable
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
186 (let ((attr (car conscell))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
187 (val (cdr conscell)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
188 (cond
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
189 ;; first special variable
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
190 ((eq attr 'c-offsets-alist)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
191 (mapcar
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
192 (function
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
193 (lambda (langentry)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
194 (let ((langelem (car langentry))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
195 (offset (cdr langentry)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
196 (c-set-offset langelem offset)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
197 )))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
198 val))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
199 ;; second special variable
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
200 ((eq attr 'c-special-indent-hook)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
201 (if (listp val)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
202 (while val
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
203 (add-hook 'c-special-indent-hook (car val))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
204 (setq val (cdr val)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
205 (add-hook 'c-special-indent-hook val)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
206 ;; all other variables
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
207 (t (set attr val)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
208 ))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
209
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
210 (defun c-set-style-2 (style basestyles)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
211 ;; Recursively set the base style. If no base style is given, the
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
212 ;; default base style is "cc-mode" and the recursion stops. Be sure
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
213 ;; to detect loops.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
214 (if (not (string-equal style "cc-mode"))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
215 (let ((base (if (stringp (car basestyles))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
216 (downcase (car basestyles))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
217 "cc-mode")))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
218 (if (memq base basestyles)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
219 (error "Style loop detected: %s in %s" base basestyles))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
220 (c-set-style-2 base (cons base basestyles))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
221 (let ((vars (cdr (or (assoc (downcase style) c-style-alist)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
222 (assoc (upcase style) c-style-alist)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
223 (assoc style c-style-alist)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
224 (error "Undefined style: %s" style)))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
225 (mapcar 'c-set-style-1 vars)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
226
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
227 (defvar c-set-style-history nil)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
228
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
229 ;;;###autoload
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
230 (defun c-set-style (stylename)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
231 "Set CC Mode variables to use one of several different indentation styles.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
232 STYLENAME is a string representing the desired style from the list of
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
233 styles described in the variable `c-style-alist'. See that variable
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
234 for details of setting up styles.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
235
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
236 The variable `c-indentation-style' always contains the buffer's current
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
237 style name."
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
238 (interactive (list (let ((completion-ignore-case t)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
239 (prompt (format "Which %s indentation style? "
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
240 mode-name)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
241 (completing-read prompt c-style-alist nil t
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
242 (cons c-indentation-style 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
243 'c-set-style-history))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
244 (c-set-style-2 stylename nil)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
245 (setq c-indentation-style stylename)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
246 (c-keep-region-active))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
247
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
248 ;;;###autoload
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
249 (defun c-add-style (style descrip &optional set-p)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
250 "Adds a style to `c-style-alist', or updates an existing one.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
251 STYLE is a string identifying the style to add or update. DESCRIP is
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
252 an association list describing the style and must be of the form:
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
253
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
254 ([BASESTYLE] (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
255
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
256 See the variable `c-style-alist' for the semantics of BASESTYLE,
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
257 VARIABLE and VALUE. This function also sets the current style to
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
258 STYLE using `c-set-style' if the optional SET-P flag is non-nil."
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
259 (interactive
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
260 (let ((stylename (completing-read "Style to add: " c-style-alist
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
261 nil nil nil 'c-set-style-history))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
262 (description (eval-minibuffer "Style description: ")))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
263 (list stylename description
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
264 (y-or-n-p "Set the style too? "))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
265 (setq style (downcase style))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
266 (let ((s (assoc style c-style-alist)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
267 (if s
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
268 (setcdr s (copy-alist descrip)) ; replace
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
269 (setq c-style-alist (cons (cons style descrip) c-style-alist))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
270 (and set-p (c-set-style style)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
271
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
272
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
273
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
274 (defconst c-offsets-alist
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
275 '((string . -1000)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
276 (c . c-lineup-C-comments)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
277 (defun-open . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
278 (defun-close . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
279 (defun-block-intro . +)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
280 (class-open . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
281 (class-close . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
282 (inline-open . +)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
283 (inline-close . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
284 (func-decl-cont . +)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
285 (knr-argdecl-intro . +)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
286 (knr-argdecl . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
287 (topmost-intro . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
288 (topmost-intro-cont . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
289 (member-init-intro . +)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
290 (member-init-cont . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
291 (inher-intro . +)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
292 (inher-cont . c-lineup-multi-inher)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
293 (block-open . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
294 (block-close . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
295 (brace-list-open . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
296 (brace-list-close . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
297 (brace-list-intro . +)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
298 (brace-list-entry . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
299 (statement . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
300 ;; some people might prefer
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
301 ;;(statement . c-lineup-runin-statements)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
302 (statement-cont . +)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
303 ;; some people might prefer
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
304 ;;(statement-cont . c-lineup-math)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
305 (statement-block-intro . +)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
306 (statement-case-intro . +)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
307 (statement-case-open . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
308 (substatement . +)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
309 (substatement-open . +)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
310 (case-label . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
311 (access-label . -)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
312 (label . 2)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
313 (do-while-closure . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
314 (else-clause . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
315 (comment-intro . c-lineup-comment)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
316 (arglist-intro . +)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
317 (arglist-cont . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
318 (arglist-cont-nonempty . c-lineup-arglist)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
319 (arglist-close . +)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
320 (stream-op . c-lineup-streamop)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
321 (inclass . +)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
322 (cpp-macro . -1000)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
323 (friend . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
324 (objc-method-intro . -1000)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
325 (objc-method-args-cont . c-lineup-ObjC-method-args)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
326 (objc-method-call-cont . c-lineup-ObjC-method-call)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
327 (extern-lang-open . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
328 (extern-lang-close . 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
329 (inextern-lang . +)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
330 )
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
331 "Association list of syntactic element symbols and indentation offsets.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
332 As described below, each cons cell in this list has the form:
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
333
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
334 (SYNTACTIC-SYMBOL . OFFSET)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
335
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
336 When a line is indented, CC Mode first determines the syntactic
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
337 context of the line by generating a list of symbols called syntactic
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
338 elements. This list can contain more than one syntactic element and
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
339 the global variable `c-syntactic-context' contains the context list
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
340 for the line being indented. Each element in this list is actually a
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
341 cons cell of the syntactic symbol and a buffer position. This buffer
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
342 position is called the relative indent point for the line. Some
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
343 syntactic symbols may not have a relative indent point associated with
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
344 them.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
345
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
346 After the syntactic context list for a line is generated, CC Mode
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
347 calculates the absolute indentation for the line by looking at each
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
348 syntactic element in the list. First, it compares the syntactic
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
349 element against the SYNTACTIC-SYMBOL's in `c-offsets-alist'. When it
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
350 finds a match, it adds the OFFSET to the column of the relative indent
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
351 point. The sum of this calculation for each element in the syntactic
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
352 list is the absolute offset for line being indented.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
353
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
354 If the syntactic element does not match any in the `c-offsets-alist',
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
355 an error is generated if `c-strict-syntax-p' is non-nil, otherwise the
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
356 element is ignored.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
357
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
358 Actually, OFFSET can be an integer, a function, a variable, or one of
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
359 the following symbols: `+', `-', `++', `--', `*', or `/'. These
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
360 latter designate positive or negative multiples of `c-basic-offset',
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
361 respectively: 1, -1, 2, -2, 0.5, and -0.5. If OFFSET is a function, it
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
362 is called with a single argument containing the cons of the syntactic
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
363 element symbol and the relative indent point. The function should
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
364 return an integer offset.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
365
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
366 Here is the current list of valid syntactic element symbols:
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
367
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
368 string -- inside multi-line string
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
369 c -- inside a multi-line C style block comment
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
370 defun-open -- brace that opens a function definition
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
371 defun-close -- brace that closes a function definition
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
372 defun-block-intro -- the first line in a top-level defun
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
373 class-open -- brace that opens a class definition
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
374 class-close -- brace that closes a class definition
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
375 inline-open -- brace that opens an in-class inline method
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
376 inline-close -- brace that closes an in-class inline method
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
377 func-decl-cont -- the region between a function definition's
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
378 argument list and the function opening brace
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
379 (excluding K&R argument declarations). In C, you
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
380 cannot put anything but whitespace and comments
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
381 between them; in C++ and Java, throws declarations
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
382 and other things can appear in this context.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
383 knr-argdecl-intro -- first line of a K&R C argument declaration
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
384 knr-argdecl -- subsequent lines in a K&R C argument declaration
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
385 topmost-intro -- the first line in a topmost construct definition
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
386 topmost-intro-cont -- topmost definition continuation lines
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
387 member-init-intro -- first line in a member initialization list
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
388 member-init-cont -- subsequent member initialization list lines
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
389 inher-intro -- first line of a multiple inheritance list
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
390 inher-cont -- subsequent multiple inheritance lines
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
391 block-open -- statement block open brace
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
392 block-close -- statement block close brace
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
393 brace-list-open -- open brace of an enum or static array list
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
394 brace-list-close -- close brace of an enum or static array list
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
395 brace-list-intro -- first line in an enum or static array list
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
396 brace-list-entry -- subsequent lines in an enum or static array list
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
397 statement -- a C (or like) statement
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
398 statement-cont -- a continuation of a C (or like) statement
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
399 statement-block-intro -- the first line in a new statement block
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
400 statement-case-intro -- the first line in a case \"block\"
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
401 statement-case-open -- the first line in a case block starting with brace
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
402 substatement -- the first line after an if/while/for/do/else
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
403 substatement-open -- the brace that opens a substatement block
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
404 case-label -- a `case' or `default' label
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
405 access-label -- C++ private/protected/public access label
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
406 label -- any ordinary label
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
407 do-while-closure -- the `while' that ends a do/while construct
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
408 else-clause -- the `else' of an if/else construct
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
409 comment-intro -- a line containing only a comment introduction
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
410 arglist-intro -- the first line in an argument list
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
411 arglist-cont -- subsequent argument list lines when no
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
412 arguments follow on the same line as the
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
413 arglist opening paren
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
414 arglist-cont-nonempty -- subsequent argument list lines when at
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
415 least one argument follows on the same
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
416 line as the arglist opening paren
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
417 arglist-close -- the solo close paren of an argument list
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
418 stream-op -- lines continuing a stream operator construct
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
419 inclass -- the construct is nested inside a class definition
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
420 cpp-macro -- the start of a cpp macro
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
421 friend -- a C++ friend declaration
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
422 objc-method-intro -- the first line of an Objective-C method definition
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
423 objc-method-args-cont -- lines continuing an Objective-C method definition
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
424 objc-method-call-cont -- lines continuing an Objective-C method call
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
425 extern-lang-open -- brace that opens an external language block
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
426 extern-lang-close -- brace that closes an external language block
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
427 inextern-lang -- analogous to `inclass' syntactic symbol
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
428 ")
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
429
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
430 (defun c-get-offset (langelem)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
431 ;; Get offset from LANGELEM which is a cons cell of the form:
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
432 ;; (SYMBOL . RELPOS). The symbol is matched against
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
433 ;; c-offsets-alist and the offset found there is either returned,
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
434 ;; or added to the indentation at RELPOS. If RELPOS is nil, then
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
435 ;; the offset is simply returned.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
436 (let* ((symbol (car langelem))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
437 (relpos (cdr langelem))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
438 (match (assq symbol c-offsets-alist))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
439 (offset (cdr-safe match)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
440 ;; offset can be a number, a function, a variable, or one of the
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
441 ;; symbols + or -
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
442 (cond
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
443 ((not match)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
444 (if c-strict-syntax-p
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
445 (error "don't know how to indent a %s" symbol)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
446 (setq offset 0
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
447 relpos 0)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
448 ((eq offset '+) (setq offset c-basic-offset))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
449 ((eq offset '-) (setq offset (- c-basic-offset)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
450 ((eq offset '++) (setq offset (* 2 c-basic-offset)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
451 ((eq offset '--) (setq offset (* 2 (- c-basic-offset))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
452 ((eq offset '*) (setq offset (/ c-basic-offset 2)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
453 ((eq offset '/) (setq offset (/ (- c-basic-offset) 2)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
454 ((functionp offset) (setq offset (funcall offset langelem)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
455 ((not (numberp offset)) (setq offset (symbol-value offset)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
456 )
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
457 (+ (if (and relpos
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
458 (< relpos (c-point 'bol)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
459 (save-excursion
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
460 (goto-char relpos)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
461 (current-column))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
462 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
463 offset)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
464
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
465
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
466 (defvar c-read-offset-history nil)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
467
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
468 (defun c-read-offset (langelem)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
469 ;; read new offset value for LANGELEM from minibuffer. return a
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
470 ;; legal value only
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
471 (let* ((oldoff (cdr-safe (assq langelem c-offsets-alist)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
472 (defstr (format "(default %s): " oldoff))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
473 (errmsg (concat "Offset must be int, func, var, "
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
474 "or in [+,-,++,--,*,/] "
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
475 defstr))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
476 (prompt (concat "Offset " defstr))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
477 offset input interned raw)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
478 (while (not offset)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
479 (setq input (completing-read prompt obarray 'fboundp nil nil
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
480 'c-read-offset-history)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
481 offset (cond ((string-equal "" input) oldoff) ; default
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
482 ((string-equal "+" input) '+)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
483 ((string-equal "-" input) '-)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
484 ((string-equal "++" input) '++)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
485 ((string-equal "--" input) '--)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
486 ((string-equal "*" input) '*)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
487 ((string-equal "/" input) '/)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
488 ((string-match "^-?[0-9]+$" input)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
489 (string-to-int input))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
490 ;; a symbol with a function binding
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
491 ((fboundp (setq interned (intern input)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
492 interned)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
493 ;; a lambda function
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
494 ((c-safe (functionp (setq raw (read input))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
495 raw)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
496 ;; a symbol with variable binding
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
497 ((boundp interned) interned)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
498 ;; error, but don't signal one, keep trying
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
499 ;; to read an input value
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
500 (t (ding)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
501 (setq prompt errmsg)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
502 nil))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
503 offset))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
504
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
505 (defun c-set-offset (symbol offset &optional add-p)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
506 "Change the value of a syntactic element symbol in `c-offsets-alist'.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
507 SYMBOL is the syntactic element symbol to change and OFFSET is the new
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
508 offset for that syntactic element. Optional ADD says to add SYMBOL to
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
509 `c-offsets-alist' if it doesn't already appear there."
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
510 (interactive
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
511 (let* ((langelem
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
512 (intern (completing-read
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
513 (concat "Syntactic symbol to change"
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
514 (if current-prefix-arg " or add" "")
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
515 ": ")
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
516 (mapcar
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
517 #'(lambda (langelem)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
518 (cons (format "%s" (car langelem)) nil))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
519 c-offsets-alist)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
520 nil (not current-prefix-arg)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
521 ;; initial contents tries to be the last element
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
522 ;; on the syntactic analysis list for the current
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
523 ;; line
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
524 (let* ((syntax (c-guess-basic-syntax))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
525 (len (length syntax))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
526 (ic (format "%s" (car (nth (1- len) syntax)))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
527 (cons ic 0))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
528 )))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
529 (offset (c-read-offset langelem)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
530 (list langelem offset current-prefix-arg)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
531 ;; sanity check offset
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
532 (or (eq offset '+)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
533 (eq offset '-)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
534 (eq offset '++)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
535 (eq offset '--)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
536 (eq offset '*)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
537 (eq offset '/)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
538 (integerp offset)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
539 (functionp offset)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
540 (boundp offset)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
541 (error "Offset must be int, func, var, or in [+,-,++,--,*,/]: %s"
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
542 offset))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
543 (let ((entry (assq symbol c-offsets-alist)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
544 (if entry
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
545 (setcdr entry offset)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
546 (if add-p
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
547 (setq c-offsets-alist (cons (cons symbol offset) c-offsets-alist))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
548 (error "%s is not a valid syntactic symbol." symbol))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
549 (c-keep-region-active))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
550
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
551
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
552
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
553 ;; Dynamically append the default value of most variables. This is
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
554 ;; crucial because future c-set-style calls will always reset the
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
555 ;; variables first to the `cc-mode' style before instituting the new
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
556 ;; style. Only do this once!
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
557 (or (assoc "cc-mode" c-style-alist)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
558 (progn
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
559 (c-add-style "cc-mode"
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
560 (mapcar
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
561 (function
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
562 (lambda (var)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
563 (let ((val (symbol-value var)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
564 (cons var (if (atom val) val
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
565 (copy-tree val)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
566 ))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
567 )))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
568 '(c-backslash-column
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
569 c-basic-offset
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
570 c-cleanup-list
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
571 c-comment-only-line-offset
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
572 c-electric-pound-behavior
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
573 c-hanging-braces-alist
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
574 c-hanging-colons-alist
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
575 c-hanging-comment-starter-p
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
576 c-hanging-comment-ender-p
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
577 c-offsets-alist
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
578 )))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
579 ;; the default style is now GNU. This can be overridden in
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
580 ;; c-mode-common-hook or {c,c++,objc,java}-mode-hook.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
581 (c-set-style c-site-default-style)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
582
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
583 (defun c-make-styles-buffer-local ()
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
584 "Make all CC Mode style variables buffer local.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
585 If you edit primarily one style of C (or C++, Objective-C, Java) code,
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
586 you probably want style variables to be global. This is the default.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
587
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
588 If you edit many different styles of C (or C++, Objective-C, Java) at
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
589 the same time, you probably want the CC Mode style variables to be
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
590 buffer local. If you do, then you will need to set any CC Mode style
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
591 variables in a hook function (e.g. off of c-mode-common-hook), instead
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
592 of at the top level of your ~/.emacs file.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
593
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
594 This function makes all the CC Mode style variables buffer local.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
595 Call it after CC Mode is loaded into your Emacs environment.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
596 Conversely, set the variable `c-style-variables-are-local-p' to t in
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
597 your .emacs file, before CC Mode is loaded, and this function will be
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
598 automatically called when CC Mode is loaded."
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
599 ;; style variables
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
600 (make-variable-buffer-local 'c-offsets-alist)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
601 (make-variable-buffer-local 'c-basic-offset)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
602 (make-variable-buffer-local 'c-file-style)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
603 (make-variable-buffer-local 'c-file-offsets)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
604 (make-variable-buffer-local 'c-comment-only-line-offset)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
605 (make-variable-buffer-local 'c-cleanup-list)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
606 (make-variable-buffer-local 'c-hanging-braces-alist)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
607 (make-variable-buffer-local 'c-hanging-colons-alist)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
608 (make-variable-buffer-local 'c-hanging-comment-starter-p)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
609 (make-variable-buffer-local 'c-hanging-comment-ender-p)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
610 (make-variable-buffer-local 'c-backslash-column)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
611 (make-variable-buffer-local 'c-label-minimum-indentation)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
612 (make-variable-buffer-local 'c-special-indent-hook)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
613 (make-variable-buffer-local 'c-indentation-style))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
614
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
615 (if c-style-variables-are-local-p
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
616 (c-make-styles-buffer-local))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
617
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
618
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
619
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
620 (provide 'cc-styles)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
621 ;;; cc-styles.el ends here