24 |
|
|
25 |
;;; Commentary: |
;;; Commentary: |
26 |
|
|
27 |
;; 1987 Dave Detlefs <dld@cs.cmu.edu> |
;; 1987 Dave Detlefs <dld@cs.cmu.edu> |
28 |
;; and Stewart Clamen <clamen@cs.cmu.edu>. |
;; and Stewart Clamen <clamen@cs.cmu.edu>. |
29 |
;; Done by fairly faithful modification of: |
;; Done by fairly faithful modification of: |
30 |
|
|
33 |
;; Feb, 1990 (Dave Detlefs, dld@cs.cmu.edu) |
;; Feb, 1990 (Dave Detlefs, dld@cs.cmu.edu) |
34 |
;; Fixed electric-c++-terminator to handle double colons, at the |
;; Fixed electric-c++-terminator to handle double colons, at the |
35 |
;; request of John Hagerman. |
;; request of John Hagerman. |
36 |
;; |
;; |
37 |
;; Jan, 1990 (Doug Lea, dl@oswego.edu) |
;; Jan, 1990 (Doug Lea, dl@oswego.edu) |
38 |
;; Replaced c++-comment-region and c++-uncomment-region with |
;; Replaced c++-comment-region and c++-uncomment-region with |
39 |
;; versions from Igor Metz that avoid potential infinite loops. |
;; versions from Igor Metz that avoid potential infinite loops. |
40 |
;; |
;; |
41 |
;; Oct, 1989 (Dave Detlefs, dld@cs.cmu.edu) |
;; Oct, 1989 (Dave Detlefs, dld@cs.cmu.edu) |
42 |
;; Added contribution from Igor Metz <metz@iam.unibe.ch>: |
;; Added contribution from Igor Metz <metz@iam.unibe.ch>: |
43 |
;; functions c++-comment-region and c++-uncomment-region and |
;; functions c++-comment-region and c++-uncomment-region and |
44 |
;; corresponding key-binding. |
;; corresponding key-binding. |
45 |
;; Also fixed bug in indentation of second line after an empty |
;; Also fixed bug in indentation of second line after an empty |
46 |
;; arglist with empty-arglist non-null. |
;; arglist with empty-arglist non-null. |
47 |
;; |
;; |
48 |
;; Sept, 1989 (Glen Ditchfield, gjditchfield@violet.uwaterloo.ca): |
;; Sept, 1989 (Glen Ditchfield, gjditchfield@violet.uwaterloo.ca): |
49 |
;; Textual changes to more closely imitate Emacs 18.55's c-mode. |
;; Textual changes to more closely imitate Emacs 18.55's c-mode. |
50 |
;; Fixed handling of "default:", where ":" was the last character in the |
;; Fixed handling of "default:", where ":" was the last character in the |
168 |
:type 'boolean |
:type 'boolean |
169 |
:group 'old-c++) |
:group 'old-c++) |
170 |
(defcustom c++-empty-arglist-indent nil |
(defcustom c++-empty-arglist-indent nil |
171 |
"*Indicates how far to indent an line following an empty argument |
"*Indicates how far to indent a line following an empty argument |
172 |
list. Nil indicates to just after the paren." |
list. Nil indicates to just after the paren." |
173 |
:type '(choice (const nil) integer) |
:type '(choice (const nil) integer) |
174 |
:group 'old-c++) |
:group 'old-c++) |
175 |
|
|
176 |
(defvar c++-imenu-generic-expression |
(defvar c++-imenu-generic-expression |
177 |
(` |
(` |
178 |
((nil |
((nil |
179 |
(, |
(, |
180 |
(concat |
(concat |
181 |
"^" ; beginning of line is required |
"^" ; beginning of line is required |
182 |
"\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there may be a "template <...>" |
"\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there may be a "template <...>" |
183 |
"\\([a-zA-Z0-9_:]+[ \t]+\\)?" ; type specs; there can be no |
"\\([a-zA-Z0-9_:]+[ \t]+\\)?" ; type specs; there can be no |
184 |
"\\([a-zA-Z0-9_:]+[ \t]+\\)?" ; more than 3 tokens, right? |
"\\([a-zA-Z0-9_:]+[ \t]+\\)?" ; more than 3 tokens, right? |
185 |
|
|
186 |
"\\(" ; last type spec including */& |
"\\(" ; last type spec including */& |
187 |
"[a-zA-Z0-9_:]+" |
"[a-zA-Z0-9_:]+" |
188 |
"\\([ \t]*[*&]+[ \t]*\\|[ \t]+\\)" ; either pointer/ref sign or whitespace |
"\\([ \t]*[*&]+[ \t]*\\|[ \t]+\\)" ; either pointer/ref sign or whitespace |
189 |
"\\)?" ; if there is a last type spec |
"\\)?" ; if there is a last type spec |
190 |
"\\(" ; name; take that into the imenu entry |
"\\(" ; name; take that into the imenu entry |
191 |
"[a-zA-Z0-9_:~]+" ; member function, ctor or dtor... |
"[a-zA-Z0-9_:~]+" ; member function, ctor or dtor... |
192 |
; (may not contain * because then |
; (may not contain * because then |
193 |
; "a::operator char*" would become "char*"!) |
; "a::operator char*" would become "char*"!) |
194 |
"\\|" |
"\\|" |
195 |
"\\([a-zA-Z0-9_:~]*::\\)?operator" |
"\\([a-zA-Z0-9_:~]*::\\)?operator" |
200 |
; catch cases with () inside the parentheses |
; catch cases with () inside the parentheses |
201 |
; surrounding the parameters |
; surrounding the parameters |
202 |
; (like "int foo(int a=bar()) {...}" |
; (like "int foo(int a=bar()) {...}" |
203 |
|
|
204 |
)) 6) |
)) 6) |
205 |
("Class" |
("Class" |
206 |
(, (concat |
(, (concat |
207 |
"^" ; beginning of line is required |
"^" ; beginning of line is required |
208 |
"\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there may be a "template <...>" |
"\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there may be a "template <...>" |
209 |
"class[ \t]+" |
"class[ \t]+" |
214 |
;; Uncomment if you want to find these too. It will be a bit slower gathering |
;; Uncomment if you want to find these too. It will be a bit slower gathering |
215 |
;; the indexes. |
;; the indexes. |
216 |
; ("Prototypes" |
; ("Prototypes" |
217 |
; (, |
; (, |
218 |
; (concat |
; (concat |
219 |
; "^" ; beginning of line is required |
; "^" ; beginning of line is required |
220 |
; "\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there may be a "template <...>" |
; "\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there may be a "template <...>" |
221 |
; "\\([a-zA-Z0-9_:]+[ \t]+\\)?" ; type specs; there can be no |
; "\\([a-zA-Z0-9_:]+[ \t]+\\)?" ; type specs; there can be no |
222 |
; "\\([a-zA-Z0-9_:]+[ \t]+\\)?" ; more than 3 tokens, right? |
; "\\([a-zA-Z0-9_:]+[ \t]+\\)?" ; more than 3 tokens, right? |
223 |
|
|
224 |
; "\\(" ; last type spec including */& |
; "\\(" ; last type spec including */& |
225 |
; "[a-zA-Z0-9_:]+" |
; "[a-zA-Z0-9_:]+" |
226 |
; "\\([ \t]*[*&]+[ \t]*\\|[ \t]+\\)" ; either pointer/ref sign or whitespace |
; "\\([ \t]*[*&]+[ \t]*\\|[ \t]+\\)" ; either pointer/ref sign or whitespace |
227 |
; "\\)?" ; if there is a last type spec |
; "\\)?" ; if there is a last type spec |
228 |
; "\\(" ; name; take that into the imenu entry |
; "\\(" ; name; take that into the imenu entry |
229 |
; "[a-zA-Z0-9_:~]+" ; member function, ctor or dtor... |
; "[a-zA-Z0-9_:~]+" ; member function, ctor or dtor... |
230 |
; ; (may not contain * because then |
; ; (may not contain * because then |
231 |
; ; "a::operator char*" would become "char*"!) |
; ; "a::operator char*" would become "char*"!) |
232 |
; "\\|" |
; "\\|" |
233 |
; "\\([a-zA-Z0-9_:~]*::\\)?operator" |
; "\\([a-zA-Z0-9_:~]*::\\)?operator" |
237 |
; ; the (...) Can't |
; ; the (...) Can't |
238 |
; ; catch cases with () inside the parentheses |
; ; catch cases with () inside the parentheses |
239 |
; ; surrounding the parameters |
; ; surrounding the parameters |
240 |
; ; (like "int foo(int a=bar());" |
; ; (like "int foo(int a=bar());" |
241 |
; )) 6) |
; )) 6) |
242 |
; ("Struct" |
; ("Struct" |
243 |
; (, (concat |
; (, (concat |
244 |
; "^" ; beginning of line is required |
; "^" ; beginning of line is required |
690 |
;; The first following code counts |
;; The first following code counts |
691 |
;; if it is before the line we want to indent. |
;; if it is before the line we want to indent. |
692 |
(and (< (point) indent-point) |
(and (< (point) indent-point) |
693 |
(- |
(- |
694 |
(if (> colon-line-end (point)) |
(if (> colon-line-end (point)) |
695 |
(- (current-indentation) c-label-offset) |
(- (current-indentation) c-label-offset) |
696 |
(current-column)) |
(current-column)) |
943 |
;; (defvar c++-match-header-strongly nil |
;; (defvar c++-match-header-strongly nil |
944 |
;; "*If nil, use `c++-defun-header-weak' to identify beginning of definitions. |
;; "*If nil, use `c++-defun-header-weak' to identify beginning of definitions. |
945 |
;; If non-nil, use `c++-defun-header-strong'.") |
;; If non-nil, use `c++-defun-header-strong'.") |
946 |
;; |
;; |
947 |
;; (defvar c++-defun-header-strong-struct-equivs "\\(class\\|struct\\|enum\\)" |
;; (defvar c++-defun-header-strong-struct-equivs "\\(class\\|struct\\|enum\\)" |
948 |
;; "Regexp to match names of structure declaration blocks in C++.") |
;; "Regexp to match names of structure declaration blocks in C++.") |
949 |
;; |
;; |
950 |
;; (defconst c++-defun-header-strong |
;; (defconst c++-defun-header-strong |
951 |
;; (let* |
;; (let* |
952 |
;; (; valid identifiers |
;; (; valid identifiers |
955 |
;; ;; to be |
;; ;; to be |
956 |
;; ;; (id "\\(_\\|\\w\\)+") |
;; ;; (id "\\(_\\|\\w\\)+") |
957 |
;; ;; things no longer work right. Try it and see! |
;; ;; things no longer work right. Try it and see! |
958 |
;; |
;; |
959 |
;; ; overloadable operators |
;; ; overloadable operators |
960 |
;; (op-sym1 |
;; (op-sym1 |
961 |
;; "[-+*/%^&|~!=<>]\\|[-+*/%^&|<>=!]=\\|<<=?\\|>>=?") |
;; "[-+*/%^&|~!=<>]\\|[-+*/%^&|<>=!]=\\|<<=?\\|>>=?") |
962 |
;; (op-sym2 |
;; (op-sym2 |
963 |
;; "&&\\|||\\|\\+\\+\\|--\\|()\\|\\[\\]") |
;; "&&\\|||\\|\\+\\+\\|--\\|()\\|\\[\\]") |
964 |
;; (op-sym (concat "\\(" op-sym1 "\\|" op-sym2 "\\)")) |
;; (op-sym (concat "\\(" op-sym1 "\\|" op-sym2 "\\)")) |
965 |
;; ; whitespace |
;; ; whitespace |
966 |
;; (middle "[^\\*]*\\(\\*+[^/\\*][^\\*]*\\)*") |
;; (middle "[^\\*]*\\(\\*+[^/\\*][^\\*]*\\)*") |
995 |
;; wh-nec id wh-opt inherit "?" wh-opt "{"))) |
;; wh-nec id wh-opt inherit "?" wh-opt "{"))) |
996 |
;; (concat "^\\(" func-header "\\|" cs-header "\\)")) |
;; (concat "^\\(" func-header "\\|" cs-header "\\)")) |
997 |
;; "Strongly-defined regexp to match beginning of structure or function def.") |
;; "Strongly-defined regexp to match beginning of structure or function def.") |
998 |
;; |
;; |
999 |
;; |
;; |
1000 |
;; ;; This part has to do with recognizing defuns. |
;; ;; This part has to do with recognizing defuns. |
1001 |
;; |
;; |
1002 |
;; ;; The weak convention we will use is that a defun begins any time |
;; ;; The weak convention we will use is that a defun begins any time |
1003 |
;; ;; there is a left curly brace, or some identifier on the left margin, |
;; ;; there is a left curly brace, or some identifier on the left margin, |
1004 |
;; ;; followed by a left curly somewhere on the line. (This will also |
;; ;; followed by a left curly somewhere on the line. (This will also |
1005 |
;; ;; incorrectly match some continued strings, but this is after all |
;; ;; incorrectly match some continued strings, but this is after all |
1006 |
;; ;; just a weak heuristic.) Suggestions for improvement (short of the |
;; ;; just a weak heuristic.) Suggestions for improvement (short of the |
1007 |
;; ;; strong scheme shown above) are welcomed. |
;; ;; strong scheme shown above) are welcomed. |
1008 |
;; |
;; |
1009 |
;; (defconst c++-defun-header-weak "^{\\|^[_a-zA-Z].*{" |
;; (defconst c++-defun-header-weak "^{\\|^[_a-zA-Z].*{" |
1010 |
;; "Weakly-defined regexp to match beginning of structure or function def.") |
;; "Weakly-defined regexp to match beginning of structure or function def.") |
1011 |
;; |
;; |
1012 |
;; (defun c++-beginning-of-defun (arg) |
;; (defun c++-beginning-of-defun (arg) |
1013 |
;; (interactive "p") |
;; (interactive "p") |
1014 |
;; (let ((c++-defun-header (if c++-match-header-strongly |
;; (let ((c++-defun-header (if c++-match-header-strongly |
1035 |
;; (forward-char (if (< arg 0) 1 -1))) |
;; (forward-char (if (< arg 0) 1 -1))) |
1036 |
;; (and (re-search-backward c++-defun-header nil 'move (or arg 1)) |
;; (and (re-search-backward c++-defun-header nil 'move (or arg 1)) |
1037 |
;; (goto-char (match-beginning 0))))))) |
;; (goto-char (match-beginning 0))))))) |
1038 |
;; |
;; |
1039 |
;; |
;; |
1040 |
;; (defun c++-end-of-defun (arg) |
;; (defun c++-end-of-defun (arg) |
1041 |
;; (interactive "p") |
;; (interactive "p") |
1042 |
;; (let ((c++-defun-header (if c++-match-header-strongly |
;; (let ((c++-defun-header (if c++-match-header-strongly |
1046 |
;; nil |
;; nil |
1047 |
;; (if (and (> arg 0) (looking-at c++-defun-header)) (forward-char 1)) |
;; (if (and (> arg 0) (looking-at c++-defun-header)) (forward-char 1)) |
1048 |
;; (let ((pos (point))) |
;; (let ((pos (point))) |
1049 |
;; (c++-beginning-of-defun |
;; (c++-beginning-of-defun |
1050 |
;; (if (< arg 0) |
;; (if (< arg 0) |
1051 |
;; (- (- arg (if (eobp) 0 1))) |
;; (- (- arg (if (eobp) 0 1))) |
1052 |
;; arg)) |
;; arg)) |
1056 |
;; (progn (forward-char -1) |
;; (progn (forward-char -1) |
1057 |
;; (forward-sexp) |
;; (forward-sexp) |
1058 |
;; (beginning-of-line 2))) |
;; (beginning-of-line 2))) |
1059 |
;; (if (and (= pos (point)) |
;; (if (and (= pos (point)) |
1060 |
;; (re-search-forward c++-defun-header nil 'move)) |
;; (re-search-forward c++-defun-header nil 'move)) |
1061 |
;; (c++-end-of-defun 1)))) |
;; (c++-end-of-defun 1)))) |
1062 |
;; t))) |
;; t))) |
1063 |
;; |
;; |
1064 |
;; (defun c++-indent-defun () |
;; (defun c++-indent-defun () |
1065 |
;; "Indents the current function definition, struct or class declaration." |
;; "Indents the current function definition, struct or class declaration." |
1066 |
;; (interactive) |
;; (interactive) |