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