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