comparison lisp/progmodes/c-mode.el @ 12705:dca7533ebb9e

(c-imenu-generic-expression): Var defined. (c-mode): Set imenu-generic-expression.
author Karl Heuer <kwzh@gnu.org>
date Fri, 28 Jul 1995 00:28:28 +0000
parents e2e84d24f0d4
children 83f275dcd93a
comparison
equal deleted inserted replaced
12704:0b36e50fb5af 12705:dca7533ebb9e
177 177
178 ;;; Regular expression used internally to recognize labels in switch 178 ;;; Regular expression used internally to recognize labels in switch
179 ;;; statements. 179 ;;; statements.
180 (defconst c-switch-label-regexp "case[ \t'/(]\\|default[ \t]*:") 180 (defconst c-switch-label-regexp "case[ \t'/(]\\|default[ \t]*:")
181 181
182 ;; This is actually the expression for C++ mode, but it's used for C too.
183 (defvar c-imenu-generic-expression
184 (`
185 ((nil
186 (,
187 (concat
188 "^" ; beginning of line is required
189 "\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there may be a "template <...>"
190 "\\([a-zA-Z0-9_:]+[ \t]+\\)?" ; type specs; there can be no
191 "\\([a-zA-Z0-9_:]+[ \t]+\\)?" ; more than 3 tokens, right?
192
193 "\\(" ; last type spec including */&
194 "[a-zA-Z0-9_:]+"
195 "\\([ \t]*[*&]+[ \t]*\\|[ \t]+\\)" ; either pointer/ref sign or whitespace
196 "\\)?" ; if there is a last type spec
197 "\\(" ; name; take that into the imenu entry
198 "[a-zA-Z0-9_:~]+" ; member function, ctor or dtor...
199 ; (may not contain * because then
200 ; "a::operator char*" would become "char*"!)
201 "\\|"
202 "\\([a-zA-Z0-9_:~]*::\\)?operator"
203 "[^a-zA-Z1-9_][^(]*" ; ...or operator
204 " \\)"
205 "[ \t]*([^)]*)[ \t\n]*[^ ;]" ; require something other than a ; after
206 ; the (...) to avoid prototypes. Can't
207 ; catch cases with () inside the parentheses
208 ; surrounding the parameters
209 ; (like "int foo(int a=bar()) {...}"
210
211 )) 6)
212 ("Class"
213 (, (concat
214 "^" ; beginning of line is required
215 "\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there may be a "template <...>"
216 "class[ \t]+"
217 "\\([a-zA-Z0-9_]+\\)" ; this is the string we want to get
218 "[ \t]*[:{]"
219 )) 2)
220 ;; Example of generic expression for finding prototypes, structs, unions, enums.
221 ;; Uncomment if you want to find these too. It will be a bit slower gathering
222 ;; the indexes.
223 ; ("Prototypes"
224 ; (,
225 ; (concat
226 ; "^" ; beginning of line is required
227 ; "\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there may be a "template <...>"
228 ; "\\([a-zA-Z0-9_:]+[ \t]+\\)?" ; type specs; there can be no
229 ; "\\([a-zA-Z0-9_:]+[ \t]+\\)?" ; more than 3 tokens, right?
230
231 ; "\\(" ; last type spec including */&
232 ; "[a-zA-Z0-9_:]+"
233 ; "\\([ \t]*[*&]+[ \t]*\\|[ \t]+\\)" ; either pointer/ref sign or whitespace
234 ; "\\)?" ; if there is a last type spec
235 ; "\\(" ; name; take that into the imenu entry
236 ; "[a-zA-Z0-9_:~]+" ; member function, ctor or dtor...
237 ; ; (may not contain * because then
238 ; ; "a::operator char*" would become "char*"!)
239 ; "\\|"
240 ; "\\([a-zA-Z0-9_:~]*::\\)?operator"
241 ; "[^a-zA-Z1-9_][^(]*" ; ...or operator
242 ; " \\)"
243 ; "[ \t]*([^)]*)[ \t\n]*;" ; require ';' after
244 ; ; the (...) Can't
245 ; ; catch cases with () inside the parentheses
246 ; ; surrounding the parameters
247 ; ; (like "int foo(int a=bar());"
248 ; )) 6)
249 ; ("Struct"
250 ; (, (concat
251 ; "^" ; beginning of line is required
252 ; "\\(static[ \t]+\\)?" ; there may be static or const.
253 ; "\\(const[ \t]+\\)?"
254 ; "struct[ \t]+"
255 ; "\\([a-zA-Z0-9_]+\\)" ; this is the string we want to get
256 ; "[ \t]*[{]"
257 ; )) 3)
258 ; ("Enum"
259 ; (, (concat
260 ; "^" ; beginning of line is required
261 ; "\\(static[ \t]+\\)?" ; there may be static or const.
262 ; "\\(const[ \t]+\\)?"
263 ; "enum[ \t]+"
264 ; "\\([a-zA-Z0-9_]+\\)" ; this is the string we want to get
265 ; "[ \t]*[{]"
266 ; )) 3)
267 ; ("Union"
268 ; (, (concat
269 ; "^" ; beginning of line is required
270 ; "\\(static[ \t]+\\)?" ; there may be static or const.
271 ; "\\(const[ \t]+\\)?"
272 ; "union[ \t]+"
273 ; "\\([a-zA-Z0-9_]+\\)" ; this is the string we want to get
274 ; "[ \t]*[{]"
275 ; )) 3)
276 ))
277 "Imenu generic expression for C mode. See `imenu-generic-expression'.")
182 278
183 (defun c-mode () 279 (defun c-mode ()
184 "Major mode for editing C code. 280 "Major mode for editing C code.
185 Expression and list commands understand all C brackets. 281 Expression and list commands understand all C brackets.
186 Tab indents for C code. 282 Tab indents for C code.
261 (setq comment-indent-function 'c-comment-indent) 357 (setq comment-indent-function 'c-comment-indent)
262 (make-local-variable 'comment-multi-line) 358 (make-local-variable 'comment-multi-line)
263 (setq comment-multi-line t) 359 (setq comment-multi-line t)
264 (make-local-variable 'parse-sexp-ignore-comments) 360 (make-local-variable 'parse-sexp-ignore-comments)
265 (setq parse-sexp-ignore-comments t) 361 (setq parse-sexp-ignore-comments t)
362 (make-local-variable 'imenu-generic-expression)
363 (setq imenu-generic-expression c-imenu-generic-expression)
266 (run-hooks 'c-mode-hook)) 364 (run-hooks 'c-mode-hook))
267 365
268 (defun c-outline-level () 366 (defun c-outline-level ()
269 (save-excursion 367 (save-excursion
270 (skip-chars-forward "\t ") 368 (skip-chars-forward "\t ")