2
|
1 ;;; cc-mode.el --- major mode for editing C, C++, Objective-C, and Java code
|
0
|
2
|
|
3 ;; Copyright (C) 1985, 87, 92, 93, 94, 95, 96 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Authors: 1992-1996 Barry A. Warsaw
|
|
6 ;; 1987 Dave Detlefs and Stewart Clamen
|
|
7 ;; 1985 Richard M. Stallman
|
|
8 ;; Created: a long, long, time ago. adapted from the original c-mode.el
|
2
|
9 ;; Version: 4.315
|
|
10 ;; Last Modified: 1996/08/20 21:08:13
|
0
|
11 ;; Keywords: c languages oop
|
|
12
|
|
13 ;; NOTE: Read the commentary below for the right way to submit bug reports!
|
|
14 ;; NOTE: See the accompanying texinfo manual for details on using this mode!
|
|
15
|
|
16 ;; This file is part of GNU Emacs.
|
|
17
|
|
18 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
19 ;; it under the terms of the GNU General Public License as published by
|
|
20 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
21 ;; any later version.
|
|
22
|
|
23 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
24 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
25 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
26 ;; GNU General Public License for more details.
|
|
27
|
|
28 ;; You should have received a copy of the GNU General Public License
|
|
29 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
30 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
31 ;; Boston, MA 02111-1307, USA.
|
|
32
|
|
33 ;;; Commentary:
|
|
34
|
|
35 ;; This package provides modes in GNU Emacs for editing C, C++,
|
|
36 ;; Objective-C, and Java code. It is intended to be a replacement for
|
|
37 ;; c-mode.el (a.k.a. BOCM -- Boring Old C-Mode), and c++-mode.el
|
|
38 ;; (a.k.a cplus-md.el and cplus-md1.el), both of which are ancestors
|
|
39 ;; of this file. A number of important improvements have been made,
|
|
40 ;; briefly: complete K&R C, ANSI C, `ARM' C++, Objective-C, and Java
|
|
41 ;; support with consistent indentation across all modes, more
|
|
42 ;; intuitive indentation controlling variables, compatibility across
|
|
43 ;; all known Emacsen, nice new features, and tons of bug fixes. This
|
|
44 ;; package is called "cc-mode" to distinguish it from its ancestors,
|
|
45 ;; but there really is no top-level cc-mode. Usage and programming
|
|
46 ;; details are contained in an accompanying texinfo manual.
|
|
47
|
2
|
48 ;; NOTE: This mode does not perform font-locking (a.k.a syntactic
|
|
49 ;; coloring, keyword highlighting, etc.). Typically this is done by a
|
|
50 ;; package called font-lock.el which I do *not* maintain. You should
|
|
51 ;; contact the Emacs maintainer for questions about coloring or
|
|
52 ;; highlighting in any language mode.
|
|
53
|
0
|
54 ;; To submit bug reports, type "C-c C-b". These will be sent to
|
2
|
55 ;; bug-gnu-emacs@prep.ai.mit.edu as well as cc-mode-help@python.org,
|
|
56 ;; and I'll read about them there (the former is mirrored as the
|
|
57 ;; Usenet newsgroup gnu.emacs.bug). Questions can sent to
|
|
58 ;; help-gnu-emacs@prep.ai.mit.edu (mirrored as gnu.emacs.help) or
|
|
59 ;; cc-mode-help@python.org. Please do not send bugs or questions to
|
|
60 ;; my personal account.
|
0
|
61
|
|
62 ;; YOU CAN IGNORE ALL BYTE-COMPILER WARNINGS. They are the result of
|
|
63 ;; the multi-Emacsen support. Emacs 19 (from the FSF), XEmacs 19
|
|
64 ;; (formerly Lucid Emacs), and GNU Emacs 18 all do things differently
|
|
65 ;; and there's no way to shut the byte-compiler up at the necessary
|
|
66 ;; granularity. Let me say this again: YOU CAN IGNORE ALL
|
|
67 ;; BYTE-COMPILER WARNINGS (you'd be surprised at how many people don't
|
|
68 ;; follow this advice :-).
|
|
69
|
|
70 ;; If your Emacs is dumped with c-mode.el and/or c++-mode.el, you will
|
|
71 ;; need to add the following to your .emacs file before any other
|
|
72 ;; reference to c-mode or c++-mode:
|
|
73 ;;
|
|
74 ;; (fmakunbound 'c-mode)
|
|
75 ;; (makunbound 'c-mode-map)
|
|
76 ;; (fmakunbound 'c++-mode)
|
|
77 ;; (makunbound 'c++-mode-map)
|
|
78 ;; (makunbound 'c-style-alist)
|
|
79
|
2
|
80 ;; If your Emacs comes with cc-mode already (and as of 5-Jul-1996
|
|
81 ;; XEmacs 19.14 and Emacs 19.31 both do), you only need to add the
|
0
|
82 ;; following to use the latest version of cc-mode:
|
|
83 ;;
|
|
84 ;; (load "cc-mode")
|
|
85 ;;
|
|
86 ;; Make sure the new version is earlier on your load-path.
|
|
87
|
|
88 ;; There are four major mode entry points provided by this package,
|
|
89 ;; one for editing C++ code, one for editing C code (both K&R and
|
|
90 ;; ANSI), one for editing Objective-C code, and one for editing Java
|
|
91 ;; code. The commands are M-x c-mode, M-x c++-mode, M-x objc-mode,
|
|
92 ;; and M-x java-mode.
|
|
93
|
|
94 ;; If you are using an old version of Emacs which does not come
|
|
95 ;; with cc-mode.el, you will need to do these things
|
|
96 ;; to use it:
|
|
97 ;;
|
|
98 ;; (autoload 'c++-mode "cc-mode" "C++ Editing Mode" t)
|
|
99 ;; (autoload 'c-mode "cc-mode" "C Editing Mode" t)
|
|
100 ;; (autoload 'objc-mode "cc-mode" "Objective-C Editing Mode" t)
|
|
101 ;; (autoload 'java-mode "cc-mode" "Java Editing Mode" t)
|
|
102 ;; (setq auto-mode-alist
|
|
103 ;; (append '(("\\.C$" . c++-mode)
|
|
104 ;; ("\\.cc$" . c++-mode)
|
|
105 ;; ("\\.c$" . c-mode)
|
|
106 ;; ("\\.h$" . c-mode)
|
|
107 ;; ("\\.m$" . objc-mode)
|
|
108 ;; ("\\.java$" . java-mode)
|
|
109 ;; ) auto-mode-alist))
|
|
110 ;;
|
|
111 ;; You do not need these changes in Emacs versions that come with cc-mode.
|
|
112
|
|
113 ;; Many, many thanks go out to all the folks on the beta test list.
|
|
114 ;; Without their patience, testing, insight, code contributions, and
|
|
115 ;; encouragement cc-mode.el would be a far inferior package.
|
|
116
|
2
|
117 ;; You can get the latest version of cc-mode, including PostScript
|
|
118 ;; documentation and separate individual files from:
|
0
|
119 ;;
|
2
|
120 ;; http://www.python.org/ftp/emacs/
|
|
121
|
|
122 ;; Or if you don't have access to the World Wide Web, through
|
|
123 ;; anonymous ftp from:
|
|
124 ;;
|
|
125 ;; ftp://ftp.python.org/pub/emacs
|
0
|
126
|
|
127 ;;; Code:
|
|
128
|
|
129
|
|
130 ;; user definable variables
|
|
131 ;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
|
|
132
|
|
133 (defvar c-inhibit-startup-warnings-p nil
|
|
134 "*If non-nil, inhibits start up compatibility warnings.")
|
|
135 (defvar c-strict-syntax-p nil
|
|
136 "*If non-nil, all syntactic symbols must be found in `c-offsets-alist'.
|
|
137 If the syntactic symbol for a particular line does not match a symbol
|
|
138 in the offsets alist, an error is generated, otherwise no error is
|
|
139 reported and the syntactic symbol is ignored.")
|
|
140 (defvar c-echo-syntactic-information-p nil
|
|
141 "*If non-nil, syntactic info is echoed when the line is indented.")
|
|
142 (defvar c-basic-offset 4
|
|
143 "*Amount of basic offset used by + and - symbols in `c-offsets-alist'.")
|
|
144
|
|
145 (defvar c-offsets-alist
|
|
146 '((string . -1000)
|
|
147 (c . c-lineup-C-comments)
|
|
148 (defun-open . 0)
|
|
149 (defun-close . 0)
|
|
150 (defun-block-intro . +)
|
|
151 (class-open . 0)
|
|
152 (class-close . 0)
|
|
153 (inline-open . +)
|
|
154 (inline-close . 0)
|
|
155 (ansi-funcdecl-cont . +)
|
|
156 (knr-argdecl-intro . +)
|
|
157 (knr-argdecl . 0)
|
|
158 (topmost-intro . 0)
|
|
159 (topmost-intro-cont . 0)
|
|
160 (member-init-intro . +)
|
|
161 (member-init-cont . 0)
|
|
162 (inher-intro . +)
|
|
163 (inher-cont . c-lineup-multi-inher)
|
|
164 (block-open . 0)
|
|
165 (block-close . 0)
|
|
166 (brace-list-open . 0)
|
|
167 (brace-list-close . 0)
|
|
168 (brace-list-intro . +)
|
|
169 (brace-list-entry . 0)
|
|
170 (statement . 0)
|
|
171 ;; some people might prefer
|
|
172 ;;(statement . c-lineup-runin-statements)
|
|
173 (statement-cont . +)
|
|
174 ;; some people might prefer
|
|
175 ;;(statement-cont . c-lineup-math)
|
|
176 (statement-block-intro . +)
|
|
177 (statement-case-intro . +)
|
|
178 (statement-case-open . 0)
|
|
179 (substatement . +)
|
|
180 (substatement-open . +)
|
|
181 (case-label . 0)
|
|
182 (access-label . -)
|
|
183 (label . 2)
|
|
184 (do-while-closure . 0)
|
|
185 (else-clause . 0)
|
|
186 (comment-intro . c-lineup-comment)
|
|
187 (arglist-intro . +)
|
|
188 (arglist-cont . 0)
|
|
189 (arglist-cont-nonempty . c-lineup-arglist)
|
|
190 (arglist-close . +)
|
|
191 (stream-op . c-lineup-streamop)
|
|
192 (inclass . +)
|
|
193 (cpp-macro . -1000)
|
|
194 (friend . 0)
|
|
195 (objc-method-intro . -1000)
|
|
196 (objc-method-args-cont . c-lineup-ObjC-method-args)
|
|
197 (objc-method-call-cont . c-lineup-ObjC-method-call)
|
2
|
198 (extern-lang-open . 0)
|
|
199 (extern-lang-close . 0)
|
|
200 (inextern-lang . +)
|
0
|
201 )
|
|
202 "*Association list of syntactic element symbols and indentation offsets.
|
|
203 As described below, each cons cell in this list has the form:
|
|
204
|
|
205 (SYNTACTIC-SYMBOL . OFFSET)
|
|
206
|
|
207 When a line is indented, cc-mode first determines the syntactic
|
|
208 context of the line by generating a list of symbols called syntactic
|
|
209 elements. This list can contain more than one syntactic element and
|
|
210 the global variable `c-syntactic-context' contains the context list
|
|
211 for the line being indented. Each element in this list is actually a
|
|
212 cons cell of the syntactic symbol and a buffer position. This buffer
|
|
213 position is called the relative indent point for the line. Some
|
|
214 syntactic symbols may not have a relative indent point associated with
|
|
215 them.
|
|
216
|
|
217 After the syntactic context list for a line is generated, cc-mode
|
|
218 calculates the absolute indentation for the line by looking at each
|
|
219 syntactic element in the list. First, it compares the syntactic
|
|
220 element against the SYNTACTIC-SYMBOL's in `c-offsets-alist'. When it
|
|
221 finds a match, it adds the OFFSET to the column of the relative indent
|
|
222 point. The sum of this calculation for each element in the syntactic
|
|
223 list is the absolute offset for line being indented.
|
|
224
|
|
225 If the syntactic element does not match any in the `c-offsets-alist',
|
|
226 an error is generated if `c-strict-syntax-p' is non-nil, otherwise
|
|
227 the element is ignored.
|
|
228
|
|
229 Actually, OFFSET can be an integer, a function, a variable, or one of
|
|
230 the following symbols: `+', `-', `++', `--', `*', or `/'. These
|
|
231 latter designate positive or negative multiples of `c-basic-offset',
|
|
232 respectively: *1, *-1, *2, *-2, *0.5, and *-0.5. If OFFSET is a
|
|
233 function, it is called with a single argument containing the cons of
|
|
234 the syntactic element symbol and the relative indent point. The
|
|
235 function should return an integer offset.
|
|
236
|
|
237 Here is the current list of valid syntactic element symbols:
|
|
238
|
|
239 string -- inside multi-line string
|
|
240 c -- inside a multi-line C style block comment
|
|
241 defun-open -- brace that opens a function definition
|
|
242 defun-close -- brace that closes a function definition
|
|
243 defun-block-intro -- the first line in a top-level defun
|
|
244 class-open -- brace that opens a class definition
|
|
245 class-close -- brace that closes a class definition
|
|
246 inline-open -- brace that opens an in-class inline method
|
|
247 inline-close -- brace that closes an in-class inline method
|
|
248 ansi-funcdecl-cont -- the nether region between an ANSI function
|
|
249 declaration and the defun opening brace
|
|
250 knr-argdecl-intro -- first line of a K&R C argument declaration
|
|
251 knr-argdecl -- subsequent lines in a K&R C argument declaration
|
|
252 topmost-intro -- the first line in a topmost construct definition
|
|
253 topmost-intro-cont -- topmost definition continuation lines
|
|
254 member-init-intro -- first line in a member initialization list
|
|
255 member-init-cont -- subsequent member initialization list lines
|
|
256 inher-intro -- first line of a multiple inheritance list
|
|
257 inher-cont -- subsequent multiple inheritance lines
|
|
258 block-open -- statement block open brace
|
|
259 block-close -- statement block close brace
|
|
260 brace-list-open -- open brace of an enum or static array list
|
|
261 brace-list-close -- close brace of an enum or static array list
|
|
262 brace-list-intro -- first line in an enum or static array list
|
|
263 brace-list-entry -- subsequent lines in an enum or static array list
|
2
|
264 statement -- a C (or like) statement
|
|
265 statement-cont -- a continuation of a C (or like) statement
|
0
|
266 statement-block-intro -- the first line in a new statement block
|
|
267 statement-case-intro -- the first line in a case `block'
|
|
268 statement-case-open -- the first line in a case block starting with brace
|
|
269 substatement -- the first line after an if/while/for/do/else
|
|
270 substatement-open -- the brace that opens a substatement block
|
|
271 case-label -- a case or default label
|
|
272 access-label -- C++ private/protected/public access label
|
2
|
273 label -- any non-special C (or like) label
|
0
|
274 do-while-closure -- the `while' that ends a do/while construct
|
|
275 else-clause -- the `else' of an if/else construct
|
|
276 comment-intro -- a line containing only a comment introduction
|
|
277 arglist-intro -- the first line in an argument list
|
|
278 arglist-cont -- subsequent argument list lines when no
|
|
279 arguments follow on the same line as the
|
2
|
280 arglist opening paren
|
0
|
281 arglist-cont-nonempty -- subsequent argument list lines when at
|
|
282 least one argument follows on the same
|
|
283 line as the arglist opening paren
|
|
284 arglist-close -- the solo close paren of an argument list
|
|
285 stream-op -- lines continuing a stream operator construct
|
|
286 inclass -- the construct is nested inside a class definition
|
|
287 cpp-macro -- the start of a cpp macro
|
|
288 friend -- a C++ friend declaration
|
|
289 objc-method-intro -- the first line of an Objective-C method definition
|
|
290 objc-method-args-cont -- lines continuing an Objective-C method definition
|
|
291 objc-method-call-cont -- lines continuing an Objective-C method call
|
2
|
292 extern-lang-open -- brace that opens an external language block
|
|
293 extern-lang-close -- brace that closes an external language block
|
|
294 inextern-lang -- analogous to `inclass' syntactic symbol
|
0
|
295 ")
|
|
296
|
|
297 (defvar c-tab-always-indent t
|
|
298 "*Controls the operation of the TAB key.
|
|
299 If t, hitting TAB always just indents the current line. If nil,
|
|
300 hitting TAB indents the current line if point is at the left margin or
|
2
|
301 in the line's indentation, otherwise it insert a `real' tab character
|
|
302 \(see note\). If other than nil or t, then tab is inserted only within
|
|
303 literals -- defined as comments and strings -- and inside preprocessor
|
0
|
304 directives, but line is always reindented.
|
|
305
|
2
|
306 Note: The value of `indent-tabs-mode' will determine whether a real
|
|
307 tab character will be inserted, or the equivalent number of space.
|
|
308 When inserting a tab, actually the function stored in the variable
|
|
309 `c-insert-tab-function' is called.
|
|
310
|
|
311 Note: indentation of lines containing only comments is also controlled
|
|
312 by the `c-comment-only-line-offset' variable.")
|
|
313
|
|
314 (defvar c-insert-tab-function 'insert-tab
|
|
315 "*Function used when inserting a tab for \\[TAB].
|
|
316 Only used when `c-tab-always-indent' indicates a `real' tab character
|
|
317 should be inserted. Value must be a function taking no arguments.")
|
0
|
318
|
|
319 (defvar c-comment-only-line-offset 0
|
|
320 "*Extra offset for line which contains only the start of a comment.
|
|
321 Can contain an integer or a cons cell of the form:
|
|
322
|
|
323 (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)
|
|
324
|
|
325 Where NON-ANCHORED-OFFSET is the amount of offset given to
|
|
326 non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
|
|
327 the amount of offset to give column-zero anchored comment-only lines.
|
|
328 Just an integer as value is equivalent to (<val> . -1000).")
|
|
329
|
|
330 (defvar c-indent-comments-syntactically-p nil
|
|
331 "*Specifies how comment-only lines should be indented.
|
|
332 When this variable is non-nil, comment-only lines are indented
|
|
333 according to syntactic analysis via `c-offsets-alist', even when
|
|
334 \\[indent-for-comment] is used.")
|
|
335
|
|
336 (defvar c-block-comments-indent-p nil
|
|
337 "*Specifies how to re-indent C style block comments.
|
|
338
|
|
339 Examples of the supported styles of C block comment indentation are
|
|
340 shown below. When this variable is nil, block comments are indented
|
|
341 as shown in styles 1 through 4. If this variable is non-nil, block
|
|
342 comments are indented as shown in style 5.
|
|
343
|
|
344 Note that cc-mode does not automatically insert any stars or block
|
|
345 comment delimiters. You must type these in manually. This variable
|
|
346 only controls how the lines within the block comment are indented when
|
|
347 you hit ``\\[c-indent-command]''.
|
|
348
|
|
349 style 1: style 2 (GNU): style 3: style 4: style 5:
|
|
350 /* /* Blah /* /* /*
|
|
351 blah blah. */ * blah ** blah blah
|
|
352 blah * blah ** blah blah
|
|
353 */ */ */ */")
|
|
354
|
|
355 (defvar c-cleanup-list '(scope-operator)
|
|
356 "*List of various C/C++/ObjC constructs to \"clean up\".
|
|
357 These clean ups only take place when the auto-newline feature is turned
|
|
358 on, as evidenced by the `/a' or `/ah' appearing next to the mode name.
|
|
359 Valid symbols are:
|
|
360
|
|
361 brace-else-brace -- cleans up `} else {' constructs by placing entire
|
|
362 construct on a single line. This clean up only
|
|
363 takes place when there is nothing but white
|
|
364 space between the braces and the `else'. Clean
|
|
365 up occurs when the open-brace after the `else'
|
|
366 is typed.
|
|
367 empty-defun-braces -- cleans up empty defun braces by placing the
|
|
368 braces on the same line. Clean up occurs when
|
|
369 the defun closing brace is typed.
|
|
370 defun-close-semi -- cleans up the terminating semi-colon on defuns
|
|
371 by placing the semi-colon on the same line as
|
|
372 the closing brace. Clean up occurs when the
|
|
373 semi-colon is typed.
|
|
374 list-close-comma -- cleans up commas following braces in array
|
|
375 and aggregate initializers. Clean up occurs
|
|
376 when the comma is typed.
|
|
377 scope-operator -- cleans up double colons which may designate
|
|
378 a C++ scope operator split across multiple
|
|
379 lines. Note that certain C++ constructs can
|
|
380 generate ambiguous situations. This clean up
|
|
381 only takes place when there is nothing but
|
|
382 whitespace between colons. Clean up occurs
|
|
383 when the second colon is typed.")
|
|
384
|
|
385 (defvar c-hanging-braces-alist '((brace-list-open)
|
|
386 (substatement-open after)
|
2
|
387 (block-close . c-snug-do-while)
|
|
388 (extern-lang-open after)
|
|
389 )
|
0
|
390 "*Controls the insertion of newlines before and after braces.
|
|
391 This variable contains an association list with elements of the
|
|
392 following form: (SYNTACTIC-SYMBOL . ACTION).
|
|
393
|
|
394 When a brace (either opening or closing) is inserted, the syntactic
|
|
395 context it defines is looked up in this list, and if found, the
|
|
396 associated ACTION is used to determine where newlines are inserted.
|
|
397 If the context is not found, the default is to insert a newline both
|
|
398 before and after the brace.
|
|
399
|
|
400 SYNTACTIC-SYMBOL can be any of: defun-open, defun-close, class-open,
|
|
401 class-close, inline-open, inline-close, block-open, block-close,
|
2
|
402 substatement-open, statement-case-open, extern-lang-open,
|
|
403 extern-lang-close, brace-list-open, brace-list-close,
|
|
404 brace-list-intro, or brace-list-entry. See `c-offsets-alist' for
|
|
405 details.
|
0
|
406
|
|
407 ACTION can be either a function symbol or a list containing any
|
|
408 combination of the symbols `before' or `after'. If the list is empty,
|
|
409 no newlines are inserted either before or after the brace.
|
|
410
|
|
411 When ACTION is a function symbol, the function is called with a two
|
|
412 arguments: the syntactic symbol for the brace and the buffer position
|
|
413 at which the brace was inserted. The function must return a list as
|
|
414 described in the preceding paragraph. Note that during the call to
|
|
415 the function, the variable `c-syntactic-context' is set to the entire
|
|
416 syntactic context for the brace line.")
|
|
417
|
|
418 (defvar c-hanging-colons-alist nil
|
|
419 "*Controls the insertion of newlines before and after certain colons.
|
|
420 This variable contains an association list with elements of the
|
|
421 following form: (SYNTACTIC-SYMBOL . ACTION).
|
|
422
|
|
423 See the variable `c-hanging-braces-alist' for the semantics of this
|
|
424 variable. Note however that making ACTION a function symbol is
|
|
425 currently not supported for this variable.")
|
|
426
|
|
427 (defvar c-hanging-semi&comma-criteria '(c-semi&comma-inside-parenlist)
|
|
428 "*List of functions that decide whether to insert a newline or not.
|
|
429 The functions in this list are called, in order, whenever the
|
|
430 auto-newline minor mode is activated (as evidenced by a `/a' or `/ah'
|
|
431 string in the mode line), and a semicolon or comma is typed (see
|
|
432 `c-electric-semi&comma'). Each function in this list is called with
|
|
433 no arguments, and should return one of the following values:
|
|
434
|
|
435 nil -- no determination made, continue checking
|
|
436 'stop -- do not insert a newline, and stop checking
|
|
437 (anything else) -- insert a newline, and stop checking
|
|
438
|
|
439 If every function in the list is called with no determination made,
|
|
440 then no newline is inserted.")
|
|
441
|
|
442 (defvar c-hanging-comment-ender-p t
|
|
443 "*If nil, `c-fill-paragraph' leaves C block comment enders on their own line.
|
|
444 Default value is t, which inhibits leaving block comment ending string
|
|
445 `*/' on a line by itself. This is BOCM's sole behavior.")
|
|
446
|
|
447 (defvar c-backslash-column 48
|
|
448 "*Column to insert backslashes when macroizing a region.")
|
|
449 (defvar c-special-indent-hook nil
|
|
450 "*Hook for user defined special indentation adjustments.
|
|
451 This hook gets called after a line is indented by the mode.")
|
|
452 (defvar c-delete-function 'backward-delete-char-untabify
|
|
453 "*Function called by `c-electric-delete' when deleting characters.")
|
|
454 (defvar c-electric-pound-behavior nil
|
|
455 "*List of behaviors for electric pound insertion.
|
|
456 Only currently supported behavior is `alignleft'.")
|
2
|
457 (defvar c-label-minimum-indentation 1
|
|
458 "*Minimum indentation for labels and case tags in `gnu' style.")
|
0
|
459
|
|
460 (defvar c-progress-interval 5
|
|
461 "*Interval used to update progress status during long re-indentation.
|
|
462 If a number, percentage complete gets updated after each interval of
|
|
463 that many seconds. Set to nil to inhibit updating. This is only
|
|
464 useful for Emacs 19.")
|
|
465
|
2
|
466 (defconst c-style-alist
|
0
|
467 '(("gnu"
|
|
468 (c-basic-offset . 2)
|
|
469 (c-comment-only-line-offset . (0 . 0))
|
|
470 (c-offsets-alist . ((statement-block-intro . +)
|
|
471 (knr-argdecl-intro . 5)
|
|
472 (substatement-open . +)
|
|
473 (label . 0)
|
|
474 (statement-case-open . +)
|
|
475 (statement-cont . +)
|
|
476 (arglist-intro . c-lineup-arglist-intro-after-paren)
|
|
477 (arglist-close . c-lineup-arglist)
|
|
478 ))
|
2
|
479 (c-special-indent-hook . c-gnu-impose-minimum)
|
0
|
480 )
|
|
481 ("k&r"
|
|
482 (c-basic-offset . 5)
|
|
483 (c-comment-only-line-offset . 0)
|
|
484 (c-offsets-alist . ((statement-block-intro . +)
|
|
485 (knr-argdecl-intro . 0)
|
|
486 (substatement-open . 0)
|
|
487 (label . 0)
|
|
488 (statement-cont . +)
|
|
489 ))
|
|
490 )
|
|
491 ("bsd"
|
|
492 (c-basic-offset . 4)
|
|
493 (c-comment-only-line-offset . 0)
|
|
494 (c-offsets-alist . ((statement-block-intro . +)
|
|
495 (knr-argdecl-intro . +)
|
|
496 (substatement-open . 0)
|
|
497 (label . 0)
|
|
498 (statement-cont . +)
|
|
499 ))
|
|
500 )
|
|
501 ("stroustrup"
|
|
502 (c-basic-offset . 4)
|
|
503 (c-comment-only-line-offset . 0)
|
|
504 (c-offsets-alist . ((statement-block-intro . +)
|
|
505 (substatement-open . 0)
|
|
506 (label . 0)
|
|
507 (statement-cont . +)
|
|
508 ))
|
|
509 )
|
|
510 ("whitesmith"
|
|
511 (c-basic-offset . 4)
|
|
512 (c-comment-only-line-offset . 0)
|
|
513 (c-offsets-alist . ((statement-block-intro . +)
|
|
514 (knr-argdecl-intro . +)
|
|
515 (substatement-open . 0)
|
|
516 (label . 0)
|
|
517 (statement-cont . +)
|
|
518 ))
|
|
519
|
|
520 )
|
|
521 ("ellemtel"
|
|
522 (c-basic-offset . 3)
|
|
523 (c-comment-only-line-offset . 0)
|
|
524 (c-hanging-braces-alist . ((substatement-open before after)))
|
|
525 (c-offsets-alist . ((topmost-intro . 0)
|
|
526 (topmost-intro-cont . 0)
|
|
527 (substatement . 3)
|
|
528 (substatement-open . 0)
|
|
529 (statement-case-intro . 0)
|
|
530 (case-label . +)
|
|
531 (access-label . -3)
|
|
532 (inclass . 6)
|
|
533 (inline-open . 0)
|
|
534 ))
|
|
535 )
|
|
536 ("java"
|
|
537 (c-basic-offset . 2)
|
|
538 (c-comment-only-line-offset . (0 . 0))
|
|
539 (c-offsets-alist . ((statement-block-intro . +)
|
|
540 (knr-argdecl-intro . 5)
|
|
541 (substatement-open . +)
|
|
542 (label . 0)
|
|
543 (statement-case-open . +)
|
|
544 (statement-cont . +)
|
|
545 (arglist-intro . c-lineup-arglist-intro-after-paren)
|
|
546 (arglist-close . c-lineup-arglist)
|
|
547 (access-label . 0)
|
|
548 ))
|
|
549
|
|
550 )
|
|
551 )
|
|
552 "Styles of Indentation.
|
|
553 Elements of this alist are of the form:
|
|
554
|
|
555 (STYLE-STRING (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
|
|
556
|
|
557 where STYLE-STRING is a short descriptive string used to select a
|
|
558 style, VARIABLE is any cc-mode variable, and VALUE is the intended
|
|
559 value for that variable when using the selected style.
|
|
560
|
|
561 There is one special case when VARIABLE is `c-offsets-alist'. In this
|
|
562 case, the VALUE is a list containing elements of the form:
|
|
563
|
|
564 (SYNTACTIC-SYMBOL . VALUE)
|
|
565
|
|
566 as described in `c-offsets-alist'. These are passed directly to
|
|
567 `c-set-offset' so there is no need to set every syntactic symbol in
|
|
568 your style, only those that are different from the default.
|
|
569
|
|
570 Note that all styles inherit from the `cc-mode' style, which is
|
|
571 computed at the time the mode is loaded.")
|
|
572
|
|
573 (defvar c-file-style nil
|
|
574 "*Variable interface for setting style via File Local Variables.
|
|
575 In a file's Local Variable section, you can set this variable to a
|
|
576 string suitable for `c-set-style'. When the file is visited, cc-mode
|
|
577 will set the style of the file to this value automatically.
|
|
578
|
|
579 Note that file style settings are applied before file offset settings
|
|
580 as designated in the variable `c-file-offsets'.")
|
|
581
|
|
582 (defvar c-file-offsets nil
|
|
583 "*Variable interface for setting offsets via File Local Variables.
|
|
584 In a file's Local Variable section, you can set this variable to an
|
|
585 association list similar to the values allowed in `c-offsets-alist'.
|
|
586 When the file is visited, cc-mode will institute these offset settings
|
|
587 automatically.
|
|
588
|
|
589 Note that file offset settings are applied after file style settings
|
|
590 as designated in the variable `c-file-style'.")
|
|
591
|
|
592 (defvar c-site-default-style "gnu"
|
|
593 "Default style for your site.
|
|
594 To change the default style at your site, you can set this variable to
|
|
595 any style defined in `c-style-alist'. However, if cc-mode is usually
|
|
596 loaded into your Emacs at compile time, you will need to set this
|
|
597 variable in the `site-init.el' file before cc-mode is loaded, then
|
|
598 re-dump Emacs.")
|
|
599
|
|
600 (defvar c-mode-hook nil
|
|
601 "*Hook called by `c-mode'.")
|
|
602 (defvar c++-mode-hook nil
|
|
603 "*Hook called by `c++-mode'.")
|
|
604 (defvar objc-mode-hook nil
|
|
605 "*Hook called by `objc-mode'.")
|
|
606 (defvar java-mode-hook nil
|
|
607 "*Hook called by `java-mode'.")
|
|
608
|
|
609 (defvar c-mode-common-hook nil
|
2
|
610 "*Hook called by all cc-mode modes for common initializations.")
|
0
|
611
|
|
612 (defvar c-mode-menu
|
|
613 '(["Comment Out Region" comment-region (mark)]
|
|
614 ["Macro Expand Region" c-macro-expand (mark)]
|
|
615 ["Backslashify" c-backslash-region (mark)]
|
|
616 ["Indent Expression" c-indent-exp
|
|
617 (memq (following-char) '(?\( ?\[ ?\{))]
|
|
618 ["Indent Line" c-indent-command t]
|
|
619 ["Fill Comment Paragraph" c-fill-paragraph t]
|
|
620 ["Up Conditional" c-up-conditional t]
|
|
621 ["Backward Conditional" c-backward-conditional t]
|
|
622 ["Forward Conditional" c-forward-conditional t]
|
|
623 ["Backward Statement" c-beginning-of-statement t]
|
|
624 ["Forward Statement" c-end-of-statement t]
|
|
625 )
|
|
626 "XEmacs 19 menu for C/C++/ObjC modes.")
|
|
627
|
|
628 ;; Sadly we need this for a macro in Emacs 19.
|
|
629 (eval-when-compile
|
|
630 ;; Imenu isn't used in XEmacs, so just ignore load errors.
|
|
631 (condition-case ()
|
|
632 (require 'imenu)
|
|
633 (error nil)))
|
|
634
|
|
635 (defvar cc-imenu-c++-generic-expression
|
|
636 (`
|
|
637 ((nil
|
|
638 (,
|
|
639 (concat
|
|
640 "^" ; beginning of line is required
|
|
641 "\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there may be a "template <...>"
|
|
642 "\\([a-zA-Z0-9_:]+[ \t]+\\)?" ; type specs; there can be no
|
|
643 "\\([a-zA-Z0-9_:]+[ \t]+\\)?" ; more than 3 tokens, right?
|
|
644
|
|
645 "\\(" ; last type spec including */&
|
|
646 "[a-zA-Z0-9_:]+"
|
|
647 "\\([ \t]*[*&]+[ \t]*\\|[ \t]+\\)" ; either pointer/ref sign or whitespace
|
|
648 "\\)?" ; if there is a last type spec
|
|
649 "\\(" ; name; take that into the imenu entry
|
|
650 "[a-zA-Z0-9_:~]+" ; member function, ctor or dtor...
|
|
651 ; (may not contain * because then
|
|
652 ; "a::operator char*" would become "char*"!)
|
|
653 "\\|"
|
|
654 "\\([a-zA-Z0-9_:~]*::\\)?operator"
|
|
655 "[^a-zA-Z1-9_][^(]*" ; ...or operator
|
|
656 " \\)"
|
|
657 "[ \t]*([^)]*)[ \t\n]*[^ ;]" ; require something other than a ; after
|
|
658 ; the (...) to avoid prototypes. Can't
|
|
659 ; catch cases with () inside the parentheses
|
|
660 ; surrounding the parameters
|
|
661 ; (like "int foo(int a=bar()) {...}"
|
|
662
|
|
663 )) 6)
|
|
664 ("Class"
|
|
665 (, (concat
|
|
666 "^" ; beginning of line is required
|
|
667 "\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there may be a "template <...>"
|
|
668 "class[ \t]+"
|
|
669 "\\([a-zA-Z0-9_]+\\)" ; this is the string we want to get
|
|
670 "[ \t]*[:{]"
|
|
671 )) 2)))
|
|
672 "Imenu generic expression for C++ mode. See `imenu-generic-expression'.")
|
|
673
|
|
674 (defvar cc-imenu-c-generic-expression
|
|
675 cc-imenu-c++-generic-expression
|
|
676 "Imenu generic expression for C mode. See `imenu-generic-expression'.")
|
|
677
|
|
678
|
|
679 ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
680 ;; NO USER DEFINABLE VARIABLES BEYOND THIS POINT
|
|
681
|
|
682 ;; Shut the byte-compiler up. Requires Emacs 19 or JWZ's improved
|
|
683 ;; byte-compiler. Otherwise, comment this line out and ignore
|
|
684 ;; any warnings.
|
|
685 ;;(byte-compiler-options (warnings nil))
|
|
686
|
|
687 ;; figure out what features this Emacs has
|
|
688 (defconst c-emacs-features
|
|
689 (let ((major (and (boundp 'emacs-major-version)
|
|
690 emacs-major-version))
|
|
691 (minor (and (boundp 'emacs-minor-version)
|
|
692 emacs-minor-version))
|
|
693 (re-suite 'old-re)
|
|
694 flavor comments)
|
|
695 ;; figure out version numbers if not already discovered
|
|
696 (and (or (not major) (not minor))
|
|
697 (string-match "\\([0-9]+\\).\\([0-9]+\\)" emacs-version)
|
|
698 (setq major (string-to-int (substring emacs-version
|
|
699 (match-beginning 1)
|
|
700 (match-end 1)))
|
|
701 minor (string-to-int (substring emacs-version
|
|
702 (match-beginning 2)
|
|
703 (match-end 2)))))
|
|
704 (if (not (and major minor))
|
|
705 (error "Cannot figure out the major and minor version numbers."))
|
|
706 ;; calculate the major version
|
|
707 (cond
|
|
708 ((= major 18) (setq major 'v18)) ;Emacs 18
|
|
709 ((= major 4) (setq major 'v18)) ;Epoch 4
|
|
710 ((= major 19) (setq major 'v19 ;Emacs 19
|
|
711 flavor (if (or (string-match "Lucid" emacs-version)
|
|
712 (string-match "XEmacs" emacs-version))
|
|
713 'XEmacs 'FSF)))
|
2
|
714 ((= major 20) (setq major 'v20 ;XEmacs 20
|
|
715 flavor 'XEmacs))
|
0
|
716 ;; I don't know
|
|
717 (t (error "Cannot recognize major version number: %s" major)))
|
|
718 ;; Regular expression suites...
|
2
|
719 (if (or (eq major 'v20)
|
|
720 (and (eq major 'v19)
|
|
721 (or (and (eq flavor 'XEmacs) (>= minor 14))
|
|
722 (and (eq flavor 'FSF) (>= minor 30)))))
|
0
|
723 (setq re-suite 'new-re))
|
|
724 ;; XEmacs 19 uses 8-bit modify-syntax-entry flags, as do all
|
|
725 ;; patched Emacs 19, Emacs 18, Epoch 4's. Only Emacs 19 uses a
|
|
726 ;; 1-bit flag. Let's be as smart as we can about figuring this
|
|
727 ;; out.
|
2
|
728 (if (or (eq major 'v20) (eq major 'v19))
|
0
|
729 (let ((table (copy-syntax-table)))
|
|
730 (modify-syntax-entry ?a ". 12345678" table)
|
|
731 (cond
|
|
732 ;; XEmacs pre 20 and Emacs pre 19.30 use vectors for syntax tables.
|
|
733 ((vectorp table)
|
|
734 (if (= (logand (lsh (aref table ?a) -16) 255) 255)
|
|
735 (setq comments '8-bit)
|
|
736 (setq comments '1-bit)))
|
|
737 ;; XEmacs 20 is known to be 8-bit
|
|
738 ((eq flavor 'XEmacs) (setq comments '8-bit))
|
|
739 ;; Emacs 19.30 and beyond are known to be 1-bit
|
|
740 ((eq flavor 'FSF) (setq comments '1-bit))
|
|
741 ;; Don't know what this is
|
|
742 (t (error "Couldn't figure out syntax table format."))
|
|
743 ))
|
|
744 ;; Emacs 18 has no support for dual comments
|
|
745 (setq comments 'no-dual-comments))
|
|
746 ;; lets do some minimal sanity checking.
|
|
747 (if (and (or
|
|
748 ;; Lucid Emacs before 19.6 had bugs
|
|
749 (and (eq major 'v19) (eq flavor 'XEmacs) (< minor 6))
|
|
750 ;; Emacs 19 before 19.21 has known bugs
|
|
751 (and (eq major 'v19) (eq flavor 'FSF) (< minor 21)))
|
|
752 (not c-inhibit-startup-warnings-p))
|
|
753 (with-output-to-temp-buffer "*cc-mode warnings*"
|
|
754 (print (format
|
|
755 "The version of Emacs that you are running, %s,
|
|
756 has known bugs in its syntax.c parsing routines which will affect the
|
|
757 performance of cc-mode. You should strongly consider upgrading to the
|
|
758 latest available version. cc-mode may continue to work, after a
|
|
759 fashion, but strange indentation errors could be encountered."
|
|
760 emacs-version))))
|
|
761 ;; Emacs 18, with no patch is not too good
|
|
762 (if (and (eq major 'v18) (eq comments 'no-dual-comments)
|
|
763 (not c-inhibit-startup-warnings-p))
|
|
764 (with-output-to-temp-buffer "*cc-mode warnings*"
|
|
765 (print (format
|
|
766 "The version of Emacs 18 you are running, %s,
|
|
767 has known deficiencies in its ability to handle dual C++ comments,
|
|
768 i.e. C++ line style comments and C block style comments. This will
|
|
769 not be much of a problem for you if you are only editing C code, but
|
|
770 if you are doing much C++ editing, you should strongly consider
|
|
771 upgrading to one of the latest Emacs 19's. In Emacs 18, you may also
|
|
772 experience performance degradations. Emacs 19 has some new built-in
|
|
773 routines which will speed things up for you.
|
|
774
|
|
775 Because of these inherent problems, cc-mode is no longer being
|
|
776 actively maintained for Emacs 18, however, until you can upgrade to
|
|
777 Emacs 19, you may want to look at cc-mode-18.el in the cc-mode
|
|
778 distribution. THIS FILE IS COMPLETELY UNSUPPORTED! If you use it,
|
|
779 you are on your own, although patch contributions will be folded into
|
|
780 the main release."
|
|
781 emacs-version))))
|
|
782 ;; Emacs 18 with the syntax patches are no longer supported
|
|
783 (if (and (eq major 'v18) (not (eq comments 'no-dual-comments))
|
|
784 (not c-inhibit-startup-warnings-p))
|
|
785 (with-output-to-temp-buffer "*cc-mode warnings*"
|
|
786 (print (format
|
|
787 "You are running a syntax patched Emacs 18 variant. While this should
|
|
788 work for you, you may want to consider upgrading to Emacs 19. The
|
|
789 syntax patches are no longer supported either for syntax.c or
|
|
790 cc-mode."))))
|
|
791 (list major comments re-suite))
|
|
792 "A list of features extant in the Emacs you are using.
|
|
793 There are many flavors of Emacs out there, each with different
|
|
794 features supporting those needed by cc-mode. Here's the current
|
|
795 supported list, along with the values for this variable:
|
|
796
|
|
797 Emacs 18/Epoch 4: (v18 no-dual-comments RS)
|
|
798 Emacs 18/Epoch 4 (patch2): (v18 8-bit RS)
|
|
799 XEmacs 19: (v19 8-bit RS)
|
2
|
800 XEmacs 20: (v20 8-bit RS)
|
0
|
801 Emacs 19: (v19 1-bit RS)
|
|
802
|
|
803 RS is the regular expression suite to use. XEmacs versions after
|
|
804 19.13, and Emacs versions after 19.29 use the `new-re' regex suite.
|
|
805 All other Emacsen use the `old-re' suite.")
|
|
806
|
|
807 (defvar c++-mode-abbrev-table nil
|
|
808 "Abbrev table in use in c++-mode buffers.")
|
|
809 (define-abbrev-table 'c++-mode-abbrev-table ())
|
|
810
|
|
811 (defvar c-mode-abbrev-table nil
|
|
812 "Abbrev table in use in c-mode buffers.")
|
|
813 (define-abbrev-table 'c-mode-abbrev-table ())
|
|
814
|
|
815 (defvar objc-mode-abbrev-table nil
|
|
816 "Abbrev table in use in objc-mode buffers.")
|
|
817 (define-abbrev-table 'objc-mode-abbrev-table ())
|
|
818
|
|
819 (defvar java-mode-abbrev-table nil
|
|
820 "Abbrev table in use in java-mode buffers.")
|
|
821 (define-abbrev-table 'java-mode-abbrev-table ())
|
|
822
|
|
823 (defun c-mode-fsf-menu (name map)
|
|
824 ;; Add menu to a keymap. FSF menus suck. Don't add them for
|
|
825 ;; XEmacs. This feature test will fail on other than Emacs 19.
|
|
826 (condition-case nil
|
|
827 (progn
|
|
828 (define-key map [menu-bar] (make-sparse-keymap))
|
|
829 (define-key map [menu-bar c] (cons name (make-sparse-keymap name)))
|
|
830
|
|
831 (define-key map [menu-bar c comment-region]
|
|
832 '("Comment Out Region" . comment-region))
|
|
833 (define-key map [menu-bar c c-macro-expand]
|
|
834 '("Macro Expand Region" . c-macro-expand))
|
|
835 (define-key map [menu-bar c c-backslash-region]
|
|
836 '("Backslashify" . c-backslash-region))
|
|
837 (define-key map [menu-bar c indent-exp]
|
|
838 '("Indent Expression" . c-indent-exp))
|
|
839 (define-key map [menu-bar c indent-line]
|
|
840 '("Indent Line" . c-indent-command))
|
|
841 (define-key map [menu-bar c fill]
|
|
842 '("Fill Comment Paragraph" . c-fill-paragraph))
|
|
843 (define-key map [menu-bar c up]
|
|
844 '("Up Conditional" . c-up-conditional))
|
|
845 (define-key map [menu-bar c backward]
|
|
846 '("Backward Conditional" . c-backward-conditional))
|
|
847 (define-key map [menu-bar c forward]
|
|
848 '("Forward Conditional" . c-forward-conditional))
|
|
849 (define-key map [menu-bar c backward-stmt]
|
|
850 '("Backward Statement" . c-beginning-of-statement))
|
|
851 (define-key map [menu-bar c forward-stmt]
|
|
852 '("Forward Statement" . c-end-of-statement))
|
|
853
|
|
854 ;; RMS: mouse-3 should not select this menu. mouse-3's global
|
|
855 ;; definition is useful in C mode and we should not interfere
|
|
856 ;; with that. The menu is mainly for beginners, and for them,
|
|
857 ;; the menubar requires less memory than a special click.
|
|
858 t)
|
|
859 (error nil)))
|
|
860
|
|
861 (defvar c-mode-map ()
|
|
862 "Keymap used in c-mode buffers.")
|
|
863 (if c-mode-map
|
|
864 ()
|
|
865 ;; TBD: should we even worry about naming this keymap. My vote: no,
|
|
866 ;; because Emacs and XEmacs do it differently.
|
|
867 (setq c-mode-map (make-sparse-keymap))
|
|
868 ;; put standard keybindings into MAP
|
|
869 ;; the following mappings correspond more or less directly to BOCM
|
|
870 (define-key c-mode-map "{" 'c-electric-brace)
|
|
871 (define-key c-mode-map "}" 'c-electric-brace)
|
|
872 (define-key c-mode-map ";" 'c-electric-semi&comma)
|
|
873 (define-key c-mode-map "#" 'c-electric-pound)
|
|
874 (define-key c-mode-map ":" 'c-electric-colon)
|
|
875 ;; Lucid Emacs 19.9 defined these two, the second of which was
|
|
876 ;; commented out...
|
|
877 ;; (define-key c-mode-map "\e{" 'c-insert-braces)
|
|
878 ;; Commented out electric square brackets because nobody likes them.
|
|
879 ;; (define-key c-mode-map "[" 'c-insert-brackets)
|
2
|
880 (define-key c-mode-map "\C-c\C-m" 'c-mark-function)
|
0
|
881 (define-key c-mode-map "\e\C-q" 'c-indent-exp)
|
|
882 (define-key c-mode-map "\ea" 'c-beginning-of-statement)
|
|
883 (define-key c-mode-map "\ee" 'c-end-of-statement)
|
|
884 ;; Emacs 19.30 introduces fill-paragraph-function, but it's not in
|
|
885 ;; every version of Emacs cc-mode supports.
|
|
886 (if (not (boundp 'fill-paragraph-function))
|
|
887 ;; I'd rather use an adaptive fill program instead of this.
|
|
888 (define-key c-mode-map "\eq" 'c-fill-paragraph))
|
|
889 (define-key c-mode-map "\C-c\C-n" 'c-forward-conditional)
|
|
890 (define-key c-mode-map "\C-c\C-p" 'c-backward-conditional)
|
|
891 (define-key c-mode-map "\C-c\C-u" 'c-up-conditional)
|
|
892 (define-key c-mode-map "\t" 'c-indent-command)
|
|
893 (define-key c-mode-map "\177" 'c-electric-delete)
|
|
894 ;; these are new keybindings, with no counterpart to BOCM
|
|
895 (define-key c-mode-map "," 'c-electric-semi&comma)
|
|
896 (define-key c-mode-map "*" 'c-electric-star)
|
|
897 (define-key c-mode-map "\C-c\C-q" 'c-indent-defun)
|
|
898 (define-key c-mode-map "\C-c\C-\\" 'c-backslash-region)
|
|
899 ;; TBD: where if anywhere, to put c-backward|forward-into-nomenclature
|
|
900 (define-key c-mode-map "\C-c\C-a" 'c-toggle-auto-state)
|
|
901 (define-key c-mode-map "\C-c\C-b" 'c-submit-bug-report)
|
|
902 (define-key c-mode-map "\C-c\C-c" 'comment-region)
|
|
903 (define-key c-mode-map "\C-c\C-d" 'c-toggle-hungry-state)
|
|
904 (define-key c-mode-map "\C-c\C-e" 'c-macro-expand)
|
|
905 (define-key c-mode-map "\C-c\C-o" 'c-set-offset)
|
|
906 (define-key c-mode-map "\C-c\C-s" 'c-show-syntactic-information)
|
|
907 (define-key c-mode-map "\C-c\C-t" 'c-toggle-auto-hungry-state)
|
|
908 ;; conflicts with OOBR
|
|
909 ;;(define-key c-mode-map "\C-c\C-v" 'c-version)
|
|
910 ;;
|
|
911 ;; Emacs 19 defines menus in the mode map. This call will return
|
|
912 ;; t on Emacs 19, otherwise no-op and return nil.
|
|
913 (if (and (not (c-mode-fsf-menu "C" c-mode-map))
|
|
914 ;; in XEmacs 19, we want the menu to popup when the 3rd
|
|
915 ;; button is hit. In Lucid Emacs 19.10 and beyond this is
|
|
916 ;; done automatically if we put the menu on mode-popup-menu
|
|
917 ;; variable, see c-common-init. Emacs 19 uses C-Mouse-3 for
|
|
918 ;; this, and it works with no special effort.
|
|
919 (boundp 'current-menubar)
|
|
920 (not (boundp 'mode-popup-menu)))
|
|
921 (define-key c-mode-map 'button3 'c-popup-menu)))
|
|
922
|
|
923 (defvar c++-mode-map ()
|
|
924 "Keymap used in c++-mode buffers.")
|
|
925 (if c++-mode-map
|
|
926 ()
|
|
927 ;; In Emacs 19, it makes more sense to inherit c-mode-map
|
2
|
928 (if (or
|
|
929 (memq 'v19 c-emacs-features)
|
|
930 (memq 'v20 c-emacs-features))
|
0
|
931 ;; XEmacs and Emacs 19 do this differently
|
|
932 (cond
|
|
933 ;; XEmacs 19.13
|
|
934 ((fboundp 'set-keymap-parents)
|
|
935 (setq c++-mode-map (make-sparse-keymap))
|
|
936 (set-keymap-parents c++-mode-map c-mode-map))
|
|
937 ((fboundp 'set-keymap-parent)
|
|
938 (setq c++-mode-map (make-sparse-keymap))
|
|
939 (set-keymap-parent c++-mode-map c-mode-map))
|
|
940 (t (setq c++-mode-map (cons 'keymap c-mode-map))))
|
|
941 ;; Do it the hard way for Emacs 18 -- given by JWZ
|
|
942 (setq c++-mode-map (nconc (make-sparse-keymap) c-mode-map)))
|
|
943 ;; add bindings which are only useful for C++
|
|
944 (define-key c++-mode-map "\C-c:" 'c-scope-operator)
|
|
945 (define-key c++-mode-map "/" 'c-electric-slash)
|
|
946 (define-key c++-mode-map "<" 'c-electric-lt-gt)
|
|
947 (define-key c++-mode-map ">" 'c-electric-lt-gt)
|
|
948 ;; Emacs 19 defines menus in the mode map. This call will return
|
|
949 ;; t on Emacs 19, otherwise no-op and return nil.
|
|
950 (c-mode-fsf-menu "C++" c++-mode-map))
|
|
951
|
|
952 (defvar objc-mode-map ()
|
|
953 "Keymap used in objc-mode buffers.")
|
|
954 (if objc-mode-map
|
|
955 ()
|
|
956 ;; In Emacs 19, it makes more sense to inherit c-mode-map
|
2
|
957 (if (or (memq 'v19 c-emacs-features) (memq 'v20 c-emacs-features))
|
0
|
958 ;; XEmacs and Emacs 19 do this differently
|
|
959 (cond
|
|
960 ;; XEmacs 19.13
|
|
961 ((fboundp 'set-keymap-parents)
|
|
962 (setq objc-mode-map (make-sparse-keymap))
|
|
963 (set-keymap-parents objc-mode-map c-mode-map))
|
|
964 ((fboundp 'set-keymap-parent)
|
|
965 (setq objc-mode-map (make-sparse-keymap))
|
|
966 (set-keymap-parent objc-mode-map c-mode-map))
|
|
967 (t (setq objc-mode-map (cons 'keymap c-mode-map))))
|
|
968 ;; Do it the hard way for Emacs 18 -- given by JWZ
|
|
969 (setq objc-mode-map (nconc (make-sparse-keymap) c-mode-map)))
|
|
970 ;; add bindings which are only useful for Objective-C
|
|
971 (define-key objc-mode-map "/" 'c-electric-slash)
|
|
972 ;; Emacs 19 defines menus in the mode map. This call will return
|
|
973 ;; t on Emacs 19, otherwise no-op and return nil.
|
|
974 (c-mode-fsf-menu "ObjC" objc-mode-map))
|
|
975
|
|
976 (defvar java-mode-map ()
|
|
977 "Keymap used in java-mode buffers.")
|
|
978 (if java-mode-map
|
|
979 ()
|
|
980 ;; In Emacs 19, it makes more sense to inherit c-mode-map
|
2
|
981 (if (or (memq 'v19 c-emacs-features) (memq 'v20 c-emacs-features))
|
0
|
982 ;; XEmacs and Emacs 19 do this differently
|
|
983 (cond
|
|
984 ;; XEmacs 19.13
|
|
985 ((fboundp 'set-keymap-parents)
|
|
986 (setq java-mode-map (make-sparse-keymap))
|
|
987 (set-keymap-parents java-mode-map c-mode-map))
|
|
988 ((fboundp 'set-keymap-parent)
|
|
989 (setq java-mode-map (make-sparse-keymap))
|
|
990 (set-keymap-parent java-mode-map c-mode-map))
|
|
991 (t (setq java-mode-map (cons 'keymap c-mode-map)))
|
|
992 )
|
|
993 ;; Do it the hard way for Emacs 18 -- given by JWZ
|
|
994 (setq java-mode-map (nconc (make-sparse-keymap) c-mode-map)))
|
|
995 ;; add bindings which are only useful for Java
|
|
996 (define-key java-mode-map "/" 'c-electric-slash)
|
|
997 ;; Emacs 19 defines menus in the mode map. This call will return t
|
|
998 ;; on Emacs 19, otherwise no-op and return nil.
|
|
999 (c-mode-fsf-menu "Java" java-mode-map))
|
|
1000
|
|
1001 (defun c-populate-syntax-table (table)
|
|
1002 ;; Populate the syntax TABLE
|
|
1003 ;; DO NOT TRY TO SET _ (UNDERSCORE) TO WORD CLASS!
|
|
1004 (modify-syntax-entry ?_ "_" table)
|
|
1005 (modify-syntax-entry ?\\ "\\" table)
|
|
1006 (modify-syntax-entry ?+ "." table)
|
|
1007 (modify-syntax-entry ?- "." table)
|
|
1008 (modify-syntax-entry ?= "." table)
|
|
1009 (modify-syntax-entry ?% "." table)
|
|
1010 (modify-syntax-entry ?< "." table)
|
|
1011 (modify-syntax-entry ?> "." table)
|
|
1012 (modify-syntax-entry ?& "." table)
|
|
1013 (modify-syntax-entry ?| "." table)
|
|
1014 (modify-syntax-entry ?\' "\"" table))
|
|
1015
|
|
1016 (defun c-setup-dual-comments (table)
|
|
1017 ;; Set up TABLE to handle block and line style comments
|
|
1018 (cond
|
|
1019 ((memq '8-bit c-emacs-features)
|
|
1020 ;; XEmacs 19 has the best implementation
|
|
1021 (modify-syntax-entry ?/ ". 1456" table)
|
|
1022 (modify-syntax-entry ?* ". 23" table)
|
|
1023 (modify-syntax-entry ?\n "> b" table)
|
|
1024 ;; Give CR the same syntax as newline, for selective-display
|
|
1025 (modify-syntax-entry ?\^m "> b" table))
|
|
1026 ((memq '1-bit c-emacs-features)
|
|
1027 ;; Emacs 19 does things differently, but we can work with it
|
|
1028 (modify-syntax-entry ?/ ". 124b" table)
|
|
1029 (modify-syntax-entry ?* ". 23" table)
|
|
1030 (modify-syntax-entry ?\n "> b" table)
|
|
1031 ;; Give CR the same syntax as newline, for selective-display
|
|
1032 (modify-syntax-entry ?\^m "> b" table))
|
|
1033 ))
|
|
1034
|
|
1035 (defvar c-mode-syntax-table nil
|
|
1036 "Syntax table used in c-mode buffers.")
|
|
1037 (if c-mode-syntax-table
|
|
1038 ()
|
|
1039 (setq c-mode-syntax-table (make-syntax-table))
|
|
1040 (c-populate-syntax-table c-mode-syntax-table)
|
|
1041 ;; add extra comment syntax
|
|
1042 (modify-syntax-entry ?/ ". 14" c-mode-syntax-table)
|
|
1043 (modify-syntax-entry ?* ". 23" c-mode-syntax-table))
|
|
1044
|
|
1045 (defvar c++-mode-syntax-table nil
|
|
1046 "Syntax table used in c++-mode buffers.")
|
|
1047 (if c++-mode-syntax-table
|
|
1048 ()
|
|
1049 (setq c++-mode-syntax-table (make-syntax-table))
|
|
1050 (c-populate-syntax-table c++-mode-syntax-table)
|
|
1051 ;; add extra comment syntax
|
|
1052 (c-setup-dual-comments c++-mode-syntax-table)
|
|
1053 ;; TBD: does it make sense for colon to be symbol class in C++?
|
|
1054 ;; I'm not so sure, since c-label-key is busted on lines like:
|
|
1055 ;; Foo::bar( i );
|
|
1056 ;; maybe c-label-key should be fixed instead of commenting this out,
|
|
1057 ;; but it also bothers me that this only seems appropriate for C++
|
|
1058 ;; and not C.
|
|
1059 ;;(modify-syntax-entry ?: "_" c++-mode-syntax-table)
|
|
1060 )
|
|
1061
|
|
1062 (defvar objc-mode-syntax-table nil
|
|
1063 "Syntax table used in objc-mode buffers.")
|
|
1064 (if objc-mode-syntax-table
|
|
1065 ()
|
|
1066 (setq objc-mode-syntax-table (make-syntax-table))
|
|
1067 (c-populate-syntax-table objc-mode-syntax-table)
|
|
1068 ;; add extra comment syntax
|
|
1069 (c-setup-dual-comments objc-mode-syntax-table)
|
|
1070 ;; everyone gets these
|
|
1071 (modify-syntax-entry ?@ "_" objc-mode-syntax-table)
|
|
1072 )
|
|
1073
|
|
1074 (defvar java-mode-syntax-table nil
|
|
1075 "Syntax table used in java-mode buffers.")
|
|
1076 (if java-mode-syntax-table
|
|
1077 ()
|
|
1078 (setq java-mode-syntax-table (make-syntax-table))
|
|
1079 (c-populate-syntax-table java-mode-syntax-table)
|
|
1080 ;; add extra comment syntax
|
|
1081 (c-setup-dual-comments java-mode-syntax-table)
|
|
1082 ;; everyone gets these
|
|
1083 (modify-syntax-entry ?@ "_" java-mode-syntax-table)
|
|
1084 )
|
|
1085
|
|
1086 (defvar c-hungry-delete-key nil
|
|
1087 "Internal state of hungry delete key feature.")
|
|
1088 (defvar c-auto-newline nil
|
|
1089 "Internal state of auto newline feature.")
|
|
1090 (defvar c-auto-hungry-string nil
|
|
1091 "Internal auto-newline/hungry-delete designation string for mode line.")
|
|
1092 (defvar c-syntactic-context nil
|
|
1093 "Variable containing syntactic analysis list during indentation.")
|
|
1094 (defvar c-comment-start-regexp nil
|
|
1095 "Buffer local variable describing how comment are introduced.")
|
|
1096 (defvar c-conditional-key nil
|
|
1097 "Buffer local language-specific conditional keyword regexp.")
|
|
1098 (defvar c-access-key nil
|
|
1099 "Buffer local language-specific access key regexp.")
|
|
1100 (defvar c-class-key nil
|
|
1101 "Buffer local language-specific class key regexp.")
|
|
1102 (defvar c-method-key nil
|
|
1103 "Buffer local language-specific method regexp.")
|
|
1104 (defvar c-double-slash-is-comments-p nil
|
|
1105 "Buffer local language-specific comment style flag.")
|
|
1106 (defconst c-protection-key
|
|
1107 "\\<\\(public\\|protected\\|private\\)\\>"
|
|
1108 "Regexp describing protection keywords.")
|
|
1109 (defconst c-symbol-key "\\(\\w\\|\\s_\\)+"
|
|
1110 "Regexp describing a C/C++/ObjC symbol.
|
|
1111 We cannot use just `word' syntax class since `_' cannot be in word
|
|
1112 class. Putting underscore in word class breaks forward word movement
|
|
1113 behavior that users are familiar with.")
|
|
1114 (defconst c-baseclass-key
|
|
1115 (concat
|
|
1116 ":?[ \t]*\\(virtual[ \t]+\\)?\\("
|
|
1117 c-protection-key "[ \t]+\\)" c-symbol-key)
|
|
1118 "Regexp describing C++ base classes in a derived class definition.")
|
|
1119
|
2
|
1120 ;; defconst'd instead of defvar'd to override any old pre-loaded versions
|
|
1121 (defconst c-recognize-knr-p t
|
|
1122 "Non-nil means K&R style argument declarations are valid.")
|
|
1123
|
0
|
1124 ;; minor mode variables
|
|
1125 (make-variable-buffer-local 'c-auto-newline)
|
|
1126 (make-variable-buffer-local 'c-hungry-delete-key)
|
|
1127 (make-variable-buffer-local 'c-auto-hungry-string)
|
|
1128 ;; language differences
|
|
1129 (make-variable-buffer-local 'c-comment-start-regexp)
|
|
1130 (make-variable-buffer-local 'c-conditional-key)
|
|
1131 (make-variable-buffer-local 'c-access-key)
|
|
1132 (make-variable-buffer-local 'c-class-key)
|
|
1133 (make-variable-buffer-local 'c-method-key)
|
|
1134 (make-variable-buffer-local 'c-double-slash-is-comments-p)
|
|
1135 (make-variable-buffer-local 'c-baseclass-key)
|
|
1136 (make-variable-buffer-local 'c-recognize-knr-p)
|
|
1137 ;; style variables are made buffer local at tail end of this file.
|
|
1138
|
|
1139 ;; cmacexp is lame because it uses no preprocessor symbols.
|
|
1140 ;; It isn't very extensible either -- hardcodes /lib/cpp.
|
|
1141 ;; [I add it here only because c-mode has it -- BAW]
|
|
1142 ;;(autoload 'c-macro-expand "cmacexp"
|
|
1143 ;; "Display the result of expanding all C macros occurring in the region.
|
|
1144 ;;The expansion is entirely correct because it uses the C preprocessor."
|
|
1145 ;; t)
|
|
1146
|
|
1147
|
|
1148 ;; constant regular expressions for looking at various constructs
|
|
1149 (defconst c-C++-class-key "\\(class\\|struct\\|union\\)"
|
|
1150 "Regexp describing a C++ class declaration, including templates.")
|
|
1151 (defconst c-C-class-key "\\(struct\\|union\\)"
|
|
1152 "Regexp describing a C struct declaration.")
|
|
1153 (defconst c-inher-key
|
|
1154 (concat "\\(\\<static\\>\\s +\\)?"
|
|
1155 c-C++-class-key "[ \t]+" c-symbol-key
|
|
1156 "\\([ \t]*:[ \t]*\\)?\\s *[^;]")
|
|
1157 "Regexp describing a class inheritance declaration.")
|
|
1158 (defconst c-switch-label-key
|
|
1159 "\\(\\(case[( \t]+\\S .*\\)\\|default[ \t]*\\):"
|
|
1160 "Regexp describing a switch's case or default label")
|
|
1161 (defconst c-C++-access-key
|
2
|
1162 (concat c-protection-key "[ \t]*:")
|
0
|
1163 "Regexp describing C++ access specification keywords.")
|
|
1164 (defconst c-label-key
|
|
1165 (concat c-symbol-key ":\\([^:]\\|$\\)")
|
|
1166 "Regexp describing any label.")
|
2
|
1167 (defconst c-C-conditionals '("for" "if" "do" "else" "while" "switch")
|
|
1168 "Shared conditional keywords for C-like languages.")
|
0
|
1169 (defconst c-C-conditional-key
|
2
|
1170 (concat "\\b\\("
|
|
1171 (mapconcat 'identity c-C-conditionals "\\|")
|
|
1172 "\\)\\b[^_]")
|
|
1173 "Regexp describing a conditional control for C.")
|
0
|
1174 (defconst c-C++-conditional-key
|
2
|
1175 (concat "\\b\\(" (mapconcat 'identity
|
|
1176 (append '("try" "catch") c-C-conditionals) "\\|")
|
|
1177 "\\)\\b[^_]")
|
0
|
1178 "Regexp describing a conditional control for C++.")
|
|
1179 (defconst c-C++-friend-key
|
|
1180 "friend[ \t]+\\|template[ \t]*<.+>[ \t]*friend[ \t]+"
|
|
1181 "Regexp describing friend declarations in C++ classes.")
|
|
1182 (defconst c-C++-comment-start-regexp "//\\|/\\*"
|
|
1183 "Dual comment value for `c-comment-start-regexp'.")
|
|
1184 (defconst c-C-comment-start-regexp "/\\*"
|
|
1185 "Single comment style value for `c-comment-start-regexp'.")
|
|
1186
|
|
1187 (defconst c-ObjC-method-key
|
|
1188 (concat
|
|
1189 "^\\s *[+-]\\s *"
|
|
1190 "\\(([^)]*)\\)?" ; return type
|
|
1191 ;; \\s- in objc syntax table does not include \n
|
|
1192 ;; since it is considered the end of //-comments.
|
|
1193 "[ \t\n]*" c-symbol-key)
|
|
1194 "Regexp describing an Objective-C method intro.")
|
|
1195 (defconst c-ObjC-access-key
|
|
1196 (concat "@" c-protection-key)
|
|
1197 "Regexp describing access specification keywords for Objective-C.")
|
|
1198 (defconst c-ObjC-class-key
|
|
1199 (concat
|
|
1200 "@\\(interface\\|implementation\\)\\s +"
|
|
1201 c-symbol-key ;name of the class
|
|
1202 "\\(\\s *:\\s *" c-symbol-key "\\)?" ;maybe followed by the superclass
|
|
1203 "\\(\\s *<[^>]+>\\)?" ;and maybe the adopted protocols list
|
|
1204 )
|
|
1205 "Regexp describing a class or protocol declaration for Objective-C.")
|
|
1206
|
|
1207 (defconst c-Java-method-key
|
|
1208 (concat
|
|
1209 "^\\s *[+-]\\s *"
|
|
1210 "\\(([^)]*)\\)?" ; return type
|
|
1211 ;; \\s- in java syntax table does not include \n
|
|
1212 ;; since it is considered the end of //-comments.
|
|
1213 "[ \t\n]*" c-symbol-key)
|
|
1214 "Regexp describing a Java method intro.")
|
|
1215 (defconst c-Java-access-key
|
|
1216 (concat c-protection-key)
|
|
1217 "Regexp describing access specification keywords for Java.")
|
|
1218 (defconst c-Java-class-key
|
|
1219 (concat
|
|
1220 "\\(interface\\|class\\)\\s +"
|
|
1221 c-symbol-key ;name of the class
|
|
1222 "\\(\\s *extends\\s *" c-symbol-key "\\)?" ;maybe followed by superclass
|
|
1223 ;;"\\(\\s *implements *[^{]+{\\)?" ;and maybe the adopted protocols list
|
|
1224 )
|
|
1225 "Regexp describing a class or protocol declaration for Java.")
|
2
|
1226 (defconst c-Java-conditional-key
|
|
1227 (concat "\\b\\("
|
|
1228 (mapconcat 'identity
|
|
1229 (append '("try" "catch" "finally" "synchronized")
|
|
1230 c-C-conditionals) "\\|")
|
|
1231 "\\)\\b[^_]")
|
|
1232 "Regexp describing a conditional control for Java.")
|
0
|
1233
|
|
1234 ;; KLUDGE ALERT. We default these variables to their `C' values so
|
|
1235 ;; that non-cc-mode-ized modes that depend on c-mode will still work
|
|
1236 ;; out of the box. The most glaring example is awk-mode. There ought
|
|
1237 ;; to be a better way.
|
|
1238 (setq-default c-conditional-key c-C-conditional-key
|
|
1239 c-class-key c-C-class-key
|
|
1240 c-comment-start-regexp c-C-comment-start-regexp)
|
|
1241
|
|
1242
|
|
1243 ;; main entry points for the modes
|
|
1244 (defconst c-list-of-mode-names nil)
|
|
1245
|
|
1246 (defun c-mode ()
|
|
1247 "Major mode for editing K&R and ANSI C code.
|
|
1248 To submit a problem report, enter `\\[c-submit-bug-report]' from a
|
|
1249 c-mode buffer. This automatically sets up a mail buffer with version
|
|
1250 information already added. You just need to add a description of the
|
|
1251 problem, including a reproducible test case and send the message.
|
|
1252
|
|
1253 To see what version of cc-mode you are running, enter `\\[c-version]'.
|
|
1254
|
|
1255 The hook variable `c-mode-hook' is run with no args, if that value is
|
|
1256 bound and has a non-nil value. Also the hook `c-mode-common-hook' is
|
|
1257 run first.
|
|
1258
|
|
1259 Key bindings:
|
|
1260 \\{c-mode-map}"
|
|
1261 (interactive)
|
|
1262 (kill-all-local-variables)
|
|
1263 (set-syntax-table c-mode-syntax-table)
|
|
1264 (setq major-mode 'c-mode
|
|
1265 mode-name "C"
|
|
1266 local-abbrev-table c-mode-abbrev-table)
|
|
1267 (use-local-map c-mode-map)
|
|
1268 (c-common-init)
|
|
1269 (setq comment-start "/* "
|
|
1270 comment-end " */"
|
|
1271 comment-multi-line t
|
|
1272 c-conditional-key c-C-conditional-key
|
|
1273 c-class-key c-C-class-key
|
|
1274 c-baseclass-key nil
|
|
1275 c-comment-start-regexp c-C-comment-start-regexp
|
|
1276 imenu-generic-expression cc-imenu-c-generic-expression)
|
|
1277 (run-hooks 'c-mode-common-hook)
|
|
1278 (run-hooks 'c-mode-hook))
|
|
1279 (setq c-list-of-mode-names (cons "C" c-list-of-mode-names))
|
|
1280
|
|
1281 (defun c++-mode ()
|
|
1282 "Major mode for editing C++ code.
|
|
1283 To submit a problem report, enter `\\[c-submit-bug-report]' from a
|
|
1284 c++-mode buffer. This automatically sets up a mail buffer with
|
|
1285 version information already added. You just need to add a description
|
|
1286 of the problem, including a reproducible test case, and send the
|
|
1287 message.
|
|
1288
|
|
1289 To see what version of cc-mode you are running, enter `\\[c-version]'.
|
|
1290
|
|
1291 The hook variable `c++-mode-hook' is run with no args, if that
|
|
1292 variable is bound and has a non-nil value. Also the hook
|
|
1293 `c-mode-common-hook' is run first.
|
|
1294
|
|
1295 Key bindings:
|
|
1296 \\{c++-mode-map}"
|
|
1297 (interactive)
|
|
1298 (kill-all-local-variables)
|
|
1299 (set-syntax-table c++-mode-syntax-table)
|
|
1300 (setq major-mode 'c++-mode
|
|
1301 mode-name "C++"
|
|
1302 local-abbrev-table c++-mode-abbrev-table)
|
|
1303 (use-local-map c++-mode-map)
|
|
1304 (c-common-init)
|
|
1305 (setq comment-start "// "
|
|
1306 comment-end ""
|
|
1307 comment-multi-line nil
|
|
1308 c-conditional-key c-C++-conditional-key
|
|
1309 c-comment-start-regexp c-C++-comment-start-regexp
|
|
1310 c-class-key c-C++-class-key
|
|
1311 c-access-key c-C++-access-key
|
|
1312 c-double-slash-is-comments-p t
|
2
|
1313 c-recognize-knr-p nil
|
0
|
1314 imenu-generic-expression cc-imenu-c++-generic-expression)
|
|
1315 (run-hooks 'c-mode-common-hook)
|
|
1316 (run-hooks 'c++-mode-hook))
|
|
1317 (setq c-list-of-mode-names (cons "C++" c-list-of-mode-names))
|
|
1318
|
|
1319 (defun objc-mode ()
|
|
1320 "Major mode for editing Objective C code.
|
|
1321 To submit a problem report, enter `\\[c-submit-bug-report]' from an
|
|
1322 objc-mode buffer. This automatically sets up a mail buffer with
|
|
1323 version information already added. You just need to add a description
|
|
1324 of the problem, including a reproducible test case, and send the
|
|
1325 message.
|
|
1326
|
|
1327 To see what version of cc-mode you are running, enter `\\[c-version]'.
|
|
1328
|
|
1329 The hook variable `objc-mode-hook' is run with no args, if that value
|
|
1330 is bound and has a non-nil value. Also the hook `c-mode-common-hook'
|
|
1331 is run first.
|
|
1332
|
|
1333 Key bindings:
|
|
1334 \\{objc-mode-map}"
|
|
1335 (interactive)
|
|
1336 (kill-all-local-variables)
|
|
1337 (set-syntax-table objc-mode-syntax-table)
|
|
1338 (setq major-mode 'objc-mode
|
|
1339 mode-name "ObjC"
|
|
1340 local-abbrev-table objc-mode-abbrev-table)
|
|
1341 (use-local-map objc-mode-map)
|
|
1342 (c-common-init)
|
|
1343 (setq comment-start "// "
|
|
1344 comment-end ""
|
|
1345 comment-multi-line nil
|
|
1346 c-conditional-key c-C-conditional-key
|
|
1347 c-comment-start-regexp c-C++-comment-start-regexp
|
|
1348 c-class-key c-ObjC-class-key
|
|
1349 c-baseclass-key nil
|
|
1350 c-access-key c-ObjC-access-key
|
|
1351 c-double-slash-is-comments-p t
|
|
1352 c-method-key c-ObjC-method-key)
|
|
1353 (run-hooks 'c-mode-common-hook)
|
|
1354 (run-hooks 'objc-mode-hook))
|
|
1355 (setq c-list-of-mode-names (cons "ObjC" c-list-of-mode-names))
|
|
1356
|
|
1357 (defun java-mode ()
|
|
1358 "Major mode for editing Java code.
|
|
1359 To submit a problem report, enter `\\[c-submit-bug-report]' from an
|
|
1360 java-mode buffer. This automatically sets up a mail buffer with
|
|
1361 version information already added. You just need to add a description
|
|
1362 of the problem, including a reproducible test case and send the
|
|
1363 message.
|
|
1364
|
|
1365 To see what version of cc-mode you are running, enter `\\[c-version]'.
|
|
1366
|
|
1367 The hook variable `java-mode-hook' is run with no args, if that value
|
|
1368 is bound and has a non-nil value. Also the common hook
|
2
|
1369 `c-mode-common-hook' is run first. Note that this mode automatically
|
|
1370 sets the \"java\" style before calling any hooks so be careful if you
|
|
1371 set styles in `c-mode-common-hook'.
|
0
|
1372
|
|
1373 Key bindings:
|
|
1374 \\{java-mode-map}"
|
|
1375 (interactive)
|
|
1376 (kill-all-local-variables)
|
|
1377 (set-syntax-table java-mode-syntax-table)
|
|
1378 (setq major-mode 'java-mode
|
|
1379 mode-name "Java"
|
|
1380 local-abbrev-table java-mode-abbrev-table)
|
|
1381 (use-local-map java-mode-map)
|
|
1382 (c-common-init)
|
|
1383 (setq comment-start "// "
|
|
1384 comment-end ""
|
|
1385 comment-multi-line nil
|
|
1386 c-conditional-key c-Java-conditional-key
|
|
1387 c-comment-start-regexp c-C++-comment-start-regexp
|
|
1388 c-class-key c-Java-class-key
|
|
1389 c-method-key c-Java-method-key
|
|
1390 c-double-slash-is-comments-p t
|
|
1391 c-baseclass-key nil
|
2
|
1392 c-recognize-knr-p nil
|
0
|
1393 c-access-key c-Java-access-key)
|
2
|
1394 (c-set-style "java")
|
0
|
1395 (run-hooks 'c-mode-common-hook)
|
|
1396 (run-hooks 'java-mode-hook))
|
|
1397 (setq c-list-of-mode-names (cons "Java" c-list-of-mode-names))
|
|
1398
|
2
|
1399 (defun c-use-java-style ()
|
|
1400 "Institutes `java' indentation style.
|
|
1401 For use with the variable `java-mode-hook'."
|
|
1402 (c-set-style "java"))
|
|
1403
|
0
|
1404 (defun c-common-init ()
|
|
1405 ;; Common initializations for c++-mode and c-mode.
|
|
1406 ;; make local variables
|
|
1407 (make-local-variable 'paragraph-start)
|
|
1408 (make-local-variable 'paragraph-separate)
|
|
1409 (make-local-variable 'paragraph-ignore-fill-prefix)
|
|
1410 (make-local-variable 'require-final-newline)
|
|
1411 (make-local-variable 'parse-sexp-ignore-comments)
|
|
1412 (make-local-variable 'indent-line-function)
|
|
1413 (make-local-variable 'indent-region-function)
|
|
1414 (make-local-variable 'comment-start)
|
|
1415 (make-local-variable 'comment-end)
|
|
1416 (make-local-variable 'comment-column)
|
|
1417 (make-local-variable 'comment-start-skip)
|
|
1418 (make-local-variable 'comment-multi-line)
|
|
1419 (make-local-variable 'outline-regexp)
|
|
1420 (make-local-variable 'outline-level)
|
|
1421 (make-local-variable 'adaptive-fill-regexp)
|
|
1422 (make-local-variable 'imenu-generic-expression) ;set in the mode functions
|
|
1423 ;; Emacs 19.30 and beyond only, AFAIK
|
|
1424 (if (boundp 'fill-paragraph-function)
|
|
1425 (progn
|
|
1426 (make-local-variable 'fill-paragraph-function)
|
|
1427 (setq fill-paragraph-function 'c-fill-paragraph)))
|
|
1428 ;; now set their values
|
|
1429 (setq paragraph-start (if (memq 'new-re c-emacs-features)
|
|
1430 (concat page-delimiter "\\|$")
|
|
1431 (concat "^$\\|" page-delimiter))
|
|
1432 paragraph-separate paragraph-start
|
|
1433 paragraph-ignore-fill-prefix t
|
|
1434 require-final-newline t
|
|
1435 parse-sexp-ignore-comments t
|
|
1436 indent-line-function 'c-indent-line
|
|
1437 indent-region-function 'c-indent-region
|
|
1438 outline-regexp "[^#\n\^M]"
|
|
1439 outline-level 'c-outline-level
|
|
1440 comment-column 32
|
|
1441 comment-start-skip "/\\*+ *\\|// *"
|
|
1442 adaptive-fill-regexp nil)
|
|
1443 ;; we have to do something special for c-offsets-alist so that the
|
|
1444 ;; buffer local value has its own alist structure.
|
|
1445 (setq c-offsets-alist (copy-alist c-offsets-alist))
|
|
1446 ;; setup the comment indent variable in a Emacs version portable way
|
|
1447 ;; ignore any byte compiler warnings you might get here
|
|
1448 (if (boundp 'comment-indent-function)
|
|
1449 (progn
|
|
1450 (make-local-variable 'comment-indent-function)
|
|
1451 (setq comment-indent-function 'c-comment-indent))
|
|
1452 (make-local-variable 'comment-indent-hook)
|
|
1453 (setq comment-indent-hook 'c-comment-indent))
|
|
1454 ;; Put C menu into menubar and on popup menu for XEmacs 19. I think
|
|
1455 ;; this happens automatically for Emacs 19.
|
|
1456 (if (and (boundp 'current-menubar)
|
|
1457 current-menubar
|
|
1458 (not (assoc mode-name current-menubar)))
|
|
1459 ;; its possible that this buffer has changed modes from one of
|
|
1460 ;; the other cc-mode modes. In that case, only the menubar
|
|
1461 ;; title of the menu changes.
|
|
1462 (let ((modes (copy-sequence c-list-of-mode-names))
|
|
1463 changed-p)
|
|
1464 (setq modes (delete major-mode modes))
|
|
1465 (while modes
|
|
1466 (if (not (assoc (car modes) current-menubar))
|
|
1467 (setq modes (cdr modes))
|
|
1468 (relabel-menu-item (list (car modes)) mode-name)
|
|
1469 (setq modes nil
|
|
1470 changed-p t)))
|
|
1471 (if (not changed-p)
|
|
1472 (progn
|
|
1473 (set-buffer-menubar (copy-sequence current-menubar))
|
|
1474 (add-menu nil mode-name c-mode-menu)))))
|
|
1475 (if (boundp 'mode-popup-menu)
|
|
1476 (setq mode-popup-menu
|
|
1477 (cons (concat mode-name " Mode Commands") c-mode-menu)))
|
|
1478 ;; put auto-hungry designators onto minor-mode-alist, but only once
|
|
1479 (or (assq 'c-auto-hungry-string minor-mode-alist)
|
|
1480 (setq minor-mode-alist
|
|
1481 (cons '(c-auto-hungry-string c-auto-hungry-string)
|
|
1482 minor-mode-alist))))
|
|
1483
|
|
1484 (defun c-postprocess-file-styles ()
|
|
1485 "Function that post processes relevant file local variables.
|
|
1486 Currently, this function simply applies any style and offset settings
|
|
1487 found in the file's Local Variable list. It first applies any style
|
|
1488 setting found in `c-file-style', then it applies any offset settings
|
|
1489 it finds in `c-file-offsets'."
|
|
1490 ;; apply file styles and offsets
|
|
1491 (and c-file-style
|
|
1492 (c-set-style c-file-style))
|
|
1493 (and c-file-offsets
|
|
1494 (mapcar
|
|
1495 (function
|
|
1496 (lambda (langentry)
|
|
1497 (let ((langelem (car langentry))
|
|
1498 (offset (cdr langentry)))
|
|
1499 (c-set-offset langelem offset)
|
|
1500 )))
|
|
1501 c-file-offsets)))
|
|
1502
|
|
1503 ;; Add the postprocessing function to hack-local-variables-hook. As
|
|
1504 ;; of 28-Aug-1995, XEmacs 19.12 and Emacs 19.29 support this.
|
|
1505 (and (fboundp 'add-hook)
|
|
1506 (add-hook 'hack-local-variables-hook 'c-postprocess-file-styles))
|
|
1507
|
|
1508 (defun c-enable-//-in-c-mode ()
|
|
1509 "Enables // as a comment delimiter in `c-mode'.
|
|
1510 ANSI C currently does *not* allow this, although many C compilers
|
|
1511 support optional C++ style comments. To use, call this function from
|
|
1512 your `.emacs' file before you visit any C files. The changes are
|
|
1513 global and affect all future `c-mode' buffers."
|
|
1514 (c-setup-dual-comments c-mode-syntax-table)
|
|
1515 (setq-default c-C-comment-start-regexp c-C++-comment-start-regexp))
|
|
1516
|
|
1517
|
|
1518 ;; macros must be defined before first use
|
|
1519 (defmacro c-point (position)
|
|
1520 ;; Returns the value of point at certain commonly referenced POSITIONs.
|
|
1521 ;; POSITION can be one of the following symbols:
|
|
1522 ;;
|
|
1523 ;; bol -- beginning of line
|
|
1524 ;; eol -- end of line
|
|
1525 ;; bod -- beginning of defun
|
|
1526 ;; boi -- back to indentation
|
|
1527 ;; ionl -- indentation of next line
|
|
1528 ;; iopl -- indentation of previous line
|
|
1529 ;; bonl -- beginning of next line
|
|
1530 ;; bopl -- beginning of previous line
|
|
1531 ;;
|
|
1532 ;; This function does not modify point or mark.
|
|
1533 (or (and (eq 'quote (car-safe position))
|
|
1534 (null (cdr (cdr position))))
|
|
1535 (error "bad buffer position requested: %s" position))
|
|
1536 (setq position (nth 1 position))
|
|
1537 (` (let ((here (point)))
|
|
1538 (,@ (cond
|
|
1539 ((eq position 'bol) '((beginning-of-line)))
|
|
1540 ((eq position 'eol) '((end-of-line)))
|
|
1541 ((eq position 'bod)
|
|
1542 '((beginning-of-defun)
|
|
1543 ;; if defun-prompt-regexp is non-nil, b-o-d won't leave
|
|
1544 ;; us at the open brace.
|
|
1545 (and (boundp 'defun-prompt-regexp)
|
|
1546 defun-prompt-regexp
|
|
1547 (looking-at defun-prompt-regexp)
|
|
1548 (goto-char (match-end 0)))
|
|
1549 ))
|
|
1550 ((eq position 'boi) '((back-to-indentation)))
|
|
1551 ((eq position 'bonl) '((forward-line 1)))
|
|
1552 ((eq position 'bopl) '((forward-line -1)))
|
|
1553 ((eq position 'iopl)
|
|
1554 '((forward-line -1)
|
|
1555 (back-to-indentation)))
|
|
1556 ((eq position 'ionl)
|
|
1557 '((forward-line 1)
|
|
1558 (back-to-indentation)))
|
|
1559 (t (error "unknown buffer position requested: %s" position))
|
|
1560 ))
|
|
1561 (prog1
|
|
1562 (point)
|
|
1563 (goto-char here))
|
|
1564 ;; workaround for an Emacs18 bug -- blech! Well, at least it
|
|
1565 ;; doesn't hurt for v19
|
|
1566 (,@ nil)
|
|
1567 )))
|
|
1568
|
|
1569 (defmacro c-auto-newline ()
|
|
1570 ;; if auto-newline feature is turned on, insert a newline character
|
|
1571 ;; and return t, otherwise return nil.
|
|
1572 (` (and c-auto-newline
|
|
1573 (not (c-in-literal))
|
|
1574 (not (newline)))))
|
|
1575
|
|
1576 (defmacro c-safe (&rest body)
|
|
1577 ;; safely execute BODY, return nil if an error occurred
|
|
1578 (` (condition-case nil
|
|
1579 (progn (,@ body))
|
|
1580 (error nil))))
|
|
1581
|
|
1582 (defun c-insert-special-chars (arg)
|
|
1583 ;; simply call self-insert-command in Emacs 19
|
|
1584 (self-insert-command (prefix-numeric-value arg)))
|
|
1585
|
|
1586 (defun c-intersect-lists (list alist)
|
|
1587 ;; return the element of ALIST that matches the first element found
|
|
1588 ;; in LIST. Uses assq.
|
|
1589 (let (match)
|
|
1590 (while (and list
|
|
1591 (not (setq match (assq (car list) alist))))
|
|
1592 (setq list (cdr list)))
|
|
1593 match))
|
|
1594
|
|
1595 (defun c-lookup-lists (list alist1 alist2)
|
|
1596 ;; first, find the first entry from LIST that is present in ALIST1,
|
|
1597 ;; then find the entry in ALIST2 for that entry.
|
|
1598 (assq (car (c-intersect-lists list alist1)) alist2))
|
|
1599
|
|
1600
|
|
1601 ;; This is used by indent-for-comment to decide how much to indent a
|
|
1602 ;; comment in C code based on its context.
|
|
1603 (defun c-comment-indent ()
|
|
1604 (if (looking-at (concat "^\\(" c-comment-start-regexp "\\)"))
|
|
1605 0 ;Existing comment at bol stays there.
|
|
1606 (let ((opoint (point))
|
|
1607 placeholder)
|
|
1608 (save-excursion
|
|
1609 (beginning-of-line)
|
|
1610 (cond
|
|
1611 ;; CASE 1: A comment following a solitary close-brace should
|
|
1612 ;; have only one space.
|
|
1613 ((looking-at (concat "[ \t]*}[ \t]*\\($\\|"
|
|
1614 c-comment-start-regexp
|
|
1615 "\\)"))
|
|
1616 (search-forward "}")
|
|
1617 (1+ (current-column)))
|
|
1618 ;; CASE 2: 2 spaces after #endif
|
|
1619 ((or (looking-at "^#[ \t]*endif[ \t]*")
|
|
1620 (looking-at "^#[ \t]*else[ \t]*"))
|
|
1621 7)
|
|
1622 ;; CASE 3: when comment-column is nil, calculate the offset
|
|
1623 ;; according to c-offsets-alist. E.g. identical to hitting
|
|
1624 ;; TAB.
|
|
1625 ((and c-indent-comments-syntactically-p
|
|
1626 (save-excursion
|
|
1627 (skip-chars-forward " \t")
|
|
1628 (or (looking-at comment-start)
|
|
1629 (eolp))))
|
|
1630 (let ((syntax (c-guess-basic-syntax)))
|
|
1631 ;; BOGOSITY ALERT: if we're looking at the eol, its
|
|
1632 ;; because indent-for-comment hasn't put the comment-start
|
|
1633 ;; in the buffer yet. this will screw up the syntactic
|
|
1634 ;; analysis so we kludge in the necessary info. Another
|
|
1635 ;; kludge is that if we're at the bol, then we really want
|
|
1636 ;; to ignore any anchoring as specified by
|
|
1637 ;; c-comment-only-line-offset since it doesn't apply here.
|
|
1638 (if (save-excursion
|
|
1639 (beginning-of-line)
|
|
1640 (skip-chars-forward " \t")
|
|
1641 (eolp))
|
|
1642 (c-add-syntax 'comment-intro))
|
|
1643 (let ((c-comment-only-line-offset
|
|
1644 (if (consp c-comment-only-line-offset)
|
|
1645 c-comment-only-line-offset
|
|
1646 (cons c-comment-only-line-offset
|
|
1647 c-comment-only-line-offset))))
|
|
1648 (apply '+ (mapcar 'c-get-offset syntax)))))
|
|
1649 ;; CASE 4: use comment-column if previous line is a
|
|
1650 ;; comment-only line indented to the left of comment-column
|
|
1651 ((save-excursion
|
|
1652 (beginning-of-line)
|
|
1653 (and (not (bobp))
|
|
1654 (forward-line -1))
|
|
1655 (skip-chars-forward " \t")
|
|
1656 (prog1
|
|
1657 (looking-at c-comment-start-regexp)
|
|
1658 (setq placeholder (point))))
|
|
1659 (goto-char placeholder)
|
|
1660 (if (< (current-column) comment-column)
|
|
1661 comment-column
|
|
1662 (current-column)))
|
|
1663 ;; CASE 5: If comment-column is 0, and nothing but space
|
|
1664 ;; before the comment, align it at 0 rather than 1.
|
|
1665 ((progn
|
|
1666 (goto-char opoint)
|
|
1667 (skip-chars-backward " \t")
|
|
1668 (and (= comment-column 0) (bolp)))
|
|
1669 0)
|
|
1670 ;; CASE 6: indent at comment column except leave at least one
|
|
1671 ;; space.
|
|
1672 (t (max (1+ (current-column))
|
|
1673 comment-column))
|
|
1674 )))))
|
|
1675
|
|
1676 ;; used by outline-minor-mode
|
|
1677 (defun c-outline-level ()
|
|
1678 (save-excursion
|
|
1679 (skip-chars-forward "\t ")
|
|
1680 (current-column)))
|
|
1681
|
|
1682 ;; active regions, and auto-newline/hungry delete key
|
|
1683 (defun c-keep-region-active ()
|
|
1684 ;; Do whatever is necessary to keep the region active in
|
|
1685 ;; XEmacs 19. ignore byte-compiler warnings you might see
|
|
1686 (and (boundp 'zmacs-region-stays)
|
|
1687 (setq zmacs-region-stays t)))
|
|
1688
|
|
1689 (defun c-update-modeline ()
|
|
1690 ;; set the c-auto-hungry-string for the correct designation on the modeline
|
|
1691 (setq c-auto-hungry-string
|
|
1692 (if c-auto-newline
|
|
1693 (if c-hungry-delete-key "/ah" "/a")
|
|
1694 (if c-hungry-delete-key "/h" nil)))
|
|
1695 ;; updates the modeline for all Emacsen
|
2
|
1696 (if (or (memq 'v19 c-emacs-features) (memq 'v20 c-emacs-features))
|
0
|
1697 (force-mode-line-update)
|
|
1698 (set-buffer-modified-p (buffer-modified-p))))
|
|
1699
|
|
1700 (defun c-calculate-state (arg prevstate)
|
|
1701 ;; Calculate the new state of PREVSTATE, t or nil, based on arg. If
|
|
1702 ;; arg is nil or zero, toggle the state. If arg is negative, turn
|
|
1703 ;; the state off, and if arg is positive, turn the state on
|
|
1704 (if (or (not arg)
|
|
1705 (zerop (setq arg (prefix-numeric-value arg))))
|
|
1706 (not prevstate)
|
|
1707 (> arg 0)))
|
|
1708
|
|
1709 (defun c-toggle-auto-state (arg)
|
|
1710 "Toggle auto-newline feature.
|
|
1711 Optional numeric ARG, if supplied turns on auto-newline when positive,
|
|
1712 turns it off when negative, and just toggles it when zero.
|
|
1713
|
|
1714 When the auto-newline feature is enabled (as evidenced by the `/a' or
|
|
1715 `/ah' on the modeline after the mode name) newlines are automatically
|
|
1716 inserted after special characters such as brace, comma, semi-colon,
|
|
1717 and colon."
|
|
1718 (interactive "P")
|
|
1719 (setq c-auto-newline (c-calculate-state arg c-auto-newline))
|
|
1720 (c-update-modeline)
|
|
1721 (c-keep-region-active))
|
|
1722
|
|
1723 (defun c-toggle-hungry-state (arg)
|
|
1724 "Toggle hungry-delete-key feature.
|
|
1725 Optional numeric ARG, if supplied turns on hungry-delete when positive,
|
|
1726 turns it off when negative, and just toggles it when zero.
|
|
1727
|
|
1728 When the hungry-delete-key feature is enabled (as evidenced by the
|
|
1729 `/h' or `/ah' on the modeline after the mode name) the delete key
|
|
1730 gobbles all preceding whitespace in one fell swoop."
|
|
1731 (interactive "P")
|
|
1732 (setq c-hungry-delete-key (c-calculate-state arg c-hungry-delete-key))
|
|
1733 (c-update-modeline)
|
|
1734 (c-keep-region-active))
|
|
1735
|
|
1736 (defun c-toggle-auto-hungry-state (arg)
|
|
1737 "Toggle auto-newline and hungry-delete-key features.
|
|
1738 Optional numeric ARG, if supplied turns on auto-newline and
|
|
1739 hungry-delete when positive, turns them off when negative, and just
|
|
1740 toggles them when zero.
|
|
1741
|
|
1742 See `c-toggle-auto-state' and `c-toggle-hungry-state' for details."
|
|
1743 (interactive "P")
|
|
1744 (setq c-auto-newline (c-calculate-state arg c-auto-newline))
|
|
1745 (setq c-hungry-delete-key (c-calculate-state arg c-hungry-delete-key))
|
|
1746 (c-update-modeline)
|
|
1747 (c-keep-region-active))
|
|
1748
|
|
1749
|
|
1750 ;; COMMANDS
|
|
1751 (defun c-electric-delete (arg)
|
|
1752 "Deletes preceding character or whitespace.
|
|
1753 If `c-hungry-delete-key' is non-nil, as evidenced by the \"/h\" or
|
|
1754 \"/ah\" string on the mode line, then all preceding whitespace is
|
|
1755 consumed. If however an ARG is supplied, or `c-hungry-delete-key' is
|
|
1756 nil, or point is inside a literal then the function in the variable
|
|
1757 `c-delete-function' is called."
|
|
1758 (interactive "P")
|
|
1759 (if (or (not c-hungry-delete-key)
|
|
1760 arg
|
|
1761 (c-in-literal))
|
|
1762 (funcall c-delete-function (prefix-numeric-value arg))
|
|
1763 (let ((here (point)))
|
|
1764 (skip-chars-backward " \t\n")
|
|
1765 (if (/= (point) here)
|
|
1766 (delete-region (point) here)
|
|
1767 (funcall c-delete-function 1)
|
|
1768 ))))
|
|
1769
|
|
1770 (defun c-electric-pound (arg)
|
|
1771 "Electric pound (`#') insertion.
|
|
1772 Inserts a `#' character specially depending on the variable
|
|
1773 `c-electric-pound-behavior'. If a numeric ARG is supplied, or if
|
|
1774 point is inside a literal, nothing special happens."
|
|
1775 (interactive "P")
|
|
1776 (if (or (c-in-literal)
|
|
1777 arg
|
|
1778 (not (memq 'alignleft c-electric-pound-behavior)))
|
|
1779 ;; do nothing special
|
|
1780 (self-insert-command (prefix-numeric-value arg))
|
|
1781 ;; place the pound character at the left edge
|
|
1782 (let ((pos (- (point-max) (point)))
|
|
1783 (bolp (bolp)))
|
|
1784 (beginning-of-line)
|
|
1785 (delete-horizontal-space)
|
|
1786 (insert-char last-command-char 1)
|
|
1787 (and (not bolp)
|
|
1788 (goto-char (- (point-max) pos)))
|
|
1789 )))
|
|
1790
|
|
1791 (defun c-electric-brace (arg)
|
|
1792 "Insert a brace.
|
|
1793
|
|
1794 If the auto-newline feature is turned on, as evidenced by the \"/a\"
|
|
1795 or \"/ah\" string on the mode line, newlines are inserted before and
|
|
1796 after braces based on the value of `c-hanging-braces-alist'.
|
|
1797
|
|
1798 Also, the line is re-indented unless a numeric ARG is supplied, there
|
|
1799 are non-whitespace characters present on the line after the brace, or
|
|
1800 the brace is inserted inside a literal."
|
|
1801 (interactive "P")
|
|
1802 (let* ((c-state-cache (c-parse-state))
|
|
1803 (safepos (c-safe-position (point) c-state-cache))
|
|
1804 (literal (c-in-literal safepos)))
|
|
1805 ;; if we're in a literal, or we're not at the end of the line, or
|
|
1806 ;; a numeric arg is provided, or auto-newlining is turned off,
|
|
1807 ;; then just insert the character.
|
|
1808 (if (or literal arg
|
|
1809 ; (not c-auto-newline)
|
|
1810 (not (looking-at "[ \t]*$")))
|
|
1811 (c-insert-special-chars arg)
|
|
1812 (let* ((syms '(class-open class-close defun-open defun-close
|
|
1813 inline-open inline-close brace-list-open brace-list-close
|
|
1814 brace-list-intro brace-list-entry block-open block-close
|
2
|
1815 substatement-open statement-case-open
|
|
1816 extern-lang-open extern-lang-close))
|
0
|
1817 ;; we want to inhibit blinking the paren since this will
|
|
1818 ;; be most disruptive. we'll blink it ourselves later on
|
|
1819 (old-blink-paren (if (boundp 'blink-paren-function)
|
|
1820 blink-paren-function
|
|
1821 blink-paren-hook))
|
|
1822 blink-paren-function ; emacs19
|
|
1823 blink-paren-hook ; emacs18
|
|
1824 (insertion-point (point))
|
|
1825 delete-temp-newline
|
|
1826 (preserve-p (= 32 (char-syntax (preceding-char))))
|
|
1827 ;; shut this up too
|
|
1828 (c-echo-syntactic-information-p nil)
|
|
1829 (syntax (progn
|
|
1830 ;; only insert a newline if there is
|
|
1831 ;; non-whitespace behind us
|
|
1832 (if (save-excursion
|
|
1833 (skip-chars-backward " \t")
|
|
1834 (not (bolp)))
|
|
1835 (progn (newline)
|
|
1836 (setq delete-temp-newline t)))
|
|
1837 (self-insert-command (prefix-numeric-value arg))
|
|
1838 ;; state cache doesn't change
|
|
1839 (c-guess-basic-syntax)))
|
|
1840 (newlines (and
|
|
1841 c-auto-newline
|
|
1842 (or (c-lookup-lists syms syntax c-hanging-braces-alist)
|
|
1843 '(ignore before after)))))
|
|
1844 ;; If syntax is a function symbol, then call it using the
|
|
1845 ;; defined semantics.
|
|
1846 (if (and (not (consp (cdr newlines)))
|
2
|
1847 (c-functionp (cdr newlines)))
|
0
|
1848 (let ((c-syntactic-context syntax))
|
|
1849 (setq newlines
|
|
1850 (funcall (cdr newlines) (car newlines) insertion-point))))
|
|
1851 ;; does a newline go before the open brace?
|
|
1852 (if (memq 'before newlines)
|
|
1853 ;; we leave the newline we've put in there before,
|
|
1854 ;; but we need to re-indent the line above
|
|
1855 (let ((pos (- (point-max) (point)))
|
|
1856 (here (point))
|
|
1857 (c-state-cache c-state-cache))
|
|
1858 (forward-line -1)
|
|
1859 ;; we may need to update the cache. this should still be
|
|
1860 ;; faster than recalculating the state in many cases
|
|
1861 (save-excursion
|
|
1862 (save-restriction
|
|
1863 (narrow-to-region here (point))
|
|
1864 (if (and (c-safe (progn (backward-up-list -1) t))
|
|
1865 (memq (preceding-char) '(?\) ?}))
|
|
1866 (progn (widen)
|
|
1867 (c-safe (progn (forward-sexp -1) t))))
|
|
1868 (setq c-state-cache
|
|
1869 (c-hack-state (point) 'open c-state-cache))
|
|
1870 (if (and (car c-state-cache)
|
|
1871 (not (consp (car c-state-cache)))
|
|
1872 (<= (point) (car c-state-cache)))
|
|
1873 (setq c-state-cache (cdr c-state-cache))
|
|
1874 ))))
|
|
1875 (let ((here (point))
|
|
1876 (shift (c-indent-line)))
|
|
1877 (setq c-state-cache (c-adjust-state (c-point 'bol) here
|
|
1878 (- shift) c-state-cache)))
|
|
1879 (goto-char (- (point-max) pos))
|
|
1880 ;; if the buffer has changed due to the indentation, we
|
|
1881 ;; need to recalculate syntax for the current line, but
|
|
1882 ;; we won't need to update the state cache.
|
|
1883 (if (/= (point) here)
|
|
1884 (setq syntax (c-guess-basic-syntax))))
|
|
1885 ;; must remove the newline we just stuck in (if we really did it)
|
|
1886 (and delete-temp-newline
|
|
1887 (save-excursion
|
|
1888 ;; if there is whitespace before point, then preserve
|
|
1889 ;; at least one space.
|
|
1890 (delete-indentation)
|
|
1891 (just-one-space)
|
|
1892 (if (not preserve-p)
|
|
1893 (delete-char -1))))
|
|
1894 ;; since we're hanging the brace, we need to recalculate
|
|
1895 ;; syntax. Update the state to accurately reflect the
|
|
1896 ;; beginning of the line. We punt if we cross any open or
|
|
1897 ;; closed parens because its just too hard to modify the
|
|
1898 ;; known state. This limitation will be fixed in v5.
|
|
1899 (save-excursion
|
|
1900 (let ((bol (c-point 'bol)))
|
|
1901 (if (zerop (car (parse-partial-sexp bol (1- (point)))))
|
|
1902 (setq c-state-cache (c-whack-state bol c-state-cache)
|
|
1903 syntax (c-guess-basic-syntax))
|
|
1904 ;; gotta punt. this requires some horrible kludgery
|
|
1905 (beginning-of-line)
|
|
1906 (makunbound 'c-state-cache)
|
|
1907 (setq c-state-cache (c-parse-state)
|
|
1908 syntax nil))))
|
|
1909 )
|
|
1910 ;; now adjust the line's indentation. don't update the state
|
|
1911 ;; cache since c-guess-basic-syntax isn't called when the
|
|
1912 ;; syntax is passed to c-indent-line
|
|
1913 (let ((here (point))
|
|
1914 (shift (c-indent-line syntax)))
|
|
1915 (setq c-state-cache (c-adjust-state (c-point 'bol) here
|
|
1916 (- shift) c-state-cache)))
|
|
1917 ;; Do all appropriate clean ups
|
|
1918 (let ((here (point))
|
|
1919 (pos (- (point-max) (point)))
|
|
1920 mbeg mend)
|
|
1921 ;; clean up empty defun braces
|
|
1922 (if (and c-auto-newline
|
|
1923 (memq 'empty-defun-braces c-cleanup-list)
|
|
1924 (= last-command-char ?\})
|
|
1925 (c-intersect-lists '(defun-close class-close inline-close)
|
|
1926 syntax)
|
|
1927 (progn
|
|
1928 (forward-char -1)
|
|
1929 (skip-chars-backward " \t\n")
|
|
1930 (= (preceding-char) ?\{))
|
|
1931 ;; make sure matching open brace isn't in a comment
|
|
1932 (not (c-in-literal)))
|
|
1933 (delete-region (point) (1- here)))
|
|
1934 ;; clean up brace-else-brace
|
|
1935 (if (and c-auto-newline
|
|
1936 (memq 'brace-else-brace c-cleanup-list)
|
|
1937 (= last-command-char ?\{)
|
|
1938 (re-search-backward "}[ \t\n]*else[ \t\n]*{" nil t)
|
|
1939 (progn
|
|
1940 (setq mbeg (match-beginning 0)
|
|
1941 mend (match-end 0))
|
|
1942 (= mend here))
|
|
1943 (not (c-in-literal)))
|
|
1944 (progn
|
|
1945 (delete-region mbeg mend)
|
|
1946 (insert "} else {")))
|
|
1947 (goto-char (- (point-max) pos))
|
|
1948 )
|
|
1949 ;; does a newline go after the brace?
|
|
1950 (if (memq 'after newlines)
|
|
1951 (progn
|
|
1952 (newline)
|
|
1953 ;; update on c-state-cache
|
|
1954 (let* ((bufpos (- (point) 2))
|
|
1955 (which (if (= (char-after bufpos) ?{) 'open 'close))
|
|
1956 (c-state-cache (c-hack-state bufpos which c-state-cache)))
|
|
1957 (c-indent-line))))
|
|
1958 ;; blink the paren
|
|
1959 (and (= last-command-char ?\})
|
|
1960 old-blink-paren
|
|
1961 (save-excursion
|
|
1962 (c-backward-syntactic-ws safepos)
|
|
1963 (if (boundp 'blink-paren-function)
|
|
1964 (funcall old-blink-paren)
|
|
1965 (run-hooks old-blink-paren))))
|
|
1966 ))))
|
|
1967
|
|
1968 (defun c-electric-slash (arg)
|
|
1969 "Insert a slash character.
|
|
1970 If slash is second of a double-slash C++ style comment introducing
|
|
1971 construct, and we are on a comment-only-line, indent line as comment.
|
|
1972 If numeric ARG is supplied or point is inside a literal, indentation
|
|
1973 is inhibited."
|
|
1974 (interactive "P")
|
|
1975 (let ((indentp (and (not arg)
|
|
1976 (= (preceding-char) ?/)
|
|
1977 (= last-command-char ?/)
|
|
1978 (not (c-in-literal))))
|
|
1979 ;; shut this up
|
|
1980 (c-echo-syntactic-information-p nil))
|
|
1981 (self-insert-command (prefix-numeric-value arg))
|
|
1982 (if indentp
|
|
1983 (c-indent-line))))
|
|
1984
|
|
1985 (defun c-electric-star (arg)
|
|
1986 "Insert a star character.
|
|
1987 If the star is the second character of a C style comment introducing
|
|
1988 construct, and we are on a comment-only-line, indent line as comment.
|
|
1989 If numeric ARG is supplied or point is inside a literal, indentation
|
|
1990 is inhibited."
|
|
1991 (interactive "P")
|
|
1992 (self-insert-command (prefix-numeric-value arg))
|
|
1993 ;; if we are in a literal, or if arg is given do not re-indent the
|
|
1994 ;; current line, unless this star introduces a comment-only line.
|
|
1995 (if (and (not arg)
|
|
1996 (memq (c-in-literal) '(c))
|
|
1997 (= (preceding-char) ?*)
|
|
1998 (save-excursion
|
|
1999 (forward-char -1)
|
|
2000 (skip-chars-backward "*")
|
|
2001 (if (= (preceding-char) ?/)
|
|
2002 (forward-char -1))
|
|
2003 (skip-chars-backward " \t")
|
|
2004 (bolp)))
|
|
2005 ;; shut this up
|
|
2006 (let (c-echo-syntactic-information-p)
|
|
2007 (c-indent-line))
|
|
2008 ))
|
|
2009
|
|
2010 (defun c-electric-semi&comma (arg)
|
|
2011 "Insert a comma or semicolon.
|
|
2012 When the auto-newline feature is turned on, as evidenced by the \"/a\"
|
|
2013 or \"/ah\" string on the mode line, a newline might be inserted. See
|
|
2014 the variable `c-hanging-semi&comma-criteria' for how newline insertion
|
|
2015 is determined.
|
|
2016
|
|
2017 When semicolon is inserted, the line is re-indented unless a numeric
|
|
2018 arg is supplied, point is inside a literal, or there are
|
|
2019 non-whitespace characters on the line following the semicolon."
|
|
2020 (interactive "P")
|
|
2021 (let* ((lim (c-most-enclosing-brace (c-parse-state)))
|
|
2022 (literal (c-in-literal lim))
|
|
2023 (here (point))
|
|
2024 ;; shut this up
|
|
2025 (c-echo-syntactic-information-p nil))
|
|
2026 (if (or literal
|
|
2027 arg
|
|
2028 (not (looking-at "[ \t]*$")))
|
|
2029 (c-insert-special-chars arg)
|
|
2030 ;; do some special stuff with the character
|
|
2031 (self-insert-command (prefix-numeric-value arg))
|
|
2032 ;; do all cleanups, reindentations, and newline insertions, but
|
|
2033 ;; only if c-auto-newline is turned on
|
|
2034 (if (not c-auto-newline) nil
|
|
2035 ;; clean ups
|
|
2036 (let ((pos (- (point-max) (point))))
|
|
2037 (if (and (or (and
|
|
2038 (= last-command-char ?,)
|
|
2039 (memq 'list-close-comma c-cleanup-list))
|
|
2040 (and
|
|
2041 (= last-command-char ?\;)
|
|
2042 (memq 'defun-close-semi c-cleanup-list)))
|
|
2043 (progn
|
|
2044 (forward-char -1)
|
|
2045 (skip-chars-backward " \t\n")
|
|
2046 (= (preceding-char) ?}))
|
|
2047 ;; make sure matching open brace isn't in a comment
|
|
2048 (not (c-in-literal lim)))
|
|
2049 (delete-region (point) here))
|
|
2050 (goto-char (- (point-max) pos)))
|
|
2051 ;; re-indent line
|
|
2052 (c-indent-line)
|
|
2053 ;; check to see if a newline should be added
|
|
2054 (let ((criteria c-hanging-semi&comma-criteria)
|
|
2055 answer add-newline-p)
|
|
2056 (while criteria
|
|
2057 (setq answer (funcall (car criteria)))
|
|
2058 ;; only nil value means continue checking
|
|
2059 (if (not answer)
|
|
2060 (setq criteria (cdr criteria))
|
|
2061 (setq criteria nil)
|
|
2062 ;; only 'stop specifically says do not add a newline
|
|
2063 (setq add-newline-p (not (eq answer 'stop)))
|
|
2064 ))
|
|
2065 (if add-newline-p
|
|
2066 (progn (newline)
|
|
2067 (c-indent-line)))
|
|
2068 )))))
|
|
2069
|
|
2070 (defun c-semi&comma-inside-parenlist ()
|
|
2071 "Determine if a newline should be added after a semicolon.
|
|
2072 If a comma was inserted, no determination is made. If a semicolon was
|
|
2073 inserted inside a parenthesis list, no newline is added otherwise a
|
|
2074 newline is added. In either case, checking is stopped. This supports
|
|
2075 exactly the old newline insertion behavior."
|
|
2076 ;; newline only after semicolon, but only if that semicolon is not
|
|
2077 ;; inside a parenthesis list (e.g. a for loop statement)
|
|
2078 (if (/= last-command-char ?\;)
|
|
2079 nil ; continue checking
|
|
2080 (if (condition-case nil
|
|
2081 (save-excursion
|
|
2082 (up-list -1)
|
|
2083 (/= (following-char) ?\())
|
|
2084 (error t))
|
|
2085 t
|
|
2086 'stop)))
|
|
2087
|
|
2088 (defun c-electric-colon (arg)
|
|
2089 "Insert a colon.
|
|
2090
|
|
2091 If the auto-newline feature is turned on, as evidenced by the \"/a\"
|
|
2092 or \"/ah\" string on the mode line, newlines are inserted before and
|
|
2093 after colons based on the value of `c-hanging-colons-alist'.
|
|
2094
|
|
2095 Also, the line is re-indented unless a numeric ARG is supplied, there
|
|
2096 are non-whitespace characters present on the line after the colon, or
|
|
2097 the colon is inserted inside a literal.
|
|
2098
|
|
2099 This function cleans up double colon scope operators based on the
|
|
2100 value of `c-cleanup-list'."
|
|
2101 (interactive "P")
|
|
2102 (let* ((bod (c-point 'bod))
|
|
2103 (literal (c-in-literal bod))
|
|
2104 syntax newlines
|
|
2105 ;; shut this up
|
|
2106 (c-echo-syntactic-information-p nil))
|
|
2107 (if (or literal
|
|
2108 arg
|
|
2109 (not (looking-at "[ \t]*$")))
|
|
2110 (c-insert-special-chars arg)
|
|
2111 ;; insert the colon, then do any specified cleanups
|
|
2112 (self-insert-command (prefix-numeric-value arg))
|
|
2113 (let ((pos (- (point-max) (point)))
|
|
2114 (here (point)))
|
|
2115 (if (and c-auto-newline
|
|
2116 (memq 'scope-operator c-cleanup-list)
|
|
2117 (= (preceding-char) ?:)
|
|
2118 (progn
|
|
2119 (forward-char -1)
|
|
2120 (skip-chars-backward " \t\n")
|
|
2121 (= (preceding-char) ?:))
|
|
2122 (not (c-in-literal))
|
|
2123 (not (= (char-after (- (point) 2)) ?:)))
|
|
2124 (delete-region (point) (1- here)))
|
|
2125 (goto-char (- (point-max) pos)))
|
|
2126 ;; lets do some special stuff with the colon character
|
|
2127 (setq syntax (c-guess-basic-syntax)
|
|
2128 ;; some language elements can only be determined by
|
|
2129 ;; checking the following line. Lets first look for ones
|
|
2130 ;; that can be found when looking on the line with the
|
|
2131 ;; colon
|
|
2132 newlines
|
|
2133 (and c-auto-newline
|
|
2134 (or (c-lookup-lists '(case-label label access-label)
|
|
2135 syntax c-hanging-colons-alist)
|
|
2136 (c-lookup-lists '(member-init-intro inher-intro)
|
|
2137 (prog2
|
|
2138 (insert "\n")
|
|
2139 (c-guess-basic-syntax)
|
|
2140 (delete-char -1))
|
|
2141 c-hanging-colons-alist))))
|
|
2142 ;; indent the current line
|
|
2143 (c-indent-line syntax)
|
|
2144 ;; does a newline go before the colon? Watch out for already
|
|
2145 ;; non-hung colons. However, we don't unhang them because that
|
|
2146 ;; would be a cleanup (and anti-social).
|
|
2147 (if (and (memq 'before newlines)
|
|
2148 (save-excursion
|
|
2149 (skip-chars-backward ": \t")
|
|
2150 (not (bolp))))
|
|
2151 (let ((pos (- (point-max) (point))))
|
|
2152 (forward-char -1)
|
|
2153 (newline)
|
|
2154 (c-indent-line)
|
|
2155 (goto-char (- (point-max) pos))))
|
|
2156 ;; does a newline go after the colon?
|
|
2157 (if (memq 'after (cdr-safe newlines))
|
|
2158 (progn
|
|
2159 (newline)
|
|
2160 (c-indent-line)))
|
|
2161 )))
|
|
2162
|
|
2163 (defun c-electric-lt-gt (arg)
|
|
2164 "Insert a less-than, or greater-than character.
|
|
2165 When the auto-newline feature is turned on, as evidenced by the \"/a\"
|
|
2166 or \"/ah\" string on the mode line, the line will be re-indented if
|
|
2167 the character inserted is the second of a C++ style stream operator
|
|
2168 and the buffer is in C++ mode.
|
|
2169
|
|
2170 The line will also not be re-indented if a numeric argument is
|
|
2171 supplied, or point is inside a literal."
|
|
2172 (interactive "P")
|
|
2173 (let ((indentp (and (not arg)
|
|
2174 (= (preceding-char) last-command-char)
|
|
2175 (not (c-in-literal))))
|
|
2176 ;; shut this up
|
|
2177 (c-echo-syntactic-information-p nil))
|
|
2178 (self-insert-command (prefix-numeric-value arg))
|
|
2179 (if indentp
|
|
2180 (c-indent-line))))
|
|
2181
|
|
2182 ;; set up electric character functions to work with pending-del,
|
|
2183 ;; (a.k.a. delsel) mode. All symbols get the t value except
|
|
2184 ;; c-electric-delete which gets 'supersede.
|
|
2185 (mapcar
|
|
2186 (function
|
|
2187 (lambda (sym)
|
|
2188 (put sym 'delete-selection t) ; for delsel (Emacs)
|
|
2189 (put sym 'pending-delete t))) ; for pending-del (XEmacs)
|
|
2190 '(c-electric-pound
|
|
2191 c-electric-brace
|
|
2192 c-electric-slash
|
|
2193 c-electric-star
|
|
2194 c-electric-semi&comma
|
|
2195 c-electric-lt-gt
|
|
2196 c-electric-colon))
|
|
2197 (put 'c-electric-delete 'delete-selection 'supersede) ; delsel
|
|
2198 (put 'c-electric-delete 'pending-delete 'supersede) ; pending-del
|
|
2199
|
|
2200
|
|
2201
|
|
2202 (defun c-read-offset (langelem)
|
|
2203 ;; read new offset value for LANGELEM from minibuffer. return a
|
|
2204 ;; legal value only
|
|
2205 (let* ((oldoff (cdr-safe (assq langelem c-offsets-alist)))
|
|
2206 (defstr (format "(default %s): " oldoff))
|
|
2207 (errmsg (concat "Offset must be int, func, var, "
|
|
2208 "or in [+,-,++,--,*,/] "
|
|
2209 defstr))
|
|
2210 (prompt (concat "Offset " defstr))
|
2
|
2211 offset input interned raw)
|
0
|
2212 (while (not offset)
|
|
2213 (setq input (read-string prompt)
|
|
2214 offset (cond ((string-equal "" input) oldoff) ; default
|
|
2215 ((string-equal "+" input) '+)
|
|
2216 ((string-equal "-" input) '-)
|
|
2217 ((string-equal "++" input) '++)
|
|
2218 ((string-equal "--" input) '--)
|
|
2219 ((string-equal "*" input) '*)
|
|
2220 ((string-equal "/" input) '/)
|
|
2221 ((string-match "^-?[0-9]+$" input)
|
|
2222 (string-to-int input))
|
2
|
2223 ;; a symbol with a function binding
|
0
|
2224 ((fboundp (setq interned (intern input)))
|
|
2225 interned)
|
2
|
2226 ;; a lambda function
|
|
2227 ((condition-case nil
|
|
2228 (c-functionp (setq raw (read input)))
|
|
2229 (error nil))
|
|
2230 raw)
|
|
2231 ;; a symbol with variable binding
|
0
|
2232 ((boundp interned) interned)
|
|
2233 ;; error, but don't signal one, keep trying
|
|
2234 ;; to read an input value
|
|
2235 (t (ding)
|
|
2236 (setq prompt errmsg)
|
|
2237 nil))))
|
|
2238 offset))
|
|
2239
|
|
2240 (defun c-set-offset (symbol offset &optional add-p)
|
|
2241 "Change the value of a syntactic element symbol in `c-offsets-alist'.
|
|
2242 SYMBOL is the syntactic element symbol to change and OFFSET is the new
|
|
2243 offset for that syntactic element. Optional ADD says to add SYMBOL to
|
|
2244 `c-offsets-alist' if it doesn't already appear there."
|
|
2245 (interactive
|
|
2246 (let* ((langelem
|
|
2247 (intern (completing-read
|
|
2248 (concat "Syntactic symbol to change"
|
|
2249 (if current-prefix-arg " or add" "")
|
|
2250 ": ")
|
|
2251 (mapcar
|
|
2252 (function
|
|
2253 (lambda (langelem)
|
|
2254 (cons (format "%s" (car langelem)) nil)))
|
|
2255 c-offsets-alist)
|
|
2256 nil (not current-prefix-arg)
|
|
2257 ;; initial contents tries to be the last element
|
|
2258 ;; on the syntactic analysis list for the current
|
|
2259 ;; line
|
|
2260 (let* ((syntax (c-guess-basic-syntax))
|
|
2261 (len (length syntax))
|
|
2262 (ic (format "%s" (car (nth (1- len) syntax)))))
|
2
|
2263 (if (or (memq 'v19 c-emacs-features)
|
|
2264 (memq 'v20 c-emacs-features))
|
0
|
2265 (cons ic 0)
|
|
2266 ic))
|
|
2267 )))
|
|
2268 (offset (c-read-offset langelem)))
|
|
2269 (list langelem offset current-prefix-arg)))
|
|
2270 ;; sanity check offset
|
|
2271 (or (eq offset '+)
|
|
2272 (eq offset '-)
|
|
2273 (eq offset '++)
|
|
2274 (eq offset '--)
|
|
2275 (eq offset '*)
|
|
2276 (eq offset '/)
|
|
2277 (integerp offset)
|
2
|
2278 (c-functionp offset)
|
0
|
2279 (boundp offset)
|
|
2280 (error "Offset must be int, func, var, or in [+,-,++,--,*,/]: %s"
|
|
2281 offset))
|
|
2282 (let ((entry (assq symbol c-offsets-alist)))
|
|
2283 (if entry
|
|
2284 (setcdr entry offset)
|
|
2285 (if add-p
|
|
2286 (setq c-offsets-alist (cons (cons symbol offset) c-offsets-alist))
|
|
2287 (error "%s is not a valid syntactic symbol." symbol))))
|
|
2288 (c-keep-region-active))
|
|
2289
|
|
2290 (defun c-set-style-1 (stylevars)
|
|
2291 ;; given a style's variable alist, institute the style
|
|
2292 (mapcar
|
|
2293 (function
|
|
2294 (lambda (conscell)
|
|
2295 (let ((attr (car conscell))
|
|
2296 (val (cdr conscell)))
|
2
|
2297 (cond
|
|
2298 ((eq attr 'c-offsets-alist)
|
0
|
2299 (mapcar
|
|
2300 (function
|
|
2301 (lambda (langentry)
|
|
2302 (let ((langelem (car langentry))
|
|
2303 (offset (cdr langentry)))
|
|
2304 (c-set-offset langelem offset)
|
|
2305 )))
|
|
2306 val))
|
2
|
2307 ((eq attr 'c-special-indent-hook)
|
|
2308 (if (listp val)
|
|
2309 (while val
|
|
2310 (add-hook 'c-special-indent-hook (car val))
|
|
2311 (setq val (cdr val)))
|
|
2312 (add-hook 'c-special-indent-hook val)))
|
|
2313 (t (set attr val)))
|
0
|
2314 )))
|
|
2315 stylevars))
|
|
2316
|
|
2317 (defun c-set-style (stylename)
|
|
2318 "Set cc-mode variables to use one of several different indentation styles.
|
|
2319 STYLENAME is a string representing the desired style from the list of
|
|
2320 styles described in the variable `c-style-alist'. See that variable
|
|
2321 for details of setting up styles."
|
|
2322 (interactive (list (let ((completion-ignore-case t)
|
|
2323 (prompt (format "Which %s indentation style? "
|
|
2324 mode-name)))
|
|
2325 (completing-read prompt c-style-alist nil t))))
|
|
2326 (let ((vars (cdr (or (assoc (downcase stylename) c-style-alist)
|
|
2327 (assoc (upcase stylename) c-style-alist)
|
2
|
2328 (assoc stylename c-style-alist)
|
0
|
2329 )))
|
|
2330 (default (cdr (assoc "cc-mode" c-style-alist))))
|
|
2331 (or vars (error "Invalid indentation style `%s'" stylename))
|
|
2332 (or default (error "No `cc-mode' style found!"))
|
|
2333 ;; first reset the style to `cc-mode' to give every style a common
|
|
2334 ;; base. Then institute the new style.
|
|
2335 (c-set-style-1 default)
|
|
2336 (if (not (string= stylename "cc-mode"))
|
|
2337 (c-set-style-1 vars)))
|
|
2338 (c-keep-region-active))
|
|
2339
|
|
2340 (defun c-add-style (style descrip &optional set-p)
|
|
2341 "Adds a style to `c-style-alist', or updates an existing one.
|
|
2342 STYLE is a string identifying the style to add or update. DESCRIP is
|
|
2343 an association list describing the style and must be of the form:
|
|
2344
|
|
2345 ((VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
|
|
2346
|
|
2347 See the variable `c-style-alist' for the semantics of VARIABLE and
|
|
2348 VALUE. This function also sets the current style to STYLE using
|
|
2349 `c-set-style' if the optional SET-P flag is non-nil."
|
|
2350 (interactive
|
|
2351 (let ((stylename (completing-read "Style to add: " c-style-alist))
|
|
2352 (description (eval-minibuffer "Style description: ")))
|
|
2353 (list stylename description
|
|
2354 (y-or-n-p "Set the style too? "))))
|
|
2355 (setq style (downcase style))
|
|
2356 (let ((s (assoc style c-style-alist)))
|
|
2357 (if s
|
|
2358 (setcdr s (copy-alist descrip)) ; replace
|
|
2359 (setq c-style-alist (cons (cons style descrip) c-style-alist))))
|
|
2360 (and set-p (c-set-style style)))
|
|
2361
|
|
2362 (defun c-fill-paragraph (&optional arg)
|
|
2363 "Like \\[fill-paragraph] but handles C and C++ style comments.
|
|
2364 If any of the current line is a comment or within a comment,
|
|
2365 fill the comment or the paragraph of it that point is in,
|
|
2366 preserving the comment indentation or line-starting decorations.
|
|
2367
|
|
2368 Optional prefix ARG means justify paragraph as well."
|
|
2369 (interactive "P")
|
|
2370 (let* (comment-start-place
|
|
2371 (first-line
|
|
2372 ;; Check for obvious entry to comment.
|
|
2373 (save-excursion
|
|
2374 (beginning-of-line)
|
|
2375 (skip-chars-forward " \t\n")
|
|
2376 (and (looking-at comment-start-skip)
|
|
2377 (setq comment-start-place (point)))))
|
|
2378 (re1 (if (memq 'new-re c-emacs-features)
|
|
2379 "\\|[ \t]*/\\*[ \t]*$\\|[ \t]*\\*/[ \t]*$\\|[ \t/*]*$"
|
|
2380 "\\|^[ \t]*/\\*[ \t]*$\\|^[ \t]*\\*/[ \t]*$\\|^[ \t/*]*$"))
|
|
2381 )
|
|
2382 (if (and c-double-slash-is-comments-p
|
|
2383 (save-excursion
|
|
2384 (beginning-of-line)
|
|
2385 (looking-at ".*//")))
|
|
2386 (let (fill-prefix
|
|
2387 ;; Lines containing just a comment start or just an end
|
|
2388 ;; should not be filled into paragraphs they are next
|
|
2389 ;; to.
|
|
2390 (paragraph-start (concat paragraph-start re1))
|
|
2391 (paragraph-separate (concat paragraph-separate re1)))
|
|
2392 (save-excursion
|
|
2393 (beginning-of-line)
|
|
2394 ;; Move up to first line of this comment.
|
|
2395 (while (and (not (bobp))
|
2
|
2396 (looking-at "[ \t]*//[ \t]*[^ \t\n]"))
|
0
|
2397 (forward-line -1))
|
2
|
2398 (if (not (looking-at ".*//[ \t]*[^ \t\n]"))
|
0
|
2399 (forward-line 1))
|
|
2400 ;; Find the comment start in this line.
|
|
2401 (re-search-forward "[ \t]*//[ \t]*")
|
|
2402 ;; Set the fill-prefix to be what all lines except the first
|
|
2403 ;; should start with.
|
|
2404 (setq fill-prefix (buffer-substring (match-beginning 0)
|
|
2405 (match-end 0)))
|
|
2406 (save-restriction
|
|
2407 ;; Narrow down to just the lines of this comment.
|
|
2408 (narrow-to-region (c-point 'bol)
|
|
2409 (save-excursion
|
|
2410 (forward-line 1)
|
|
2411 (while (looking-at fill-prefix)
|
|
2412 (forward-line 1))
|
|
2413 (point)))
|
|
2414 (fill-paragraph arg)
|
|
2415 t)))
|
|
2416 ;; else C style comments
|
|
2417 (if (or first-line
|
|
2418 ;; t if we enter a comment between start of function and
|
|
2419 ;; this line.
|
|
2420 (eq (c-in-literal) 'c)
|
|
2421 ;; t if this line contains a comment starter.
|
|
2422 (setq first-line
|
|
2423 (save-excursion
|
|
2424 (beginning-of-line)
|
|
2425 (prog1
|
|
2426 (re-search-forward comment-start-skip
|
|
2427 (save-excursion (end-of-line)
|
|
2428 (point))
|
|
2429 t)
|
|
2430 (setq comment-start-place (point))))))
|
|
2431 ;; Inside a comment: fill one comment paragraph.
|
|
2432 (let ((fill-prefix
|
|
2433 ;; The prefix for each line of this paragraph
|
|
2434 ;; is the appropriate part of the start of this line,
|
|
2435 ;; up to the column at which text should be indented.
|
|
2436 (save-excursion
|
|
2437 (beginning-of-line)
|
|
2438 (if (looking-at "[ \t]*/\\*.*\\*/")
|
|
2439 (progn (re-search-forward comment-start-skip)
|
|
2440 (make-string (current-column) ?\ ))
|
|
2441 (if first-line (forward-line 1))
|
|
2442
|
|
2443 (let ((line-width (progn (end-of-line) (current-column))))
|
|
2444 (beginning-of-line)
|
|
2445 (prog1
|
|
2446 (buffer-substring
|
|
2447 (point)
|
|
2448
|
|
2449 ;; How shall we decide where the end of the
|
|
2450 ;; fill-prefix is?
|
|
2451 (progn
|
|
2452 (beginning-of-line)
|
|
2453 (skip-chars-forward " \t*" (c-point 'eol))
|
|
2454 (point)))
|
|
2455
|
|
2456 ;; If the comment is only one line followed
|
|
2457 ;; by a blank line, calling move-to-column
|
|
2458 ;; above may have added some spaces and tabs
|
|
2459 ;; to the end of the line; the fill-paragraph
|
|
2460 ;; function will then delete it and the
|
|
2461 ;; newline following it, so we'll lose a
|
|
2462 ;; blank line when we shouldn't. So delete
|
|
2463 ;; anything move-to-column added to the end
|
|
2464 ;; of the line. We record the line width
|
|
2465 ;; instead of the position of the old line
|
|
2466 ;; end because move-to-column might break a
|
|
2467 ;; tab into spaces, and the new characters
|
|
2468 ;; introduced there shouldn't be deleted.
|
|
2469
|
|
2470 ;; If you can see a better way to do this,
|
|
2471 ;; please make the change. This seems very
|
|
2472 ;; messy to me.
|
|
2473 (delete-region (progn (move-to-column line-width)
|
|
2474 (point))
|
|
2475 (progn (end-of-line) (point))))))))
|
|
2476
|
|
2477 ;; Lines containing just a comment start or just an end
|
|
2478 ;; should not be filled into paragraphs they are next
|
|
2479 ;; to.
|
|
2480 (paragraph-start (concat paragraph-start re1))
|
|
2481 (paragraph-separate (concat paragraph-separate re1))
|
|
2482 (chars-to-delete 0))
|
|
2483 (save-restriction
|
|
2484 ;; Don't fill the comment together with the code
|
|
2485 ;; following it. So temporarily exclude everything
|
|
2486 ;; before the comment start, and everything after the
|
|
2487 ;; line where the comment ends. If comment-start-place
|
|
2488 ;; is non-nil, the comment starter is there. Otherwise,
|
|
2489 ;; point is inside the comment.
|
|
2490 (narrow-to-region (save-excursion
|
|
2491 (if comment-start-place
|
|
2492 (goto-char comment-start-place)
|
|
2493 (search-backward "/*"))
|
|
2494 ;; Protect text before the comment
|
|
2495 ;; start by excluding it. Add
|
|
2496 ;; spaces to bring back proper
|
|
2497 ;; indentation of that point.
|
|
2498 (let ((column (current-column)))
|
|
2499 (prog1 (point)
|
|
2500 (setq chars-to-delete column)
|
|
2501 (insert-char ?\ column))))
|
|
2502 (save-excursion
|
|
2503 (if comment-start-place
|
|
2504 (goto-char (+ comment-start-place 2)))
|
|
2505 (search-forward "*/" nil 'move)
|
|
2506 (forward-line 1)
|
|
2507 (point)))
|
|
2508 (fill-paragraph arg)
|
|
2509 (save-excursion
|
|
2510 ;; Delete the chars we inserted to avoid clobbering
|
|
2511 ;; the stuff before the comment start.
|
|
2512 (goto-char (point-min))
|
|
2513 (if (> chars-to-delete 0)
|
|
2514 (delete-region (point) (+ (point) chars-to-delete)))
|
|
2515 ;; Find the comment ender (should be on last line of
|
|
2516 ;; buffer, given the narrowing) and don't leave it on
|
|
2517 ;; its own line, unless that's the style that's desired.
|
|
2518 (goto-char (point-max))
|
|
2519 (forward-line -1)
|
|
2520 (search-forward "*/" nil 'move)
|
|
2521 (beginning-of-line)
|
|
2522 (if (and c-hanging-comment-ender-p
|
|
2523 (looking-at "[ \t]*\\*/"))
|
|
2524 ;(delete-indentation)))))
|
|
2525 (let ((fill-column (+ fill-column 9999)))
|
|
2526 (forward-line -1)
|
|
2527 (fill-region-as-paragraph (point) (point-max))))))
|
|
2528 t)))))
|
|
2529
|
2
|
2530
|
0
|
2531 ;; better movement routines for ThisStyleOfVariablesCommonInCPlusPlus
|
|
2532 ;; originally contributed by Terry_Glanfield.Southern@rxuk.xerox.com
|
|
2533 (defun c-forward-into-nomenclature (&optional arg)
|
|
2534 "Move forward to end of a nomenclature section or word.
|
|
2535 With arg, to it arg times."
|
|
2536 (interactive "p")
|
|
2537 (let ((case-fold-search nil))
|
|
2538 (if (> arg 0)
|
|
2539 (re-search-forward "\\W*\\([A-Z]*[a-z0-9]*\\)" (point-max) t arg)
|
|
2540 (while (and (< arg 0)
|
|
2541 (re-search-backward
|
|
2542 "\\(\\(\\W\\|[a-z0-9]\\)[A-Z]+\\|\\W\\w+\\)"
|
|
2543 (point-min) 0))
|
|
2544 (forward-char 1)
|
|
2545 (setq arg (1+ arg)))))
|
|
2546 (c-keep-region-active))
|
|
2547
|
|
2548 (defun c-backward-into-nomenclature (&optional arg)
|
|
2549 "Move backward to beginning of a nomenclature section or word.
|
|
2550 With optional ARG, move that many times. If ARG is negative, move
|
|
2551 forward."
|
|
2552 (interactive "p")
|
|
2553 (c-forward-into-nomenclature (- arg))
|
|
2554 (c-keep-region-active))
|
|
2555
|
|
2556 (defun c-scope-operator ()
|
|
2557 "Insert a double colon scope operator at point.
|
|
2558 No indentation or other \"electric\" behavior is performed."
|
|
2559 (interactive)
|
|
2560 (insert "::"))
|
|
2561
|
|
2562
|
|
2563 (defun c-beginning-of-statement (&optional count lim sentence-flag)
|
|
2564 "Go to the beginning of the innermost C statement.
|
|
2565 With prefix arg, go back N - 1 statements. If already at the
|
|
2566 beginning of a statement then go to the beginning of the preceding
|
|
2567 one. If within a string or comment, or next to a comment (only
|
|
2568 whitespace between), move by sentences instead of statements.
|
|
2569
|
|
2570 When called from a program, this function takes 3 optional args: the
|
|
2571 repetition count, a buffer position limit which is the farthest back
|
|
2572 to search, and a flag saying whether to do sentence motion when in a
|
|
2573 comment."
|
|
2574 (interactive (list (prefix-numeric-value current-prefix-arg)
|
|
2575 nil t))
|
|
2576 (let ((here (point))
|
|
2577 (count (or count 1))
|
|
2578 (lim (or lim (c-point 'bod)))
|
|
2579 state)
|
|
2580 (save-excursion
|
|
2581 (goto-char lim)
|
|
2582 (setq state (parse-partial-sexp (point) here nil nil)))
|
|
2583 (if (and sentence-flag
|
|
2584 (or (nth 3 state)
|
|
2585 (nth 4 state)
|
|
2586 (looking-at (concat "[ \t]*" comment-start-skip))
|
|
2587 (save-excursion
|
|
2588 (skip-chars-backward " \t")
|
|
2589 (goto-char (- (point) 2))
|
|
2590 (looking-at "\\*/"))))
|
|
2591 (forward-sentence (- count))
|
|
2592 (while (> count 0)
|
|
2593 (c-beginning-of-statement-1 lim)
|
|
2594 (setq count (1- count)))
|
|
2595 (while (< count 0)
|
|
2596 (c-end-of-statement-1)
|
|
2597 (setq count (1+ count))))
|
|
2598 ;; its possible we've been left up-buf of lim
|
|
2599 (goto-char (max (point) lim))
|
|
2600 )
|
|
2601 (c-keep-region-active))
|
|
2602
|
|
2603 (defun c-end-of-statement (&optional count lim sentence-flag)
|
|
2604 "Go to the end of the innermost C statement.
|
|
2605
|
|
2606 With prefix arg, go forward N - 1 statements. Move forward to end of
|
|
2607 the next statement if already at end. If within a string or comment,
|
|
2608 move by sentences instead of statements.
|
|
2609
|
|
2610 When called from a program, this function takes 3 optional args: the
|
|
2611 repetition count, a buffer position limit which is the farthest back
|
|
2612 to search, and a flag saying whether to do sentence motion when in a
|
|
2613 comment."
|
|
2614 (interactive (list (prefix-numeric-value current-prefix-arg)
|
|
2615 nil t))
|
|
2616 (c-beginning-of-statement (- (or count 1)) lim sentence-flag)
|
|
2617 (c-keep-region-active))
|
|
2618
|
2
|
2619 ;; WARNING: Be *exceptionally* careful about modifications to this
|
|
2620 ;; function! Much of cc-mode depends on this Doing The Right Thing.
|
|
2621 ;; If you break it you will be sorry.
|
0
|
2622 (defun c-beginning-of-statement-1 (&optional lim)
|
|
2623 ;; move to the start of the current statement, or the previous
|
|
2624 ;; statement if already at the beginning of one.
|
|
2625 (let ((firstp t)
|
|
2626 (substmt-p t)
|
|
2627 donep c-in-literal-cache
|
|
2628 ;; KLUDGE ALERT: maybe-labelp is used to pass information
|
|
2629 ;; between c-crosses-statement-barrier-p and
|
|
2630 ;; c-beginning-of-statement-1. A better way should be
|
|
2631 ;; implemented.
|
|
2632 maybe-labelp
|
|
2633 (last-begin (point)))
|
|
2634 (while (not donep)
|
|
2635 ;; stop at beginning of buffer
|
|
2636 (if (bobp) (setq donep t)
|
|
2637 ;; go backwards one balanced expression, but be careful of
|
|
2638 ;; unbalanced paren being reached
|
|
2639 (if (not (c-safe (progn (backward-sexp 1) t)))
|
|
2640 (progn
|
|
2641 (if firstp
|
|
2642 (backward-up-list 1)
|
|
2643 (goto-char last-begin))
|
|
2644 ;; skip over any unary operators, or other special
|
|
2645 ;; characters appearing at front of identifier
|
|
2646 (save-excursion
|
|
2647 (c-backward-syntactic-ws lim)
|
|
2648 (skip-chars-backward "-+!*&:.~ \t\n")
|
|
2649 (if (= (preceding-char) ?\()
|
|
2650 (setq last-begin (point))))
|
|
2651 (goto-char last-begin)
|
|
2652 (setq last-begin (point)
|
|
2653 donep t)))
|
|
2654
|
|
2655 (setq maybe-labelp nil)
|
|
2656 ;; see if we're in a literal. if not, then this bufpos may be
|
|
2657 ;; a candidate for stopping
|
|
2658 (cond
|
|
2659 ;; CASE 0: did we hit the error condition above?
|
|
2660 (donep)
|
|
2661 ;; CASE 1: are we in a literal?
|
|
2662 ((eq (c-in-literal lim) 'pound)
|
|
2663 (beginning-of-line))
|
|
2664 ;; CASE 2: some other kind of literal?
|
|
2665 ((c-in-literal lim))
|
|
2666 ;; CASE 3: are we looking at a conditional keyword?
|
|
2667 ((or (looking-at c-conditional-key)
|
|
2668 (and (= (following-char) ?\()
|
|
2669 (save-excursion
|
|
2670 (forward-sexp 1)
|
|
2671 (c-forward-syntactic-ws)
|
|
2672 (/= (following-char) ?\;))
|
|
2673 (let ((here (point))
|
|
2674 (foundp (progn
|
|
2675 (c-backward-syntactic-ws lim)
|
|
2676 (forward-word -1)
|
|
2677 (and lim
|
|
2678 (<= lim (point))
|
|
2679 (not (c-in-literal lim))
|
|
2680 (looking-at c-conditional-key)
|
|
2681 ))))
|
|
2682 ;; did we find a conditional?
|
|
2683 (if (not foundp)
|
|
2684 (goto-char here))
|
|
2685 foundp)))
|
|
2686 ;; are we in the middle of an else-if clause?
|
|
2687 (if (save-excursion
|
|
2688 (and (not substmt-p)
|
|
2689 (c-safe (progn (forward-sexp -1) t))
|
|
2690 (looking-at "\\<else\\>[ \t\n]+\\<if\\>")
|
|
2691 (not (c-in-literal lim))))
|
|
2692 (progn
|
|
2693 (forward-sexp -1)
|
|
2694 (c-backward-to-start-of-if lim)))
|
|
2695 ;; are we sitting at an else clause, that we are not a
|
|
2696 ;; substatement of?
|
|
2697 (if (and (not substmt-p)
|
|
2698 (looking-at "\\<else\\>[^_]"))
|
|
2699 (c-backward-to-start-of-if lim))
|
|
2700 ;; are we sitting at the while of a do-while?
|
|
2701 (if (and (looking-at "\\<while\\>[^_]")
|
|
2702 (c-backward-to-start-of-do lim))
|
|
2703 (setq substmt-p nil))
|
|
2704 (setq last-begin (point)
|
|
2705 donep substmt-p))
|
|
2706 ;; CASE 4: are we looking at a label?
|
|
2707 ((looking-at c-label-key))
|
|
2708 ;; CASE 5: is this the first time we're checking?
|
|
2709 (firstp (setq firstp nil
|
|
2710 substmt-p (not (c-crosses-statement-barrier-p
|
|
2711 (point) last-begin))
|
|
2712 last-begin (point)))
|
|
2713 ;; CASE 6: have we crossed a statement barrier?
|
|
2714 ((c-crosses-statement-barrier-p (point) last-begin)
|
|
2715 (setq donep t))
|
|
2716 ;; CASE 7: ignore labels
|
|
2717 ((and maybe-labelp
|
|
2718 (or (and c-access-key (looking-at c-access-key))
|
|
2719 ;; with switch labels, we have to go back further
|
|
2720 ;; to try to pick up the case or default
|
|
2721 ;; keyword. Potential bogosity alert: we assume
|
|
2722 ;; `case' or `default' is first thing on line
|
|
2723 (let ((here (point)))
|
|
2724 (beginning-of-line)
|
|
2725 (c-forward-syntactic-ws)
|
|
2726 (if (looking-at c-switch-label-key)
|
|
2727 t
|
|
2728 (goto-char here)
|
|
2729 nil))
|
|
2730 (looking-at c-label-key))))
|
|
2731 ;; CASE 8: ObjC or Java method def
|
|
2732 ((and c-method-key
|
|
2733 (setq last-begin (c-in-method-def-p)))
|
|
2734 (setq donep t))
|
|
2735 ;; CASE 9: nothing special
|
|
2736 (t (setq last-begin (point)))
|
|
2737 )))
|
|
2738 (goto-char last-begin)
|
|
2739 ;; we always do want to skip over non-whitespace modifier
|
|
2740 ;; characters that didn't get skipped above
|
|
2741 (skip-chars-backward "-+!*&:.~" (c-point 'boi))))
|
|
2742
|
|
2743 (defun c-end-of-statement-1 ()
|
|
2744 (condition-case ()
|
|
2745 (progn
|
|
2746 (while (and (not (eobp))
|
|
2747 (let ((beg (point)))
|
|
2748 (forward-sexp 1)
|
|
2749 (let ((end (point)))
|
|
2750 (save-excursion
|
|
2751 (goto-char beg)
|
|
2752 (not (re-search-forward "[;{}]" end t)))))))
|
|
2753 (re-search-backward "[;}]")
|
|
2754 (forward-char 1))
|
|
2755 (error
|
|
2756 (let ((beg (point)))
|
|
2757 (backward-up-list -1)
|
|
2758 (let ((end (point)))
|
|
2759 (goto-char beg)
|
|
2760 (search-forward ";" end 'move))))))
|
|
2761
|
|
2762 (defun c-crosses-statement-barrier-p (from to)
|
|
2763 ;; Does buffer positions FROM to TO cross a C statement boundary?
|
|
2764 (let ((here (point))
|
|
2765 (lim from)
|
|
2766 crossedp)
|
|
2767 (condition-case ()
|
|
2768 (progn
|
|
2769 (goto-char from)
|
|
2770 (while (and (not crossedp)
|
|
2771 (< (point) to))
|
|
2772 (skip-chars-forward "^;{}:" to)
|
|
2773 (if (not (c-in-literal lim))
|
|
2774 (progn
|
|
2775 (if (memq (following-char) '(?\; ?{ ?}))
|
|
2776 (setq crossedp t)
|
|
2777 (if (= (following-char) ?:)
|
|
2778 (setq maybe-labelp t))
|
|
2779 (forward-char 1))
|
|
2780 (setq lim (point)))
|
|
2781 (forward-char 1))))
|
|
2782 (error (setq crossedp nil)))
|
|
2783 (goto-char here)
|
|
2784 crossedp))
|
|
2785
|
|
2786
|
|
2787 (defun c-up-conditional (count)
|
|
2788 "Move back to the containing preprocessor conditional, leaving mark behind.
|
|
2789 A prefix argument acts as a repeat count. With a negative argument,
|
|
2790 move forward to the end of the containing preprocessor conditional.
|
|
2791 When going backwards, `#elif' is treated like `#else' followed by
|
|
2792 `#if'. When going forwards, `#elif' is ignored."
|
|
2793 (interactive "p")
|
|
2794 (c-forward-conditional (- count) t)
|
|
2795 (c-keep-region-active))
|
|
2796
|
|
2797 (defun c-backward-conditional (count &optional up-flag)
|
|
2798 "Move back across a preprocessor conditional, leaving mark behind.
|
|
2799 A prefix argument acts as a repeat count. With a negative argument,
|
|
2800 move forward across a preprocessor conditional."
|
|
2801 (interactive "p")
|
|
2802 (c-forward-conditional (- count) up-flag)
|
|
2803 (c-keep-region-active))
|
|
2804
|
|
2805 (defun c-forward-conditional (count &optional up-flag)
|
|
2806 "Move forward across a preprocessor conditional, leaving mark behind.
|
|
2807 A prefix argument acts as a repeat count. With a negative argument,
|
|
2808 move backward across a preprocessor conditional."
|
|
2809 (interactive "p")
|
|
2810 (let* ((forward (> count 0))
|
|
2811 (increment (if forward -1 1))
|
|
2812 (search-function (if forward 're-search-forward 're-search-backward))
|
|
2813 (new))
|
|
2814 (save-excursion
|
|
2815 (while (/= count 0)
|
|
2816 (let ((depth (if up-flag 0 -1)) found)
|
|
2817 (save-excursion
|
|
2818 ;; Find the "next" significant line in the proper direction.
|
|
2819 (while (and (not found)
|
|
2820 ;; Rather than searching for a # sign that
|
|
2821 ;; comes at the beginning of a line aside from
|
|
2822 ;; whitespace, search first for a string
|
|
2823 ;; starting with # sign. Then verify what
|
|
2824 ;; precedes it. This is faster on account of
|
|
2825 ;; the fastmap feature of the regexp matcher.
|
|
2826 (funcall search-function
|
|
2827 "#[ \t]*\\(if\\|elif\\|endif\\)"
|
|
2828 nil t))
|
|
2829 (beginning-of-line)
|
|
2830 ;; Now verify it is really a preproc line.
|
|
2831 (if (looking-at "^[ \t]*#[ \t]*\\(if\\|elif\\|endif\\)")
|
|
2832 (let ((prev depth))
|
|
2833 ;; Update depth according to what we found.
|
|
2834 (beginning-of-line)
|
|
2835 (cond ((looking-at "[ \t]*#[ \t]*endif")
|
|
2836 (setq depth (+ depth increment)))
|
|
2837 ((looking-at "[ \t]*#[ \t]*elif")
|
|
2838 (if (and forward (= depth 0))
|
|
2839 (setq found (point))))
|
|
2840 (t (setq depth (- depth increment))))
|
|
2841 ;; If we are trying to move across, and we find an
|
|
2842 ;; end before we find a beginning, get an error.
|
|
2843 (if (and (< prev 0) (< depth prev))
|
|
2844 (error (if forward
|
|
2845 "No following conditional at this level"
|
|
2846 "No previous conditional at this level")))
|
|
2847 ;; When searching forward, start from next line so
|
|
2848 ;; that we don't find the same line again.
|
|
2849 (if forward (forward-line 1))
|
|
2850 ;; If this line exits a level of conditional, exit
|
|
2851 ;; inner loop.
|
|
2852 (if (< depth 0)
|
|
2853 (setq found (point))))
|
|
2854 ;; else
|
|
2855 (if forward (forward-line 1))
|
|
2856 )))
|
|
2857 (or found
|
|
2858 (error "No containing preprocessor conditional"))
|
|
2859 (goto-char (setq new found)))
|
|
2860 (setq count (+ count increment))))
|
|
2861 (push-mark)
|
|
2862 (goto-char new))
|
|
2863 (c-keep-region-active))
|
|
2864
|
|
2865
|
|
2866 ;; commands to indent lines, regions, defuns, and expressions
|
|
2867 (defun c-indent-command (&optional whole-exp)
|
|
2868 "Indent current line as C++ code, or in some cases insert a tab character.
|
|
2869
|
|
2870 If `c-tab-always-indent' is t, always just indent the current line.
|
|
2871 If nil, indent the current line only if point is at the left margin or
|
|
2872 in the line's indentation; otherwise insert a tab. If other than nil
|
|
2873 or t, then tab is inserted only within literals (comments and strings)
|
|
2874 and inside preprocessor directives, but line is always reindented.
|
|
2875
|
|
2876 A numeric argument, regardless of its value, means indent rigidly all
|
|
2877 the lines of the expression starting after point so that this line
|
|
2878 becomes properly indented. The relative indentation among the lines
|
|
2879 of the expression are preserved."
|
|
2880 (interactive "P")
|
|
2881 (let ((bod (c-point 'bod)))
|
|
2882 (if whole-exp
|
|
2883 ;; If arg, always indent this line as C
|
|
2884 ;; and shift remaining lines of expression the same amount.
|
|
2885 (let ((shift-amt (c-indent-line))
|
|
2886 beg end)
|
|
2887 (save-excursion
|
|
2888 (if (eq c-tab-always-indent t)
|
|
2889 (beginning-of-line))
|
|
2890 (setq beg (point))
|
|
2891 (forward-sexp 1)
|
|
2892 (setq end (point))
|
|
2893 (goto-char beg)
|
|
2894 (forward-line 1)
|
|
2895 (setq beg (point)))
|
|
2896 (if (> end beg)
|
|
2897 (indent-code-rigidly beg end (- shift-amt) "#")))
|
|
2898 ;; No arg supplied, use c-tab-always-indent to determine
|
|
2899 ;; behavior
|
|
2900 (cond
|
|
2901 ;; CASE 1: indent when at column zero or in lines indentation,
|
|
2902 ;; otherwise insert a tab
|
|
2903 ((not c-tab-always-indent)
|
|
2904 (if (save-excursion
|
|
2905 (skip-chars-backward " \t")
|
|
2906 (not (bolp)))
|
2
|
2907 (funcall c-insert-tab-function)
|
0
|
2908 (c-indent-line)))
|
|
2909 ;; CASE 2: just indent the line
|
|
2910 ((eq c-tab-always-indent t)
|
|
2911 (c-indent-line))
|
|
2912 ;; CASE 3: if in a literal, insert a tab, but always indent the
|
|
2913 ;; line
|
|
2914 (t
|
|
2915 (if (c-in-literal bod)
|
2
|
2916 (funcall c-insert-tab-function))
|
0
|
2917 (c-indent-line)
|
|
2918 )))))
|
|
2919
|
|
2920 (defun c-indent-exp (&optional shutup-p)
|
|
2921 "Indent each line in balanced expression following point.
|
|
2922 Optional SHUTUP-P if non-nil, inhibits message printing and error checking."
|
|
2923 (interactive "P")
|
|
2924 (let ((here (point))
|
|
2925 end progress-p)
|
|
2926 (unwind-protect
|
|
2927 (let ((c-echo-syntactic-information-p nil) ;keep quiet for speed
|
|
2928 (start (progn
|
|
2929 ;; try to be smarter about finding the range of
|
|
2930 ;; lines to indent. skip all following
|
|
2931 ;; whitespace. failing that, try to find any
|
|
2932 ;; opening brace on the current line
|
|
2933 (skip-chars-forward " \t\n")
|
|
2934 (if (memq (following-char) '(?\( ?\[ ?\{))
|
|
2935 (point)
|
|
2936 (let ((state (parse-partial-sexp (point)
|
|
2937 (c-point 'eol))))
|
|
2938 (and (nth 1 state)
|
|
2939 (goto-char (nth 1 state))
|
|
2940 (memq (following-char) '(?\( ?\[ ?\{))
|
|
2941 (point)))))))
|
|
2942 ;; find balanced expression end
|
|
2943 (setq end (and (c-safe (progn (forward-sexp 1) t))
|
|
2944 (point-marker)))
|
|
2945 ;; sanity check
|
|
2946 (and (not start)
|
|
2947 (not shutup-p)
|
|
2948 (error "Cannot find start of balanced expression to indent."))
|
|
2949 (and (not end)
|
|
2950 (not shutup-p)
|
|
2951 (error "Cannot find end of balanced expression to indent."))
|
|
2952 (c-progress-init start end 'c-indent-exp)
|
|
2953 (setq progress-p t)
|
|
2954 (goto-char start)
|
|
2955 (beginning-of-line)
|
|
2956 (while (< (point) end)
|
|
2957 (if (not (looking-at "[ \t]*$"))
|
|
2958 (c-indent-line))
|
|
2959 (c-progress-update)
|
|
2960 (forward-line 1)))
|
|
2961 ;; make sure marker is deleted
|
|
2962 (and end
|
|
2963 (set-marker end nil))
|
|
2964 (and progress-p
|
|
2965 (c-progress-fini 'c-indent-exp))
|
|
2966 (goto-char here))))
|
|
2967
|
|
2968 (defun c-indent-defun ()
|
|
2969 "Re-indents the current top-level function def, struct or class declaration."
|
|
2970 (interactive)
|
|
2971 (let ((here (point-marker))
|
|
2972 (c-echo-syntactic-information-p nil)
|
|
2973 (brace (c-least-enclosing-brace (c-parse-state))))
|
|
2974 (if brace
|
|
2975 (goto-char brace)
|
|
2976 (beginning-of-defun))
|
|
2977 ;; if we're sitting at b-o-b, it might be because there was no
|
|
2978 ;; least enclosing brace and we were sitting on the defun's open
|
|
2979 ;; brace.
|
|
2980 (if (and (bobp) (not (= (following-char) ?\{)))
|
|
2981 (goto-char here))
|
|
2982 ;; if defun-prompt-regexp is non-nil, b-o-d might not leave us at
|
|
2983 ;; the open brace. I consider this an Emacs bug.
|
|
2984 (and (boundp 'defun-prompt-regexp)
|
|
2985 defun-prompt-regexp
|
|
2986 (looking-at defun-prompt-regexp)
|
|
2987 (goto-char (match-end 0)))
|
|
2988 ;; catch all errors in c-indent-exp so we can 1. give more
|
|
2989 ;; meaningful error message, and 2. restore point
|
|
2990 (unwind-protect
|
|
2991 (c-indent-exp)
|
|
2992 (goto-char here)
|
|
2993 (set-marker here nil))))
|
|
2994
|
|
2995 (defun c-indent-region (start end)
|
|
2996 ;; Indent every line whose first char is between START and END inclusive.
|
|
2997 (save-excursion
|
|
2998 (goto-char start)
|
|
2999 ;; Advance to first nonblank line.
|
|
3000 (skip-chars-forward " \t\n")
|
|
3001 (beginning-of-line)
|
|
3002 (let (endmark)
|
|
3003 (unwind-protect
|
|
3004 (let ((c-tab-always-indent t)
|
|
3005 ;; shut up any echo msgs on indiv lines
|
|
3006 (c-echo-syntactic-information-p nil))
|
|
3007 (c-progress-init start end 'c-indent-region)
|
|
3008 (setq endmark (copy-marker end))
|
|
3009 (while (and (bolp)
|
|
3010 (not (eobp))
|
|
3011 (< (point) endmark))
|
|
3012 ;; update progress
|
|
3013 (c-progress-update)
|
|
3014 ;; Indent one line as with TAB.
|
|
3015 (let (nextline sexpend sexpbeg)
|
|
3016 ;; skip blank lines
|
|
3017 (skip-chars-forward " \t\n")
|
|
3018 (beginning-of-line)
|
|
3019 ;; indent the current line
|
|
3020 (c-indent-line)
|
|
3021 (if (save-excursion
|
|
3022 (beginning-of-line)
|
|
3023 (looking-at "[ \t]*#"))
|
|
3024 (forward-line 1)
|
|
3025 (save-excursion
|
|
3026 ;; Find beginning of following line.
|
|
3027 (setq nextline (c-point 'bonl))
|
|
3028 ;; Find first beginning-of-sexp for sexp extending past
|
|
3029 ;; this line.
|
|
3030 (beginning-of-line)
|
|
3031 (while (< (point) nextline)
|
|
3032 (condition-case nil
|
|
3033 (progn
|
|
3034 (forward-sexp 1)
|
|
3035 (setq sexpend (point)))
|
|
3036 (error (setq sexpend nil)
|
|
3037 (goto-char nextline)))
|
|
3038 (c-forward-syntactic-ws))
|
|
3039 (if sexpend
|
|
3040 (progn
|
|
3041 ;; make sure the sexp we found really starts on the
|
|
3042 ;; current line and extends past it
|
|
3043 (goto-char sexpend)
|
|
3044 (setq sexpend (point-marker))
|
|
3045 (c-safe (backward-sexp 1))
|
|
3046 (setq sexpbeg (point)))))
|
|
3047 ;; check to see if the next line starts a
|
|
3048 ;; comment-only line
|
|
3049 (save-excursion
|
|
3050 (forward-line 1)
|
|
3051 (skip-chars-forward " \t")
|
|
3052 (if (looking-at c-comment-start-regexp)
|
|
3053 (setq sexpbeg (c-point 'bol))))
|
|
3054 ;; If that sexp ends within the region, indent it all at
|
|
3055 ;; once, fast.
|
|
3056 (condition-case nil
|
|
3057 (if (and sexpend
|
|
3058 (> sexpend nextline)
|
|
3059 (<= sexpend endmark))
|
|
3060 (progn
|
|
3061 (goto-char sexpbeg)
|
|
3062 (c-indent-exp 'shutup)
|
|
3063 (c-progress-update)
|
|
3064 (goto-char sexpend)))
|
|
3065 (error
|
|
3066 (goto-char sexpbeg)
|
|
3067 (c-indent-line)))
|
|
3068 ;; Move to following line and try again.
|
|
3069 (and sexpend
|
|
3070 (markerp sexpend)
|
|
3071 (set-marker sexpend nil))
|
|
3072 (forward-line 1)))))
|
|
3073 (set-marker endmark nil)
|
|
3074 (c-progress-fini 'c-indent-region)
|
|
3075 ))))
|
|
3076
|
|
3077 (defun c-mark-function ()
|
|
3078 "Put mark at end of a C, C++, or Objective-C defun, point at beginning."
|
|
3079 (interactive)
|
|
3080 (let ((here (point))
|
|
3081 ;; there should be a c-point position for 'eod
|
|
3082 (eod (save-excursion (end-of-defun) (point)))
|
|
3083 (state (c-parse-state))
|
|
3084 brace)
|
|
3085 (while state
|
|
3086 (setq brace (car state))
|
|
3087 (if (consp brace)
|
|
3088 (goto-char (cdr brace))
|
|
3089 (goto-char brace))
|
|
3090 (setq state (cdr state)))
|
|
3091 (if (= (following-char) ?{)
|
|
3092 (progn
|
|
3093 (forward-line -1)
|
|
3094 (while (not (or (bobp)
|
|
3095 (looking-at "[ \t]*$")))
|
|
3096 (forward-line -1)))
|
|
3097 (forward-line 1)
|
|
3098 (skip-chars-forward " \t\n"))
|
|
3099 (push-mark here)
|
|
3100 (push-mark eod nil t)))
|
|
3101
|
|
3102
|
|
3103 ;; for progress reporting
|
|
3104 (defvar c-progress-info nil)
|
|
3105
|
|
3106 (defun c-progress-init (start end context)
|
|
3107 ;; start the progress update messages. if this emacs doesn't have a
|
|
3108 ;; built-in timer, just be dumb about it
|
|
3109 (if (not (fboundp 'current-time))
|
|
3110 (message "indenting region... (this may take a while)")
|
|
3111 ;; if progress has already been initialized, do nothing. otherwise
|
|
3112 ;; initialize the counter with a vector of:
|
|
3113 ;; [start end lastsec context]
|
|
3114 (if c-progress-info
|
|
3115 ()
|
|
3116 (setq c-progress-info (vector start
|
|
3117 (save-excursion
|
|
3118 (goto-char end)
|
|
3119 (point-marker))
|
|
3120 (nth 1 (current-time))
|
|
3121 context))
|
|
3122 (message "indenting region..."))))
|
|
3123
|
|
3124 (defun c-progress-update ()
|
|
3125 ;; update progress
|
|
3126 (if (not (and c-progress-info c-progress-interval))
|
|
3127 nil
|
|
3128 (let ((now (nth 1 (current-time)))
|
|
3129 (start (aref c-progress-info 0))
|
|
3130 (end (aref c-progress-info 1))
|
|
3131 (lastsecs (aref c-progress-info 2)))
|
|
3132 ;; should we update? currently, update happens every 2 seconds,
|
|
3133 ;; what's the right value?
|
|
3134 (if (< c-progress-interval (- now lastsecs))
|
|
3135 (progn
|
|
3136 (message "indenting region... (%d%% complete)"
|
|
3137 (/ (* 100 (- (point) start)) (- end start)))
|
|
3138 (aset c-progress-info 2 now)))
|
|
3139 )))
|
|
3140
|
|
3141 (defun c-progress-fini (context)
|
|
3142 ;; finished
|
|
3143 (if (or (eq context (aref c-progress-info 3))
|
|
3144 (eq context t))
|
|
3145 (progn
|
|
3146 (set-marker (aref c-progress-info 1) nil)
|
|
3147 (setq c-progress-info nil)
|
|
3148 (message "indenting region...done"))))
|
|
3149
|
|
3150
|
|
3151 ;; Skipping of "syntactic whitespace" for Emacs 19. Syntactic
|
|
3152 ;; whitespace is defined as lexical whitespace, C and C++ style
|
|
3153 ;; comments, and preprocessor directives. Search no farther back or
|
|
3154 ;; forward than optional LIM. If LIM is omitted, `beginning-of-defun'
|
|
3155 ;; is used for backward skipping, point-max is used for forward
|
|
3156 ;; skipping. Note that Emacs 18 support has been moved to cc-mode-18.el.
|
|
3157
|
|
3158 (defun c-forward-syntactic-ws (&optional lim)
|
|
3159 ;; Forward skip of syntactic whitespace for Emacs 19.
|
|
3160 (save-restriction
|
|
3161 (let* ((lim (or lim (point-max)))
|
|
3162 (here lim)
|
|
3163 (hugenum (point-max)))
|
|
3164 (narrow-to-region lim (point))
|
|
3165 (while (/= here (point))
|
|
3166 (setq here (point))
|
|
3167 (forward-comment hugenum)
|
|
3168 ;; skip preprocessor directives
|
|
3169 (if (and (= (following-char) ?#)
|
|
3170 (= (c-point 'boi) (point)))
|
|
3171 (end-of-line)
|
|
3172 )))))
|
|
3173
|
|
3174 (defun c-backward-syntactic-ws (&optional lim)
|
|
3175 ;; Backward skip over syntactic whitespace for Emacs 19.
|
|
3176 (save-restriction
|
|
3177 (let* ((lim (or lim (c-point 'bod)))
|
|
3178 (here lim)
|
|
3179 (hugenum (- (point-max))))
|
|
3180 (if (< lim (point))
|
|
3181 (progn
|
|
3182 (narrow-to-region lim (point))
|
|
3183 (while (/= here (point))
|
|
3184 (setq here (point))
|
|
3185 (forward-comment hugenum)
|
|
3186 (if (eq (c-in-literal lim) 'pound)
|
|
3187 (beginning-of-line))
|
|
3188 )))
|
|
3189 )))
|
|
3190
|
|
3191
|
|
3192 ;; Return `c' if in a C-style comment, `c++' if in a C++ style
|
|
3193 ;; comment, `string' if in a string literal, `pound' if on a
|
|
3194 ;; preprocessor line, or nil if not in a comment at all. Optional LIM
|
|
3195 ;; is used as the backward limit of the search. If omitted, or nil,
|
|
3196 ;; `beginning-of-defun' is used."
|
|
3197
|
|
3198 ;; This is for all v19 Emacsen supporting either 1-bit or 8-bit syntax
|
|
3199 (defun c-in-literal (&optional lim)
|
|
3200 ;; Determine if point is in a C++ literal. we cache the last point
|
|
3201 ;; calculated if the cache is enabled
|
|
3202 (if (and (boundp 'c-in-literal-cache)
|
|
3203 c-in-literal-cache
|
|
3204 (= (point) (aref c-in-literal-cache 0)))
|
|
3205 (aref c-in-literal-cache 1)
|
|
3206 (let ((rtn (save-excursion
|
|
3207 (let* ((lim (or lim (c-point 'bod)))
|
|
3208 (here (point))
|
|
3209 (state (parse-partial-sexp lim (point))))
|
|
3210 (cond
|
|
3211 ((nth 3 state) 'string)
|
|
3212 ((nth 4 state) (if (nth 7 state) 'c++ 'c))
|
|
3213 ((progn
|
|
3214 (goto-char here)
|
|
3215 (beginning-of-line)
|
|
3216 (looking-at "[ \t]*#"))
|
|
3217 'pound)
|
|
3218 (t nil))))))
|
|
3219 ;; cache this result if the cache is enabled
|
|
3220 (and (boundp 'c-in-literal-cache)
|
|
3221 (setq c-in-literal-cache (vector (point) rtn)))
|
|
3222 rtn)))
|
|
3223
|
|
3224
|
|
3225 ;; utilities for moving and querying around syntactic elements
|
|
3226 (defun c-parse-state ()
|
|
3227 ;; Finds and records all open parens between some important point
|
|
3228 ;; earlier in the file and point.
|
|
3229 ;;
|
|
3230 ;; if there's a state cache, return it
|
|
3231 (if (boundp 'c-state-cache) c-state-cache
|
|
3232 (let* (at-bob
|
|
3233 (pos (save-excursion
|
|
3234 ;; go back 2 bods, but ignore any bogus positions
|
|
3235 ;; returned by beginning-of-defun (i.e. open paren
|
|
3236 ;; in column zero)
|
|
3237 (let ((cnt 2))
|
|
3238 (while (not (or at-bob (zerop cnt)))
|
|
3239 (beginning-of-defun)
|
|
3240 (if (= (following-char) ?\{)
|
|
3241 (setq cnt (1- cnt)))
|
|
3242 (if (bobp)
|
|
3243 (setq at-bob t))))
|
|
3244 (point)))
|
|
3245 (here (save-excursion
|
|
3246 ;;(skip-chars-forward " \t}")
|
|
3247 (point)))
|
|
3248 (last-bod pos) (last-pos pos)
|
|
3249 placeholder state sexp-end)
|
|
3250 ;; cache last bod position
|
|
3251 (while (catch 'backup-bod
|
|
3252 (setq state nil)
|
|
3253 (while (and pos (< pos here))
|
|
3254 (setq last-pos pos)
|
|
3255 (if (and (setq pos (c-safe (scan-lists pos 1 -1)))
|
|
3256 (<= pos here))
|
|
3257 (progn
|
|
3258 (setq sexp-end (c-safe (scan-sexps (1- pos) 1)))
|
|
3259 (if (and sexp-end
|
|
3260 (<= sexp-end here))
|
|
3261 ;; we want to record both the start and end
|
|
3262 ;; of this sexp, but we only want to record
|
|
3263 ;; the last-most of any of them before here
|
|
3264 (progn
|
|
3265 (if (= (char-after (1- pos)) ?\{)
|
|
3266 (setq state (cons (cons (1- pos) sexp-end)
|
|
3267 (if (consp (car state))
|
|
3268 (cdr state)
|
|
3269 state))))
|
|
3270 (setq pos sexp-end))
|
|
3271 ;; we're contained in this sexp so put pos on
|
|
3272 ;; front of list
|
|
3273 (setq state (cons (1- pos) state))))
|
|
3274 ;; something bad happened. check to see if we
|
|
3275 ;; crossed an unbalanced close brace. if so, we
|
|
3276 ;; didn't really find the right `important bufpos'
|
|
3277 ;; so lets back up and try again
|
|
3278 (if (and (not pos) (not at-bob)
|
|
3279 (setq placeholder
|
|
3280 (c-safe (scan-lists last-pos 1 1)))
|
|
3281 ;;(char-after (1- placeholder))
|
|
3282 (<= placeholder here)
|
|
3283 (= (char-after (1- placeholder)) ?\}))
|
|
3284 (while t
|
|
3285 (setq last-bod (c-safe (scan-lists last-bod -1 1)))
|
|
3286 (if (not last-bod)
|
|
3287 (error "unbalanced close brace at position %d"
|
|
3288 (1- placeholder))
|
|
3289 (setq at-bob (= last-bod (point-min))
|
|
3290 pos last-bod)
|
|
3291 (if (= (char-after last-bod) ?\{)
|
|
3292 (throw 'backup-bod t)))
|
|
3293 )) ;end-if
|
|
3294 )) ;end-while
|
|
3295 nil))
|
|
3296 state)))
|
|
3297
|
|
3298 (defun c-whack-state (bufpos state)
|
|
3299 ;; whack off any state information that appears on STATE which lies
|
|
3300 ;; after the bounds of BUFPOS.
|
|
3301 (let (newstate car)
|
|
3302 (while state
|
|
3303 (setq car (car state)
|
|
3304 state (cdr state))
|
|
3305 (if (consp car)
|
|
3306 ;; just check the car, because in a balanced brace
|
|
3307 ;; expression, it must be impossible for the corresponding
|
|
3308 ;; close brace to be before point, but the open brace to be
|
|
3309 ;; after.
|
|
3310 (if (<= bufpos (car car))
|
|
3311 nil ; whack it off
|
|
3312 ;; its possible that the open brace is before bufpos, but
|
|
3313 ;; the close brace is after. In that case, convert this
|
|
3314 ;; to a non-cons element.
|
|
3315 (if (<= bufpos (cdr car))
|
|
3316 (setq newstate (append newstate (list (car car))))
|
|
3317 ;; we know that both the open and close braces are
|
|
3318 ;; before bufpos, so we also know that everything else
|
|
3319 ;; on state is before bufpos, so we can glom up the
|
|
3320 ;; whole thing and exit.
|
|
3321 (setq newstate (append newstate (list car) state)
|
|
3322 state nil)))
|
|
3323 (if (<= bufpos car)
|
|
3324 nil ; whack it off
|
|
3325 ;; it's before bufpos, so everything else should too
|
|
3326 (setq newstate (append newstate (list car) state)
|
|
3327 state nil))))
|
|
3328 newstate))
|
|
3329
|
|
3330 (defun c-hack-state (bufpos which state)
|
|
3331 ;; Using BUFPOS buffer position, and WHICH (must be 'open or
|
|
3332 ;; 'close), hack the c-parse-state STATE and return the results.
|
|
3333 (if (eq which 'open)
|
|
3334 (let ((car (car state)))
|
|
3335 (if (or (null car)
|
|
3336 (consp car)
|
|
3337 (/= bufpos car))
|
|
3338 (cons bufpos state)
|
|
3339 state))
|
|
3340 (if (not (eq which 'close))
|
|
3341 (error "c-hack-state, bad argument: %s" which))
|
|
3342 ;; 'close brace
|
|
3343 (let ((car (car state))
|
|
3344 (cdr (cdr state)))
|
|
3345 (if (consp car)
|
|
3346 (setq car (car cdr)
|
|
3347 cdr (cdr cdr)))
|
|
3348 ;; TBD: is this test relevant???
|
|
3349 (if (consp car)
|
|
3350 state ;on error, don't change
|
|
3351 ;; watch out for balanced expr already on cdr of list
|
|
3352 (cons (cons car bufpos)
|
|
3353 (if (consp (car cdr))
|
|
3354 (cdr cdr) cdr))
|
|
3355 ))))
|
|
3356
|
|
3357 (defun c-adjust-state (from to shift state)
|
|
3358 ;; Adjust all points in state that lie in the region FROM..TO by
|
|
3359 ;; SHIFT amount (as would be returned by c-indent-line).
|
|
3360 (mapcar
|
|
3361 (function
|
|
3362 (lambda (e)
|
|
3363 (if (consp e)
|
|
3364 (let ((car (car e))
|
|
3365 (cdr (cdr e)))
|
|
3366 (if (and (<= from car) (< car to))
|
|
3367 (setcar e (+ shift car)))
|
|
3368 (if (and (<= from cdr) (< cdr to))
|
|
3369 (setcdr e (+ shift cdr))))
|
|
3370 (if (and (<= from e) (< e to))
|
|
3371 (setq e (+ shift e))))
|
|
3372 e))
|
|
3373 state))
|
|
3374
|
|
3375
|
|
3376 (defun c-beginning-of-inheritance-list (&optional lim)
|
|
3377 ;; Go to the first non-whitespace after the colon that starts a
|
|
3378 ;; multiple inheritance introduction. Optional LIM is the farthest
|
|
3379 ;; back we should search.
|
|
3380 (let ((lim (or lim (c-point 'bod)))
|
|
3381 (placeholder (progn
|
|
3382 (back-to-indentation)
|
|
3383 (point))))
|
|
3384 (c-backward-syntactic-ws lim)
|
|
3385 (while (and (> (point) lim)
|
|
3386 (memq (preceding-char) '(?, ?:))
|
|
3387 (progn
|
|
3388 (beginning-of-line)
|
|
3389 (setq placeholder (point))
|
|
3390 (skip-chars-forward " \t")
|
|
3391 (not (looking-at c-class-key))
|
|
3392 ))
|
|
3393 (c-backward-syntactic-ws lim))
|
|
3394 (goto-char placeholder)
|
|
3395 (skip-chars-forward "^:" (c-point 'eol))))
|
|
3396
|
|
3397 (defun c-beginning-of-macro (&optional lim)
|
|
3398 ;; Go to the beginning of the macro. Right now we don't support
|
|
3399 ;; multi-line macros too well
|
|
3400 (back-to-indentation))
|
|
3401
|
|
3402 (defun c-in-method-def-p ()
|
|
3403 ;; Return nil if we aren't in a method definition, otherwise the
|
|
3404 ;; position of the initial [+-].
|
|
3405 (save-excursion
|
|
3406 (beginning-of-line)
|
|
3407 (and c-method-key
|
|
3408 (looking-at c-method-key)
|
|
3409 (point))
|
|
3410 ))
|
|
3411
|
|
3412 (defun c-just-after-func-arglist-p (&optional containing)
|
|
3413 ;; Return t if we are between a function's argument list closing
|
|
3414 ;; paren and its opening brace. Note that the list close brace
|
|
3415 ;; could be followed by a "const" specifier or a member init hanging
|
|
3416 ;; colon. Optional CONTAINING is position of containing s-exp open
|
|
3417 ;; brace. If not supplied, point is used as search start.
|
|
3418 (save-excursion
|
|
3419 (c-backward-syntactic-ws)
|
|
3420 (let ((checkpoint (or containing (point))))
|
|
3421 (goto-char checkpoint)
|
|
3422 ;; could be looking at const specifier
|
|
3423 (if (and (= (preceding-char) ?t)
|
|
3424 (forward-word -1)
|
|
3425 (looking-at "\\<const\\>"))
|
|
3426 (c-backward-syntactic-ws)
|
|
3427 ;; otherwise, we could be looking at a hanging member init
|
|
3428 ;; colon
|
|
3429 (goto-char checkpoint)
|
|
3430 (if (and (= (preceding-char) ?:)
|
|
3431 (progn
|
|
3432 (forward-char -1)
|
|
3433 (c-backward-syntactic-ws)
|
|
3434 (looking-at "[ \t\n]*:\\([^:]+\\|$\\)")))
|
|
3435 nil
|
|
3436 (goto-char checkpoint))
|
|
3437 )
|
|
3438 (and (= (preceding-char) ?\))
|
|
3439 ;; check if we are looking at a method def
|
|
3440 (or (not c-method-key)
|
|
3441 (progn
|
|
3442 (forward-sexp -1)
|
|
3443 (forward-char -1)
|
|
3444 (c-backward-syntactic-ws)
|
|
3445 (not (or (= (preceding-char) ?-)
|
|
3446 (= (preceding-char) ?+)
|
|
3447 ;; or a class category
|
|
3448 (progn
|
|
3449 (forward-sexp -2)
|
|
3450 (looking-at c-class-key))
|
|
3451 )))))
|
|
3452 )))
|
|
3453
|
|
3454 ;; defuns to look backwards for things
|
|
3455 (defun c-backward-to-start-of-do (&optional lim)
|
|
3456 ;; Move to the start of the last "unbalanced" do expression.
|
|
3457 ;; Optional LIM is the farthest back to search. If none is found,
|
|
3458 ;; nil is returned and point is left unchanged, otherwise t is returned.
|
|
3459 (let ((do-level 1)
|
|
3460 (case-fold-search nil)
|
|
3461 (lim (or lim (c-point 'bod)))
|
|
3462 (here (point))
|
|
3463 foundp)
|
|
3464 (while (not (zerop do-level))
|
|
3465 ;; we protect this call because trying to execute this when the
|
|
3466 ;; while is not associated with a do will throw an error
|
|
3467 (condition-case nil
|
|
3468 (progn
|
|
3469 (backward-sexp 1)
|
|
3470 (cond
|
|
3471 ((memq (c-in-literal lim) '(c c++)))
|
|
3472 ((looking-at "while\\b[^_]")
|
|
3473 (setq do-level (1+ do-level)))
|
|
3474 ((looking-at "do\\b[^_]")
|
|
3475 (if (zerop (setq do-level (1- do-level)))
|
|
3476 (setq foundp t)))
|
|
3477 ((<= (point) lim)
|
|
3478 (setq do-level 0)
|
|
3479 (goto-char lim))))
|
|
3480 (error
|
|
3481 (goto-char lim)
|
|
3482 (setq do-level 0))))
|
|
3483 (if (not foundp)
|
|
3484 (goto-char here))
|
|
3485 foundp))
|
|
3486
|
|
3487 (defun c-backward-to-start-of-if (&optional lim)
|
|
3488 ;; Move to the start of the last "unbalanced" if and return t. If
|
|
3489 ;; none is found, and we are looking at an if clause, nil is
|
|
3490 ;; returned. If none is found and we are looking at an else clause,
|
|
3491 ;; an error is thrown.
|
|
3492 (let ((if-level 1)
|
|
3493 (here (c-point 'bol))
|
|
3494 (case-fold-search nil)
|
|
3495 (lim (or lim (c-point 'bod)))
|
|
3496 (at-if (looking-at "if\\b[^_]")))
|
|
3497 (catch 'orphan-if
|
|
3498 (while (and (not (bobp))
|
|
3499 (not (zerop if-level)))
|
|
3500 (c-backward-syntactic-ws)
|
|
3501 (condition-case nil
|
|
3502 (backward-sexp 1)
|
|
3503 (error
|
|
3504 (if at-if
|
|
3505 (throw 'orphan-if nil)
|
|
3506 (error "No matching `if' found for `else' on line %d."
|
|
3507 (1+ (count-lines 1 here))))))
|
|
3508 (cond
|
|
3509 ((looking-at "else\\b[^_]")
|
|
3510 (setq if-level (1+ if-level)))
|
|
3511 ((looking-at "if\\b[^_]")
|
|
3512 ;; check for else if... skip over
|
|
3513 (let ((here (point)))
|
|
3514 (c-safe (forward-sexp -1))
|
|
3515 (if (looking-at "\\<else\\>[ \t]+\\<if\\>")
|
|
3516 nil
|
|
3517 (setq if-level (1- if-level))
|
|
3518 (goto-char here))))
|
|
3519 ((< (point) lim)
|
|
3520 (setq if-level 0)
|
|
3521 (goto-char lim))
|
|
3522 ))
|
|
3523 t)))
|
|
3524
|
|
3525 (defun c-skip-conditional ()
|
|
3526 ;; skip forward over conditional at point, including any predicate
|
|
3527 ;; statements in parentheses. No error checking is performed.
|
2
|
3528 (forward-sexp (cond
|
|
3529 ;; else if()
|
|
3530 ((looking-at "\\<else\\>[ \t]+\\<if\\>") 3)
|
|
3531 ;; do, else, try, finally
|
|
3532 ((looking-at "\\<\\(do\\|else\\|try\\|finally\\)\\>") 1)
|
|
3533 ;; for, if, while, switch, catch, synchronized
|
|
3534 (t 2))))
|
0
|
3535
|
|
3536 (defun c-skip-case-statement-forward (state &optional lim)
|
|
3537 ;; skip forward over case/default bodies, with optional maximal
|
|
3538 ;; limit. if no next case body is found, nil is returned and point
|
|
3539 ;; is not moved
|
|
3540 (let ((lim (or lim (point-max)))
|
|
3541 (here (point))
|
|
3542 donep foundp bufpos
|
|
3543 (safepos (point))
|
|
3544 (balanced (car state)))
|
|
3545 ;; search until we've passed the limit, or we've found our match
|
|
3546 (while (and (< (point) lim)
|
|
3547 (not donep))
|
|
3548 (setq safepos (point))
|
|
3549 ;; see if we can find a case statement, not in a literal
|
|
3550 (if (and (re-search-forward c-switch-label-key lim 'move)
|
|
3551 (setq bufpos (match-beginning 0))
|
|
3552 (not (c-in-literal safepos))
|
|
3553 (/= bufpos here))
|
|
3554 ;; if we crossed into a balanced sexp, we know the case is
|
|
3555 ;; not part of our switch statement, so just bound over the
|
|
3556 ;; sexp and keep looking.
|
|
3557 (if (and (consp balanced)
|
|
3558 (> bufpos (car balanced))
|
|
3559 (< bufpos (cdr balanced)))
|
|
3560 (goto-char (cdr balanced))
|
|
3561 (goto-char bufpos)
|
|
3562 (setq donep t
|
|
3563 foundp t))))
|
|
3564 (if (not foundp)
|
|
3565 (goto-char here))
|
|
3566 foundp))
|
|
3567
|
|
3568 (defun c-search-uplist-for-classkey (brace-state)
|
|
3569 ;; search for the containing class, returning a 2 element vector if
|
|
3570 ;; found. aref 0 contains the bufpos of the class key, and aref 1
|
|
3571 ;; contains the bufpos of the open brace.
|
|
3572 (if (null brace-state)
|
|
3573 ;; no brace-state means we cannot be inside a class
|
|
3574 nil
|
|
3575 (let ((carcache (car brace-state))
|
|
3576 search-start search-end)
|
|
3577 (if (consp carcache)
|
|
3578 ;; a cons cell in the first element means that there is some
|
|
3579 ;; balanced sexp before the current bufpos. this we can
|
|
3580 ;; ignore. the nth 1 and nth 2 elements define for us the
|
|
3581 ;; search boundaries
|
|
3582 (setq search-start (nth 2 brace-state)
|
|
3583 search-end (nth 1 brace-state))
|
|
3584 ;; if the car was not a cons cell then nth 0 and nth 1 define
|
|
3585 ;; for us the search boundaries
|
|
3586 (setq search-start (nth 1 brace-state)
|
|
3587 search-end (nth 0 brace-state)))
|
|
3588 ;; search-end cannot be a cons cell
|
|
3589 (and (consp search-end)
|
|
3590 (error "consp search-end: %s" search-end))
|
|
3591 ;; if search-end is nil, or if the search-end character isn't an
|
|
3592 ;; open brace, we are definitely not in a class
|
|
3593 (if (or (not search-end)
|
|
3594 (< search-end (point-min))
|
|
3595 (/= (char-after search-end) ?{))
|
|
3596 nil
|
|
3597 ;; now, we need to look more closely at search-start. if
|
|
3598 ;; search-start is nil, then our start boundary is really
|
|
3599 ;; point-min.
|
|
3600 (if (not search-start)
|
|
3601 (setq search-start (point-min))
|
|
3602 ;; if search-start is a cons cell, then we can start
|
|
3603 ;; searching from the end of the balanced sexp just ahead of
|
|
3604 ;; us
|
|
3605 (if (consp search-start)
|
|
3606 (setq search-start (cdr search-start))))
|
|
3607 ;; now we can do a quick regexp search from search-start to
|
|
3608 ;; search-end and see if we can find a class key. watch for
|
|
3609 ;; class like strings in literals
|
|
3610 (save-excursion
|
|
3611 (save-restriction
|
|
3612 (goto-char search-start)
|
2
|
3613 (let ((search-key (concat c-class-key "\\|extern[^_]"))
|
|
3614 foundp class match-end)
|
0
|
3615 (while (and (not foundp)
|
|
3616 (progn
|
|
3617 (c-forward-syntactic-ws)
|
|
3618 (> search-end (point)))
|
2
|
3619 (re-search-forward search-key search-end t))
|
0
|
3620 (setq class (match-beginning 0)
|
|
3621 match-end (match-end 0))
|
|
3622 (if (c-in-literal search-start)
|
|
3623 nil ; its in a comment or string, ignore
|
|
3624 (goto-char class)
|
|
3625 (skip-chars-forward " \t\n")
|
|
3626 (setq foundp (vector (c-point 'boi) search-end))
|
|
3627 (cond
|
|
3628 ;; check for embedded keywords
|
|
3629 ((let ((char (char-after (1- class))))
|
|
3630 (and char
|
|
3631 (memq (char-syntax char) '(?w ?_))))
|
|
3632 (goto-char match-end)
|
|
3633 (setq foundp nil))
|
|
3634 ;; make sure we're really looking at the start of a
|
|
3635 ;; class definition, and not a forward decl, return
|
|
3636 ;; arg, template arg list, or an ObjC or Java method.
|
|
3637 ((and c-method-key
|
|
3638 (re-search-forward c-method-key search-end t))
|
|
3639 (setq foundp nil))
|
|
3640 ;; Its impossible to define a regexp for this, and
|
|
3641 ;; nearly so to do it programmatically.
|
|
3642 ;;
|
|
3643 ;; ; picks up forward decls
|
|
3644 ;; = picks up init lists
|
|
3645 ;; ) picks up return types
|
|
3646 ;; > picks up templates, but remember that we can
|
|
3647 ;; inherit from templates!
|
|
3648 ((let ((skipchars "^;=)"))
|
|
3649 ;; try to see if we found the `class' keyword
|
|
3650 ;; inside a template arg list
|
|
3651 (save-excursion
|
|
3652 (skip-chars-backward "^<>" search-start)
|
|
3653 (if (= (preceding-char) ?<)
|
|
3654 (setq skipchars (concat skipchars ">"))))
|
|
3655 (skip-chars-forward skipchars search-end)
|
|
3656 (/= (point) search-end))
|
|
3657 (setq foundp nil))
|
|
3658 )))
|
|
3659 foundp))
|
|
3660 )))))
|
|
3661
|
|
3662 (defun c-inside-bracelist-p (containing-sexp brace-state)
|
|
3663 ;; return the buffer position of the beginning of the brace list
|
|
3664 ;; statement if we're inside a brace list, otherwise return nil.
|
|
3665 ;; CONTAINING-SEXP is the buffer pos of the innermost containing
|
|
3666 ;; paren. BRACE-STATE is the remainder of the state of enclosing braces
|
|
3667 ;;
|
|
3668 ;; N.B.: This algorithm can potentially get confused by cpp macros
|
|
3669 ;; places in inconvenient locations. Its a trade-off we make for
|
|
3670 ;; speed.
|
|
3671 (or
|
|
3672 ;; this will pick up enum lists
|
|
3673 (condition-case ()
|
|
3674 (save-excursion
|
|
3675 (goto-char containing-sexp)
|
|
3676 (forward-sexp -1)
|
|
3677 (if (or (looking-at "enum[\t\n ]+")
|
|
3678 (progn (forward-sexp -1)
|
|
3679 (looking-at "enum[\t\n ]+")))
|
|
3680 (point)))
|
|
3681 (error nil))
|
|
3682 ;; this will pick up array/aggregate init lists, even if they are nested.
|
|
3683 (save-excursion
|
|
3684 (let (bufpos failedp)
|
|
3685 (while (and (not bufpos)
|
|
3686 containing-sexp)
|
|
3687 (if (consp containing-sexp)
|
|
3688 (setq containing-sexp (car brace-state)
|
|
3689 brace-state (cdr brace-state))
|
|
3690 ;; see if significant character just before brace is an equal
|
|
3691 (goto-char containing-sexp)
|
|
3692 (setq failedp nil)
|
|
3693 (condition-case ()
|
|
3694 (progn
|
|
3695 (forward-sexp -1)
|
|
3696 (forward-sexp 1)
|
|
3697 (c-forward-syntactic-ws containing-sexp))
|
|
3698 (error (setq failedp t)))
|
|
3699 (if (or failedp (/= (following-char) ?=))
|
|
3700 ;; lets see if we're nested. find the most nested
|
|
3701 ;; containing brace
|
|
3702 (setq containing-sexp (car brace-state)
|
|
3703 brace-state (cdr brace-state))
|
|
3704 ;; we've hit the beginning of the aggregate list
|
|
3705 (c-beginning-of-statement-1 (c-most-enclosing-brace brace-state))
|
|
3706 (setq bufpos (point)))
|
|
3707 ))
|
|
3708 bufpos))
|
|
3709 ))
|
|
3710
|
|
3711
|
|
3712 ;; defuns for calculating the syntactic state and indenting a single
|
|
3713 ;; line of C/C++/ObjC code
|
|
3714 (defmacro c-add-syntax (symbol &optional relpos)
|
|
3715 ;; a simple macro to append the syntax in symbol to the syntax list.
|
|
3716 ;; try to increase performance by using this macro
|
|
3717 (` (setq syntax (cons (cons (, symbol) (, relpos)) syntax))))
|
|
3718
|
|
3719 (defun c-most-enclosing-brace (state)
|
|
3720 ;; return the bufpos of the most enclosing brace that hasn't been
|
|
3721 ;; narrowed out by any enclosing class, or nil if none was found
|
|
3722 (let (enclosingp)
|
|
3723 (while (and state (not enclosingp))
|
|
3724 (setq enclosingp (car state)
|
|
3725 state (cdr state))
|
|
3726 (if (consp enclosingp)
|
|
3727 (setq enclosingp nil)
|
|
3728 (if (> (point-min) enclosingp)
|
|
3729 (setq enclosingp nil))
|
|
3730 (setq state nil)))
|
|
3731 enclosingp))
|
|
3732
|
|
3733 (defun c-least-enclosing-brace (state)
|
|
3734 ;; return the bufpos of the least (highest) enclosing brace that
|
|
3735 ;; hasn't been narrowed out by any enclosing class, or nil if none
|
|
3736 ;; was found.
|
|
3737 (c-most-enclosing-brace (nreverse state)))
|
|
3738
|
|
3739 (defun c-safe-position (bufpos state)
|
|
3740 ;; return the closest known safe position higher up than point
|
|
3741 (let ((safepos nil))
|
|
3742 (while state
|
|
3743 (setq safepos
|
|
3744 (if (consp (car state))
|
|
3745 (cdr (car state))
|
|
3746 (car state)))
|
|
3747 (if (< safepos bufpos)
|
|
3748 (setq state nil)
|
|
3749 (setq state (cdr state))))
|
|
3750 safepos))
|
|
3751
|
|
3752 (defun c-narrow-out-enclosing-class (state lim)
|
|
3753 ;; narrow the buffer so that the enclosing class is hidden
|
|
3754 (let (inclass-p)
|
|
3755 (and state
|
|
3756 (setq inclass-p (c-search-uplist-for-classkey state))
|
|
3757 (narrow-to-region
|
|
3758 (progn
|
|
3759 (goto-char (1+ (aref inclass-p 1)))
|
|
3760 (skip-chars-forward " \t\n" lim)
|
|
3761 ;; if point is now left of the class opening brace, we're
|
|
3762 ;; hosed, so try a different tact
|
|
3763 (if (<= (point) (aref inclass-p 1))
|
|
3764 (progn
|
|
3765 (goto-char (1+ (aref inclass-p 1)))
|
|
3766 (c-forward-syntactic-ws lim)))
|
|
3767 (point))
|
|
3768 ;; end point is the end of the current line
|
|
3769 (progn
|
|
3770 (goto-char lim)
|
|
3771 (c-point 'eol))))
|
|
3772 ;; return the class vector
|
|
3773 inclass-p))
|
|
3774
|
|
3775 (defun c-guess-basic-syntax ()
|
|
3776 ;; guess the syntactic description of the current line of C++ code.
|
|
3777 (save-excursion
|
|
3778 (save-restriction
|
|
3779 (beginning-of-line)
|
|
3780 (let* ((indent-point (point))
|
|
3781 (case-fold-search nil)
|
|
3782 (fullstate (c-parse-state))
|
|
3783 (state fullstate)
|
|
3784 (in-method-intro-p (and c-method-key
|
|
3785 (looking-at c-method-key)))
|
|
3786 literal containing-sexp char-before-ip char-after-ip lim
|
|
3787 syntax placeholder c-in-literal-cache inswitch-p
|
2
|
3788 ;; narrow out any enclosing class or extern "C" block
|
0
|
3789 (inclass-p (c-narrow-out-enclosing-class state indent-point))
|
2
|
3790 (inextern-p (and inclass-p
|
|
3791 (save-excursion
|
|
3792 (save-restriction
|
|
3793 (widen)
|
|
3794 (goto-char (aref inclass-p 0))
|
|
3795 (looking-at "extern[^_]")))))
|
0
|
3796 )
|
|
3797
|
|
3798 ;; get the buffer position of the most nested opening brace,
|
|
3799 ;; if there is one, and it hasn't been narrowed out
|
|
3800 (save-excursion
|
|
3801 (goto-char indent-point)
|
|
3802 (skip-chars-forward " \t}")
|
|
3803 (skip-chars-backward " \t")
|
|
3804 (while (and state
|
|
3805 (not in-method-intro-p)
|
|
3806 (not containing-sexp))
|
|
3807 (setq containing-sexp (car state)
|
|
3808 state (cdr state))
|
|
3809 (if (consp containing-sexp)
|
|
3810 ;; if cdr == point, then containing sexp is the brace
|
|
3811 ;; that opens the sexp we close
|
|
3812 (if (= (cdr containing-sexp) (point))
|
|
3813 (setq containing-sexp (car containing-sexp))
|
|
3814 ;; otherwise, ignore this element
|
|
3815 (setq containing-sexp nil))
|
|
3816 ;; ignore the bufpos if its been narrowed out by the
|
|
3817 ;; containing class
|
|
3818 (if (<= containing-sexp (point-min))
|
|
3819 (setq containing-sexp nil)))))
|
|
3820
|
|
3821 ;; set the limit on the farthest back we need to search
|
|
3822 (setq lim (or containing-sexp
|
|
3823 (if (consp (car fullstate))
|
|
3824 (cdr (car fullstate))
|
|
3825 nil)
|
|
3826 (point-min)))
|
|
3827
|
|
3828 ;; cache char before and after indent point, and move point to
|
|
3829 ;; the most likely position to perform the majority of tests
|
|
3830 (goto-char indent-point)
|
|
3831 (skip-chars-forward " \t")
|
|
3832 (setq char-after-ip (following-char))
|
|
3833 (c-backward-syntactic-ws lim)
|
|
3834 (setq char-before-ip (preceding-char))
|
|
3835 (goto-char indent-point)
|
|
3836 (skip-chars-forward " \t")
|
|
3837
|
|
3838 ;; are we in a literal?
|
|
3839 (setq literal (c-in-literal lim))
|
|
3840
|
|
3841 ;; now figure out syntactic qualities of the current line
|
|
3842 (cond
|
|
3843 ;; CASE 1: in a string.
|
|
3844 ((memq literal '(string))
|
|
3845 (c-add-syntax 'string (c-point 'bopl)))
|
|
3846 ;; CASE 2: in a C or C++ style comment.
|
|
3847 ((memq literal '(c c++))
|
|
3848 ;; we need to catch multi-paragraph C comments
|
|
3849 (while (and (zerop (forward-line -1))
|
|
3850 (looking-at "^[ \t]*$")))
|
|
3851 (c-add-syntax literal (c-point 'bol)))
|
|
3852 ;; CASE 3: in a cpp preprocessor
|
|
3853 ((eq literal 'pound)
|
|
3854 (c-beginning-of-macro lim)
|
|
3855 (c-add-syntax 'cpp-macro (c-point 'boi)))
|
|
3856 ;; CASE 4: in an objective-c method intro
|
|
3857 (in-method-intro-p
|
|
3858 (c-add-syntax 'objc-method-intro (c-point 'boi)))
|
|
3859 ;; CASE 5: Line is at top level.
|
|
3860 ((null containing-sexp)
|
|
3861 (cond
|
|
3862 ;; CASE 5A: we are looking at a defun, class, or
|
|
3863 ;; inline-inclass method opening brace
|
|
3864 ((= char-after-ip ?{)
|
|
3865 (cond
|
2
|
3866 ;; CASE 5A.1: extern declaration
|
|
3867 ((save-excursion
|
|
3868 (goto-char indent-point)
|
|
3869 (skip-chars-forward " \t")
|
|
3870 (and (c-safe (progn (backward-sexp 2) t))
|
|
3871 (looking-at "extern[^_]")
|
|
3872 (progn
|
|
3873 (setq placeholder (point))
|
|
3874 (forward-sexp 1)
|
|
3875 (c-forward-syntactic-ws)
|
|
3876 (= (following-char) ?\"))))
|
|
3877 (goto-char placeholder)
|
|
3878 (c-add-syntax 'extern-lang-open (c-point 'boi)))
|
|
3879 ;; CASE 5A.2: we are looking at a class opening brace
|
0
|
3880 ((save-excursion
|
|
3881 (goto-char indent-point)
|
|
3882 (skip-chars-forward " \t{")
|
|
3883 ;; TBD: watch out! there could be a bogus
|
|
3884 ;; c-state-cache in place when we get here. we have
|
|
3885 ;; to go through much chicanery to ignore the cache.
|
|
3886 ;; But of course, there may not be! BLECH! BOGUS!
|
|
3887 (let ((decl
|
|
3888 (if (boundp 'c-state-cache)
|
|
3889 (let ((old-cache c-state-cache))
|
|
3890 (prog2
|
|
3891 (makunbound 'c-state-cache)
|
|
3892 (c-search-uplist-for-classkey (c-parse-state))
|
|
3893 (setq c-state-cache old-cache)))
|
|
3894 (c-search-uplist-for-classkey (c-parse-state))
|
|
3895 )))
|
|
3896 (and decl
|
|
3897 (setq placeholder (aref decl 0)))
|
|
3898 ))
|
|
3899 (c-add-syntax 'class-open placeholder))
|
2
|
3900 ;; CASE 5A.3: brace list open
|
0
|
3901 ((save-excursion
|
|
3902 (c-beginning-of-statement-1 lim)
|
|
3903 ;; c-b-o-s could have left us at point-min
|
|
3904 (and (bobp)
|
|
3905 (c-forward-syntactic-ws indent-point))
|
|
3906 (setq placeholder (point))
|
|
3907 (and (or (looking-at "enum[ \t\n]+")
|
|
3908 (= char-before-ip ?=))
|
|
3909 (save-excursion
|
|
3910 (skip-chars-forward "^;(" indent-point)
|
|
3911 (not (memq (following-char) '(?\; ?\()))
|
|
3912 )))
|
|
3913 (c-add-syntax 'brace-list-open placeholder))
|
2
|
3914 ;; CASE 5A.4: inline defun open
|
|
3915 ((and inclass-p (not inextern-p))
|
|
3916 (c-add-syntax 'inline-open)
|
|
3917 (c-add-syntax 'inclass (aref inclass-p 0)))
|
|
3918 ;; CASE 5A.5: ordinary defun open
|
0
|
3919 (t
|
|
3920 (goto-char placeholder)
|
|
3921 (c-add-syntax 'defun-open (c-point 'bol))
|
|
3922 )))
|
|
3923 ;; CASE 5B: first K&R arg decl or member init
|
|
3924 ((c-just-after-func-arglist-p)
|
|
3925 (cond
|
|
3926 ;; CASE 5B.1: a member init
|
|
3927 ((or (= char-before-ip ?:)
|
|
3928 (= char-after-ip ?:))
|
|
3929 ;; this line should be indented relative to the beginning
|
|
3930 ;; of indentation for the topmost-intro line that contains
|
|
3931 ;; the prototype's open paren
|
|
3932 ;; TBD: is the following redundant?
|
|
3933 (if (= char-before-ip ?:)
|
|
3934 (forward-char -1))
|
|
3935 (c-backward-syntactic-ws lim)
|
|
3936 ;; TBD: is the preceding redundant?
|
|
3937 (if (= (preceding-char) ?:)
|
|
3938 (progn (forward-char -1)
|
|
3939 (c-backward-syntactic-ws lim)))
|
|
3940 (if (= (preceding-char) ?\))
|
|
3941 (backward-sexp 1))
|
|
3942 (c-add-syntax 'member-init-intro (c-point 'boi))
|
|
3943 ;; we don't need to add any class offset since this
|
|
3944 ;; should be relative to the ctor's indentation
|
|
3945 )
|
|
3946 ;; CASE 5B.2: K&R arg decl intro
|
|
3947 (c-recognize-knr-p
|
|
3948 (c-add-syntax 'knr-argdecl-intro (c-point 'boi))
|
|
3949 (and inclass-p (c-add-syntax 'inclass (aref inclass-p 0))))
|
|
3950 ;; CASE 5B.3: Nether region after a C++ func decl, which
|
|
3951 ;; could include a `throw' declaration.
|
|
3952 (t
|
|
3953 (c-beginning-of-statement-1 lim)
|
|
3954 (c-add-syntax 'ansi-funcdecl-cont (c-point 'boi))
|
|
3955 )))
|
|
3956 ;; CASE 5C: inheritance line. could be first inheritance
|
|
3957 ;; line, or continuation of a multiple inheritance
|
|
3958 ((or (and c-baseclass-key (looking-at c-baseclass-key))
|
|
3959 (and (or (= char-before-ip ?:)
|
|
3960 (= char-after-ip ?:))
|
|
3961 (save-excursion
|
|
3962 (c-backward-syntactic-ws lim)
|
|
3963 (if (= char-before-ip ?:)
|
|
3964 (progn
|
|
3965 (forward-char -1)
|
|
3966 (c-backward-syntactic-ws lim)))
|
|
3967 (back-to-indentation)
|
|
3968 (looking-at c-class-key))))
|
|
3969 (cond
|
|
3970 ;; CASE 5C.1: non-hanging colon on an inher intro
|
|
3971 ((= char-after-ip ?:)
|
|
3972 (c-backward-syntactic-ws lim)
|
|
3973 (c-add-syntax 'inher-intro (c-point 'boi))
|
|
3974 ;; don't add inclass symbol since relative point already
|
|
3975 ;; contains any class offset
|
|
3976 )
|
|
3977 ;; CASE 5C.2: hanging colon on an inher intro
|
|
3978 ((= char-before-ip ?:)
|
|
3979 (c-add-syntax 'inher-intro (c-point 'boi))
|
|
3980 (and inclass-p (c-add-syntax 'inclass (aref inclass-p 0))))
|
|
3981 ;; CASE 5C.3: a continued inheritance line
|
|
3982 (t
|
|
3983 (c-beginning-of-inheritance-list lim)
|
|
3984 (c-add-syntax 'inher-cont (point))
|
|
3985 ;; don't add inclass symbol since relative point already
|
|
3986 ;; contains any class offset
|
|
3987 )))
|
|
3988 ;; CASE 5D: this could be a top-level compound statement or a
|
|
3989 ;; member init list continuation
|
|
3990 ((= char-before-ip ?,)
|
|
3991 (goto-char indent-point)
|
|
3992 (c-backward-syntactic-ws lim)
|
|
3993 (while (and (< lim (point))
|
|
3994 (= (preceding-char) ?,))
|
|
3995 ;; this will catch member inits with multiple
|
|
3996 ;; line arglists
|
|
3997 (forward-char -1)
|
|
3998 (c-backward-syntactic-ws (c-point 'bol))
|
|
3999 (if (= (preceding-char) ?\))
|
|
4000 (backward-sexp 1))
|
|
4001 ;; now continue checking
|
|
4002 (beginning-of-line)
|
|
4003 (c-backward-syntactic-ws lim))
|
|
4004 (cond
|
|
4005 ;; CASE 5D.1: hanging member init colon, but watch out
|
|
4006 ;; for bogus matches on access specifiers inside classes.
|
|
4007 ((and (= (preceding-char) ?:)
|
|
4008 (save-excursion
|
|
4009 (forward-word -1)
|
|
4010 (not (looking-at c-access-key))))
|
|
4011 (goto-char indent-point)
|
|
4012 (c-backward-syntactic-ws lim)
|
|
4013 (c-safe (backward-sexp 1))
|
|
4014 (c-add-syntax 'member-init-cont (c-point 'boi))
|
|
4015 ;; we do not need to add class offset since relative
|
|
4016 ;; point is the member init above us
|
|
4017 )
|
|
4018 ;; CASE 5D.2: non-hanging member init colon
|
|
4019 ((progn
|
|
4020 (c-forward-syntactic-ws indent-point)
|
|
4021 (= (following-char) ?:))
|
|
4022 (skip-chars-forward " \t:")
|
|
4023 (c-add-syntax 'member-init-cont (point)))
|
|
4024 ;; CASE 5D.3: perhaps a multiple inheritance line?
|
|
4025 ((looking-at c-inher-key)
|
|
4026 (c-add-syntax 'inher-cont (c-point 'boi)))
|
|
4027 ;; CASE 5D.4: perhaps a template list continuation?
|
|
4028 ((save-excursion
|
|
4029 (skip-chars-backward "^<" lim)
|
|
4030 ;; not sure if this is the right test, but it should
|
|
4031 ;; be fast and mostly accurate.
|
|
4032 (and (= (preceding-char) ?<)
|
|
4033 (not (c-in-literal lim))))
|
|
4034 ;; we can probably indent it just like and arglist-cont
|
|
4035 (c-add-syntax 'arglist-cont (point)))
|
|
4036 ;; CASE 5D.5: perhaps a top-level statement-cont
|
|
4037 (t
|
|
4038 (c-beginning-of-statement-1 lim)
|
|
4039 ;; skip over any access-specifiers
|
|
4040 (and inclass-p c-access-key
|
|
4041 (while (looking-at c-access-key)
|
|
4042 (forward-line 1)))
|
|
4043 ;; skip over comments, whitespace
|
|
4044 (c-forward-syntactic-ws indent-point)
|
|
4045 (c-add-syntax 'statement-cont (c-point 'boi)))
|
|
4046 ))
|
|
4047 ;; CASE 5E: we are looking at a access specifier
|
|
4048 ((and inclass-p
|
|
4049 c-access-key
|
|
4050 (looking-at c-access-key))
|
|
4051 (c-add-syntax 'access-label (c-point 'bonl))
|
|
4052 (c-add-syntax 'inclass (aref inclass-p 0)))
|
2
|
4053 ;; CASE 5F: extern-lang-close?
|
|
4054 ((and inextern-p
|
|
4055 (= char-after-ip ?}))
|
|
4056 (c-add-syntax 'extern-lang-close (aref inclass-p 1)))
|
|
4057 ;; CASE 5G: we are looking at the brace which closes the
|
0
|
4058 ;; enclosing nested class decl
|
|
4059 ((and inclass-p
|
|
4060 (= char-after-ip ?})
|
|
4061 (save-excursion
|
|
4062 (save-restriction
|
|
4063 (widen)
|
|
4064 (forward-char 1)
|
|
4065 (and
|
|
4066 (condition-case nil
|
|
4067 (progn (backward-sexp 1) t)
|
|
4068 (error nil))
|
|
4069 (= (point) (aref inclass-p 1))
|
|
4070 ))))
|
|
4071 (save-restriction
|
|
4072 (widen)
|
|
4073 (goto-char (aref inclass-p 0))
|
|
4074 (c-add-syntax 'class-close (c-point 'boi))))
|
2
|
4075 ;; CASE 5H: we could be looking at subsequent knr-argdecls
|
0
|
4076 ((and c-recognize-knr-p
|
2
|
4077 ;; here we essentially use the hack that is used in
|
|
4078 ;; Emacs' c-mode.el to limit how far back we should
|
|
4079 ;; look. The assumption is made that argdecls are
|
|
4080 ;; indented at least one space and that function
|
|
4081 ;; headers are not indented.
|
|
4082 (let ((limit (save-excursion
|
|
4083 (re-search-backward "^[^ \^L\t\n#]" nil 'move)
|
|
4084 (point))))
|
|
4085 (save-excursion
|
|
4086 (c-backward-syntactic-ws limit)
|
|
4087 (while (and (memq (preceding-char) '(?\; ?,))
|
|
4088 (> (point) limit))
|
|
4089 (beginning-of-line)
|
|
4090 (setq placeholder (point))
|
|
4091 (c-backward-syntactic-ws limit))
|
|
4092 (and (= (preceding-char) ?\))
|
|
4093 (or (not c-method-key)
|
|
4094 (progn
|
|
4095 (forward-sexp -1)
|
|
4096 (forward-char -1)
|
|
4097 (c-backward-syntactic-ws)
|
|
4098 (not (or (= (preceding-char) ?-)
|
|
4099 (= (preceding-char) ?+)
|
|
4100 ;; or a class category
|
|
4101 (progn
|
|
4102 (forward-sexp -2)
|
|
4103 (looking-at c-class-key))
|
|
4104 )))))
|
|
4105 ))
|
0
|
4106 (save-excursion
|
|
4107 (c-beginning-of-statement-1)
|
|
4108 (not (looking-at "typedef[ \t\n]+"))))
|
|
4109 (goto-char placeholder)
|
|
4110 (c-add-syntax 'knr-argdecl (c-point 'boi)))
|
2
|
4111 ;; CASE 5I: we are at the topmost level, make sure we skip
|
0
|
4112 ;; back past any access specifiers
|
|
4113 ((progn
|
|
4114 (c-backward-syntactic-ws lim)
|
|
4115 (while (and inclass-p
|
|
4116 c-access-key
|
|
4117 (not (bobp))
|
|
4118 (save-excursion
|
|
4119 (c-safe (progn (backward-sexp 1) t))
|
|
4120 (looking-at c-access-key)))
|
|
4121 (backward-sexp 1)
|
|
4122 (c-backward-syntactic-ws lim))
|
|
4123 (or (bobp)
|
|
4124 (memq (preceding-char) '(?\; ?\}))))
|
|
4125 ;; real beginning-of-line could be narrowed out due to
|
|
4126 ;; enclosure in a class block
|
|
4127 (save-restriction
|
|
4128 (widen)
|
|
4129 (c-add-syntax 'topmost-intro (c-point 'bol))
|
|
4130 (if inclass-p
|
|
4131 (progn
|
|
4132 (goto-char (aref inclass-p 1))
|
2
|
4133 (if inextern-p
|
|
4134 (c-add-syntax 'inextern-lang)
|
|
4135 (c-add-syntax 'inclass (c-point 'boi)))))
|
|
4136 ))
|
|
4137 ;; CASE 5J: we are at an ObjC or Java method definition
|
0
|
4138 ;; continuation line.
|
|
4139 ((and c-method-key
|
|
4140 (progn
|
|
4141 (c-beginning-of-statement-1 lim)
|
|
4142 (beginning-of-line)
|
|
4143 (looking-at c-method-key)))
|
|
4144 (c-add-syntax 'objc-method-args-cont (point)))
|
2
|
4145 ;; CASE 5K: we are at a topmost continuation line
|
0
|
4146 (t
|
|
4147 (c-beginning-of-statement-1 lim)
|
|
4148 (c-forward-syntactic-ws)
|
|
4149 (c-add-syntax 'topmost-intro-cont (c-point 'boi)))
|
|
4150 )) ; end CASE 5
|
|
4151 ;; CASE 6: line is an expression, not a statement. Most
|
|
4152 ;; likely we are either in a function prototype or a function
|
|
4153 ;; call argument list
|
|
4154 ((/= (char-after containing-sexp) ?{)
|
|
4155 (c-backward-syntactic-ws containing-sexp)
|
|
4156 (cond
|
|
4157 ;; CASE 6A: we are looking at the arglist closing paren or
|
|
4158 ;; at an Objective-C or Java method call closing bracket.
|
|
4159 ((and (/= char-before-ip ?,)
|
|
4160 (memq char-after-ip '(?\) ?\])))
|
|
4161 (if (and c-method-key
|
|
4162 (progn
|
|
4163 (goto-char (1- containing-sexp))
|
|
4164 (c-backward-syntactic-ws lim)
|
|
4165 (not (looking-at c-symbol-key))))
|
|
4166 (c-add-syntax 'statement-cont containing-sexp)
|
|
4167 (goto-char containing-sexp)
|
|
4168 (c-add-syntax 'arglist-close (c-point 'boi))))
|
|
4169 ;; CASE 6B: we are looking at the first argument in an empty
|
|
4170 ;; argument list. Use arglist-close if we're actually
|
|
4171 ;; looking at a close paren or bracket.
|
|
4172 ((memq char-before-ip '(?\( ?\[))
|
|
4173 (goto-char containing-sexp)
|
|
4174 (c-add-syntax 'arglist-intro (c-point 'boi)))
|
|
4175 ;; CASE 6C: we are inside a conditional test clause. treat
|
|
4176 ;; these things as statements
|
|
4177 ((save-excursion
|
|
4178 (goto-char containing-sexp)
|
|
4179 (and (c-safe (progn (forward-sexp -1) t))
|
|
4180 (looking-at "\\<for\\>")))
|
|
4181 (goto-char (1+ containing-sexp))
|
|
4182 (c-forward-syntactic-ws indent-point)
|
|
4183 (c-beginning-of-statement-1 containing-sexp)
|
|
4184 (if (= char-before-ip ?\;)
|
|
4185 (c-add-syntax 'statement (point))
|
|
4186 (c-add-syntax 'statement-cont (point))
|
|
4187 ))
|
|
4188 ;; CASE 6D: maybe a continued method call. This is the case
|
|
4189 ;; when we are inside a [] bracketed exp, and what precede
|
|
4190 ;; the opening bracket is not an identifier.
|
|
4191 ((and c-method-key
|
|
4192 (= (char-after containing-sexp) ?\[)
|
|
4193 (save-excursion
|
|
4194 (goto-char (1- containing-sexp))
|
|
4195 (c-backward-syntactic-ws (c-point 'bod))
|
|
4196 (if (not (looking-at c-symbol-key))
|
|
4197 (c-add-syntax 'objc-method-call-cont containing-sexp))
|
|
4198 )))
|
|
4199 ;; CASE 6E: we are looking at an arglist continuation line,
|
|
4200 ;; but the preceding argument is on the same line as the
|
|
4201 ;; opening paren. This case includes multi-line
|
|
4202 ;; mathematical paren groupings, but we could be on a
|
|
4203 ;; for-list continuation line
|
|
4204 ((and (save-excursion
|
|
4205 (goto-char (1+ containing-sexp))
|
|
4206 (skip-chars-forward " \t")
|
|
4207 (not (eolp)))
|
|
4208 (save-excursion
|
|
4209 (c-beginning-of-statement-1 lim)
|
|
4210 (skip-chars-backward " \t([")
|
|
4211 (<= (point) containing-sexp)))
|
|
4212 (goto-char containing-sexp)
|
|
4213 (c-add-syntax 'arglist-cont-nonempty (c-point 'boi)))
|
|
4214 ;; CASE 6F: we are looking at just a normal arglist
|
|
4215 ;; continuation line
|
|
4216 (t (c-beginning-of-statement-1 containing-sexp)
|
|
4217 (forward-char 1)
|
|
4218 (c-forward-syntactic-ws indent-point)
|
|
4219 (c-add-syntax 'arglist-cont (c-point 'boi)))
|
|
4220 ))
|
|
4221 ;; CASE 7: func-local multi-inheritance line
|
|
4222 ((and c-baseclass-key
|
|
4223 (save-excursion
|
|
4224 (goto-char indent-point)
|
|
4225 (skip-chars-forward " \t")
|
|
4226 (looking-at c-baseclass-key)))
|
|
4227 (goto-char indent-point)
|
|
4228 (skip-chars-forward " \t")
|
|
4229 (cond
|
|
4230 ;; CASE 7A: non-hanging colon on an inher intro
|
|
4231 ((= char-after-ip ?:)
|
|
4232 (c-backward-syntactic-ws lim)
|
|
4233 (c-add-syntax 'inher-intro (c-point 'boi)))
|
|
4234 ;; CASE 7B: hanging colon on an inher intro
|
|
4235 ((= char-before-ip ?:)
|
|
4236 (c-add-syntax 'inher-intro (c-point 'boi)))
|
|
4237 ;; CASE 7C: a continued inheritance line
|
|
4238 (t
|
|
4239 (c-beginning-of-inheritance-list lim)
|
|
4240 (c-add-syntax 'inher-cont (point))
|
|
4241 )))
|
|
4242 ;; CASE 8: we are inside a brace-list
|
|
4243 ((setq placeholder (c-inside-bracelist-p containing-sexp state))
|
|
4244 (cond
|
|
4245 ;; CASE 8A: brace-list-close brace
|
|
4246 ((and (= char-after-ip ?})
|
|
4247 (c-safe (progn (forward-char 1)
|
|
4248 (backward-sexp 1)
|
|
4249 t))
|
|
4250 (= (point) containing-sexp))
|
|
4251 (c-add-syntax 'brace-list-close (c-point 'boi)))
|
|
4252 ;; CASE 8B: we're looking at the first line in a brace-list
|
|
4253 ((save-excursion
|
|
4254 (goto-char indent-point)
|
|
4255 (c-backward-syntactic-ws containing-sexp)
|
|
4256 (= (point) (1+ containing-sexp)))
|
|
4257 (goto-char containing-sexp)
|
|
4258 ;;(if (= char-after-ip ?{)
|
|
4259 ;;(c-add-syntax 'brace-list-open (c-point 'boi))
|
|
4260 (c-add-syntax 'brace-list-intro (c-point 'boi))
|
|
4261 )
|
|
4262 ;;)) ; end CASE 8B
|
|
4263 ;; CASE 8C: this is just a later brace-list-entry
|
|
4264 (t (goto-char (1+ containing-sexp))
|
|
4265 (c-forward-syntactic-ws indent-point)
|
|
4266 (if (= char-after-ip ?{)
|
|
4267 (c-add-syntax 'brace-list-open (point))
|
|
4268 (c-add-syntax 'brace-list-entry (point))
|
|
4269 )) ; end CASE 8C
|
|
4270 )) ; end CASE 8
|
|
4271 ;; CASE 9: A continued statement
|
|
4272 ((and (not (memq char-before-ip '(?\; ?} ?:)))
|
|
4273 (> (point)
|
|
4274 (save-excursion
|
|
4275 (c-beginning-of-statement-1 containing-sexp)
|
|
4276 (setq placeholder (point))))
|
|
4277 (/= placeholder containing-sexp))
|
|
4278 (goto-char indent-point)
|
|
4279 (skip-chars-forward " \t")
|
|
4280 (let ((after-cond-placeholder
|
|
4281 (save-excursion
|
|
4282 (goto-char placeholder)
|
|
4283 (if (looking-at c-conditional-key)
|
|
4284 (progn
|
|
4285 (c-safe (c-skip-conditional))
|
|
4286 (c-forward-syntactic-ws)
|
|
4287 (if (memq (following-char) '(?\;))
|
|
4288 (progn
|
|
4289 (forward-char 1)
|
|
4290 (c-forward-syntactic-ws)))
|
|
4291 (point))
|
|
4292 nil))))
|
|
4293 (cond
|
|
4294 ;; CASE 9A: substatement
|
|
4295 ((and after-cond-placeholder
|
|
4296 (>= after-cond-placeholder indent-point))
|
|
4297 (goto-char placeholder)
|
|
4298 (if (= char-after-ip ?{)
|
|
4299 (c-add-syntax 'substatement-open (c-point 'boi))
|
|
4300 (c-add-syntax 'substatement (c-point 'boi))))
|
|
4301 ;; CASE 9B: open braces for class or brace-lists
|
|
4302 ((= char-after-ip ?{)
|
|
4303 (cond
|
|
4304 ;; CASE 9B.1: class-open
|
|
4305 ((save-excursion
|
|
4306 (goto-char indent-point)
|
|
4307 (skip-chars-forward " \t{")
|
|
4308 (let ((decl (c-search-uplist-for-classkey (c-parse-state))))
|
|
4309 (and decl
|
|
4310 (setq placeholder (aref decl 0)))
|
|
4311 ))
|
|
4312 (c-add-syntax 'class-open placeholder))
|
|
4313 ;; CASE 9B.2: brace-list-open
|
|
4314 ((or (save-excursion
|
|
4315 (goto-char placeholder)
|
|
4316 (looking-at "\\<enum\\>"))
|
|
4317 (= char-before-ip ?=))
|
|
4318 (c-add-syntax 'brace-list-open placeholder))
|
|
4319 ;; CASE 9B.3: catch-all for unknown construct.
|
|
4320 (t
|
|
4321 ;; Can and should I add an extensibility hook here?
|
|
4322 ;; Something like c-recognize-hook so support for
|
|
4323 ;; unknown constructs could be added. It's probably a
|
|
4324 ;; losing proposition, so I dunno.
|
|
4325 (goto-char placeholder)
|
|
4326 (c-add-syntax 'statement-cont (c-point 'boi))
|
|
4327 (c-add-syntax 'block-open))
|
|
4328 ))
|
|
4329 ;; CASE 9C: iostream insertion or extraction operator
|
|
4330 ((looking-at "<<\\|>>")
|
|
4331 (goto-char placeholder)
|
|
4332 (and after-cond-placeholder
|
|
4333 (goto-char after-cond-placeholder))
|
|
4334 (while (and (re-search-forward "<<\\|>>" indent-point 'move)
|
|
4335 (c-in-literal placeholder)))
|
|
4336 ;; if we ended up at indent-point, then the first
|
|
4337 ;; streamop is on a separate line. Indent the line like
|
|
4338 ;; a statement-cont instead
|
|
4339 (if (/= (point) indent-point)
|
|
4340 (c-add-syntax 'stream-op (c-point 'boi))
|
|
4341 (c-backward-syntactic-ws lim)
|
|
4342 (c-add-syntax 'statement-cont (c-point 'boi))))
|
|
4343 ;; CASE 9D: continued statement. find the accurate
|
|
4344 ;; beginning of statement or substatement
|
|
4345 (t
|
|
4346 (c-beginning-of-statement-1 after-cond-placeholder)
|
|
4347 ;; KLUDGE ALERT! c-beginning-of-statement-1 can leave
|
|
4348 ;; us before the lim we're passing in. It should be
|
|
4349 ;; fixed, but I'm worried about side-effects at this
|
|
4350 ;; late date. Fix for v5.
|
|
4351 (goto-char (or (and after-cond-placeholder
|
|
4352 (max after-cond-placeholder (point)))
|
|
4353 (point)))
|
|
4354 (c-add-syntax 'statement-cont (point)))
|
|
4355 )))
|
|
4356 ;; CASE 10: an else clause?
|
|
4357 ((looking-at "\\<else\\>[^_]")
|
|
4358 (c-backward-to-start-of-if containing-sexp)
|
|
4359 (c-add-syntax 'else-clause (c-point 'boi)))
|
|
4360 ;; CASE 11: Statement. But what kind? Lets see if its a
|
|
4361 ;; while closure of a do/while construct
|
|
4362 ((progn
|
|
4363 (goto-char indent-point)
|
|
4364 (skip-chars-forward " \t")
|
|
4365 (and (looking-at "while\\b[^_]")
|
|
4366 (save-excursion
|
|
4367 (c-backward-to-start-of-do containing-sexp)
|
|
4368 (setq placeholder (point))
|
|
4369 (looking-at "do\\b[^_]"))
|
|
4370 ))
|
|
4371 (c-add-syntax 'do-while-closure placeholder))
|
|
4372 ;; CASE 12: A case or default label
|
|
4373 ((looking-at c-switch-label-key)
|
|
4374 (goto-char containing-sexp)
|
|
4375 ;; check for hanging braces
|
|
4376 (if (/= (point) (c-point 'boi))
|
|
4377 (forward-sexp -1))
|
|
4378 (c-add-syntax 'case-label (c-point 'boi)))
|
|
4379 ;; CASE 13: any other label
|
|
4380 ((looking-at c-label-key)
|
|
4381 (goto-char containing-sexp)
|
|
4382 (c-add-syntax 'label (c-point 'boi)))
|
|
4383 ;; CASE 14: block close brace, possibly closing the defun or
|
|
4384 ;; the class
|
|
4385 ((= char-after-ip ?})
|
|
4386 (let* ((lim (c-safe-position containing-sexp fullstate))
|
|
4387 (relpos (save-excursion
|
|
4388 (goto-char containing-sexp)
|
|
4389 (if (/= (point) (c-point 'boi))
|
|
4390 (c-beginning-of-statement-1 lim))
|
|
4391 (c-point 'boi))))
|
|
4392 (cond
|
|
4393 ;; CASE 14A: does this close an inline?
|
2
|
4394 ((let ((inclass-p (progn
|
|
4395 (goto-char containing-sexp)
|
|
4396 (c-search-uplist-for-classkey state))))
|
|
4397 ;; inextern-p in higher level let*
|
|
4398 (setq inextern-p (and inclass-p
|
|
4399 (progn
|
|
4400 (goto-char (aref inclass-p 0))
|
|
4401 (looking-at "extern[^_]"))))
|
|
4402 (and inclass-p (not inextern-p)))
|
0
|
4403 (c-add-syntax 'inline-close relpos))
|
|
4404 ;; CASE 14B: if there an enclosing brace that hasn't
|
|
4405 ;; been narrowed out by a class, then this is a
|
|
4406 ;; block-close
|
2
|
4407 ((and (not inextern-p)
|
|
4408 (c-most-enclosing-brace state))
|
0
|
4409 (c-add-syntax 'block-close relpos))
|
|
4410 ;; CASE 14C: find out whether we're closing a top-level
|
|
4411 ;; class or a defun
|
|
4412 (t
|
|
4413 (save-restriction
|
|
4414 (narrow-to-region (point-min) indent-point)
|
|
4415 (let ((decl (c-search-uplist-for-classkey (c-parse-state))))
|
|
4416 (if decl
|
|
4417 (c-add-syntax 'class-close (aref decl 0))
|
|
4418 (c-add-syntax 'defun-close relpos)))))
|
|
4419 )))
|
|
4420 ;; CASE 15: statement catchall
|
|
4421 (t
|
|
4422 ;; we know its a statement, but we need to find out if it is
|
|
4423 ;; the first statement in a block
|
|
4424 (goto-char containing-sexp)
|
|
4425 (forward-char 1)
|
|
4426 (c-forward-syntactic-ws indent-point)
|
|
4427 ;; now skip forward past any case/default clauses we might find.
|
|
4428 (while (or (c-skip-case-statement-forward fullstate indent-point)
|
|
4429 (and (looking-at c-switch-label-key)
|
|
4430 (not inswitch-p)))
|
|
4431 (setq inswitch-p t))
|
|
4432 ;; we want to ignore non-case labels when skipping forward
|
|
4433 (while (and (looking-at c-label-key)
|
|
4434 (goto-char (match-end 0)))
|
|
4435 (c-forward-syntactic-ws indent-point))
|
|
4436 (cond
|
|
4437 ;; CASE 15A: we are inside a case/default clause inside a
|
|
4438 ;; switch statement. find out if we are at the statement
|
|
4439 ;; just after the case/default label.
|
|
4440 ((and inswitch-p
|
|
4441 (progn
|
|
4442 (goto-char indent-point)
|
|
4443 (c-backward-syntactic-ws containing-sexp)
|
|
4444 (back-to-indentation)
|
|
4445 (setq placeholder (point))
|
|
4446 (looking-at c-switch-label-key)))
|
|
4447 (goto-char indent-point)
|
|
4448 (skip-chars-forward " \t")
|
|
4449 (if (= (following-char) ?{)
|
|
4450 (c-add-syntax 'statement-case-open placeholder)
|
|
4451 (c-add-syntax 'statement-case-intro placeholder)))
|
|
4452 ;; CASE 15B: continued statement
|
|
4453 ((= char-before-ip ?,)
|
|
4454 (c-add-syntax 'statement-cont (c-point 'boi)))
|
|
4455 ;; CASE 15C: a question/colon construct? But make sure
|
|
4456 ;; what came before was not a label, and what comes after
|
|
4457 ;; is not a globally scoped function call!
|
|
4458 ((or (and (memq char-before-ip '(?: ??))
|
|
4459 (save-excursion
|
|
4460 (goto-char indent-point)
|
|
4461 (c-backward-syntactic-ws lim)
|
|
4462 (back-to-indentation)
|
|
4463 (not (looking-at c-label-key))))
|
|
4464 (and (memq char-after-ip '(?: ??))
|
|
4465 (save-excursion
|
|
4466 (goto-char indent-point)
|
|
4467 (skip-chars-forward " \t")
|
|
4468 ;; watch out for scope operator
|
|
4469 (not (looking-at "::")))))
|
|
4470 (c-add-syntax 'statement-cont (c-point 'boi)))
|
|
4471 ;; CASE 15D: any old statement
|
|
4472 ((< (point) indent-point)
|
|
4473 (let ((safepos (c-most-enclosing-brace fullstate)))
|
|
4474 (goto-char indent-point)
|
|
4475 (c-beginning-of-statement-1 safepos)
|
|
4476 ;; It is possible we're on the brace that opens a nested
|
|
4477 ;; function.
|
|
4478 (if (and (= (following-char) ?{)
|
|
4479 (save-excursion
|
|
4480 (c-backward-syntactic-ws safepos)
|
|
4481 (/= (preceding-char) ?\;)))
|
|
4482 (c-beginning-of-statement-1 safepos))
|
|
4483 (c-add-syntax 'statement (c-point 'boi))
|
|
4484 (if (= char-after-ip ?{)
|
|
4485 (c-add-syntax 'block-open))))
|
|
4486 ;; CASE 15E: first statement in an inline, or first
|
|
4487 ;; statement in a top-level defun. we can tell this is it
|
|
4488 ;; if there are no enclosing braces that haven't been
|
|
4489 ;; narrowed out by a class (i.e. don't use bod here!)
|
|
4490 ((save-excursion
|
|
4491 (save-restriction
|
|
4492 (widen)
|
|
4493 (goto-char containing-sexp)
|
|
4494 (c-narrow-out-enclosing-class state containing-sexp)
|
|
4495 (not (c-most-enclosing-brace state))))
|
|
4496 (goto-char containing-sexp)
|
|
4497 ;; if not at boi, then defun-opening braces are hung on
|
|
4498 ;; right side, so we need a different relpos
|
|
4499 (if (/= (point) (c-point 'boi))
|
|
4500 (progn
|
|
4501 (c-backward-syntactic-ws)
|
|
4502 (c-safe (forward-sexp (if (= (preceding-char) ?\))
|
|
4503 -1 -2)))
|
|
4504 ))
|
|
4505 (c-add-syntax 'defun-block-intro (c-point 'boi)))
|
|
4506 ;; CASE 15F: first statement in a block
|
|
4507 (t (goto-char containing-sexp)
|
|
4508 (if (/= (point) (c-point 'boi))
|
|
4509 (c-beginning-of-statement-1
|
|
4510 (if (= (point) lim)
|
|
4511 (c-safe-position (point) state) lim)))
|
|
4512 (c-add-syntax 'statement-block-intro (c-point 'boi))
|
|
4513 (if (= char-after-ip ?{)
|
|
4514 (c-add-syntax 'block-open)))
|
|
4515 ))
|
|
4516 )
|
|
4517
|
|
4518 ;; now we need to look at any modifiers
|
|
4519 (goto-char indent-point)
|
|
4520 (skip-chars-forward " \t")
|
|
4521 ;; are we looking at a comment only line?
|
|
4522 (if (looking-at c-comment-start-regexp)
|
|
4523 (c-add-syntax 'comment-intro))
|
|
4524 ;; we might want to give additional offset to friends (in C++).
|
|
4525 (if (and (eq major-mode 'c++-mode)
|
|
4526 (looking-at c-C++-friend-key))
|
|
4527 (c-add-syntax 'friend))
|
|
4528 ;; return the syntax
|
|
4529 syntax))))
|
|
4530
|
|
4531
|
|
4532 ;; indent via syntactic language elements
|
|
4533 (defun c-get-offset (langelem)
|
|
4534 ;; Get offset from LANGELEM which is a cons cell of the form:
|
|
4535 ;; (SYMBOL . RELPOS). The symbol is matched against
|
|
4536 ;; c-offsets-alist and the offset found there is either returned,
|
|
4537 ;; or added to the indentation at RELPOS. If RELPOS is nil, then
|
|
4538 ;; the offset is simply returned.
|
|
4539 (let* ((symbol (car langelem))
|
|
4540 (relpos (cdr langelem))
|
|
4541 (match (assq symbol c-offsets-alist))
|
|
4542 (offset (cdr-safe match)))
|
|
4543 ;; offset can be a number, a function, a variable, or one of the
|
|
4544 ;; symbols + or -
|
|
4545 (cond
|
|
4546 ((not match)
|
|
4547 (if c-strict-syntax-p
|
|
4548 (error "don't know how to indent a %s" symbol)
|
|
4549 (setq offset 0
|
|
4550 relpos 0)))
|
2
|
4551 ((eq offset '+) (setq offset c-basic-offset))
|
|
4552 ((eq offset '-) (setq offset (- c-basic-offset)))
|
|
4553 ((eq offset '++) (setq offset (* 2 c-basic-offset)))
|
|
4554 ((eq offset '--) (setq offset (* 2 (- c-basic-offset))))
|
|
4555 ((eq offset '*) (setq offset (/ c-basic-offset 2)))
|
|
4556 ((eq offset '/) (setq offset (/ (- c-basic-offset) 2)))
|
|
4557 ((c-functionp offset) (setq offset (funcall offset langelem)))
|
|
4558 ((not (numberp offset)) (setq offset (symbol-value offset)))
|
0
|
4559 )
|
|
4560 (+ (if (and relpos
|
|
4561 (< relpos (c-point 'bol)))
|
|
4562 (save-excursion
|
|
4563 (goto-char relpos)
|
|
4564 (current-column))
|
|
4565 0)
|
|
4566 offset)))
|
|
4567
|
|
4568 (defun c-indent-line (&optional syntax)
|
|
4569 ;; indent the current line as C/C++/ObjC code. Optional SYNTAX is the
|
|
4570 ;; syntactic information for the current line. Returns the amount of
|
|
4571 ;; indentation change
|
|
4572 (let* ((c-syntactic-context (or syntax (c-guess-basic-syntax)))
|
|
4573 (pos (- (point-max) (point)))
|
|
4574 (indent (apply '+ (mapcar 'c-get-offset c-syntactic-context)))
|
|
4575 (shift-amt (- (current-indentation) indent)))
|
|
4576 (and c-echo-syntactic-information-p
|
|
4577 (message "syntax: %s, indent= %d" c-syntactic-context indent))
|
|
4578 (if (zerop shift-amt)
|
|
4579 nil
|
|
4580 (delete-region (c-point 'bol) (c-point 'boi))
|
|
4581 (beginning-of-line)
|
|
4582 (indent-to indent))
|
|
4583 (if (< (point) (c-point 'boi))
|
|
4584 (back-to-indentation)
|
|
4585 ;; If initial point was within line's indentation, position after
|
|
4586 ;; the indentation. Else stay at same point in text.
|
|
4587 (if (> (- (point-max) pos) (point))
|
|
4588 (goto-char (- (point-max) pos)))
|
|
4589 )
|
|
4590 (run-hooks 'c-special-indent-hook)
|
|
4591 shift-amt))
|
|
4592
|
2
|
4593 (defun c-show-syntactic-information (arg)
|
|
4594 "Show syntactic information for current line.
|
|
4595 With universal argument, inserts the analysis as a comment on that line."
|
|
4596 (interactive "P")
|
|
4597 (let ((syntax (c-guess-basic-syntax)))
|
|
4598 (if (not (consp arg))
|
|
4599 (message "syntactic analysis: %s" (c-guess-basic-syntax))
|
|
4600 (indent-for-comment)
|
|
4601 (insert (format "%s" syntax))
|
|
4602 ))
|
0
|
4603 (c-keep-region-active))
|
|
4604
|
|
4605
|
|
4606 ;; Standard indentation line-ups
|
|
4607 (defun c-lineup-arglist (langelem)
|
|
4608 ;; lineup the current arglist line with the arglist appearing just
|
|
4609 ;; after the containing paren which starts the arglist.
|
|
4610 (save-excursion
|
|
4611 (let* ((containing-sexp
|
|
4612 (save-excursion
|
|
4613 ;; arglist-cont-nonempty gives relpos ==
|
|
4614 ;; to boi of containing-sexp paren. This
|
|
4615 ;; is good when offset is +, but bad
|
|
4616 ;; when it is c-lineup-arglist, so we
|
|
4617 ;; have to special case a kludge here.
|
|
4618 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
|
|
4619 (progn
|
|
4620 (beginning-of-line)
|
|
4621 (backward-up-list 1)
|
|
4622 (skip-chars-forward " \t" (c-point 'eol)))
|
|
4623 (goto-char (cdr langelem)))
|
|
4624 (point)))
|
|
4625 (cs-curcol (save-excursion
|
|
4626 (goto-char (cdr langelem))
|
|
4627 (current-column))))
|
|
4628 (if (save-excursion
|
|
4629 (beginning-of-line)
|
|
4630 (looking-at "[ \t]*)"))
|
|
4631 (progn (goto-char (match-end 0))
|
|
4632 (forward-sexp -1)
|
|
4633 (forward-char 1)
|
|
4634 (c-forward-syntactic-ws)
|
|
4635 (- (current-column) cs-curcol))
|
|
4636 (goto-char containing-sexp)
|
|
4637 (or (eolp)
|
|
4638 (not (memq (following-char) '(?{ ?\( )))
|
|
4639 (let ((eol (c-point 'eol))
|
|
4640 (here (progn
|
|
4641 (forward-char 1)
|
|
4642 (skip-chars-forward " \t")
|
|
4643 (point))))
|
|
4644 (c-forward-syntactic-ws)
|
|
4645 (if (< (point) eol)
|
|
4646 (goto-char here))))
|
|
4647 (- (current-column) cs-curcol)
|
|
4648 ))))
|
|
4649
|
|
4650 (defun c-lineup-arglist-intro-after-paren (langelem)
|
|
4651 ;; lineup an arglist-intro line to just after the open paren
|
|
4652 (save-excursion
|
|
4653 (let ((cs-curcol (save-excursion
|
|
4654 (goto-char (cdr langelem))
|
|
4655 (current-column)))
|
|
4656 (ce-curcol (save-excursion
|
|
4657 (beginning-of-line)
|
|
4658 (backward-up-list 1)
|
|
4659 (skip-chars-forward " \t" (c-point 'eol))
|
|
4660 (current-column))))
|
|
4661 (- ce-curcol cs-curcol -1))))
|
|
4662
|
2
|
4663 (defun c-lineup-arglist-close-under-paren (langelem)
|
|
4664 ;; lineup an arglist-intro line to just after the open paren
|
|
4665 (save-excursion
|
|
4666 (let ((cs-curcol (save-excursion
|
|
4667 (goto-char (cdr langelem))
|
|
4668 (current-column)))
|
|
4669 (ce-curcol (save-excursion
|
|
4670 (beginning-of-line)
|
|
4671 (backward-up-list 1)
|
|
4672 (current-column))))
|
|
4673 (- ce-curcol cs-curcol))))
|
|
4674
|
0
|
4675 (defun c-lineup-streamop (langelem)
|
|
4676 ;; lineup stream operators
|
|
4677 (save-excursion
|
|
4678 (let* ((relpos (cdr langelem))
|
|
4679 (curcol (progn (goto-char relpos)
|
|
4680 (current-column))))
|
|
4681 (re-search-forward "<<\\|>>" (c-point 'eol) 'move)
|
|
4682 (goto-char (match-beginning 0))
|
|
4683 (- (current-column) curcol))))
|
|
4684
|
|
4685 (defun c-lineup-multi-inher (langelem)
|
|
4686 ;; line up multiple inheritance lines
|
|
4687 (save-excursion
|
|
4688 (let (cs-curcol
|
|
4689 (eol (c-point 'eol))
|
|
4690 (here (point)))
|
|
4691 (goto-char (cdr langelem))
|
|
4692 (setq cs-curcol (current-column))
|
|
4693 (skip-chars-forward "^:" eol)
|
|
4694 (skip-chars-forward " \t:" eol)
|
|
4695 (if (or (eolp)
|
|
4696 (looking-at c-comment-start-regexp))
|
|
4697 (c-forward-syntactic-ws here))
|
|
4698 (- (current-column) cs-curcol)
|
|
4699 )))
|
|
4700
|
|
4701 (defun c-lineup-C-comments (langelem)
|
|
4702 ;; line up C block comment continuation lines
|
|
4703 (save-excursion
|
|
4704 (let ((stars (progn
|
|
4705 (beginning-of-line)
|
|
4706 (skip-chars-forward " \t")
|
|
4707 (if (looking-at "\\*\\*?")
|
|
4708 (- (match-end 0) (match-beginning 0))
|
|
4709 0)))
|
|
4710 (cs-curcol (progn (goto-char (cdr langelem))
|
|
4711 (current-column))))
|
|
4712 (back-to-indentation)
|
|
4713 (if (re-search-forward "/\\*[ \t]*" (c-point 'eol) t)
|
|
4714 (goto-char (+ (match-beginning 0)
|
|
4715 (cond
|
|
4716 (c-block-comments-indent-p 0)
|
|
4717 ((= stars 1) 1)
|
|
4718 ((= stars 2) 0)
|
|
4719 (t (- (match-end 0) (match-beginning 0)))))))
|
|
4720 (- (current-column) cs-curcol))))
|
|
4721
|
|
4722 (defun c-lineup-comment (langelem)
|
|
4723 ;; support old behavior for comment indentation. we look at
|
|
4724 ;; c-comment-only-line-offset to decide how to indent comment
|
|
4725 ;; only-lines
|
|
4726 (save-excursion
|
|
4727 (back-to-indentation)
|
2
|
4728 ;; this highly kludgiforous flag prevents the mapcar over
|
|
4729 ;; c-syntactic-context from entering an infinite loop
|
|
4730 (let ((recurse-prevention-flag (boundp 'recurse-prevention-flag)))
|
|
4731 (cond
|
|
4732 ;; CASE 1: preserve comment-column
|
|
4733 (recurse-prevention-flag 0)
|
|
4734 ((= (current-column) comment-column)
|
|
4735 ;; we have to subtract out all other indentation
|
|
4736 (- comment-column (apply '+ (mapcar 'c-get-offset
|
|
4737 c-syntactic-context))))
|
|
4738 ;; indent as specified by c-comment-only-line-offset
|
|
4739 ((not (bolp))
|
0
|
4740 (or (car-safe c-comment-only-line-offset)
|
2
|
4741 c-comment-only-line-offset))
|
|
4742 (t
|
|
4743 (or (cdr-safe c-comment-only-line-offset)
|
|
4744 (car-safe c-comment-only-line-offset)
|
|
4745 -1000)) ;jam it against the left side
|
|
4746 ))))
|
0
|
4747
|
|
4748 (defun c-lineup-runin-statements (langelem)
|
|
4749 ;; line up statements in coding standards which place the first
|
|
4750 ;; statement on the same line as the block opening brace.
|
|
4751 (if (= (char-after (cdr langelem)) ?{)
|
|
4752 (save-excursion
|
|
4753 (let ((curcol (progn
|
|
4754 (goto-char (cdr langelem))
|
|
4755 (current-column))))
|
|
4756 (forward-char 1)
|
|
4757 (skip-chars-forward " \t")
|
|
4758 (- (current-column) curcol)))
|
|
4759 0))
|
|
4760
|
|
4761 (defun c-lineup-math (langelem)
|
|
4762 ;; line up math statement-cont after the equals
|
|
4763 (save-excursion
|
|
4764 (let* ((relpos (cdr langelem))
|
|
4765 (equalp (save-excursion
|
|
4766 (goto-char (c-point 'boi))
|
|
4767 (skip-chars-forward "^=" (c-point 'eol))
|
|
4768 (and (= (following-char) ?=)
|
|
4769 (- (point) (c-point 'boi)))))
|
|
4770 (curcol (progn
|
|
4771 (goto-char relpos)
|
|
4772 (current-column)))
|
|
4773 donep)
|
|
4774 (while (and (not donep)
|
|
4775 (< (point) (c-point 'eol)))
|
|
4776 (skip-chars-forward "^=" (c-point 'eol))
|
|
4777 (if (c-in-literal (cdr langelem))
|
|
4778 (forward-char 1)
|
|
4779 (setq donep t)))
|
|
4780 (if (/= (following-char) ?=)
|
|
4781 ;; there's no equal sign on the line
|
|
4782 c-basic-offset
|
|
4783 ;; calculate indentation column after equals and ws, unless
|
|
4784 ;; our line contains an equals sign
|
|
4785 (if (not equalp)
|
|
4786 (progn
|
|
4787 (forward-char 1)
|
|
4788 (skip-chars-forward " \t")
|
|
4789 (setq equalp 0)))
|
|
4790 (- (current-column) equalp curcol))
|
|
4791 )))
|
|
4792
|
|
4793 (defun c-lineup-ObjC-method-call (langelem)
|
|
4794 ;; Line up methods args as elisp-mode does with function args: go to
|
|
4795 ;; the position right after the message receiver, and if you are at
|
|
4796 ;; (eolp) indent the current line by a constant offset from the
|
|
4797 ;; opening bracket; otherwise we are looking at the first character
|
|
4798 ;; of the first method call argument, so lineup the current line
|
|
4799 ;; with it.
|
|
4800 (save-excursion
|
|
4801 (let* ((extra (save-excursion
|
|
4802 (back-to-indentation)
|
|
4803 (c-backward-syntactic-ws (cdr langelem))
|
|
4804 (if (= (preceding-char) ?:)
|
|
4805 (- c-basic-offset)
|
|
4806 0)))
|
|
4807 (open-bracket-pos (cdr langelem))
|
|
4808 (open-bracket-col (progn
|
|
4809 (goto-char open-bracket-pos)
|
|
4810 (current-column)))
|
|
4811 (target-col (progn
|
|
4812 (forward-char)
|
|
4813 (forward-sexp)
|
|
4814 (skip-chars-forward " \t")
|
|
4815 (if (eolp)
|
|
4816 (+ open-bracket-col c-basic-offset)
|
|
4817 (current-column))))
|
|
4818 )
|
|
4819 (- target-col open-bracket-col extra))))
|
|
4820
|
|
4821 (defun c-lineup-ObjC-method-args (langelem)
|
|
4822 ;; Line up the colons that separate args. This is done trying to
|
|
4823 ;; align colons vertically.
|
|
4824 (save-excursion
|
|
4825 (let* ((here (c-point 'boi))
|
|
4826 (curcol (progn (goto-char here) (current-column)))
|
|
4827 (eol (c-point 'eol))
|
|
4828 (relpos (cdr langelem))
|
|
4829 (first-col-column (progn
|
|
4830 (goto-char relpos)
|
|
4831 (skip-chars-forward "^:" eol)
|
|
4832 (and (= (following-char) ?:)
|
|
4833 (current-column)))))
|
|
4834 (if (not first-col-column)
|
|
4835 c-basic-offset
|
|
4836 (goto-char here)
|
|
4837 (skip-chars-forward "^:" eol)
|
|
4838 (if (= (following-char) ?:)
|
|
4839 (+ curcol (- first-col-column (current-column)))
|
|
4840 c-basic-offset)))))
|
|
4841
|
|
4842 (defun c-lineup-ObjC-method-args-2 (langelem)
|
|
4843 ;; Line up the colons that separate args. This is done trying to
|
|
4844 ;; align the colon on the current line with the previous one.
|
|
4845 (save-excursion
|
|
4846 (let* ((here (c-point 'boi))
|
|
4847 (curcol (progn (goto-char here) (current-column)))
|
|
4848 (eol (c-point 'eol))
|
|
4849 (relpos (cdr langelem))
|
|
4850 (prev-col-column (progn
|
|
4851 (skip-chars-backward "^:" relpos)
|
|
4852 (and (= (preceding-char) ?:)
|
|
4853 (- (current-column) 1)))))
|
|
4854 (if (not prev-col-column)
|
|
4855 c-basic-offset
|
|
4856 (goto-char here)
|
|
4857 (skip-chars-forward "^:" eol)
|
|
4858 (if (= (following-char) ?:)
|
|
4859 (+ curcol (- prev-col-column (current-column)))
|
|
4860 c-basic-offset)))))
|
|
4861
|
|
4862 (defun c-snug-do-while (syntax pos)
|
|
4863 "Dynamically calculate brace hanginess for do-while statements.
|
|
4864 Using this function, `while' clauses that end a `do-while' block will
|
|
4865 remain on the same line as the brace that closes that block.
|
|
4866
|
|
4867 See `c-hanging-braces-alist' for how to utilize this function as an
|
|
4868 ACTION associated with `block-close' syntax."
|
|
4869 (save-excursion
|
|
4870 (let (langelem)
|
|
4871 (if (and (eq syntax 'block-close)
|
|
4872 (setq langelem (assq 'block-close c-syntactic-context))
|
|
4873 (progn (goto-char (cdr langelem))
|
|
4874 (if (= (following-char) ?{)
|
|
4875 (c-safe (forward-sexp -1)))
|
|
4876 (looking-at "\\<do\\>[^_]")))
|
|
4877 '(before)
|
|
4878 '(before after)))))
|
|
4879
|
2
|
4880 (defun c-gnu-impose-minimum ()
|
|
4881 "Imposes a minimum indentation for labels and case tags.
|
|
4882 The variable `c-label-minimum-indentation' specifies the minimum
|
|
4883 indentation amount."
|
|
4884 (let ((non-top-levels '(defun-block-intro statement statement-cont
|
|
4885 statement-block-intro statement-case-intro
|
|
4886 statement-case-open substatement substatement-open
|
|
4887 case-label label do-while-closure else-clause
|
|
4888 ))
|
|
4889 (syntax c-syntactic-context)
|
|
4890 langelem)
|
|
4891 (while syntax
|
|
4892 (setq langelem (car (car syntax))
|
|
4893 syntax (cdr syntax))
|
|
4894 ;; don't adjust comment-only lines
|
|
4895 (cond ((eq langelem 'comment-intro)
|
|
4896 (setq syntax nil))
|
|
4897 ((memq langelem non-top-levels)
|
|
4898 (save-excursion
|
|
4899 (setq syntax nil)
|
|
4900 (back-to-indentation)
|
|
4901 (if (zerop (current-column))
|
|
4902 (insert (make-string c-label-minimum-indentation 32)))
|
|
4903 ))
|
|
4904 ))))
|
|
4905
|
0
|
4906
|
|
4907 ;;; This page handles insertion and removal of backslashes for C macros.
|
|
4908
|
|
4909 (defun c-backslash-region (from to delete-flag)
|
|
4910 "Insert, align, or delete end-of-line backslashes on the lines in the region.
|
|
4911 With no argument, inserts backslashes and aligns existing backslashes.
|
|
4912 With an argument, deletes the backslashes.
|
|
4913
|
|
4914 This function does not modify the last line of the region if the region ends
|
|
4915 right at the start of the following line; it does not modify blank lines
|
|
4916 at the start of the region. So you can put the region around an entire macro
|
|
4917 definition and conveniently use this command."
|
|
4918 (interactive "r\nP")
|
|
4919 (save-excursion
|
|
4920 (goto-char from)
|
|
4921 (let ((column c-backslash-column)
|
|
4922 (endmark (make-marker)))
|
|
4923 (move-marker endmark to)
|
|
4924 ;; Compute the smallest column number past the ends of all the lines.
|
|
4925 (if (not delete-flag)
|
|
4926 (while (< (point) to)
|
|
4927 (end-of-line)
|
|
4928 (if (= (preceding-char) ?\\)
|
|
4929 (progn (forward-char -1)
|
|
4930 (skip-chars-backward " \t")))
|
|
4931 (setq column (max column (1+ (current-column))))
|
|
4932 (forward-line 1)))
|
|
4933 ;; Adjust upward to a tab column, if that doesn't push past the margin.
|
|
4934 (if (> (% column tab-width) 0)
|
|
4935 (let ((adjusted (* (/ (+ column tab-width -1) tab-width) tab-width)))
|
|
4936 (if (< adjusted (window-width))
|
|
4937 (setq column adjusted))))
|
|
4938 ;; Don't modify blank lines at start of region.
|
|
4939 (goto-char from)
|
|
4940 (while (and (< (point) endmark) (eolp))
|
|
4941 (forward-line 1))
|
|
4942 ;; Add or remove backslashes on all the lines.
|
|
4943 (while (and (< (point) endmark)
|
|
4944 ;; Don't backslashify the last line
|
|
4945 ;; if the region ends right at the start of the next line.
|
|
4946 (save-excursion
|
|
4947 (forward-line 1)
|
|
4948 (< (point) endmark)))
|
|
4949 (if (not delete-flag)
|
|
4950 (c-append-backslash column)
|
|
4951 (c-delete-backslash))
|
|
4952 (forward-line 1))
|
|
4953 (move-marker endmark nil))))
|
|
4954
|
|
4955 (defun c-append-backslash (column)
|
|
4956 (end-of-line)
|
|
4957 ;; Note that "\\\\" is needed to get one backslash.
|
|
4958 (if (= (preceding-char) ?\\)
|
|
4959 (progn (forward-char -1)
|
|
4960 (delete-horizontal-space)
|
|
4961 (indent-to column))
|
|
4962 (indent-to column)
|
|
4963 (insert "\\")))
|
|
4964
|
|
4965 (defun c-delete-backslash ()
|
|
4966 (end-of-line)
|
|
4967 (or (bolp)
|
|
4968 (progn
|
2
|
4969 (forward-char -1)
|
|
4970 (if (looking-at "\\\\")
|
|
4971 (delete-region (1+ (point))
|
|
4972 (progn (skip-chars-backward " \t") (point)))))))
|
0
|
4973
|
|
4974
|
|
4975 ;; defuns for submitting bug reports
|
|
4976
|
2
|
4977 (defconst c-version "4.315"
|
0
|
4978 "cc-mode version number.")
|
2
|
4979 (defconst c-mode-help-address
|
|
4980 "bug-gnu-emacs@prep.ai.mit.edu, cc-mode-help@python.org"
|
0
|
4981 "Address for cc-mode bug reports.")
|
|
4982
|
|
4983 (defun c-version ()
|
|
4984 "Echo the current version of cc-mode in the minibuffer."
|
|
4985 (interactive)
|
|
4986 (message "Using cc-mode version %s" c-version)
|
|
4987 (c-keep-region-active))
|
|
4988
|
|
4989 ;; get reporter-submit-bug-report when byte-compiling
|
|
4990 (eval-when-compile
|
|
4991 (require 'reporter))
|
|
4992
|
|
4993 (defun c-submit-bug-report ()
|
|
4994 "Submit via mail a bug report on cc-mode."
|
|
4995 (interactive)
|
|
4996 ;; load in reporter
|
|
4997 (let ((reporter-prompt-for-summary-p t)
|
|
4998 (reporter-dont-compact-list '(c-offsets-alist)))
|
|
4999 (and
|
|
5000 (if (y-or-n-p "Do you want to submit a report on cc-mode? ")
|
|
5001 t (message "") nil)
|
|
5002 (require 'reporter)
|
|
5003 (reporter-submit-bug-report
|
|
5004 c-mode-help-address
|
|
5005 (concat "cc-mode " c-version " ("
|
|
5006 (cond ((eq major-mode 'c++-mode) "C++")
|
|
5007 ((eq major-mode 'c-mode) "C")
|
|
5008 ((eq major-mode 'objc-mode) "ObjC")
|
|
5009 ((eq major-mode 'java-mode) "Java")
|
|
5010 )
|
|
5011 ")")
|
|
5012 (let ((vars (list
|
|
5013 ;; report only the vars that affect indentation
|
|
5014 'c-basic-offset
|
|
5015 'c-offsets-alist
|
|
5016 'c-block-comments-indent-p
|
|
5017 'c-cleanup-list
|
|
5018 'c-comment-only-line-offset
|
|
5019 'c-backslash-column
|
|
5020 'c-delete-function
|
|
5021 'c-electric-pound-behavior
|
|
5022 'c-hanging-braces-alist
|
|
5023 'c-hanging-colons-alist
|
|
5024 'c-hanging-comment-ender-p
|
|
5025 'c-tab-always-indent
|
|
5026 'c-recognize-knr-p
|
2
|
5027 'c-label-minimum-indentation
|
0
|
5028 'defun-prompt-regexp
|
|
5029 'tab-width
|
|
5030 )))
|
|
5031 (if (not (boundp 'defun-prompt-regexp))
|
|
5032 (delq 'defun-prompt-regexp vars)
|
|
5033 vars))
|
|
5034 (function
|
|
5035 (lambda ()
|
|
5036 (insert
|
|
5037 (if c-special-indent-hook
|
|
5038 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
|
|
5039 "c-special-indent-hook is set to '"
|
|
5040 (format "%s" c-special-indent-hook)
|
|
5041 ".\nPerhaps this is your problem?\n"
|
|
5042 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
|
|
5043 "\n")
|
|
5044 (format "c-emacs-features: %s\n" c-emacs-features)
|
|
5045 )))
|
|
5046 nil
|
|
5047 "Dear Barry,"
|
|
5048 ))))
|
|
5049
|
|
5050
|
|
5051 ;; menus for XEmacs 19
|
|
5052 (defun c-popup-menu (e)
|
|
5053 "Pops up the C/C++/ObjC menu."
|
|
5054 (interactive "@e")
|
|
5055 (popup-menu (cons (concat mode-name " Mode Commands") c-mode-menu))
|
|
5056 (c-keep-region-active))
|
|
5057
|
|
5058
|
2
|
5059 ;; Emacs/XEmacs Compatibility
|
|
5060 ;; XEmacs has these, Emacs (even 19.31) does not
|
|
5061
|
|
5062 ;; Lift XEmacs 19.13's functionp from subr.el
|
|
5063 (defun c-functionp (obj)
|
|
5064 "Returns t if OBJ is a function, nil otherwise."
|
|
5065 (cond
|
|
5066 ((symbolp obj) (fboundp obj))
|
|
5067 ((subrp obj))
|
|
5068 ((compiled-function-p obj))
|
|
5069 ((consp obj)
|
|
5070 (if (eq (car obj) 'lambda) (listp (car (cdr obj)))))
|
|
5071 (t nil)))
|
|
5072
|
0
|
5073 (defun c-copy-tree (tree)
|
|
5074 ;; Lift XEmacs 19.12's copy-tree
|
|
5075 (if (consp tree)
|
|
5076 (cons (c-copy-tree (car tree))
|
|
5077 (c-copy-tree (cdr tree)))
|
|
5078 (if (vectorp tree)
|
|
5079 (let* ((new (copy-sequence tree))
|
|
5080 (i (1- (length new))))
|
|
5081 (while (>= i 0)
|
|
5082 (aset new i (c-copy-tree (aref new i)))
|
|
5083 (setq i (1- i)))
|
|
5084 new)
|
|
5085 tree)))
|
|
5086
|
|
5087 (defun c-mapcar-defun (var)
|
|
5088 (let ((val (symbol-value var)))
|
|
5089 (cons var (if (atom val) val
|
|
5090 ;; XEmacs 19.12 and Emacs 19 + lucid.el have this
|
|
5091 (if (fboundp 'copy-tree)
|
|
5092 (copy-tree val)
|
|
5093 ;; Emacs 19 and Emacs 18
|
|
5094 (c-copy-tree val)
|
|
5095 )))
|
|
5096 ))
|
|
5097
|
2
|
5098
|
|
5099
|
0
|
5100 ;; Dynamically append the default value of most variables. This is
|
|
5101 ;; crucial because future c-set-style calls will always reset the
|
|
5102 ;; variables first to the `cc-mode' style before instituting the new
|
|
5103 ;; style. Only do this once!
|
|
5104 (or (assoc "cc-mode" c-style-alist)
|
|
5105 (progn
|
|
5106 (c-add-style "cc-mode"
|
|
5107 (mapcar 'c-mapcar-defun
|
|
5108 '(c-backslash-column
|
|
5109 c-basic-offset
|
|
5110 c-block-comments-indent-p
|
|
5111 c-cleanup-list
|
|
5112 c-comment-only-line-offset
|
|
5113 c-echo-syntactic-information-p
|
|
5114 c-electric-pound-behavior
|
|
5115 c-hanging-braces-alist
|
|
5116 c-hanging-colons-alist
|
|
5117 c-hanging-comment-ender-p
|
|
5118 c-offsets-alist
|
|
5119 c-strict-syntax-p
|
|
5120 c-tab-always-indent
|
|
5121 c-inhibit-startup-warnings-p
|
|
5122 )))
|
|
5123 ;; the default style is now GNU. This can be overridden in
|
2
|
5124 ;; c-mode-common-hook or {c,c++,objc,java}-mode-hook.
|
0
|
5125 (c-set-style c-site-default-style)))
|
|
5126
|
|
5127 ;; style variables
|
|
5128 (make-variable-buffer-local 'c-offsets-alist)
|
|
5129 (make-variable-buffer-local 'c-basic-offset)
|
|
5130 (make-variable-buffer-local 'c-file-style)
|
|
5131 (make-variable-buffer-local 'c-file-offsets)
|
|
5132 (make-variable-buffer-local 'c-comment-only-line-offset)
|
|
5133 (make-variable-buffer-local 'c-block-comments-indent-p)
|
|
5134 (make-variable-buffer-local 'c-cleanup-list)
|
|
5135 (make-variable-buffer-local 'c-hanging-braces-alist)
|
|
5136 (make-variable-buffer-local 'c-hanging-colons-alist)
|
|
5137 (make-variable-buffer-local 'c-hanging-comment-ender-p)
|
|
5138 (make-variable-buffer-local 'c-backslash-column)
|
2
|
5139 (make-variable-buffer-local 'c-label-minimum-indentation)
|
|
5140 (make-variable-buffer-local 'c-special-indent-hook)
|
0
|
5141
|
|
5142
|
|
5143 ;; fsets for compatibility with BOCM
|
|
5144 (fset 'electric-c-brace 'c-electric-brace)
|
|
5145 (fset 'electric-c-semi 'c-electric-semi&comma)
|
|
5146 (fset 'electric-c-sharp-sign 'c-electric-pound)
|
|
5147 ;; there is no cc-mode equivalent for electric-c-terminator
|
|
5148 (fset 'mark-c-function 'c-mark-function)
|
|
5149 (fset 'indent-c-exp 'c-indent-exp)
|
|
5150 (fset 'set-c-style 'c-set-style)
|
|
5151 ;; Lucid Emacs 19.9 + font-lock + cc-mode - c++-mode lossage
|
|
5152 (fset 'c++-beginning-of-defun 'beginning-of-defun)
|
|
5153 (fset 'c++-end-of-defun 'end-of-defun)
|
|
5154
|
|
5155 ;; set up bc warnings for obsolete variables, but for now lets not
|
|
5156 ;; worry about obsolete functions. maybe later some will be important
|
|
5157 ;; to flag
|
2
|
5158 (and (or (memq 'v19 c-emacs-features) (memq 'v20 c-emacs-features))
|
0
|
5159 (let* ((na "Nothing appropriate.")
|
|
5160 (vars
|
|
5161 (list
|
|
5162 (cons 'c++-c-mode-syntax-table 'c-mode-syntax-table)
|
|
5163 (cons 'c++-tab-always-indent 'c-tab-always-indent)
|
|
5164 (cons 'c++-always-arglist-indent-p na)
|
|
5165 (cons 'c++-block-close-brace-offset 'c-offsets-alist)
|
|
5166 (cons 'c++-paren-as-block-close-p na)
|
|
5167 (cons 'c++-continued-member-init-offset 'c-offsets-alist)
|
|
5168 (cons 'c++-member-init-indent 'c-offsets-alist)
|
|
5169 (cons 'c++-friend-offset na)
|
|
5170 (cons 'c++-access-specifier-offset 'c-offsets-alist)
|
|
5171 (cons 'c++-empty-arglist-indent 'c-offsets-alist)
|
|
5172 (cons 'c++-comment-only-line-offset 'c-comment-only-line-offset)
|
|
5173 (cons 'c++-C-block-comments-indent-p 'c-block-comments-indent-p)
|
|
5174 (cons 'c++-cleanup-list 'c-cleanup-list)
|
|
5175 (cons 'c++-hanging-braces 'c-hanging-braces-alist)
|
|
5176 (cons 'c++-hanging-member-init-colon 'c-hanging-colons-alist)
|
|
5177 (cons 'c++-auto-hungry-initial-state
|
|
5178 "Use `c-auto-newline' and `c-hungry-delete-key' instead.")
|
|
5179 (cons 'c++-auto-hungry-toggle na)
|
|
5180 (cons 'c++-relative-offset-p na)
|
|
5181 (cons 'c++-special-indent-hook 'c-special-indent-hook)
|
|
5182 (cons 'c++-delete-function 'c-delete-function)
|
|
5183 (cons 'c++-electric-pound-behavior 'c-electric-pound-behavior)
|
|
5184 (cons 'c++-hungry-delete-key 'c-hungry-delete-key)
|
|
5185 (cons 'c++-auto-newline 'c-auto-newline)
|
|
5186 (cons 'c++-match-header-strongly na)
|
|
5187 (cons 'c++-defun-header-strong-struct-equivs na)
|
|
5188 (cons 'c++-version 'c-version)
|
|
5189 (cons 'c++-mode-help-address 'c-mode-help-address)
|
|
5190 (cons 'c-indent-level 'c-basic-offset)
|
|
5191 (cons 'c-brace-imaginary-offset na)
|
|
5192 (cons 'c-brace-offset 'c-offsets-alist)
|
|
5193 (cons 'c-argdecl-indent 'c-offsets-alist)
|
|
5194 (cons 'c-label-offset 'c-offsets-alist)
|
|
5195 (cons 'c-continued-statement-offset 'c-offsets-alist)
|
|
5196 (cons 'c-continued-brace-offset 'c-offsets-alist)
|
|
5197 (cons 'c-default-macroize-column 'c-backslash-column)
|
|
5198 (cons 'c++-default-macroize-column 'c-backslash-column)
|
|
5199 )))
|
|
5200 (mapcar
|
|
5201 (function
|
|
5202 (lambda (elt)
|
|
5203 (make-obsolete-variable (car elt) (cdr elt))))
|
|
5204 vars)))
|
|
5205
|
|
5206 (provide 'cc-mode)
|
|
5207 ;;; cc-mode.el ends here
|