]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/cc-menus.el
Many trivial doc fixes.
[gnu-emacs] / lisp / progmodes / cc-menus.el
index 832b3f8fb7c9a01fbb99c24b531ac56b73af79ba..3bdb456e05f1e04da8b58f61dd56a84daa9d8a67 100644 (file)
@@ -1,11 +1,13 @@
 ;;; cc-menus.el --- imenu support for CC Mode
 
-;; Copyright (C) 1985,87,92,93,94,95,96,97 Free Software Foundation, Inc.
+;; Copyright (C) 1985,1987,1992-2001 Free Software Foundation, Inc.
 
-;; Authors:    1992-1997 Barry A. Warsaw
+;; Authors:    2000- Martin Stjernholm
+;;            1998-1999 Barry A. Warsaw and Martin Stjernholm
+;;             1992-1997 Barry A. Warsaw
 ;;             1987 Dave Detlefs and Stewart Clamen
 ;;             1985 Richard M. Stallman
-;; Maintainer: cc-mode-help@python.org
+;; Maintainer: bug-cc-mode@gnu.org
 ;; Created:    22-Apr-1997 (split from cc-mode.el)
 ;; Version:    See cc-mode.el
 ;; Keywords:   c languages oop
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; along with GNU Emacs; see the file COPYING.  If not, write to
+;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 ;; Boston, MA 02111-1307, USA.
 
+;;; Commentary:
+
+;;; Code:
+
+(eval-when-compile
+  (let ((load-path
+        (if (and (boundp 'byte-compile-dest-file)
+                 (stringp byte-compile-dest-file))
+            (cons (file-name-directory byte-compile-dest-file) load-path)
+          load-path)))
+    (require 'cc-bytecomp)))
+
+;; Try to pull in imenu if it exists.
+(condition-case nil
+    (require 'imenu)
+  (error nil))
+
+;; The things referenced in imenu, which we don't require.
+(cc-bytecomp-defvar imenu-case-fold-search)
+(cc-bytecomp-defvar imenu-generic-expression)
+(cc-bytecomp-defun imenu-progress-message)
+
 \f
 ;; imenu integration
-(require 'imenu)
-
 (defvar cc-imenu-c-prototype-macro-regexp nil
   "RE matching macro names used to conditionally specify function prototypes.
 
@@ -47,14 +69,12 @@ For example:
 A sample value might look like: `\\(_P\\|_PROTO\\)'.")
 
 (defvar cc-imenu-c++-generic-expression
-  (` 
-   (
+  `(
     ;; Try to match ::operator definitions first. Otherwise `X::operator new ()'
     ;; will be incorrectly recognised as function `new ()' because the regexps
     ;; work by backtracking from the end of the definition.
     (nil
-     (, 
-      (concat
+     ,(concat
        "^\\<.*"
        "[^a-zA-Z0-9_:<>~]"                    ; match any non-identifier char
                                               ; (note: this can be `\n')
@@ -72,35 +92,35 @@ A sample value might look like: `\\(_P\\|_PROTO\\)'.")
                                               ; the parentheses surrounding
                                               ; the parameters.  e.g.:
                                               ; `int foo(int a=bar()) {...}'
-       )) 1)
+       ) 1)
     ;; Special case to match a line like `main() {}'
     ;; e.g. no return type, not even on the previous line.
     (nil
-     (, 
-      (concat
+     ,(concat
        "^"
        "\\([a-zA-Z_][a-zA-Z0-9_:<>~]*\\)"     ; match function name
-       "[ \t]*([^)]*)[ \t]*[^ \t;]"           ; see above
-       )) 1)
+       "[ \t]*("                             ; see above, BUT
+       "[ \t]*\\([^ \t(*][^)]*\\)?)"          ; the arg list must not start
+       "[ \t]*[^ \t;(]"                       ; with an asterisk or parentheses
+       ) 1)
     ;; General function name regexp
     (nil
-     (, 
-      (concat
-       "^\\<.*"                               ; line MUST start with word char
+     ,(concat
+       "^\\<"                                 ; line MUST start with word char
+       "[^()]*"                               ; no parentheses before
        "[^a-zA-Z0-9_:<>~]"                    ; match any non-identifier char
        "\\([a-zA-Z_][a-zA-Z0-9_:<>~]*\\)"     ; match function name
-       "[ \t]*("                             ; see above, BUT
-       "[ \t]*[^ \t(][^)]*)[ \t]*[^ \t;]"     ; the argument list must not start
-                                             ; with a parentheses
-       )) 1)
+       "\\([ \t\n]\\|\\\\\n\\)*("            ; see above, BUT the arg list
+       "\\([ \t\n]\\|\\\\\n\\)*\\([^ \t\n(*][^)]*\\)?)" ; must not start
+       "\\([ \t\n]\\|\\\\\n\\)*[^ \t\n;(]"    ; with an asterisk or parentheses
+       ) 1)
     ;; Special case for definitions using phony prototype macros like:
     ;; `int main _PROTO( (int argc,char *argv[]) )'.
     ;; This case is only included if cc-imenu-c-prototype-macro-regexp is set.
     ;; Only supported in c-code, so no `:<>~' chars in function name!
-    (,@ (if cc-imenu-c-prototype-macro-regexp
-            (` ((nil
-                 (,
-                  (concat
+    ,@(if cc-imenu-c-prototype-macro-regexp
+            `((nil
+                 ,(concat
                    "^\\<.*"                   ; line MUST start with word char
                    "[^a-zA-Z0-9_]"            ; match any non-identifier char
                    "\\([a-zA-Z_][a-zA-Z0-9_]*\\)"       ; match function name
@@ -108,16 +128,19 @@ A sample value might look like: `\\(_P\\|_PROTO\\)'.")
                    cc-imenu-c-prototype-macro-regexp
                    "[ \t]*("                  ; ws followed by first paren.
                    "[ \t]*([^)]*)[ \t]*)[ \t]*[^ \t;]" ; see above
-                   )) 1)))))
+                   ) 1)))
     ;; Class definitions
     ("Class" 
-     (, (concat 
+     ,(concat
          "^"                                  ; beginning of line is required
          "\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there may be a `template <...>'
-         "class[ \t]+"
-         "\\([a-zA-Z0-9_]+\\)"                ; the string we want to get
-         "[ \t]*[:{]"
-         )) 2)))
+         "\\(class\\|struct\\)[ \t]+"
+         "\\("                                ; the string we want to get
+         "[a-zA-Z0-9_]+"                      ; class name
+         "\\(<[^>]+>\\)?"                     ; possibly explicitly specialized
+         "\\)"
+         "\\([ \t\n]\\|\\\\\n\\)*[:{]"
+         ) 3))
   "Imenu generic expression for C++ mode.  See `imenu-generic-expression'.")
  
 (defvar cc-imenu-c-generic-expression
@@ -125,50 +148,72 @@ A sample value might look like: `\\(_P\\|_PROTO\\)'.")
   "Imenu generic expression for C mode.  See `imenu-generic-expression'.")
 
 (defvar cc-imenu-java-generic-expression
-  (`
-   ((nil
-     (,
-      (concat
+  `((nil
+     ,(concat
        "^\\([ \t]\\)*"
-       "\\([A-Za-z0-9_-]+[ \t]+\\)?"         ; type specs; there can be
-        "\\([A-Za-z0-9_-]+[ \t]+\\)?"        ; more than 3 tokens, right?
-       "\\([A-Za-z0-9_-]+[ \t]*[[]?[]]?\\)"
+       "\\([.A-Za-z0-9_-]+[ \t]+\\)?"        ; type specs; there can be
+       "\\([.A-Za-z0-9_-]+[ \t]+\\)?"        ; more than 3 tokens, right?
+       "\\([.A-Za-z0-9_-]+[ \t]*[[]?[]]?\\)"
        "\\([ \t]\\)"
        "\\([A-Za-z0-9_-]+\\)"                ; the string we want to get
        "\\([ \t]*\\)+("
-       "\\([a-zA-Z,_1-9\n \t]*[[]?[]]?\\)*"   ; arguments
+       "[][a-zA-Z,_1-9\n \t]*"               ; arguments
        ")[ \t]*"
 ;       "[^;(]"
        "[,a-zA-Z_1-9\n \t]*{"               
-       )) 6)))
+       ) 6))
   "Imenu generic expression for Java mode.  See `imenu-generic-expression'.")
 
