annotate lisp/progmodes/cc-styles.el @ 21433:25b02305130b

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