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