+;;                        *Warning for cc-mode developers* 
+;;
+;; `cc-imenu-objc-generic-expression' elements depend on
+;; `cc-imenu-c++-generic-expression'. So if you change this
+;; expression, you need to change following variables,
+;; `cc-imenu-objc-generic-expression-*-index',
+;; too. `cc-imenu-objc-function' uses these *-index variables, in
+;; order to know where the each regexp *group \\(foobar\\)* elements
+;; are started.
+;;
+;; *-index variables are initialized during `cc-imenu-objc-generic-expression' 
+;; being initialized. 
+;;
+
+;; Internal variables
+(defvar cc-imenu-objc-generic-expression-noreturn-index nil)
+(defvar cc-imenu-objc-generic-expression-general-func-index nil)
+(defvar cc-imenu-objc-generic-expression-proto-index nil)
+(defvar cc-imenu-objc-generic-expression-objc-base-index nil)
+
 (defvar cc-imenu-objc-generic-expression 
   (concat 
    ;;
    ;; For C 
-   ;;                     *Warning for developers* 
-   ;; This expression elements depend on `cc-imenu-c++-generic-expression'.
    ;;
    ;; > Special case to match a line like `main() {}'
    ;; > e.g. no return type, not even on the previous line.
    ;; Pick a token by (match-string 1)
-   (car (cdr (nth 1 cc-imenu-c++-generic-expression))) ; 
+   (car (cdr (nth 1 cc-imenu-c++-generic-expression))) ; -> index += 2
+   (prog2 (setq cc-imenu-objc-generic-expression-noreturn-index 1) "")
    "\\|"
    ;; > General function name regexp
-   ;; Pick a token by  (match-string 2)
-   (car (cdr (nth 2 cc-imenu-c++-generic-expression)))
+   ;; Pick a token by  (match-string 3)
+   (car (cdr (nth 2 cc-imenu-c++-generic-expression))) ; -> index += 2
+   (prog2 (setq cc-imenu-objc-generic-expression-general-func-index 3) "")
    ;; > Special case for definitions using phony prototype macros like:
    ;; > `int main _PROTO( (int argc,char *argv[]) )'.
