changelog shortlog tags changeset files revisions annotate raw

cc-mode+.el

changeset 66: 5b737eefe5ea
author: kim.vanwyk
date: Wed Nov 10 15:19:03 2010 +0200 (18 months ago)
permissions: -rw-r--r--
description: Adding CSharp Mode and Google Weather
1;;; cc-mode+.el --- Extensions to `c-mode.el' & `cc-mode.el'.
2;;
3;; Filename: cc-mode+.el
4;; Description: Extensions to `c-mode.el' & `cc-mode.el'.
5;; Author: Drew Adams
6;; Maintainer: Drew Adams
7;; Copyright (C) 1999-2007, Drew Adams, all rights reserved.
8;; Created: Mon Aug 30 13:01:25 1999
9;; Version: 20.0
10;; Last-Updated: Fri May 18 13:55:29 2007 (-25200 Pacific Daylight Time)
11;; By: dradams
12;; Update #: 60
13;; URL: http://www.emacswiki.org/cgi-bin/wiki/cc-mode+.el
14;; Keywords: c, c++, programming
15;; Compatibility: GNU Emacs 20.x
16;;
17;; Features that might be required by this library:
18;;
19;; `cc-align', `cc-cmds', `cc-defs', `cc-engine', `cc-langs',
20;; `cc-menus', `cc-mode', `cc-styles', `cc-vars', `cl', `custom',
21;; `derived', `easymenu', `imenu', `imenu+', `outline', `widget'.
22;;
23;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
24;;
25;;; Commentary:
26;;
27;; Extensions to `c-mode.el' & `cc-mode.el'.
28;;
29;; This is old code, and might well be useless now.
30;;
31;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
32;;
33;;; Change log:
34;;
35;; 2007/05/18 dadams
36;; Require cl.el only at compile time, and only for Emacs < 20.
37;;
38;; RCS $Log: cc-mode+.el,v $
39;; RCS Revision 1.6 2001/01/08 22:28:26 dadams
40;; RCS Adapted file header for Emacs Lisp Archive.
41;; RCS
42;; RCS Revision 1.5 2001/01/03 17:31:35 dadams
43;; RCS *** empty log message ***
44;; RCS
45;; RCS Revision 1.4 2001/01/03 00:33:46 dadams
46;; RCS *** empty log message ***
47;; RCS
48;; RCS Revision 1.3 2001/01/02 23:26:08 dadams
49;; RCS Optional require of imenu+.el via 3rd arg=t now.
50;; RCS
51;; RCS Revision 1.2 2000/11/01 15:41:07 dadams
52;; RCS Put imenu-add-defs-to-menubar inside condition-case, in c-mode-common-hook.
53;; RCS
54;; RCS Revision 1.1 2000/09/13 20:06:14 dadams
55;; RCS Initial revision
56;; RCS
57; Revision 1.3 1999/08/30 13:15:44 dadams
58; Added: cc-imenu-c-generic-expression, cc-imenu-c++-generic-expression.
59;
60; Revision 1.2 1999/08/30 12:13:40 dadams
61; *** empty log message ***
62;
63; Revision 1.1 1999/08/30 11:53:00 dadams
64; Initial revision
65;;
66;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
67;;
68;; This program is free software; you can redistribute it and/or modify
69;; it under the terms of the GNU General Public License as published by
70;; the Free Software Foundation; either version 2, or (at your option)
71;; any later version.
72
73;; This program is distributed in the hope that it will be useful,
74;; but WITHOUT ANY WARRANTY; without even the implied warranty of
75;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
76;; GNU General Public License for more details.
77
78;; You should have received a copy of the GNU General Public License
79;; along with this program; see the file COPYING. If not, write to
80;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
81;; Floor, Boston, MA 02110-1301, USA.
82;;
83;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
84;;
85;;; Code:
86
87(eval-when-compile (when (< emacs-major-version 20)(require 'cl))) ;; cddr, when
88(require 'cc-mode)
89(require 'imenu+ nil t) ;; (no error if not found): imenu-add-defs-to-menubar
90
91;;;;;;;;;;;;;;;;;;;;;;;;;;;
92
93(add-hook 'c-mode-common-hook
94 '(lambda ()
95 (setq imenu-generic-expression
96 c-imenu-generic-expression)
97 (condition-case nil
98 (imenu-add-defs-to-menubar) ; no error if not defined
99 (error nil))))
100
101;; This is the expression for C++ mode, but it's used for C too.
102(defvar c-imenu-generic-expression
103 (`
104 ((nil
105 (,
106 (concat
107 "^" ; beginning of line is required
108 "\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there may be a "template <...>"
109 "\\([a-zA-Z0-9_:]+[ \t]+\\)?" ; type specs; there can be no
110 "\\([a-zA-Z0-9_:]+[ \t]+\\)?" ; more than 3 tokens, right?
111
112 "\\(" ; last type spec including */&
113 "[a-zA-Z0-9_:]+"
114 "\\([ \t]*[*&]+[ \t]*\\|[ \t]+\\)" ; either pointer/ref sign or whitespace
115 "\\)?" ; if there is a last type spec
116 "\\(" ; name; take that into the imenu entry
117 "[a-zA-Z0-9_:~]+" ; member function, ctor or dtor...
118 ; (may not contain * because then
119 ; "a::operator char*" would become "char*"!)
120 "\\|"
121 "\\([a-zA-Z0-9_:~]*::\\)?operator"
122 "[^a-zA-Z1-9_][^(]*" ; ...or operator
123 " \\)"
124 "[ \t]*([^)]*)[ \t\n]*[^ ;]" ; require something other than a ; after
125 ; the (...) to avoid prototypes. Can't
126 ; catch cases with () inside the parentheses
127 ; surrounding the parameters
128 ; (like "int foo(int a=bar()) {...}"
129
130 )) 6)
131 ("Class"
132 (, (concat
133 "^" ; beginning of line is required
134 "\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there may be a "template <...>"
135 "class[ \t]+"
136 "\\([a-zA-Z0-9_]+\\)" ; this is the string we want to get
137 "[ \t]*[:{]"
138 )) 2)
139 ;; For finding prototypes, structs, unions, enums.
140 ("Prototypes"
141 (,
142 (concat
143 "^" ; beginning of line is required
144 "\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there may be a "template <...>"
145 "\\([a-zA-Z0-9_:]+[ \t]+\\)?" ; type specs; there can be no
146 "\\([a-zA-Z0-9_:]+[ \t]+\\)?" ; more than 3 tokens, right?
147
148 "\\(" ; last type spec including */&
149 "[a-zA-Z0-9_:]+"
150 "\\([ \t]*[*&]+[ \t]*\\|[ \t]+\\)" ; either pointer/ref sign or whitespace
151 "\\)?" ; if there is a last type spec
152 "\\(" ; name; take that into the imenu entry
153 "[a-zA-Z0-9_:~]+" ; member function, ctor or dtor...
154 ; (may not contain * because then
155 ; "a::operator char*" would become "char*"!)
156 "\\|"
157 "\\([a-zA-Z0-9_:~]*::\\)?operator"
158 "[^a-zA-Z1-9_][^(]*" ; ...or operator
159 " \\)"
160 "[ \t]*([^)]*)[ \t\n]* ;" ; require ';' after
161 ; the (...) Can't
162 ; catch cases with () inside the parentheses
163 ; surrounding the parameters
164 ; (like "int foo(int a=bar());"
165 )) 6)
166 ("Struct"
167 (, (concat
168 "^" ; beginning of line is required
169 "\\(static[ \t]+\\)?" ; there may be static or const.
170 "\\(const[ \t]+\\)?"
171 "struct[ \t]+"
172 "\\([a-zA-Z0-9_]+\\)" ; this is the string we want to get
173 "[ \t]*[{]"
174 )) 3)
175 ("Enum"
176 (, (concat
177 "^" ; beginning of line is required
178 "\\(static[ \t]+\\)?" ; there may be static or const.
179 "\\(const[ \t]+\\)?"
180 "enum[ \t]+"
181 "\\([a-zA-Z0-9_]+\\)" ; this is the string we want to get
182 "[ \t]*[{]"
183 )) 3)
184 ("Union"
185 (, (concat
186 "^" ; beginning of line is required
187 "\\(static[ \t]+\\)?" ; there may be static or const.
188 "\\(const[ \t]+\\)?"
189 "union[ \t]+"
190 "\\([a-zA-Z0-9_]+\\)" ; this is the string we want to get
191 "[ \t]*[{]"
192 )) 3)
193 ))
194 "*Imenu generic expression for C mode. See `imenu-generic-expression'.")
195
196(defvar cc-imenu-c-generic-expression c-imenu-generic-expression
197 "*Imenu generic expression for C mode. See `imenu-generic-expression'.")
198
199(defvar cc-imenu-c++-generic-expression c-imenu-generic-expression
200 "*Imenu generic expression for C++ mode. See `imenu-generic-expression'.")
201
202
203;;;;;;;;;;;;;;;;;;;;;;;
204
205(provide 'cc-mode+)
206
207;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
208;;; cc-mode+.el ends here