comparison lisp/progmodes/cc-menus.el @ 26817:03befb219d03

Installed version 5.26
author Gerd Moellmann <gerd@gnu.org>
date Sun, 12 Dec 1999 18:24:19 +0000
parents 69377a75bead
children f1a6dfd30c21
comparison
equal deleted inserted replaced
26816:e719053e967a 26817:03befb219d03
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,98 Free Software Foundation, Inc. 3 ;; Copyright (C) 1985,1987,1992-1999 Free Software Foundation, Inc.
4 4
5 ;; Authors: 1998 Barry A. Warsaw and Martin Stjernholm 5 ;; Authors: 1998-1999 Barry A. Warsaw and Martin Stjernholm
6 ;; 1992-1997 Barry A. Warsaw 6 ;; 1992-1997 Barry A. Warsaw
7 ;; 1987 Dave Detlefs and Stewart Clamen 7 ;; 1987 Dave Detlefs and Stewart Clamen
8 ;; 1985 Richard M. Stallman 8 ;; 1985 Richard M. Stallman
9 ;; Maintainer: bug-cc-mode@gnu.org 9 ;; Maintainer: bug-cc-mode@gnu.org
10 ;; Created: 22-Apr-1997 (split from cc-mode.el) 10 ;; Created: 22-Apr-1997 (split from cc-mode.el)
26 ;; You should have received a copy of the GNU General Public License 26 ;; You should have received a copy of the GNU General Public License
27 ;; along with GNU Emacs; see the file COPYING. If not, write to the 27 ;; along with GNU Emacs; see the file COPYING. If not, write to the
28 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 28 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
29 ;; Boston, MA 02111-1307, USA. 29 ;; Boston, MA 02111-1307, USA.
30 30
31 ;; Pull in Imenu when compiling, if it exists
32 (eval-when-compile 31 (eval-when-compile
32 (let ((load-path
33 (if (and (boundp 'byte-compile-current-file)
34 (stringp byte-compile-current-file))
35 (cons (file-name-directory byte-compile-current-file)
36 load-path)
37 load-path)))
38 (load "cc-defs" nil t)))
39
40 ;; Dummy definitions to shut up the compiler in case imenu doesn't exist.
41 (defvar imenu-generic-expression)
42 (defvar imenu-case-fold-search)
43 (or (fboundp 'imenu-progress-message)
44 (defun imenu-progress-message (&rest args) nil))
45
46 ;; Try to pull in imenu.
47 (eval-and-compile
33 (condition-case nil 48 (condition-case nil
34 (require 'imenu) 49 (require 'imenu)
35 (error nil))) 50 (error nil)))
36 51
37 52
50 int main _P( (int argc, char *argv[]) ) 65 int main _P( (int argc, char *argv[]) )
51 66
52 A sample value might look like: `\\(_P\\|_PROTO\\)'.") 67 A sample value might look like: `\\(_P\\|_PROTO\\)'.")
53 68
54 (defvar cc-imenu-c++-generic-expression 69 (defvar cc-imenu-c++-generic-expression
55 (` 70 `(
56 (
57 ;; Try to match ::operator definitions first. Otherwise `X::operator new ()' 71 ;; Try to match ::operator definitions first. Otherwise `X::operator new ()'
58 ;; will be incorrectly recognised as function `new ()' because the regexps 72 ;; will be incorrectly recognised as function `new ()' because the regexps
59 ;; work by backtracking from the end of the definition. 73 ;; work by backtracking from the end of the definition.
60 (nil 74 (nil
61 (, 75 ,(concat
62 (concat
63 "^\\<.*" 76 "^\\<.*"
64 "[^a-zA-Z0-9_:<>~]" ; match any non-identifier char 77 "[^a-zA-Z0-9_:<>~]" ; match any non-identifier char
65 ; (note: this can be `\n') 78 ; (note: this can be `\n')
66 "\\(" 79 "\\("
67 "\\([a-zA-Z0-9_:<>~]*::\\)?" ; match an operator 80 "\\([a-zA-Z0-9_:<>~]*::\\)?" ; match an operator
75 ; avoid prototypes. Can't 88 ; avoid prototypes. Can't
76 ; catch cases with () inside 89 ; catch cases with () inside
77 ; the parentheses surrounding 90 ; the parentheses surrounding
78 ; the parameters. e.g.: 91 ; the parameters. e.g.:
79 ; `int foo(int a=bar()) {...}' 92 ; `int foo(int a=bar()) {...}'
80 )) 1) 93 ) 1)
81 ;; Special case to match a line like `main() {}' 94 ;; Special case to match a line like `main() {}'
82 ;; e.g. no return type, not even on the previous line. 95 ;; e.g. no return type, not even on the previous line.
83 (nil 96 (nil
84 (, 97 ,(concat
85 (concat
86 "^" 98 "^"
87 "\\([a-zA-Z_][a-zA-Z0-9_:<>~]*\\)" ; match function name 99 "\\([a-zA-Z_][a-zA-Z0-9_:<>~]*\\)" ; match function name
88 "[ \t]*(" ; see above, BUT 100 "[ \t]*(" ; see above, BUT
89 "[ \t]*\\([^ \t(*][^)]*\\)?)" ; the arg list must not start 101 "[ \t]*\\([^ \t(*][^)]*\\)?)" ; the arg list must not start
90 "[ \t]*[^ \t;(]" ; with an asterisk or parentheses 102 "[ \t]*[^ \t;(]" ; with an asterisk or parentheses
91 )) 1) 103 ) 1)
92 ;; General function name regexp 104 ;; General function name regexp
93 (nil 105 (nil
94 (, 106 ,(concat
95 (concat 107 "^\\<" ; line MUST start with word char
96 "^\\<.*" ; line MUST start with word char 108 "[^()]*" ; no parentheses before
97 "[^a-zA-Z0-9_:<>~]" ; match any non-identifier char 109 "[^a-zA-Z0-9_:<>~]" ; match any non-identifier char
98 "\\([a-zA-Z_][a-zA-Z0-9_:<>~]*\\)" ; match function name 110 "\\([a-zA-Z_][a-zA-Z0-9_:<>~]*\\)" ; match function name
99 "[ \t]*(" ; see above, BUT 111 "[ \t]*(" ; see above, BUT
100 "[ \t]*\\([^ \t(*][^)]*\\)?)" ; the arg list must not start 112 "[ \t]*\\([^ \t(*][^)]*\\)?)" ; the arg list must not start
101 "[ \t]*[^ \t;(]" ; with an asterisk or parentheses 113 "[ \t]*[^ \t;(]" ; with an asterisk or parentheses
102 )) 1) 114 ) 1)
103 ;; Special case for definitions using phony prototype macros like: 115 ;; Special case for definitions using phony prototype macros like:
104 ;; `int main _PROTO( (int argc,char *argv[]) )'. 116 ;; `int main _PROTO( (int argc,char *argv[]) )'.
105 ;; This case is only included if cc-imenu-c-prototype-macro-regexp is set. 117 ;; This case is only included if cc-imenu-c-prototype-macro-regexp is set.
106 ;; Only supported in c-code, so no `:<>~' chars in function name! 118 ;; Only supported in c-code, so no `:<>~' chars in function name!
107 (,@ (if cc-imenu-c-prototype-macro-regexp 119 ,@(if cc-imenu-c-prototype-macro-regexp
108 (` ((nil 120 `((nil
109 (, 121 ,(concat
110 (concat
111 "^\\<.*" ; line MUST start with word char 122 "^\\<.*" ; line MUST start with word char
112 "[^a-zA-Z0-9_]" ; match any non-identifier char 123 "[^a-zA-Z0-9_]" ; match any non-identifier char
113 "\\([a-zA-Z_][a-zA-Z0-9_]*\\)" ; match function name 124 "\\([a-zA-Z_][a-zA-Z0-9_]*\\)" ; match function name
114 "[ \t]*" ; whitespace before macro name 125 "[ \t]*" ; whitespace before macro name
115 cc-imenu-c-prototype-macro-regexp 126 cc-imenu-c-prototype-macro-regexp
116 "[ \t]*(" ; ws followed by first paren. 127 "[ \t]*(" ; ws followed by first paren.
117 "[ \t]*([^)]*)[ \t]*)[ \t]*[^ \t;]" ; see above 128 "[ \t]*([^)]*)[ \t]*)[ \t]*[^ \t;]" ; see above
118 )) 1))))) 129 ) 1)))
119 ;; Class definitions 130 ;; Class definitions
120 ("Class" 131 ("Class"
121 (, (concat 132 ,(concat
122 "^" ; beginning of line is required 133 "^" ; beginning of line is required
123 "\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there may be a `template <...>' 134 "\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there may be a `template <...>'
124 "class[ \t]+" 135 "class[ \t]+"
125 "\\(" ; the string we want to get 136 "\\(" ; the string we want to get
126 "[a-zA-Z0-9_]+" ; class name 137 "[a-zA-Z0-9_]+" ; class name
127 "\\(<[^>]+>\\)?" ; possibly explicitely specialized 138 "\\(<[^>]+>\\)?" ; possibly explicitely specialized
128 "\\)" 139 "\\)"
129 "[ \t]*[:{]" 140 "[ \t\n]*[:{]"
130 )) 2))) 141 ) 2))
131 "Imenu generic expression for C++ mode. See `imenu-generic-expression'.") 142 "Imenu generic expression for C++ mode. See `imenu-generic-expression'.")
132 143
133 (defvar cc-imenu-c-generic-expression 144 (defvar cc-imenu-c-generic-expression
134 cc-imenu-c++-generic-expression 145 cc-imenu-c++-generic-expression
135 "Imenu generic expression for C mode. See `imenu-generic-expression'.") 146 "Imenu generic expression for C mode. See `imenu-generic-expression'.")
136 147
137 (defvar cc-imenu-java-generic-expression 148 (defvar cc-imenu-java-generic-expression
138 (` 149 `((nil
139 ((nil 150 ,(concat
140 (,
141 (concat
142 "^\\([ \t]\\)*" 151 "^\\([ \t]\\)*"
143 "\\([A-Za-z0-9_-]+[ \t]+\\)?" ; type specs; there can be 152 "\\([.A-Za-z0-9_-]+[ \t]+\\)?" ; type specs; there can be
144 "\\([A-Za-z0-9_-]+[ \t]+\\)?" ; more than 3 tokens, right? 153 "\\([.A-Za-z0-9_-]+[ \t]+\\)?" ; more than 3 tokens, right?
145 "\\([A-Za-z0-9_-]+[ \t]*[[]?[]]?\\)" 154 "\\([.A-Za-z0-9_-]+[ \t]*[[]?[]]?\\)"
146 "\\([ \t]\\)" 155 "\\([ \t]\\)"
147 "\\([A-Za-z0-9_-]+\\)" ; the string we want to get 156 "\\([A-Za-z0-9_-]+\\)" ; the string we want to get
148 "\\([ \t]*\\)+(" 157 "\\([ \t]*\\)+("
149 "[][a-zA-Z,_1-9\n \t]*" ; arguments 158 "[][a-zA-Z,_1-9\n \t]*" ; arguments
150 ")[ \t]*" 159 ")[ \t]*"
151 ; "[^;(]" 160 ; "[^;(]"
152 "[,a-zA-Z_1-9\n \t]*{" 161 "[,a-zA-Z_1-9\n \t]*{"
153 )) 6))) 162 ) 6))
154 "Imenu generic expression for Java mode. See `imenu-generic-expression'.") 163 "Imenu generic expression for Java mode. See `imenu-generic-expression'.")
155 164
156 ;; *Warning for cc-mode developers* 165 ;; *Warning for cc-mode developers*
157 ;; 166 ;;
158 ;; `cc-imenu-objc-generic-expression' elements depend on 167 ;; `cc-imenu-objc-generic-expression' elements depend on
396 405
397 ;(defvar cc-imenu-pike-generic-expression 406 ;(defvar cc-imenu-pike-generic-expression
398 ; ()) 407 ; ())
399 ; FIXME: Please contribute one! 408 ; FIXME: Please contribute one!
400 409
410 (defun cc-imenu-init (mode-generic-expression)
411 (setq imenu-generic-expression mode-generic-expression
412 imenu-case-fold-search nil))
413
401 414
402 (provide 'cc-menus) 415 (provide 'cc-menus)
403 ;;; cc-menus.el ends here 416 ;;; cc-menus.el ends here