-   ;; Pick a token by  (match-string 3)
+   ;; Pick a token by  (match-string 5)
    (if cc-imenu-c-prototype-macro-regexp
        (concat    
        "\\|"
-       (car (cdr (nth 3 cc-imenu-c++-generic-expression))))
-     "")
+       (car (cdr (nth 3 cc-imenu-c++-generic-expression))) ; -> index += 1
+       (prog2 (setq cc-imenu-objc-generic-expression-objc-base-index 6) "")
+       )
+     (prog2 (setq cc-imenu-objc-generic-expression-objc-base-index 5) "")
+     "")                               ; -> index += 0
+   (prog2 (setq cc-imenu-objc-generic-expression-proto-index 5) "")
    ;;
    ;; For Objective-C
-   ;; Pick a token by (match-string 3 or 4)
+   ;; Pick a token by (match-string 5 or 6)
    ;;
    "\\|\\("                                         
    "^[-+][:a-zA-Z0-9()*_<>\n\t ]*[;{]"        ; Methods
@@ -252,19 +297,18 @@ Example:
   (let (methodlist
        clist
        ;;
-       ;; OBJC, C1, C2, C3 are constants.
+       ;; OBJC, Cnoreturn, Cgeneralfunc, Cproto are constants.
        ;;
        ;;                  *Warning for developers* 
        ;; These constants depend on `cc-imenu-c++-generic-expression'.
        ;;
-       (OBJC 
-        (if cc-imenu-c-prototype-macro-regexp 4 3))
-       (C1 ; > Special case to match a line like `main() {}'
-        1) 
-       (C2 ; > General function name regexp
-        2) 
-       (C3 ; > Special case for definitions using phony prototype macros like:
-        3)
+       (OBJC cc-imenu-objc-generic-expression-objc-base-index)
+       ;; Special case to match a line like `main() {}'
+       (Cnoreturn cc-imenu-objc-generic-expression-noreturn-index)
+       ;; General function name regexp
+       (Cgeneralfunc cc-imenu-objc-generic-expression-general-func-index)
+       ;; Special case for definitions using phony prototype macros like:
+       (Cproto cc-imenu-objc-generic-expression-proto-index)
        langnum
        ;;
        (classcount 0)
@@ -275,14 +319,14 @@ Example:
        (intflen (length "@interface"))
        (implen  (length "@implementation"))
        (prtlen  (length "@protocol"))
-       bufsubst-fun)
-    ;;
-    ;; Does this emacs has buffer-substring-no-properties? 
-    ;;
-    (fset 'bufsubst-fun (if (fboundp 'buffer-substring-no-properties)
-                           (symbol-function 'buffer-substring-no-properties)
-                         (symbol-function 'buffer-substring)))
-    (goto-char (point-max)) 
+       (func
+        ;;
+        ;; Does this emacs has buffer-substring-no-properties? 
+        ;;
+        (if (fboundp 'buffer-substring-no-properties)
+            'buffer-substring-no-properties
+          'buffer-substring)))
+    (goto-char (point-max))
     (imenu-progress-message stupid 0)
     ;;
     (while (re-search-backward cc-imenu-objc-generic-expression nil t)
@@ -290,10 +334,10 @@ Example:
       (setq langnum (if (match-beginning OBJC) 
                        OBJC
                      (cond
-                      ((match-beginning C3) C3)
-                      ((match-beginning C2) C2)
-                      ((match-beginning C1) C1))))
-      (setq str (bufsubst-fun (match-beginning langnum) (match-end langnum)))
+                      ((match-beginning Cproto) Cproto)
+                      ((match-beginning Cgeneralfunc) Cgeneralfunc)
+                      ((match-beginning Cnoreturn) Cnoreturn))))
+      (setq str (funcall func (match-beginning langnum) (match-end langnum)))
       ;;
       (cond 
        ;;
@@ -361,6 +405,15 @@ Example:
     toplist
     ))
 
+;(defvar cc-imenu-pike-generic-expression
+;  ())
+; FIXME: Please contribute one!
+
+(defun cc-imenu-init (mode-generic-expression)
+  (setq imenu-generic-expression mode-generic-expression
+       imenu-case-fold-search nil))
+
 \f
-(provide 'cc-menus)
+(cc-provide 'cc-menus)
+
 ;;; cc-menus.el ends here