Mercurial > emacs
annotate lisp/progmodes/cplus-md.el @ 7561:22a4985ddad3
(rmail-output): Doc fix.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 19 May 1994 20:44:03 +0000 |
parents | cc7cd83ccf3f |
children | 57533025d628 |
rev | line source |
---|---|
3806
d43666cf0dbb
Comment changes for renaming from c++-mode.el to cplus-md.el.
Richard M. Stallman <rms@gnu.org>
parents:
3627
diff
changeset
|
1 ;;; cplus-md.el --- C++ code editing commands for Emacs |
7300 | 2 ;;; Copyright (C) 1985, 1992, 1994 Free Software Foundation, Inc. |
896 | 3 |
4 ;; This file is part of GNU Emacs. | |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
257
diff
changeset
|
5 |
896 | 6 ;; GNU Emacs is free software; you can redistribute it and/or modify |
7 ;; it under the terms of the GNU General Public License as published by | |
8 ;; the Free Software Foundation; either version 2, or (at your option) | |
9 ;; any later version. | |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
10 |
896 | 11 ;; GNU Emacs is distributed in the hope that it will be useful, |
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 ;; GNU General Public License for more details. | |
15 | |
16 ;; You should have received a copy of the GNU General Public License | |
17 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
18 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
798
b7932f859d4e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
19 ;; Maintainer: Dave Detlefs <dld@cs.cmu.edu> |
b7932f859d4e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
20 ;; Keywords: c |
b7932f859d4e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
21 |
b7932f859d4e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
22 ;;; Commentary: |
b7932f859d4e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
23 |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
896
diff
changeset
|
24 ;; 1987 Dave Detlefs <dld@cs.cmu.edu> |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
896
diff
changeset
|
25 ;; and Stewart Clamen <clamen@cs.cmu.edu>. |
257 | 26 ;; Done by fairly faithful modification of: |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
896
diff
changeset
|
27 |
798
b7932f859d4e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
28 ;;; Change Log: |
b7932f859d4e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
29 |
257 | 30 ;; Feb, 1990 (Dave Detlefs, dld@cs.cmu.edu) |
31 ;; Fixed electric-c++-terminator to handle double colons, at the | |
32 ;; request of John Hagerman. | |
33 ;; | |
34 ;; Jan, 1990 (Doug Lea, dl@oswego.edu) | |
35 ;; Replaced c++-comment-region and c++-uncomment-region with | |
36 ;; versions from Igor Metz that avoid potential infinite loops. | |
37 ;; | |
38 ;; Oct, 1989 (Dave Detlefs, dld@cs.cmu.edu) | |
39 ;; Added contribution from Igor Metz <metz@iam.unibe.ch>: | |
40 ;; functions c++-comment-region and c++-uncomment-region and | |
41 ;; corresponding key-binding. | |
42 ;; Also fixed bug in indentation of second line after an empty | |
43 ;; arglist with empty-arglist non-null. | |
44 ;; | |
45 ;; Sept, 1989 (Glen Ditchfield, gjditchfield@violet.uwaterloo.ca): | |
46 ;; Textual changes to more closely imitate Emacs 18.55's c-mode. | |
47 ;; Fixed handling of "default:", where ":" was the last character in the | |
48 ;; buffer. Fixed indentation of comments starting in column 0, and when | |
49 ;; previous line contained more than one comment start string. Fixed | |
5300
954744cd720f
(c++-indent-line, calculate-c++-indent):
Richard M. Stallman <rms@gnu.org>
parents:
4308
diff
changeset
|
50 ;; handling of "friend". |
257 | 51 ;; |
52 ;; Aug 7, 1989; John Hagerman (hagerman@ece.cmu.edu): | |
53 ;; Changed calculate-c++-indent to handle member initializations | |
54 ;; more flexibly. Two new variables are used to control behavior: | |
55 ;; c++-member-init-indent and c++-continued-member-init-offset. | |
56 ;; Note the assumption that member initializations and argument | |
57 ;; declarations are not mixed in one function definition. | |
58 ;; | |
59 ;; June 1989 (Dave Detlefs, dld@cs.cmu.edu) | |
60 ;; Fixed calculate-c++-indent to handle continued lines ending in | |
61 ;; {'s. (I wasn't following C-mode closely enough, or C-mode | |
62 ;; changed.) Made ' a quote character, at the behest of someone | |
63 ;; whose mail I apparently deleted (if they send me mail I'll credit | |
64 ;; them here in a future revision.) | |
65 ;; Dan Weinreb (dlw@odi.com) pointed out that 'c++-mode successively | |
66 ;; bound c++-indent-exp and c++-indent-defun to ESC-^q. ESC-^q is | |
67 ;; now bound to c++-indent-exp, while, c++-indent-defun is invoked | |
68 ;; with ESC-^x. | |
69 | |
70 ;; February 1989 (Dave Detlefs, dld@cs.cmu.edu) | |
71 ;; Fixed some errors in c++-indent-defun, as pointed out by Sam | |
72 ;; Haradhvala (odi!sam@talcott.harvard.edu). | |
73 ;; October 1988 (Dave Detlefs, dld@cs.cmu.edu) | |
74 ;; It turns out I had only *thought* I had made | |
75 ;; beginning(end)-of-defun work. It should work better now -- you | |
76 ;; can either attempt to match defun headers "strongly," using a | |
77 ;; very complicated regexp, or "weakly," using a simple one. This | |
78 ;; is settable by a variable; the default is the cheaper weak | |
79 ;; method. (Stewart Clamen was intimately involved in this, too.) | |
80 ;; | |
81 ;; I made "'" *not* be a string delimiter, because that was causing | |
82 ;; comments containing contractions to ("// don't") to mess up paren | |
83 ;; balancing. | |
84 ;; | |
85 ;; I also incorporated another slight indentation fix from Glen | |
86 ;; Ditchfield. | |
87 ;; | |
88 ;; We hope this is will make into version 19 of gnu-emacs. | |
89 ;; | |
90 ;; September 1988: incorporated changes from Fred Calm at Schlumberger. | |
91 ;; Also, made beginning(end)-of-defun, indent-defun work. | |
92 ;; | |
93 ;; August 1987: incorporated changes done by Glen Ditchfield of Waterloo. | |
94 | |
798
b7932f859d4e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
95 ;;; Code: |
b7932f859d4e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
96 |
257 | 97 (defvar c++-mode-abbrev-table nil |
98 "Abbrev table used in C++ mode.") | |
99 (define-abbrev-table 'c++-mode-abbrev-table ()) | |
100 | |
101 (defvar c++-mode-map () | |
102 "Keymap used in C++ mode.") | |
103 (if c++-mode-map | |
104 () | |
105 (setq c++-mode-map (make-sparse-keymap)) | |
106 (define-key c++-mode-map "\C-j" 'reindent-then-newline-and-indent) | |
107 (define-key c++-mode-map "{" 'electric-c++-brace) | |
108 (define-key c++-mode-map "}" 'electric-c++-brace) | |
109 (define-key c++-mode-map ";" 'electric-c++-semi) | |
110 (define-key c++-mode-map "\e\C-h" 'mark-c-function) | |
111 (define-key c++-mode-map "\e\C-q" 'indent-c++-exp) | |
112 (define-key c++-mode-map "\177" 'backward-delete-char-untabify) | |
113 (define-key c++-mode-map "\t" 'c++-indent-command) | |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
114 ;; (define-key c++-mode-map "\C-c\C-i" 'c++-insert-header) |
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
115 (define-key c++-mode-map "\C-c\C-\\" 'c-backslash-region)) |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
116 ;; (define-key c++-mode-map "\e\C-a" 'c++-beginning-of-defun) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
117 ;; (define-key c++-mode-map "\e\C-e" 'c++-end-of-defun) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
118 ;; (define-key c++-mode-map "\e\C-x" 'c++-indent-defun)) |
257 | 119 |
120 (defvar c++-mode-syntax-table nil | |
121 "Syntax table used in C++ mode.") | |
122 | |
123 (if c++-mode-syntax-table | |
124 () | |
125 (setq c++-mode-syntax-table (copy-syntax-table c-mode-syntax-table)) | |
4285
37dded875497
(c++-mode-syntax-table): Handle C-style comments.
Richard M. Stallman <rms@gnu.org>
parents:
3806
diff
changeset
|
126 (modify-syntax-entry ?* ". 23b" c++-mode-syntax-table) |
37dded875497
(c++-mode-syntax-table): Handle C-style comments.
Richard M. Stallman <rms@gnu.org>
parents:
3806
diff
changeset
|
127 (modify-syntax-entry ?/ ". 124" c++-mode-syntax-table) |
4308
7775929411c1
(c++-mode-syntax-table): Don't alter syntax of '.
Richard M. Stallman <rms@gnu.org>
parents:
4285
diff
changeset
|
128 (modify-syntax-entry ?\n ">" c++-mode-syntax-table)) |
257 | 129 |
130 (defvar c++-continued-member-init-offset nil | |
131 "*Extra indent for continuation lines of member inits; | |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
132 nil means to align with previous initializations rather than |
257 | 133 with the colon on the first line.") |
134 (defvar c++-member-init-indent 0 | |
135 "*Indentation level of member initializations in function declarations.") | |
136 (defvar c++-friend-offset -4 | |
5300
954744cd720f
(c++-indent-line, calculate-c++-indent):
Richard M. Stallman <rms@gnu.org>
parents:
4308
diff
changeset
|
137 "*Offset of C++ friend declarations relative to member declarations.") |
257 | 138 (defvar c++-electric-colon t |
139 "*If t, colon is an electric terminator.") | |
140 (defvar c++-empty-arglist-indent nil | |
141 "*Indicates how far to indent an line following an empty argument | |
142 list. Nil indicates to just after the paren.") | |
143 | |
144 | |
145 ;;;###autoload | |
146 (defun c++-mode () | |
147 "Major mode for editing C++ code. Very much like editing C code. | |
148 Expression and list commands understand all C++ brackets. | |
149 Tab at left margin indents for C++ code | |
150 Comments are delimited with /* ... */ {or with // ... <newline>} | |
151 Paragraphs are separated by blank lines only. | |
152 Delete converts tabs to spaces as it moves back. | |
153 \\{c++-mode-map} | |
154 Variables controlling indentation style: | |
155 c-tab-always-indent | |
156 Non-nil means TAB in C mode should always reindent the current line, | |
157 regardless of where in the line point is when the TAB command is used. | |
158 Default is t. | |
159 c-auto-newline | |
160 Non-nil means automatically newline before and after braces, | |
161 and after colons and semicolons, inserted in C code. | |
162 c-indent-level | |
163 Indentation of C statements within surrounding block. | |
164 The surrounding block's indentation is the indentation | |
165 of the line on which the open-brace appears. | |
166 c-continued-statement-offset | |
167 Extra indentation given to a substatement, such as the | |
168 then-clause of an if or body of a while. | |
169 c-continued-brace-offset | |
170 Extra indentation given to a brace that starts a substatement. | |
171 This is in addition to c-continued-statement-offset. | |
172 c-brace-offset | |
173 Extra indentation for line if it starts with an open brace. | |
174 c-brace-imaginary-offset | |
175 An open brace following other text is treated as if it were | |
176 this far to the right of the start of its line. | |
177 c-argdecl-indent | |
178 Indentation level of declarations of C function arguments. | |
179 c-label-offset | |
180 Extra indentation for line that is a label, or case or ``default:'', or | |
181 ``public:'' or ``private:'', or ``protected:''. | |
182 c++-electric-colon | |
183 If non-nil at invocation of c++-mode (t is the default) colon electricly | |
184 indents. | |
185 c++-empty-arglist-indent | |
186 If non-nil, a function declaration or invocation which ends a line with a | |
187 left paren is indented this many extra spaces, instead of flush with the | |
188 left paren. | |
189 c++-friend-offset | |
5300
954744cd720f
(c++-indent-line, calculate-c++-indent):
Richard M. Stallman <rms@gnu.org>
parents:
4308
diff
changeset
|
190 Offset of C++ friend declarations relative to member declarations. |
257 | 191 c++-member-init-indent |
192 Indentation level of member initializations in function declarations, | |
193 if they are on a separate line beginning with a colon. | |
194 c++-continued-member-init-offset | |
195 Extra indentation for continuation lines of member initializations; NIL | |
196 means to align with previous initializations rather than with the colon. | |
197 | |
198 Settings for K&R, BSD, and Stroustrup indentation styles are | |
199 c-indent-level 5 8 4 | |
200 c-continued-statement-offset 5 8 4 | |
201 c-continued-brace-offset 0 | |
202 c-brace-offset -5 -8 0 | |
203 c-brace-imaginary-offset 0 | |
204 c-argdecl-indent 0 8 4 | |
205 c-label-offset -5 -8 -4 | |
206 c++-empty-arglist-indent 4 | |
207 c++-friend-offset 0 | |
208 | |
209 Turning on C++ mode calls the value of the variable `c++-mode-hook' with | |
210 no args if that value is non-nil." | |
211 (interactive) | |
212 (kill-all-local-variables) | |
213 (use-local-map c++-mode-map) | |
214 (set-syntax-table c++-mode-syntax-table) | |
215 (setq major-mode 'c++-mode | |
216 mode-name "C++" | |
217 comment-column 32 | |
218 local-abbrev-table c++-mode-abbrev-table) | |
219 (set (make-local-variable 'indent-line-function) 'c++-indent-line) | |
220 (set (make-local-variable 'comment-start) "// ") | |
221 (set (make-local-variable 'comment-end) "") | |
222 (set (make-local-variable 'comment-start-skip) "/\\*+ *\\|// *") | |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
896
diff
changeset
|
223 (set (make-local-variable 'comment-indent-function) 'c++-comment-indent) |
257 | 224 (set (make-local-variable 'paragraph-start) (concat "^$\\|" page-delimiter)) |
225 (set (make-local-variable 'paragraph-separate) paragraph-start) | |
226 (set (make-local-variable 'paragraph-ignore-fill-prefix) t) | |
227 (set (make-local-variable 'require-final-newline) t) | |
5957
334f7ce7c8db
(c++-mode): Set parse-sexp-ignore-comments to t.
Richard M. Stallman <rms@gnu.org>
parents:
5300
diff
changeset
|
228 (set (make-local-variable 'parse-sexp-ignore-comments) t) |
257 | 229 (run-hooks 'c++-mode-hook) |
230 (if c++-electric-colon | |
231 (define-key c++-mode-map ":" 'electric-c++-terminator))) | |
232 | |
233 ;; This is used by indent-for-comment | |
234 ;; to decide how much to indent a comment in C++ code | |
235 ;; based on its context. | |
236 (defun c++-comment-indent () | |
237 (if (looking-at "^\\(/\\*\\|//\\)") | |
238 0 ; Existing comment at bol stays there. | |
239 (save-excursion | |
240 (skip-chars-backward " \t") | |
241 (max | |
242 ;; leave at least one space on non-empty lines. | |
243 (if (zerop (current-column)) 0 (1+ (current-column))) | |
244 (let ((cur-pt (point))) | |
245 (beginning-of-line 0) | |
246 ;; If previous line had a comment, use it's indent | |
247 (if (re-search-forward comment-start-skip cur-pt t) | |
248 (progn | |
249 (goto-char (match-beginning 0)) | |
250 (current-column)) | |
251 comment-column)))))) ; otherwise indent at comment column. | |
252 | |
253 (defun electric-c++-brace (arg) | |
254 "Insert character and correct line's indentation." | |
255 (interactive "P") | |
256 (let (insertpos) | |
257 (if (and (not arg) | |
258 (eolp) | |
259 (or (save-excursion | |
260 (skip-chars-backward " \t") | |
261 (bolp)) | |
262 (if c-auto-newline (progn (c++-indent-line) (newline) t)))) | |
263 (progn | |
264 (insert last-command-char) | |
265 (c++-indent-line) | |
266 (if c-auto-newline | |
267 (progn | |
268 (newline) | |
269 ;; (newline) may have done auto-fill | |
270 (setq insertpos (- (point) 2)) | |
271 (c++-indent-line))) | |
272 (save-excursion | |
273 (if insertpos (goto-char (1+ insertpos))) | |
274 (delete-char -1)))) | |
275 (if insertpos | |
276 (save-excursion | |
277 (goto-char insertpos) | |
278 (self-insert-command (prefix-numeric-value arg))) | |
279 (self-insert-command (prefix-numeric-value arg))))) | |
280 | |
281 (defun electric-c++-semi (arg) | |
282 "Insert character and correct line's indentation." | |
283 (interactive "P") | |
284 (if c-auto-newline | |
285 (electric-c++-terminator arg) | |
286 (self-insert-command (prefix-numeric-value arg)))) | |
287 | |
288 (defun electric-c++-terminator (arg) | |
289 "Insert character and correct line's indentation." | |
290 (interactive "P") | |
291 (let (insertpos (end (point))) | |
292 (if (and (not arg) (eolp) | |
293 (not (save-excursion | |
294 (beginning-of-line) | |
295 (skip-chars-forward " \t") | |
296 (or (= (following-char) ?#) | |
297 ;; Colon is special only after a label, or | |
298 ;; case, or another colon. | |
299 ;; So quickly rule out most other uses of colon | |
300 ;; and do no indentation for them. | |
301 (and (eq last-command-char ?:) | |
302 (not (looking-at "case[ \t]")) | |
303 (save-excursion | |
304 (forward-word 1) | |
305 (skip-chars-forward " \t") | |
306 (< (point) end)) | |
307 ;; Do re-indent double colons | |
308 (save-excursion | |
309 (end-of-line 1) | |
310 (looking-at ":"))) | |
311 (progn | |
312 (beginning-of-defun) | |
313 (let ((pps (parse-partial-sexp (point) end))) | |
314 (or (nth 3 pps) (nth 4 pps) (nth 5 pps)))))))) | |
315 (progn | |
316 (insert last-command-char) | |
317 (c++-indent-line) | |
318 (and c-auto-newline | |
319 (not (c-inside-parens-p)) | |
320 (progn | |
321 ;; the new marker object, used to be just an integer | |
322 (setq insertpos (make-marker)) | |
323 ;; changed setq to set-marker | |
324 (set-marker insertpos (1- (point))) | |
325 ;; do this before the newline, since in auto fill can break | |
326 (newline) | |
327 (c-indent-line))) | |
328 (save-excursion | |
329 (if insertpos (goto-char (1+ insertpos))) | |
330 (delete-char -1)))) | |
331 (if insertpos | |
332 (save-excursion | |
333 (goto-char insertpos) | |
334 (self-insert-command (prefix-numeric-value arg))) | |
335 (self-insert-command (prefix-numeric-value arg))))) | |
336 | |
337 (defun c++-indent-command (&optional whole-exp) | |
338 "Indent current line as C++ code, or in some cases insert a tab character. | |
339 If `c-tab-always-indent' is non-nil (the default), always indent current | |
340 line. Otherwise, indent the current line only if point is at the left | |
341 margin or in the line's indentation; otherwise insert a tab. | |
342 | |
343 A numeric argument, regardless of its value, means indent rigidly all means | |
344 indent rigidly all the lines of the expression starting after point so that | |
345 this line becomes properly indented. The relative indentation among the | |
346 lines of the expression are preserved." | |
347 (interactive "P") | |
348 (if whole-exp | |
349 ;; If arg, always indent this line as C | |
350 ;; and shift remaining lines of expression the same amount. | |
351 (let ((shift-amt (c++-indent-line)) | |
352 beg end) | |
353 (save-excursion | |
354 (if c-tab-always-indent | |
355 (beginning-of-line)) | |
356 (setq beg (point)) | |
357 (forward-sexp 1) | |
358 (setq end (point)) | |
359 (goto-char beg) | |
360 (forward-line 1) | |
361 (setq beg (point))) | |
362 (if (> end beg) | |
363 (indent-code-rigidly beg end shift-amt "#"))) | |
364 (if (and (not c-tab-always-indent) | |
365 (save-excursion | |
366 (skip-chars-backward " \t") | |
367 (not (bolp)))) | |
368 (insert-tab) | |
369 (c++-indent-line)))) | |
370 | |
371 (defun c++-indent-line () | |
372 "Indent current line as C++ code. | |
373 Return the amount the indentation changed by." | |
374 (let ((indent (calculate-c++-indent nil)) | |
375 beg shift-amt | |
376 (case-fold-search nil) | |
377 (pos (- (point-max) (point)))) | |
378 (beginning-of-line) | |
379 (setq beg (point)) | |
380 (cond ((eq indent nil) | |
381 (setq indent (current-indentation))) | |
382 ((eq indent t) | |
383 (setq indent (calculate-c-indent-within-comment))) | |
384 ((looking-at "[ \t]*#") | |
385 (setq indent 0)) | |
386 (t | |
387 (skip-chars-forward " \t") | |
388 (if (listp indent) (setq indent (car indent))) | |
389 (cond ((looking-at "\\(default\\|public\\|private\\|protected\\):") | |
390 (setq indent (+ indent c-label-offset))) | |
391 ((or (looking-at "case\\b") | |
392 (and (looking-at "[A-Za-z]") | |
393 (save-excursion | |
394 (forward-sexp 1) | |
395 (looking-at ":[^:]")))) | |
396 (setq indent (max 1 (+ indent c-label-offset)))) | |
397 ((and (looking-at "else\\b") | |
398 (not (looking-at "else\\s_"))) | |
399 (setq indent (save-excursion | |
400 (c-backward-to-start-of-if) | |
401 (current-indentation)))) | |
5300
954744cd720f
(c++-indent-line, calculate-c++-indent):
Richard M. Stallman <rms@gnu.org>
parents:
4308
diff
changeset
|
402 ((looking-at "friend\[ \t]") |
257 | 403 (setq indent (+ indent c++-friend-offset))) |
404 ((= (following-char) ?}) | |
405 (setq indent (- indent c-indent-level))) | |
406 ((= (following-char) ?{) | |
407 (setq indent (+ indent c-brace-offset)))))) | |
408 (skip-chars-forward " \t") | |
409 (setq shift-amt (- indent (current-column))) | |
410 (if (zerop shift-amt) | |
411 (if (> (- (point-max) pos) (point)) | |
412 (goto-char (- (point-max) pos))) | |
413 (delete-region beg (point)) | |
414 (indent-to indent) | |
415 ;; If initial point was within line's indentation, | |
416 ;; position after the indentation. Else stay at same point in text. | |
417 (if (> (- (point-max) pos) (point)) | |
418 (goto-char (- (point-max) pos)))) | |
419 shift-amt)) | |
420 | |
421 (defun calculate-c++-indent (&optional parse-start) | |
422 "Return appropriate indentation for current line as C++ code. | |
423 In usual case returns an integer: the column to indent to. | |
424 Returns nil if line starts inside a string, t if in a comment." | |
425 (save-excursion | |
426 (beginning-of-line) | |
427 (let ((indent-point (point)) | |
428 (case-fold-search nil) | |
429 state | |
430 containing-sexp) | |
431 (if parse-start | |
432 (goto-char parse-start) | |
433 (beginning-of-defun)) | |
434 (while (< (point) indent-point) | |
435 (setq parse-start (point)) | |
436 (setq state (parse-partial-sexp (point) indent-point 0)) | |
437 (setq containing-sexp (car (cdr state)))) | |
438 (cond ((or (nth 3 state) (nth 4 state)) | |
439 ;; return nil or t if should not change this line | |
440 (nth 4 state)) | |
441 ((null containing-sexp) | |
442 ;; Line is at top level. May be data or function definition, or | |
443 ;; may be function argument declaration or member initialization. | |
444 ;; Indent like the previous top level line unless | |
445 ;; (1) the previous line ends in a closeparen without semicolon, | |
446 ;; in which case this line is the first argument declaration or | |
447 ;; member initialization, or | |
448 ;; (2) the previous line begins with a colon, | |
449 ;; in which case this is the second line of member inits. | |
450 ;; It is assumed that arg decls and member inits are not mixed. | |
451 (goto-char indent-point) | |
452 (skip-chars-forward " \t") | |
453 (if (= (following-char) ?{) | |
454 0 ; Unless it starts a function body | |
455 (c++-backward-to-noncomment (or parse-start (point-min))) | |
456 (if (= (preceding-char) ?\)) | |
457 (progn ; first arg decl or member init | |
458 (goto-char indent-point) | |
459 (skip-chars-forward " \t") | |
460 (if (= (following-char) ?:) | |
461 c++-member-init-indent | |
462 c-argdecl-indent)) | |
463 (if (= (preceding-char) ?\;) | |
464 (backward-char 1)) | |
465 (if (= (preceding-char) ?}) | |
466 0 | |
467 (beginning-of-line) ; continued arg decls or member inits | |
468 (skip-chars-forward " \t") | |
469 (if (= (following-char) ?:) | |
470 (if c++-continued-member-init-offset | |
471 (+ (current-indentation) | |
472 c++-continued-member-init-offset) | |
473 (progn | |
474 (forward-char 1) | |
475 (skip-chars-forward " \t") | |
476 (current-column))) | |
477 (current-indentation))) | |
478 ))) | |
479 ((/= (char-after containing-sexp) ?{) | |
480 ;; line is expression, not statement: | |
481 ;; indent to just after the surrounding open -- unless | |
482 ;; empty arg list, in which case we do what | |
483 ;; c++-empty-arglist-indent says to do. | |
484 (if (and c++-empty-arglist-indent | |
485 (or (null (nth 2 state)) ;; indicates empty arg | |
486 ;; list. | |
487 ;; Use a heuristic: if the first | |
488 ;; non-whitespace following left paren on | |
489 ;; same line is not a comment, | |
490 ;; is not an empty arglist. | |
491 (save-excursion | |
492 (goto-char (1+ containing-sexp)) | |
493 (not | |
494 (looking-at "\\( \\|\t\\)*[^/\n]"))))) | |
495 (progn | |
496 (goto-char containing-sexp) | |
497 (beginning-of-line) | |
498 (skip-chars-forward " \t") | |
499 (goto-char (min (+ (point) c++-empty-arglist-indent) | |
500 (1+ containing-sexp))) | |
501 (current-column)) | |
502 ;; In C-mode, we would always indent to one after the | |
503 ;; left paren. Here, though, we may have an | |
504 ;; empty-arglist, so we'll indent to the min of that | |
505 ;; and the beginning of the first argument. | |
506 (goto-char (1+ containing-sexp)) | |
507 (current-column))) | |
508 (t | |
509 ;; Statement. Find previous non-comment character. | |
510 (goto-char indent-point) | |
511 (c++-backward-to-noncomment containing-sexp) | |
512 (if (not (memq (preceding-char) '(nil ?\, ?\; ?} ?: ?\{))) | |
513 ;; This line is continuation of preceding line's statement; | |
514 ;; indent c-continued-statement-offset more than the | |
515 ;; previous line of the statement. | |
516 (progn | |
517 (c-backward-to-start-of-continued-exp containing-sexp) | |
3627
6895c2df25a6
(calculate-c++-indent): Respect
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
518 (+ c-continued-statement-offset (current-column) |
6895c2df25a6
(calculate-c++-indent): Respect
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
519 (if (save-excursion (goto-char indent-point) |
6895c2df25a6
(calculate-c++-indent): Respect
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
520 (skip-chars-forward " \t") |
6895c2df25a6
(calculate-c++-indent): Respect
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
521 (eq (following-char) ?{)) |
6895c2df25a6
(calculate-c++-indent): Respect
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
522 c-continued-brace-offset 0))) |
257 | 523 ;; This line starts a new statement. |
524 ;; Position following last unclosed open. | |
525 (goto-char containing-sexp) | |
526 ;; Is line first statement after an open-brace? | |
527 (or | |
528 ;; If no, find that first statement and indent like it. | |
529 (save-excursion | |
530 (forward-char 1) | |
531 (while (progn (skip-chars-forward " \t\n") | |
532 (looking-at | |
533 (concat | |
534 "#\\|/\\*\\|//" | |
535 "\\|case[ \t]" | |
536 "\\|[a-zA-Z0-9_$]*:[^:]" | |
5300
954744cd720f
(c++-indent-line, calculate-c++-indent):
Richard M. Stallman <rms@gnu.org>
parents:
4308
diff
changeset
|
537 "\\|friend[ \t]"))) |
257 | 538 ;; Skip over comments and labels following openbrace. |
539 (cond ((= (following-char) ?\#) | |
540 (forward-line 1)) | |
541 ((looking-at "/\\*") | |
542 (search-forward "*/" nil 'move)) | |
5300
954744cd720f
(c++-indent-line, calculate-c++-indent):
Richard M. Stallman <rms@gnu.org>
parents:
4308
diff
changeset
|
543 ((looking-at "//\\|friend[ \t]") |
257 | 544 (forward-line 1)) |
545 (t | |
546 (re-search-forward ":[^:]" nil 'move)))) | |
547 ;; The first following code counts | |
548 ;; if it is before the line we want to indent. | |
549 (and (< (point) indent-point) | |
550 (current-column))) | |
551 ;; If no previous statement, | |
552 ;; indent it relative to line brace is on. | |
553 ;; For open brace in column zero, don't let statement | |
554 ;; start there too. If c-indent-offset is zero, | |
555 ;; use c-brace-offset + c-continued-statement-offset instead. | |
556 ;; For open-braces not the first thing in a line, | |
557 ;; add in c-brace-imaginary-offset. | |
558 (+ (if (and (bolp) (zerop c-indent-level)) | |
559 (+ c-brace-offset c-continued-statement-offset) | |
560 c-indent-level) | |
561 ;; Move back over whitespace before the openbrace. | |
562 ;; If openbrace is not first nonwhite thing on the line, | |
563 ;; add the c-brace-imaginary-offset. | |
564 (progn (skip-chars-backward " \t") | |
565 (if (bolp) 0 c-brace-imaginary-offset)) | |
566 ;; If the openbrace is preceded by a parenthesized exp, | |
567 ;; move to the beginning of that; | |
568 ;; possibly a different line | |
569 (progn | |
570 (if (eq (preceding-char) ?\)) | |
571 (forward-sexp -1)) | |
572 ;; Get initial indentation of the line we are on. | |
573 (current-indentation)))))))))) | |
574 | |
575 (defun c++-backward-to-noncomment (lim) | |
576 (let (opoint stop) | |
577 (while (not stop) | |
578 (skip-chars-backward " \t\n\r\f" lim) | |
579 (setq opoint (point)) | |
580 (cond ((and (>= (point) (+ 2 lim)) | |
581 (save-excursion | |
582 (forward-char -2) | |
583 (looking-at "\\*/"))) | |
584 (search-backward "/*" lim 'move)) | |
585 ((and | |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
586 (search-backward "//" (max (c++-point-bol) lim) 'move) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
587 (not (c++-within-string-p (point) opoint)))) |
257 | 588 (t (beginning-of-line) |
589 (skip-chars-forward " \t") | |
590 (if (looking-at "#") | |
591 (setq stop (<= (point) lim)) | |
592 (setq stop t) | |
593 (goto-char opoint))))))) | |
594 | |
595 (defun indent-c++-exp () | |
596 "Indent each line of the C++ grouping following point." | |
597 (interactive) | |
598 (let ((indent-stack (list nil)) | |
599 (contain-stack (list (point))) | |
600 (case-fold-search nil) | |
601 restart outer-loop-done inner-loop-done state ostate | |
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
602 this-indent last-sexp last-depth |
257 | 603 at-else at-brace |
604 (opoint (point)) | |
605 (next-depth 0)) | |
606 (save-excursion | |
607 (forward-sexp 1)) | |
608 (save-excursion | |
609 (setq outer-loop-done nil) | |
610 (while (and (not (eobp)) (not outer-loop-done)) | |
611 (setq last-depth next-depth) | |
612 ;; Compute how depth changes over this line | |
613 ;; plus enough other lines to get to one that | |
614 ;; does not end inside a comment or string. | |
615 ;; Meanwhile, do appropriate indentation on comment lines. | |
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
616 (setq inner-loop-done nil) |
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
617 (while (and (not inner-loop-done) |
257 | 618 (not (and (eobp) (setq outer-loop-done t)))) |
619 (setq ostate state) | |
620 (setq state (parse-partial-sexp (point) (progn (end-of-line) (point)) | |
621 nil nil state)) | |
622 (setq next-depth (car state)) | |
623 (if (and (car (cdr (cdr state))) | |
624 (>= (car (cdr (cdr state))) 0)) | |
625 (setq last-sexp (car (cdr (cdr state))))) | |
626 (if (or (nth 4 ostate)) | |
627 (c++-indent-line)) | |
628 (if (or (nth 3 state)) | |
629 (forward-line 1) | |
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
630 (setq inner-loop-done t))) |
257 | 631 (if (<= next-depth 0) |
632 (setq outer-loop-done t)) | |
633 (if outer-loop-done | |
634 nil | |
635 ;; If this line had ..))) (((.. in it, pop out of the levels | |
636 ;; that ended anywhere in this line, even if the final depth | |
637 ;; doesn't indicate that they ended. | |
638 (while (> last-depth (nth 6 state)) | |
639 (setq indent-stack (cdr indent-stack) | |
640 contain-stack (cdr contain-stack) | |
641 last-depth (1- last-depth))) | |
642 (if (/= last-depth next-depth) | |
643 (setq last-sexp nil)) | |
644 ;; Add levels for any parens that were started in this line. | |
645 (while (< last-depth next-depth) | |
646 (setq indent-stack (cons nil indent-stack) | |
647 contain-stack (cons nil contain-stack) | |
648 last-depth (1+ last-depth))) | |
649 (if (null (car contain-stack)) | |
650 (setcar contain-stack (or (car (cdr state)) | |
651 (save-excursion (forward-sexp -1) | |
652 (point))))) | |
653 (forward-line 1) | |
654 (skip-chars-forward " \t") | |
655 (if (eolp) | |
656 nil | |
657 (if (and (car indent-stack) | |
658 (>= (car indent-stack) 0)) | |
659 ;; Line is on an existing nesting level. | |
660 ;; Lines inside parens are handled specially. | |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
661 (if (/= (char-after (car contain-stack)) ?\{) |
257 | 662 (setq this-indent (car indent-stack)) |
663 ;; Line is at statement level. | |
664 ;; Is it a new statement? Is it an else? | |
665 ;; Find last non-comment character before this line | |
666 (save-excursion | |
667 (setq at-else (looking-at "else\\W")) | |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
668 (setq at-brace (= (following-char) ?\{)) |
257 | 669 (c++-backward-to-noncomment opoint) |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
670 (if (not (memq (preceding-char) '(nil ?\, ?\; ?\} ?: ?\{))) |
257 | 671 ;; Preceding line did not end in comma or semi; |
672 ;; indent this line c-continued-statement-offset | |
673 ;; more than previous. | |
674 (progn | |
675 (c-backward-to-start-of-continued-exp | |
676 (car contain-stack)) | |
677 (setq this-indent | |
678 (+ c-continued-statement-offset | |
679 (current-column) | |
680 (if at-brace c-continued-brace-offset 0)))) | |
681 ;; Preceding line ended in comma or semi; | |
682 ;; use the standard indent for this level. | |
683 (if at-else | |
684 (progn (c-backward-to-start-of-if opoint) | |
685 (setq this-indent (current-indentation))) | |
686 (setq this-indent (car indent-stack)))))) | |
687 ;; Just started a new nesting level. | |
688 ;; Compute the standard indent for this level. | |
689 (let ((val (calculate-c++-indent | |
690 (if (car indent-stack) | |
691 (- (car indent-stack)))))) | |
692 (setcar indent-stack | |
693 (setq this-indent val)))) | |
694 ;; Adjust line indentation according to its contents | |
695 (if (looking-at "\\(public\\|private\\|protected\\):") | |
696 (setq this-indent (- this-indent c-indent-level))) | |
697 (if (or (looking-at "case[ \t]") | |
698 (and (looking-at "[A-Za-z]") | |
699 (save-excursion | |
700 (forward-sexp 1) | |
701 (looking-at ":[^:]")))) | |
702 (setq this-indent (max 1 (+ this-indent c-label-offset)))) | |
5300
954744cd720f
(c++-indent-line, calculate-c++-indent):
Richard M. Stallman <rms@gnu.org>
parents:
4308
diff
changeset
|
703 (if (looking-at "friend[ \t]") |
257 | 704 (setq this-indent (+ this-indent c++-friend-offset))) |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
705 (if (= (following-char) ?\}) |
257 | 706 (setq this-indent (- this-indent c-indent-level))) |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
707 (if (= (following-char) ?\{) |
257 | 708 (setq this-indent (+ this-indent c-brace-offset))) |
709 ;; Put chosen indentation into effect. | |
710 (or (= (current-column) this-indent) | |
711 (= (following-char) ?\#) | |
712 (progn | |
713 (delete-region (point) (progn (beginning-of-line) (point))) | |
714 (indent-to this-indent))) | |
715 ;; Indent any comment following the text. | |
716 (or (looking-at comment-start-skip) | |
717 (if (re-search-forward comment-start-skip | |
718 (save-excursion (end-of-line) | |
719 (point)) t) | |
720 (progn | |
721 (indent-for-comment) | |
722 (beginning-of-line)))))))))) | |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
723 |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
724 (defun fill-c++-comment () |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
725 "Fill a comment contained in consecutive lines containing point. |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
726 The fill lines remain a comment." |
257 | 727 (interactive) |
728 (save-excursion | |
729 (let ((save fill-prefix)) | |
730 (beginning-of-line 1) | |
731 (save-excursion | |
732 (re-search-forward comment-start-skip | |
733 (save-excursion (end-of-line) (point)) | |
734 t) | |
735 (goto-char (match-end 0)) | |
736 (set-fill-prefix)) | |
737 (while (looking-at fill-prefix) | |
738 (previous-line 1)) | |
739 (next-line 1) | |
740 (insert-string "\n") | |
741 (fill-paragraph nil) | |
742 (delete-char -1) | |
743 (setq fill-prefix save)))) | |
744 | |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
745 (defun c++-point-bol () |
257 | 746 "Returns the value of the point at the beginning of the current line." |
747 (save-excursion | |
748 (beginning-of-line) | |
749 (point))) | |
750 | |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
751 ;; (defun c++-insert-header () |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
752 ;; "Insert header denoting C++ code at top of buffer." |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
753 ;; (interactive) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
754 ;; (save-excursion |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
755 ;; (goto-char (point-min)) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
756 ;; (insert "// " |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
757 ;; "This may look like C code, but it is really " |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
758 ;; "-*- C++ -*-" |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
759 ;; "\n\n"))) |
257 | 760 |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
761 (defun c++-within-string-p (point1 point2) |
257 | 762 "Returns true if number of double quotes between two points is odd." |
763 (let ((s (buffer-substring point1 point2))) | |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
764 (not (zerop (% (c++-count-char-in-string ?\" s) 2))))) |
257 | 765 |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
766 (defun c++-count-char-in-string (c s) |
257 | 767 (let ((count 0) |
768 (pos 0)) | |
769 (while (< pos (length s)) | |
770 (setq count (+ count (if (\= (aref s pos) c) 1 0))) | |
771 (setq pos (1+ pos))) | |
772 count)) | |
773 | |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
774 ;; rms: This page is creeping featurism, and not worth having. |
257 | 775 |
776 ;;; Below are two regular expressions that attempt to match defuns | |
777 ;;; "strongly" and "weakly." The strong one almost reconstructs the | |
778 ;;; grammar of C++; the weak one just figures anything id or curly on | |
779 ;;; the left begins a defun. The constant "c++-match-header-strongly" | |
780 ;;; determines which to use; the default is the weak one. | |
781 | |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
782 ;; (defvar c++-match-header-strongly nil |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
783 ;; "*If nil, use `c++-defun-header-weak' to identify beginning of definitions. |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
784 ;; If non-nil, use `c++-defun-header-strong'.") |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
785 ;; |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
786 ;; (defvar c++-defun-header-strong-struct-equivs "\\(class\\|struct\\|enum\\)" |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
787 ;; "Regexp to match names of structure declaration blocks in C++.") |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
788 ;; |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
789 ;; (defconst c++-defun-header-strong |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
790 ;; (let* |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
791 ;; (; valid identifiers |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
2307
diff
changeset
|
792 ;; ;; There's a real weirdness here -- if I switch the below |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
793 ;; (id "\\(\\w\\|_\\)+") |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
794 ;; ;; to be |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
795 ;; ;; (id "\\(_\\|\\w\\)+") |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
796 ;; ;; things no longer work right. Try it and see! |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
797 ;; |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
798 ;; ; overloadable operators |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
799 ;; (op-sym1 |
6309
9217f29851c2
Don't use triple-hyphen in a character class.
Karl Heuer <kwzh@gnu.org>
parents:
5957
diff
changeset
|
800 ;; "[-+*/%^&|~!=<>]\\|[-+*/%^&|<>=!]=\\|<<=?\\|>>=?") |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
801 ;; (op-sym2 |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
802 ;; "&&\\|||\\|\\+\\+\\|--\\|()\\|\\[\\]") |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
803 ;; (op-sym (concat "\\(" op-sym1 "\\|" op-sym2 "\\)")) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
804 ;; ; whitespace |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
805 ;; (middle "[^\\*]*\\(\\*+[^/\\*][^\\*]*\\)*") |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
806 ;; (c-comment (concat "/\\*" middle "\\*+/")) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
807 ;; (wh (concat "\\(\\s \\|\n\\|//.*$\\|" c-comment "\\)")) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
808 ;; (wh-opt (concat wh "*")) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
809 ;; (wh-nec (concat wh "+")) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
810 ;; (oper (concat "\\(" "operator" "\\(" |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
811 ;; wh-opt op-sym "\\|" wh-nec id "\\)" "\\)")) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
812 ;; (dcl-list "([^():]*)") |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
813 ;; (func-name (concat "\\(" oper "\\|" id "::" id "\\|" id "\\)")) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
814 ;; (inits |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
815 ;; (concat "\\(:" |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
816 ;; "\\(" wh-opt id "(.*\\()" wh-opt "," "\\)\\)*" |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
817 ;; wh-opt id "(.*)" wh-opt "{" |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
818 ;; "\\|" wh-opt "{\\)")) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
819 ;; (type-name (concat |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
820 ;; "\\(" c++-defun-header-strong-struct-equivs wh-nec "\\)?" |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
821 ;; id)) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
822 ;; (type (concat "\\(const" wh-nec "\\)?" |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
823 ;; "\\(" type-name "\\|" type-name wh-opt "\\*+" "\\|" |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
824 ;; type-name wh-opt "&" "\\)")) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
825 ;; (modifier "\\(inline\\|virtual\\|overload\\|auto\\|static\\)") |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
826 ;; (modifiers (concat "\\(" modifier wh-nec "\\)*")) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
827 ;; (func-header |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
828 ;; ;; type arg-dcl |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
829 ;; (concat modifiers type wh-nec func-name wh-opt dcl-list wh-opt inits)) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
830 ;; (inherit (concat "\\(:" wh-opt "\\(public\\|private\\)?" |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
831 ;; wh-nec id "\\)")) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
832 ;; (cs-header (concat |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
833 ;; c++-defun-header-strong-struct-equivs |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
834 ;; wh-nec id wh-opt inherit "?" wh-opt "{"))) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
835 ;; (concat "^\\(" func-header "\\|" cs-header "\\)")) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
836 ;; "Strongly-defined regexp to match beginning of structure or function def.") |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
837 ;; |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
838 ;; |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
839 ;; ;; This part has to do with recognizing defuns. |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
840 ;; |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
841 ;; ;; The weak convention we will use is that a defun begins any time |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
842 ;; ;; there is a left curly brace, or some identifier on the left margin, |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
843 ;; ;; followed by a left curly somewhere on the line. (This will also |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
844 ;; ;; incorrectly match some continued strings, but this is after all |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
845 ;; ;; just a weak heuristic.) Suggestions for improvement (short of the |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
846 ;; ;; strong scheme shown above) are welcomed. |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
847 ;; |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
848 ;; (defconst c++-defun-header-weak "^{\\|^[_a-zA-Z].*{" |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
849 ;; "Weakly-defined regexp to match beginning of structure or function def.") |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
850 ;; |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
851 ;; (defun c++-beginning-of-defun (arg) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
852 ;; (interactive "p") |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
853 ;; (let ((c++-defun-header (if c++-match-header-strongly |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
854 ;; c++-defun-header-strong |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
855 ;; c++-defun-header-weak))) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
856 ;; (cond ((or (= arg 0) (and (> arg 0) (bobp))) nil) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
857 ;; ((and (not (looking-at c++-defun-header)) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
858 ;; (let ((curr-pos (point)) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
859 ;; (open-pos (if (search-forward "{" nil 'move) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
860 ;; (point))) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
861 ;; (beg-pos |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
862 ;; (if (re-search-backward c++-defun-header nil 'move) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
863 ;; (match-beginning 0)))) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
864 ;; (if (and open-pos beg-pos |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
865 ;; (< beg-pos curr-pos) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
866 ;; (> open-pos curr-pos)) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
867 ;; (progn |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
868 ;; (goto-char beg-pos) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
869 ;; (if (= arg 1) t nil));; Are we done? |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
870 ;; (goto-char curr-pos) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
871 ;; nil)))) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
872 ;; (t |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
873 ;; (if (and (looking-at c++-defun-header) (not (bobp))) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
874 ;; (forward-char (if (< arg 0) 1 -1))) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
875 ;; (and (re-search-backward c++-defun-header nil 'move (or arg 1)) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
876 ;; (goto-char (match-beginning 0))))))) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
877 ;; |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
878 ;; |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
879 ;; (defun c++-end-of-defun (arg) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
880 ;; (interactive "p") |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
881 ;; (let ((c++-defun-header (if c++-match-header-strongly |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
882 ;; c++-defun-header-strong |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
883 ;; c++-defun-header-weak))) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
884 ;; (if (and (eobp) (> arg 0)) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
885 ;; nil |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
886 ;; (if (and (> arg 0) (looking-at c++-defun-header)) (forward-char 1)) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
887 ;; (let ((pos (point))) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
888 ;; (c++-beginning-of-defun |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
889 ;; (if (< arg 0) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
890 ;; (- (- arg (if (eobp) 0 1))) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
891 ;; arg)) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
892 ;; (if (and (< arg 0) (bobp)) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
893 ;; t |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
894 ;; (if (re-search-forward c++-defun-header nil 'move) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
895 ;; (progn (forward-char -1) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
896 ;; (forward-sexp) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
897 ;; (beginning-of-line 2))) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
898 ;; (if (and (= pos (point)) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
899 ;; (re-search-forward c++-defun-header nil 'move)) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
900 ;; (c++-end-of-defun 1)))) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
901 ;; t))) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
902 ;; |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
903 ;; (defun c++-indent-defun () |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
904 ;; "Indents the current function definition, struct or class declaration." |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
905 ;; (interactive) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
906 ;; (let ((restore (point))) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
907 ;; (c++-end-of-defun 1) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
908 ;; (beginning-of-line 1) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
909 ;; (let ((end (point))) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
910 ;; (c++-beginning-of-defun 1) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
911 ;; (while (<= (point) end) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
912 ;; (c++-indent-line) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
913 ;; (next-line 1) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
914 ;; (beginning-of-line 1))) |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
915 ;; (goto-char restore))) |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
257
diff
changeset
|
916 |
3806
d43666cf0dbb
Comment changes for renaming from c++-mode.el to cplus-md.el.
Richard M. Stallman <rms@gnu.org>
parents:
3627
diff
changeset
|
917 ;;; cplus-md.el ends here |