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