;;; cc-menus.el --- imenu support for CC Mode
-;; Copyright (C) 1985,1987,1992-2000 Free Software Foundation, Inc.
+;; Copyright (C) 1985, 1987, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
+;; 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
+;; Free Software Foundation, Inc.
-;; Authors: 2000- Martin Stjernholm
-;; 1998-1999 Barry A. Warsaw and Martin Stjernholm
-;; 1992-1997 Barry A. Warsaw
+;; Authors: 1998- Martin Stjernholm
+;; 1992-1999 Barry A. Warsaw
;; 1987 Dave Detlefs and Stewart Clamen
;; 1985 Richard M. Stallman
;; Maintainer: bug-cc-mode@gnu.org
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
+;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; 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,
-;; Boston, MA 02111-1307, USA.
+;; along with this program; see the file COPYING. If not, write to
+;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
+
+;;; Commentary:
+
+;;; Code:
(eval-when-compile
(let ((load-path
- (if (and (boundp 'byte-compile-current-file)
- (stringp byte-compile-current-file))
- (cons (file-name-directory byte-compile-current-file)
- 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)))
- (load "cc-defs" nil t)))
+ (load "cc-bytecomp" nil t)))
-;; Dummy definitions to shut up the compiler in case imenu doesn't exist.
-(defvar imenu-generic-expression)
-(defvar imenu-case-fold-search)
-(or (fboundp 'imenu-progress-message)
- (defun imenu-progress-message (&rest args) nil))
+(cc-require 'cc-defs)
-;; Try to pull in imenu.
-(eval-and-compile
- (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-defvar imenu-create-index-function)
+(cc-bytecomp-defun imenu-progress-message)
\f
;; imenu integration
(nil
,(concat
"^\\<.*"
- "[^a-zA-Z0-9_:<>~]" ; match any non-identifier char
+ "[^" c-alnum "_:<>~]" ; match any non-identifier char
; (note: this can be `\n')
"\\("
- "\\([a-zA-Z0-9_:<>~]*::\\)?" ; match an operator
+ "\\([" c-alnum "_:<>~]*::\\)?" ; match an operator
"operator\\>[ \t]*"
"\\(()\\|[^(]*\\)" ; special case for `()' operator
"\\)"
(nil
,(concat
"^"
- "\\([a-zA-Z_][a-zA-Z0-9_:<>~]*\\)" ; match function name
+ "\\([" c-alpha "_][" c-alnum "_:<>~]*\\)" ; match function name
"[ \t]*(" ; see above, BUT
"[ \t]*\\([^ \t(*][^)]*\\)?)" ; the arg list must not start
"[ \t]*[^ \t;(]" ; with an asterisk or parentheses
(nil
,(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(*][^)]*\\)?)" ; the arg list must not start
- "[ \t]*[^ \t;(]" ; with an asterisk or parentheses
+ ;; \n added to prevent overflow in regexp matcher.
+ ;; http://lists.gnu.org/archive/html/emacs-pretest-bug/2007-02/msg00021.html
+ "[^()\n]*" ; no parentheses before
+ "[^" c-alnum "_:<>~]" ; match any non-identifier char
+ "\\([" c-alpha "_][" c-alnum "_:<>~]*\\)" ; match function name
+ "\\([ \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[]) )'.
`((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
+ "[^" c-alnum "_]" ; match any non-identifier char
+ "\\([" c-alpha "_][" c-alnum "_]*\\)" ; match function name
"[ \t]*" ; whitespace before macro name
cc-imenu-c-prototype-macro-regexp
"[ \t]*(" ; ws followed by first paren.
,(concat
"^" ; beginning of line is required
"\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there may be a `template <...>'
- "class[ \t]+"
+ "\\(class\\|struct\\)[ \t]+"
"\\(" ; the string we want to get
- "[a-zA-Z0-9_]+" ; class name
- "\\(<[^>]+>\\)?" ; possibly explicitely specialized
+ "[" c-alnum "_]+" ; class name
+ "\\(<[^>]+>\\)?" ; possibly explicitly specialized
"\\)"
- "[ \t\n]*[:{]"
- ) 2))
+ "\\([ \t\n]\\|\\\\\n\\)*[:{]"
+ ) 3))
"Imenu generic expression for C++ mode. See `imenu-generic-expression'.")
(defvar cc-imenu-c-generic-expression
(defvar cc-imenu-java-generic-expression
`((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]*[[]?[]]?\\)"
- "\\([ \t]\\)"
- "\\([A-Za-z0-9_-]+\\)" ; the string we want to get
- "\\([ \t]*\\)+("
- "[][a-zA-Z,_1-9\n \t]*" ; arguments
- ")[ \t]*"
-; "[^;(]"
- "[,a-zA-Z_1-9\n \t]*{"
- ) 6))
+ "[" c-alpha "_][\]\[." c-alnum "_]+[ \t\n\r]+" ; type spec
+ "\\([" c-alpha "_][" c-alnum "_]+\\)" ; method name
+ "[ \t\n\r]*"
+ ;; An argument list that is either empty or contains at least
+ ;; two identifiers with only space between them. This avoids
+ ;; matching e.g. "else if (foo)".
+ (concat "([ \t\n\r]*"
+ "\\([\]\[.," c-alnum "_]+"
+ "[ \t\n\r]+"
+ "[\]\[.," c-alnum "_]"
+ "[\]\[.," c-alnum "_ \t\n\r]*"
+ "\\)?)")
+ "[.," c-alnum "_ \t\n\r]*"
+ "{"
+ ) 1))
"Imenu generic expression for Java mode. See `imenu-generic-expression'.")
;; *Warning for cc-mode developers*
"\\|"
;; > General function name regexp
;; Pick a token by (match-string 3)
- (car (cdr (nth 2 cc-imenu-c++-generic-expression))) ; -> index += 2
+ (car (cdr (nth 2 cc-imenu-c++-generic-expression))) ; -> index += 5
(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 5)
+ ;; Pick a token by (match-string 8)
(if cc-imenu-c-prototype-macro-regexp
(concat
"\\|"
(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 9) "")
)
- (prog2 (setq cc-imenu-objc-generic-expression-objc-base-index 5) "")
+ (prog2 (setq cc-imenu-objc-generic-expression-objc-base-index 8) "")
"") ; -> index += 0
- (prog2 (setq cc-imenu-objc-generic-expression-proto-index 5) "")
+ (prog2 (setq cc-imenu-objc-generic-expression-proto-index 8) "")
;;
;; For Objective-C
- ;; Pick a token by (match-string 5 or 6)
+ ;; Pick a token by (match-string 8 or 9)
;;
"\\|\\("
- "^[-+][:a-zA-Z0-9()*_<>\n\t ]*[;{]" ; Methods
+ "^[-+][:" c-alnum "()*_<>\n\t ]*[;{]" ; Methods
"\\|"
- "^@interface[\t ]+[a-zA-Z0-9_]+[\t ]*:"
+ "^@interface[\t ]+[" c-alnum "_]+[\t ]*:"
"\\|"
- "^@interface[\t ]+[a-zA-Z0-9_]+[\t ]*([a-zA-Z0-9_]+)"
+ "^@interface[\t ]+[" c-alnum "_]+[\t ]*([" c-alnum "_]+)"
"\\|"
;; For NSObject, NSProxy and Object... They don't have super class.
- "^@interface[\t ]+[a-zA-Z0-9_]+[\t ]*.*$"
+ "^@interface[\t ]+[" c-alnum "_]+[\t ]*.*$"
"\\|"
- "^@implementation[\t ]+[a-zA-Z0-9_]+[\t ]*([a-zA-Z0-9_]+)"
+ "^@implementation[\t ]+[" c-alnum "_]+[\t ]*([" c-alnum "_]+)"
"\\|"
- "^@implementation[\t ]+[a-zA-Z0-9_]+"
+ "^@implementation[\t ]+[" c-alnum "_]+"
"\\|"
- "^@protocol[\t ]+[a-zA-Z0-9_]+" "\\)")
+ "^@protocol[\t ]+[" c-alnum "_]+" "\\)")
"Imenu generic expression for ObjC mode. See `imenu-generic-expression'.")
(setq last (cdr last)))
(setcdr last clist))))
;; Add C lang tokens as a sub menu
- (setq toplist (cons (cons "C" clist) toplist)))
+ (if clist
+ (setq toplist (cons (cons "C" clist) toplist))))
;;
toplist
))
; ())
; FIXME: Please contribute one!
-(defun cc-imenu-init (mode-generic-expression)
+(defun cc-imenu-init (mode-generic-expression
+ &optional mode-create-index-function)
(setq imenu-generic-expression mode-generic-expression
- imenu-case-fold-search nil))
+ imenu-case-fold-search nil)
+ (when mode-create-index-function
+ (setq imenu-create-index-function mode-create-index-function)))
\f
-(provide 'cc-menus)
+(cc-provide 'cc-menus)
+
+;;; arch-tag: f6b60933-91f0-4145-ab44-70ca6d1b919b
;;; cc-menus.el ends here