Mercurial > emacs
comparison lisp/progmodes/cc-menus.el @ 20916:704b7ccba694
Imenu support changed.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 17 Feb 1998 07:10:49 +0000 |
parents | 07a8c7f7cfe8 |
children | ce4bb28a20e4 |
comparison
equal
deleted
inserted
replaced
20915:c746c93c9c95 | 20916:704b7ccba694 |
---|---|
1 ;;; cc-menus.el --- imenu support for CC Mode | 1 ;;; cc-menus.el --- imenu support for CC Mode |
2 | 2 |
3 ;; Copyright (C) 1985,87,92,93,94,95,96,97 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1985,87,92,93,94,95,96,97,98 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Authors: 1992-1997 Barry A. Warsaw | 5 ;; Authors: 1992-1997 Barry A. Warsaw |
6 ;; 1987 Dave Detlefs and Stewart Clamen | 6 ;; 1987 Dave Detlefs and Stewart Clamen |
7 ;; 1985 Richard M. Stallman | 7 ;; 1985 Richard M. Stallman |
8 ;; Maintainer: cc-mode-help@python.org | 8 ;; Maintainer: cc-mode-help@python.org |
78 (nil | 78 (nil |
79 (, | 79 (, |
80 (concat | 80 (concat |
81 "^" | 81 "^" |
82 "\\([a-zA-Z_][a-zA-Z0-9_:<>~]*\\)" ; match function name | 82 "\\([a-zA-Z_][a-zA-Z0-9_:<>~]*\\)" ; match function name |
83 "[ \t]*([^)]*)[ \t]*[^ \t;]" ; see above | 83 "[ \t]*(" ; see above, BUT |
84 "[ \t]*\\([^ \t(*][^)]*\\)?)" ; the arg list must not start | |
85 "[ \t]*[^ \t;(]" ; with an asterisk or parentheses | |
84 )) 1) | 86 )) 1) |
85 ;; General function name regexp | 87 ;; General function name regexp |
86 (nil | 88 (nil |
87 (, | 89 (, |
88 (concat | 90 (concat |
89 "^\\<.*" ; line MUST start with word char | 91 "^\\<.*" ; line MUST start with word char |
90 "[^a-zA-Z0-9_:<>~]" ; match any non-identifier char | 92 "[^a-zA-Z0-9_:<>~]" ; match any non-identifier char |
91 "\\([a-zA-Z_][a-zA-Z0-9_:<>~]*\\)" ; match function name | 93 "\\([a-zA-Z_][a-zA-Z0-9_:<>~]*\\)" ; match function name |
92 "[ \t]*(" ; see above, BUT | 94 "[ \t]*(" ; see above, BUT |
93 "[ \t]*[^ \t(][^)]*)[ \t]*[^ \t;]" ; the argument list must not start | 95 "[ \t]*\\([^ \t(*][^)]*\\)?)" ; the arg list must not start |
94 ; with a parentheses | 96 "[ \t]*[^ \t;(]" ; with an asterisk or parentheses |
95 )) 1) | 97 )) 1) |
96 ;; Special case for definitions using phony prototype macros like: | 98 ;; Special case for definitions using phony prototype macros like: |
97 ;; `int main _PROTO( (int argc,char *argv[]) )'. | 99 ;; `int main _PROTO( (int argc,char *argv[]) )'. |
98 ;; This case is only included if cc-imenu-c-prototype-macro-regexp is set. | 100 ;; This case is only included if cc-imenu-c-prototype-macro-regexp is set. |
99 ;; Only supported in c-code, so no `:<>~' chars in function name! | 101 ;; Only supported in c-code, so no `:<>~' chars in function name! |
141 ; "[^;(]" | 143 ; "[^;(]" |
142 "[,a-zA-Z_1-9\n \t]*{" | 144 "[,a-zA-Z_1-9\n \t]*{" |
143 )) 6))) | 145 )) 6))) |
144 "Imenu generic expression for Java mode. See `imenu-generic-expression'.") | 146 "Imenu generic expression for Java mode. See `imenu-generic-expression'.") |
145 | 147 |
148 ;; *Warning for cc-mode developers* | |
149 ;; | |
150 ;; `cc-imenu-objc-generic-expression' elements depend on | |
151 ;; `cc-imenu-c++-generic-expression'. So if you change this | |
152 ;; expression, you need to change following variables, | |
153 ;; `cc-imenu-objc-generic-expression-*-index', | |
154 ;; too. `cc-imenu-objc-function' uses these *-index variables, in | |
155 ;; order to know where the each regexp *group \\(foobar\\)* elements | |
156 ;; are started. | |
157 ;; | |
158 ;; *-index variables are initialized during `cc-imenu-objc-generic-expression' | |
159 ;; being initialized. | |
160 ;; | |
161 | |
162 ;; Internal variables | |
163 (defvar cc-imenu-objc-generic-expression-noreturn-index nil) | |
164 (defvar cc-imenu-objc-generic-expression-general-func-index nil) | |
165 (defvar cc-imenu-objc-generic-expression-proto-index nil) | |
166 (defvar cc-imenu-objc-generic-expression-objc-base-index nil) | |
167 | |
146 (defvar cc-imenu-objc-generic-expression | 168 (defvar cc-imenu-objc-generic-expression |
147 (concat | 169 (concat |
148 ;; | 170 ;; |
149 ;; For C | 171 ;; For C |
150 ;; *Warning for developers* | |
151 ;; This expression elements depend on `cc-imenu-c++-generic-expression'. | |
152 ;; | 172 ;; |
153 ;; > Special case to match a line like `main() {}' | 173 ;; > Special case to match a line like `main() {}' |
154 ;; > e.g. no return type, not even on the previous line. | 174 ;; > e.g. no return type, not even on the previous line. |
155 ;; Pick a token by (match-string 1) | 175 ;; Pick a token by (match-string 1) |
156 (car (cdr (nth 1 cc-imenu-c++-generic-expression))) ; | 176 (car (cdr (nth 1 cc-imenu-c++-generic-expression))) ; -> index += 2 |
177 (prog2 (setq cc-imenu-objc-generic-expression-noreturn-index 1) "") | |
157 "\\|" | 178 "\\|" |
158 ;; > General function name regexp | 179 ;; > General function name regexp |
159 ;; Pick a token by (match-string 2) | 180 ;; Pick a token by (match-string 3) |
160 (car (cdr (nth 2 cc-imenu-c++-generic-expression))) | 181 (car (cdr (nth 2 cc-imenu-c++-generic-expression))) ; -> index += 2 |
182 (prog2 (setq cc-imenu-objc-generic-expression-general-func-index 3) "") | |
161 ;; > Special case for definitions using phony prototype macros like: | 183 ;; > Special case for definitions using phony prototype macros like: |
162 ;; > `int main _PROTO( (int argc,char *argv[]) )'. | 184 ;; > `int main _PROTO( (int argc,char *argv[]) )'. |
163 ;; Pick a token by (match-string 3) | 185 ;; Pick a token by (match-string 5) |
164 (if cc-imenu-c-prototype-macro-regexp | 186 (if cc-imenu-c-prototype-macro-regexp |
165 (concat | 187 (concat |
166 "\\|" | 188 "\\|" |
167 (car (cdr (nth 3 cc-imenu-c++-generic-expression)))) | 189 (car (cdr (nth 3 cc-imenu-c++-generic-expression))) ; -> index += 1 |
168 "") | 190 (prog2 (setq cc-imenu-objc-generic-expression-objc-base-index 6) "") |
191 ) | |
192 (prog2 (setq cc-imenu-objc-generic-expression-objc-base-index 5) "") | |
193 "") ; -> index += 0 | |
194 (prog2 (setq cc-imenu-objc-generic-expression-proto-index 5) "") | |
169 ;; | 195 ;; |
170 ;; For Objective-C | 196 ;; For Objective-C |
171 ;; Pick a token by (match-string 3 or 4) | 197 ;; Pick a token by (match-string 5 or 6) |
172 ;; | 198 ;; |
173 "\\|\\(" | 199 "\\|\\(" |
174 "^[-+][:a-zA-Z0-9()*_<>\n\t ]*[;{]" ; Methods | 200 "^[-+][:a-zA-Z0-9()*_<>\n\t ]*[;{]" ; Methods |
175 "\\|" | 201 "\\|" |
176 "^@interface[\t ]+[a-zA-Z0-9_]+[\t ]*:" | 202 "^@interface[\t ]+[a-zA-Z0-9_]+[\t ]*:" |
250 (defun cc-imenu-objc-function () | 276 (defun cc-imenu-objc-function () |
251 "imenu supports for objc-mode." | 277 "imenu supports for objc-mode." |
252 (let (methodlist | 278 (let (methodlist |
253 clist | 279 clist |
254 ;; | 280 ;; |
255 ;; OBJC, C1, C2, C3 are constants. | 281 ;; OBJC, Cnoreturn, Cgeneralfunc, Cproto are constants. |
256 ;; | 282 ;; |
257 ;; *Warning for developers* | 283 ;; *Warning for developers* |
258 ;; These constants depend on `cc-imenu-c++-generic-expression'. | 284 ;; These constants depend on `cc-imenu-c++-generic-expression'. |
259 ;; | 285 ;; |
260 (OBJC | 286 (OBJC cc-imenu-objc-generic-expression-objc-base-index) |
261 (if cc-imenu-c-prototype-macro-regexp 4 3)) | 287 ;; Special case to match a line like `main() {}' |
262 (C1 ; > Special case to match a line like `main() {}' | 288 (Cnoreturn cc-imenu-objc-generic-expression-noreturn-index) |
263 1) | 289 ;; General function name regexp |
264 (C2 ; > General function name regexp | 290 (Cgeneralfunc cc-imenu-objc-generic-expression-general-func-index) |
265 2) | 291 ;; Special case for definitions using phony prototype macros like: |
266 (C3 ; > Special case for definitions using phony prototype macros like: | 292 (Cproto cc-imenu-objc-generic-expression-proto-index) |
267 3) | |
268 langnum | 293 langnum |
269 ;; | 294 ;; |
270 (classcount 0) | 295 (classcount 0) |
271 toplist | 296 toplist |
272 stupid | 297 stupid |
273 str | 298 str |
274 str2 | 299 str2 |
275 (intflen (length "@interface")) | 300 (intflen (length "@interface")) |
276 (implen (length "@implementation")) | 301 (implen (length "@implementation")) |
277 (prtlen (length "@protocol")) | 302 (prtlen (length "@protocol")) |
278 bufsubst-fun) | 303 (func |
279 ;; | 304 ;; |
280 ;; Does this emacs has buffer-substring-no-properties? | 305 ;; Does this emacs has buffer-substring-no-properties? |
281 ;; | 306 ;; |
282 (setq bufsubst-fun (if (fboundp 'buffer-substring-no-properties) | 307 (if (fboundp 'buffer-substring-no-properties) |
283 (symbol-function 'buffer-substring-no-properties) | 308 'buffer-substring-no-properties |
284 (symbol-function 'buffer-substring))) | 309 'buffer-substring))) |
285 (goto-char (point-max)) | 310 (goto-char (point-max)) |
286 (imenu-progress-message stupid 0) | 311 (imenu-progress-message stupid 0) |
287 ;; | 312 ;; |
288 (while (re-search-backward cc-imenu-objc-generic-expression nil t) | 313 (while (re-search-backward cc-imenu-objc-generic-expression nil t) |
289 (imenu-progress-message stupid) | 314 (imenu-progress-message stupid) |
290 (setq langnum (if (match-beginning OBJC) | 315 (setq langnum (if (match-beginning OBJC) |
291 OBJC | 316 OBJC |
292 (cond | 317 (cond |
293 ((match-beginning C3) C3) | 318 ((match-beginning Cproto) Cproto) |
294 ((match-beginning C2) C2) | 319 ((match-beginning Cgeneralfunc) Cgeneralfunc) |
295 ((match-beginning C1) C1)))) | 320 ((match-beginning Cnoreturn) Cnoreturn)))) |
296 (setq str (funcall bufsubst-fun | 321 (setq str (funcall func (match-beginning langnum) (match-end langnum))) |
297 (match-beginning langnum) (match-end langnum))) | |
298 ;; | 322 ;; |
299 (cond | 323 (cond |
300 ;; | 324 ;; |
301 ;; C | 325 ;; C |
302 ;; | 326 ;; |