Commit | Line | Data |
---|---|---|
d3d82e7b CY |
1 | ;;; semantic.el --- Semantic buffer evaluator. |
2 | ||
3 | ;;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, | |
4 | ;;; 2007, 2008, 2009 Free Software Foundation, Inc. | |
5 | ||
6 | ;; Author: Eric M. Ludlam <zappo@gnu.org> | |
7 | ;; Keywords: syntax | |
8 | ||
9 | ;; This file is part of GNU Emacs. | |
10 | ||
11 | ;; GNU Emacs is free software: you can redistribute it and/or modify | |
12 | ;; it under the terms of the GNU General Public License as published by | |
13 | ;; the Free Software Foundation, either version 3 of the License, or | |
14 | ;; (at your option) any later version. | |
15 | ||
16 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | ;; GNU General Public License for more details. | |
20 | ||
21 | ;; You should have received a copy of the GNU General Public License | |
22 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |
23 | ||
24 | ;;; Commentary: | |
25 | ;; | |
26 | ;; API for providing the semantic content of a buffer. | |
27 | ;; | |
28 | ;; The semantic API provides an interface to a series of different parser | |
29 | ;; implementations. Each parser outputs a parse tree in a similar format | |
30 | ;; designed to handle typical functional and object oriented languages. | |
31 | ||
d3d82e7b | 32 | (require 'assoc) |
715f35a5 | 33 | (require 'cedet) |
9d389824 CY |
34 | (require 'semantic/tag) |
35 | (require 'semantic/lex) | |
d3d82e7b | 36 | |
00999a2e CY |
37 | (defvar semantic-version "2.0pre7" |
38 | "Current version of Semantic.") | |
39 | ||
d3d82e7b | 40 | (declare-function inversion-test "inversion") |
17e1f4bc | 41 | (declare-function semanticdb-load-ebrowse-caches "semantic/db-ebrowse") |
d3d82e7b CY |
42 | |
43 | (defun semantic-require-version (major minor &optional beta) | |
44 | "Non-nil if this version of semantic does not satisfy a specific version. | |
45 | Arguments can be: | |
46 | ||
47 | (MAJOR MINOR &optional BETA) | |
48 | ||
49 | Values MAJOR and MINOR must be integers. BETA can be an integer, or | |
50 | excluded if a released version is required. | |
51 | ||
52 | It is assumed that if the current version is newer than that specified, | |
53 | everything passes. Exceptions occur when known incompatibilities are | |
54 | introduced." | |
55 | (require 'inversion) | |
56 | (inversion-test 'semantic | |
57 | (concat major "." minor | |
58 | (when beta (concat "beta" beta))))) | |
59 | ||
60 | (defgroup semantic nil | |
61 | "Parser Generator and parser framework." | |
62 | :group 'lisp) | |
63 | ||
64 | (defgroup semantic-faces nil | |
65 | "Faces used for Semantic enabled tools." | |
66 | :group 'semantic) | |
67 | ||
9d389824 | 68 | (require 'semantic/fw) |
d3d82e7b CY |
69 | |
70 | ;;; Code: | |
71 | ;; | |
72 | ||
73 | ;;; Variables and Configuration | |
74 | ;; | |
75 | (defvar semantic--parse-table nil | |
76 | "Variable that defines how to parse top level items in a buffer. | |
77 | This variable is for internal use only, and its content depends on the | |
78 | external parser used.") | |
79 | (make-variable-buffer-local 'semantic--parse-table) | |
80 | (semantic-varalias-obsolete 'semantic-toplevel-bovine-table | |
81 | 'semantic--parse-table) | |
82 | ||
83 | (defvar semantic-symbol->name-assoc-list | |
84 | '((type . "Types") | |
85 | (variable . "Variables") | |
86 | (function . "Functions") | |
87 | (include . "Dependencies") | |
88 | (package . "Provides")) | |
89 | "Association between symbols returned, and a string. | |
90 | The string is used to represent a group of objects of the given type. | |
91 | It is sometimes useful for a language to use a different string | |
92 | in place of the default, even though that language will still | |
93 | return a symbol. For example, Java return's includes, but the | |
94 | string can be replaced with `Imports'.") | |
95 | (make-variable-buffer-local 'semantic-symbol->name-assoc-list) | |
96 | ||
97 | (defvar semantic-symbol->name-assoc-list-for-type-parts nil | |
98 | "Like `semantic-symbol->name-assoc-list' for type parts. | |
99 | Some tags that have children (see `semantic-tag-children-compatibility') | |
100 | will want to define the names of classes of tags differently than at | |
101 | the top level. For example, in C++, a Function may be called a | |
102 | Method. In addition, there may be new types of tags that exist only | |
103 | in classes, such as protection labels.") | |
104 | (make-variable-buffer-local 'semantic-symbol->name-assoc-list-for-type-parts) | |
105 | ||
106 | (defvar semantic-case-fold nil | |
107 | "Value for `case-fold-search' when parsing.") | |
108 | (make-variable-buffer-local 'semantic-case-fold) | |
109 | ||
110 | (defvar semantic-expand-nonterminal nil | |
111 | "Function to call for each nonterminal production. | |
112 | Return a list of non-terminals derived from the first argument, or nil | |
113 | if it does not need to be expanded. | |
114 | Languages with compound definitions should use this function to expand | |
115 | from one compound symbol into several. For example, in C the definition | |
116 | int a, b; | |
117 | is easily parsed into one tag. This function should take this | |
118 | compound tag and turn it into two tags, one for A, and the other for B.") | |
119 | (make-variable-buffer-local 'semantic-expand-nonterminal) | |
120 | ||
121 | (defvar semantic--buffer-cache nil | |
122 | "A cache of the fully parsed buffer. | |
123 | If no significant changes have been made (based on the state) then | |
124 | this is returned instead of re-parsing the buffer. | |
125 | ||
126 | DO NOT USE THIS VARIABLE IN PROGRAMS. | |
127 | ||
128 | If you need a tag list, use `semantic-fetch-tags'. If you need the | |
129 | cached values for some reason, chances are you can, add a hook to | |
130 | `semantic-after-toplevel-cache-change-hook'.") | |
131 | (make-variable-buffer-local 'semantic--buffer-cache) | |
132 | (semantic-varalias-obsolete 'semantic-toplevel-bovine-cache | |
133 | 'semantic--buffer-cache) | |
134 | ||
135 | (defvar semantic-unmatched-syntax-cache nil | |
136 | "A cached copy of unmatched syntax tokens.") | |
137 | (make-variable-buffer-local 'semantic-unmatched-syntax-cache) | |
138 | ||
139 | (defvar semantic-unmatched-syntax-cache-check nil | |
140 | "Non nil if the unmatched syntax cache is out of date. | |
141 | This is tracked with `semantic-change-function'.") | |
142 | (make-variable-buffer-local 'semantic-unmatched-syntax-cache-check) | |
143 | ||
144 | (defvar semantic-edits-are-safe nil | |
145 | "When non-nil, modifications do not require a reparse. | |
146 | This prevents tags from being marked dirty, and it prevents top level | |
147 | edits from causing a cache check. | |
148 | Use this when writing programs that could cause a full reparse, but | |
149 | will not change the tag structure, such as adding or updating | |
150 | `top-level' comments.") | |
151 | ||
152 | (defvar semantic-unmatched-syntax-hook nil | |
153 | "Hooks run when semantic detects syntax not matched in a grammar. | |
154 | Each individual piece of syntax (such as a symbol or punctuation | |
155 | character) is called with this hook when it doesn't match in the | |
156 | grammar, and multiple unmatched syntax elements are not grouped | |
157 | together. Each hook is called with one argument, which is a list of | |
158 | syntax tokens created by the semantic lexer. Use the functions | |
159 | `semantic-lex-token-start', `semantic-lex-token-end' and | |
160 | `semantic-lex-token-text' to get information about these tokens. The | |
161 | current buffer is the buffer these tokens are derived from.") | |
162 | ||
163 | (defvar semantic--before-fetch-tags-hook nil | |
164 | "Hooks run before a buffer is parses for tags. | |
165 | It is called before any request for tags is made via the function | |
166 | `semantic-fetch-tags' by an application. | |
167 | If any hook returns a nil value, the cached value is returned | |
168 | immediately, even if it is empty.") | |
169 | (semantic-varalias-obsolete 'semantic-before-toplevel-bovination-hook | |
170 | 'semantic--before-fetch-tags-hook) | |
171 | ||
172 | (defvar semantic-after-toplevel-bovinate-hook nil | |
173 | "Hooks run after a toplevel parse. | |
174 | It is not run if the toplevel parse command is called, and buffer does | |
175 | not need to be fully reparsed. | |
176 | For language specific hooks, make sure you define this as a local hook. | |
177 | ||
178 | This hook should not be used any more. | |
179 | Use `semantic-after-toplevel-cache-change-hook' instead.") | |
180 | (make-obsolete-variable 'semantic-after-toplevel-bovinate-hook nil) | |
181 | ||
182 | (defvar semantic-after-toplevel-cache-change-hook nil | |
183 | "Hooks run after the buffer tag list has changed. | |
184 | This list will change when a buffer is reparsed, or when the tag list | |
185 | in a buffer is cleared. It is *NOT* called if the current tag list is | |
186 | partially reparsed. | |
187 | ||
188 | Hook functions must take one argument, which is the new list of tags | |
189 | associated with this buffer. | |
190 | ||
191 | For language specific hooks, make sure you define this as a local hook.") | |
192 | ||
193 | (defvar semantic-before-toplevel-cache-flush-hook nil | |
194 | "Hooks run before the toplevel tag cache is flushed. | |
195 | For language specific hooks, make sure you define this as a local | |
196 | hook. This hook is called before a corresponding | |
197 | `semantic-after-toplevel-cache-change-hook' which is also called | |
198 | during a flush when the cache is given a new value of nil.") | |
199 | ||
200 | (defcustom semantic-dump-parse nil | |
201 | "When non-nil, dump parsing information." | |
202 | :group 'semantic | |
203 | :type 'boolean) | |
204 | ||
205 | (defvar semantic-parser-name "LL" | |
206 | "Optional name of the parser used to parse input stream.") | |
207 | (make-variable-buffer-local 'semantic-parser-name) | |
8bf997ef CY |
208 | |
209 | (defvar semantic--completion-cache nil | |
210 | "Internal variable used by `semantic-complete-symbol'.") | |
211 | (make-variable-buffer-local 'semantic--completion-cache) | |
d3d82e7b CY |
212 | \f |
213 | ;;; Parse tree state management API | |
214 | ;; | |
215 | (defvar semantic-parse-tree-state 'needs-rebuild | |
216 | "State of the current parse tree.") | |
217 | (make-variable-buffer-local 'semantic-parse-tree-state) | |
218 | ||
219 | (defmacro semantic-parse-tree-unparseable () | |
220 | "Indicate that the current buffer is unparseable. | |
221 | It is also true that the parse tree will need either updating or | |
222 | a rebuild. This state will be changed when the user edits the buffer." | |
223 | `(setq semantic-parse-tree-state 'unparseable)) | |
224 | ||
225 | (defmacro semantic-parse-tree-unparseable-p () | |
226 | "Return non-nil if the current buffer has been marked unparseable." | |
227 | `(eq semantic-parse-tree-state 'unparseable)) | |
228 | ||
229 | (defmacro semantic-parse-tree-set-needs-update () | |
230 | "Indicate that the current parse tree needs to be updated. | |
231 | The parse tree can be updated by `semantic-parse-changes'." | |
232 | `(setq semantic-parse-tree-state 'needs-update)) | |
233 | ||
234 | (defmacro semantic-parse-tree-needs-update-p () | |
235 | "Return non-nil if the current parse tree needs to be updated." | |
236 | `(eq semantic-parse-tree-state 'needs-update)) | |
237 | ||
238 | (defmacro semantic-parse-tree-set-needs-rebuild () | |
239 | "Indicate that the current parse tree needs to be rebuilt. | |
240 | The parse tree must be rebuilt by `semantic-parse-region'." | |
241 | `(setq semantic-parse-tree-state 'needs-rebuild)) | |
242 | ||
243 | (defmacro semantic-parse-tree-needs-rebuild-p () | |
244 | "Return non-nil if the current parse tree needs to be rebuilt." | |
245 | `(eq semantic-parse-tree-state 'needs-rebuild)) | |
246 | ||
247 | (defmacro semantic-parse-tree-set-up-to-date () | |
248 | "Indicate that the current parse tree is up to date." | |
249 | `(setq semantic-parse-tree-state nil)) | |
250 | ||
251 | (defmacro semantic-parse-tree-up-to-date-p () | |
252 | "Return non-nil if the current parse tree is up to date." | |
253 | `(null semantic-parse-tree-state)) | |
254 | ||
255 | ;;; Interfacing with the system | |
256 | ;; | |
257 | (defcustom semantic-inhibit-functions nil | |
258 | "List of functions to call with no arguments before Semantic is setup. | |
259 | If any of these functions returns non-nil, the current buffer is not | |
260 | setup to use Semantic." | |
261 | :group 'semantic | |
262 | :type 'hook) | |
263 | ||
b82525f2 CY |
264 | (defvar semantic-init-hook nil |
265 | "Hook run when a buffer is initialized with a parsing table.") | |
d3d82e7b | 266 | |
b82525f2 CY |
267 | (defvar semantic-init-mode-hook nil |
268 | "Hook run when a buffer of a particular mode is initialized.") | |
269 | (make-variable-buffer-local 'semantic-init-mode-hook) | |
d3d82e7b | 270 | |
b82525f2 CY |
271 | (defvar semantic-init-db-hook nil |
272 | "Hook run when a buffer is initialized with a parsing table for DBs. | |
d3d82e7b CY |
273 | This hook is for database functions which intend to swap in a tag table. |
274 | This guarantees that the DB will go before other modes that require | |
275 | a parse of the buffer.") | |
276 | ||
1ac9ebc8 CY |
277 | (semantic-varalias-obsolete 'semantic-init-hooks |
278 | 'semantic-init-hook) | |
279 | (semantic-varalias-obsolete 'semantic-init-mode-hooks | |
280 | 'semantic-init-mode-hook) | |
281 | (semantic-varalias-obsolete 'semantic-init-db-hooks | |
282 | 'semantic-init-db-hook) | |
b82525f2 | 283 | |
d3d82e7b CY |
284 | (defvar semantic-new-buffer-fcn-was-run nil |
285 | "Non nil after `semantic-new-buffer-fcn' has been executed.") | |
286 | (make-variable-buffer-local 'semantic-new-buffer-fcn-was-run) | |
287 | ||
288 | (defsubst semantic-active-p () | |
289 | "Return non-nil if the current buffer was set up for parsing." | |
290 | semantic-new-buffer-fcn-was-run) | |
291 | ||
292 | (defsubst semantic--umatched-syntax-needs-refresh-p () | |
293 | "Return non-nil if the unmatched syntax cache needs a refresh. | |
294 | That is if it is dirty or if the current parse tree isn't up to date." | |
295 | (or semantic-unmatched-syntax-cache-check | |
296 | (not (semantic-parse-tree-up-to-date-p)))) | |
297 | ||
298 | (defun semantic-new-buffer-fcn () | |
299 | "Setup the current buffer to use Semantic. | |
300 | If the major mode is ready for Semantic, and no | |
301 | `semantic-inhibit-functions' disabled it, the current buffer is setup | |
302 | to use Semantic, and `semantic-init-hook' is run." | |
303 | ;; Do stuff if semantic was activated by a mode hook in this buffer, | |
304 | ;; and not afterwards disabled. | |
305 | (when (and semantic--parse-table | |
306 | (not (semantic-active-p)) | |
307 | (not (run-hook-with-args-until-success | |
308 | 'semantic-inhibit-functions))) | |
309 | ;; Make sure that if this buffer is cloned, our tags and overlays | |
310 | ;; don't go along for the ride. | |
311 | (add-hook 'clone-indirect-buffer-hook 'semantic-clear-toplevel-cache | |
312 | nil t) | |
313 | ;; Specify that this function has done it's work. At this point | |
314 | ;; we can consider that semantic is active in this buffer. | |
315 | (setq semantic-new-buffer-fcn-was-run t) | |
316 | ;; Here are some buffer local variables we can initialize ourselves | |
317 | ;; of a mode does not choose to do so. | |
318 | (semantic-lex-init) | |
319 | ;; Force this buffer to have its cache refreshed. | |
320 | (semantic-clear-toplevel-cache) | |
321 | ;; Call DB hooks before regular init hooks | |
b82525f2 | 322 | (run-hooks 'semantic-init-db-hook) |
d3d82e7b | 323 | ;; Set up semantic modes |
b82525f2 | 324 | (run-hooks 'semantic-init-hook) |
d3d82e7b | 325 | ;; Set up major-mode specific semantic modes |
b82525f2 | 326 | (run-hooks 'semantic-init-mode-hook))) |
d3d82e7b CY |
327 | |
328 | (defun semantic-fetch-tags-fast () | |
329 | "For use in a hook. When only a partial reparse is needed, reparse." | |
330 | (condition-case nil | |
331 | (if (semantic-parse-tree-needs-update-p) | |
332 | (semantic-fetch-tags)) | |
333 | (error nil)) | |
334 | semantic--buffer-cache) | |
d3d82e7b CY |
335 | \f |
336 | ;;; Parsing Commands | |
337 | ;; | |
338 | (eval-when-compile | |
339 | (condition-case nil (require 'pp) (error nil))) | |
340 | ||
341 | (defvar semantic-edebug nil | |
342 | "When non-nil, activate the interactive parsing debugger. | |
343 | Do not set this yourself. Call `semantic-debug'.") | |
344 | ||
345 | (defun semantic-elapsed-time (start end) | |
346 | "Copied from elp.el. Was elp-elapsed-time. | |
347 | Argument START and END bound the time being calculated." | |
348 | (+ (* (- (car end) (car start)) 65536.0) | |
349 | (- (car (cdr end)) (car (cdr start))) | |
350 | (/ (- (car (cdr (cdr end))) (car (cdr (cdr start)))) 1000000.0))) | |
351 | ||
352 | (defun bovinate (&optional clear) | |
353 | "Parse the current buffer. Show output in a temp buffer. | |
354 | Optional argument CLEAR will clear the cache before parsing. | |
355 | If CLEAR is negative, it will do a full reparse, and also not display | |
356 | the output buffer." | |
357 | (interactive "P") | |
358 | (if clear (semantic-clear-toplevel-cache)) | |
359 | (if (eq clear '-) (setq clear -1)) | |
360 | (let* ((start (current-time)) | |
361 | (out (semantic-fetch-tags)) | |
362 | (end (current-time))) | |
363 | (message "Retrieving tags took %.2f seconds." | |
364 | (semantic-elapsed-time start end)) | |
365 | (when (or (null clear) (not (listp clear))) | |
366 | (pop-to-buffer "*Parser Output*") | |
367 | (require 'pp) | |
368 | (erase-buffer) | |
369 | (insert (pp-to-string out)) | |
370 | (goto-char (point-min))))) | |
371 | \f | |
372 | ;;; Functions of the parser plug-in API | |
373 | ;; | |
374 | ;; Overload these functions to create new types of parsers. | |
375 | ;; | |
376 | (define-overloadable-function semantic-parse-stream (stream nonterminal) | |
377 | "Parse STREAM, starting at the first NONTERMINAL rule. | |
378 | For bovine and wisent based parsers, STREAM is from the output of | |
379 | `semantic-lex', and NONTERMINAL is a rule in the apropriate language | |
380 | specific rules file. | |
381 | The default parser table used for bovine or wisent based parsers is | |
382 | `semantic--parse-table'. | |
383 | ||
384 | Must return a list: (STREAM TAGS) where STREAM is the unused elements | |
385 | from STREAM, and TAGS is the list of semantic tags found, usually only | |
386 | one tag is returned with the exception of compound statements") | |
387 | ||
388 | (define-overloadable-function semantic-parse-changes () | |
389 | "Reparse changes in the current buffer. | |
390 | The list of changes are tracked as a series of overlays in the buffer. | |
391 | When overloading this function, use `semantic-changes-in-region' to | |
392 | analyze.") | |
393 | ||
394 | (define-overloadable-function semantic-parse-region | |
395 | (start end &optional nonterminal depth returnonerror) | |
396 | "Parse the area between START and END, and return any tags found. | |
397 | If END needs to be extended due to a lexical token being too large, it | |
398 | will be silently ignored. | |
399 | ||
400 | Optional arguments: | |
401 | NONTERMINAL is the rule to start parsing at. | |
402 | DEPTH specifies the lexical depth to decend for parser that use | |
403 | lexical analysis as their first step. | |
404 | RETURNONERROR specifies that parsing should stop on the first | |
405 | unmatched syntax encountered. When nil, parsing skips the syntax, | |
406 | adding it to the unmatched syntax cache. | |
407 | ||
408 | Must return a list of semantic tags wich have been cooked | |
409 | \(repositioned properly) but which DO NOT HAVE OVERLAYS associated | |
410 | with them. When overloading this function, use `semantic--tag-expand' | |
411 | to cook raw tags.") | |
412 | ||
413 | (defun semantic-parse-region-default | |
414 | (start end &optional nonterminal depth returnonerror) | |
415 | "Parse the area between START and END, and return any tags found. | |
416 | If END needs to be extended due to a lexical token being too large, it | |
417 | will be silently ignored. | |
418 | Optional arguments: | |
419 | NONTERMINAL is the rule to start parsing at if it is known. | |
420 | DEPTH specifies the lexical depth to scan. | |
421 | RETURNONERROR specifies that parsing should end when encountering | |
422 | unterminated syntax." | |
423 | (when (or (null semantic--parse-table) (eq semantic--parse-table t)) | |
424 | ;; If there is no table, or it was set to t, then we are here by | |
425 | ;; some other mistake. Do not throw an error deep in the parser. | |
426 | (error "No support found to parse buffer %S" (buffer-name))) | |
427 | (save-restriction | |
428 | (widen) | |
429 | (when (or (< end start) (> end (point-max))) | |
430 | (error "Invalid parse region bounds %S, %S" start end)) | |
431 | (nreverse | |
432 | (semantic-repeat-parse-whole-stream | |
433 | (or (cdr (assq start semantic-lex-block-streams)) | |
434 | (semantic-lex start end depth)) | |
435 | nonterminal returnonerror)))) | |
436 | \f | |
437 | ;;; Parsing functions | |
438 | ;; | |
439 | (defun semantic-set-unmatched-syntax-cache (unmatched-syntax) | |
440 | "Set the unmatched syntax cache. | |
441 | Argument UNMATCHED-SYNTAX is the syntax to set into the cache." | |
442 | ;; This function is not actually called by the main parse loop. | |
443 | ;; This is intended for use by semanticdb. | |
444 | (setq semantic-unmatched-syntax-cache unmatched-syntax | |
445 | semantic-unmatched-syntax-cache-check nil) | |
446 | ;; Refresh the display of unmatched syntax tokens if enabled | |
447 | (run-hook-with-args 'semantic-unmatched-syntax-hook | |
448 | semantic-unmatched-syntax-cache)) | |
449 | ||
450 | (defun semantic-clear-unmatched-syntax-cache () | |
451 | "Clear the cache of unmatched syntax tokens." | |
452 | (setq semantic-unmatched-syntax-cache nil | |
453 | semantic-unmatched-syntax-cache-check t)) | |
454 | ||
455 | (defun semantic-unmatched-syntax-tokens () | |
456 | "Return the list of unmatched syntax tokens." | |
457 | ;; If the cache need refresh then do a full re-parse. | |
458 | (if (semantic--umatched-syntax-needs-refresh-p) | |
459 | ;; To avoid a recursive call, temporarily disable | |
460 | ;; `semantic-unmatched-syntax-hook'. | |
461 | (let (semantic-unmatched-syntax-hook) | |
462 | (condition-case nil | |
463 | (progn | |
464 | (semantic-clear-toplevel-cache) | |
465 | (semantic-fetch-tags)) | |
466 | (quit | |
467 | (message "semantic-unmatched-syntax-tokens:\ | |
468 | parsing of buffer canceled")) | |
469 | ))) | |
470 | semantic-unmatched-syntax-cache) | |
471 | ||
472 | (defun semantic-clear-toplevel-cache () | |
473 | "Clear the toplevel tag cache for the current buffer. | |
474 | Clearing the cache will force a complete reparse next time a tag list | |
475 | is requested." | |
476 | (interactive) | |
477 | (run-hooks 'semantic-before-toplevel-cache-flush-hook) | |
478 | (setq semantic--buffer-cache nil) | |
479 | (semantic-clear-unmatched-syntax-cache) | |
480 | (semantic-clear-parser-warnings) | |
481 | ;; Nuke all semantic overlays. This is faster than deleting based | |
482 | ;; on our data structure. | |
483 | (let ((l (semantic-overlay-lists))) | |
484 | (mapc 'semantic-delete-overlay-maybe (car l)) | |
485 | (mapc 'semantic-delete-overlay-maybe (cdr l)) | |
486 | ) | |
487 | (semantic-parse-tree-set-needs-rebuild) | |
488 | ;; Remove this hook which tracks if a buffer is up to date or not. | |
489 | (remove-hook 'after-change-functions 'semantic-change-function t) | |
490 | ;; Old model. Delete someday. | |
491 | ;;(run-hooks 'semantic-after-toplevel-bovinate-hook) | |
492 | ||
493 | (run-hook-with-args 'semantic-after-toplevel-cache-change-hook | |
494 | semantic--buffer-cache) | |
8bf997ef CY |
495 | |
496 | (setq semantic--completion-cache nil)) | |
d3d82e7b CY |
497 | |
498 | (defvar semantic-bovinate-nonterminal-check-obarray) | |
499 | ||
500 | (defun semantic--set-buffer-cache (tagtable) | |
501 | "Set the toplevel cache cache to TAGTABLE." | |
502 | (setq semantic--buffer-cache tagtable | |
06511291 CY |
503 | semantic-unmatched-syntax-cache-check nil) |
504 | ;; This is specific to the bovine parser. | |
505 | (set (make-local-variable 'semantic-bovinate-nonterminal-check-obarray) | |
506 | nil) | |
d3d82e7b CY |
507 | (semantic-parse-tree-set-up-to-date) |
508 | (semantic-make-local-hook 'after-change-functions) | |
509 | (add-hook 'after-change-functions 'semantic-change-function nil t) | |
510 | (run-hook-with-args 'semantic-after-toplevel-cache-change-hook | |
511 | semantic--buffer-cache) | |
8bf997ef | 512 | (setq semantic--completion-cache nil) |
d3d82e7b CY |
513 | ;; Refresh the display of unmatched syntax tokens if enabled |
514 | (run-hook-with-args 'semantic-unmatched-syntax-hook | |
515 | semantic-unmatched-syntax-cache) | |
516 | ;; Old Semantic 1.3 hook API. Maybe useful forever? | |
517 | (run-hooks 'semantic-after-toplevel-bovinate-hook) | |
518 | ) | |
519 | ||
520 | (defvar semantic-working-type 'percent | |
521 | "*The type of working message to use when parsing. | |
522 | 'percent means we are doing a linear parse through the buffer. | |
523 | 'dynamic means we are reparsing specific tags.") | |
524 | (semantic-varalias-obsolete 'semantic-bovination-working-type | |
525 | 'semantic-working-type) | |
526 | ||
527 | (defvar semantic-minimum-working-buffer-size (* 1024 5) | |
528 | "*The minimum size of a buffer before working messages are displayed. | |
529 | Buffers smaller than will parse silently. | |
530 | Bufferse larger than this will display the working progress bar.") | |
531 | ||
532 | (defsubst semantic-parser-working-message (&optional arg) | |
533 | "Return the message string displayed while parsing. | |
534 | If optional argument ARG is non-nil it is appended to the message | |
535 | string." | |
17e1f4bc CY |
536 | (concat "Parsing" |
537 | (if arg (format " %s" arg)) | |
538 | (if semantic-parser-name (format " (%s)" semantic-parser-name)) | |
539 | "...")) | |
d3d82e7b CY |
540 | \f |
541 | ;;; Application Parser Entry Points | |
542 | ;; | |
543 | ;; The best way to call the parser from programs is via | |
544 | ;; `semantic-fetch-tags'. This, in turn, uses other internal | |
545 | ;; API functions which plug-in parsers can take advantage of. | |
546 | ||
547 | (defun semantic-fetch-tags () | |
548 | "Fetch semantic tags from the current buffer. | |
549 | If the buffer cache is up to date, return that. | |
550 | If the buffer cache is out of date, attempt an incremental reparse. | |
551 | If the buffer has not been parsed before, or if the incremental reparse | |
552 | fails, then parse the entire buffer. | |
553 | If a lexcial error had been previously discovered and the buffer | |
554 | was marked unparseable, then do nothing, and return the cache." | |
555 | (and | |
556 | ;; Is this a semantic enabled buffer? | |
557 | (semantic-active-p) | |
558 | ;; Application hooks say the buffer is safe for parsing | |
559 | (run-hook-with-args-until-failure | |
560 | 'semantic-before-toplevel-bovination-hook) | |
561 | (run-hook-with-args-until-failure | |
562 | 'semantic--before-fetch-tags-hook) | |
563 | ;; If the buffer was previously marked unparseable, | |
564 | ;; then don't waste our time. | |
565 | (not (semantic-parse-tree-unparseable-p)) | |
566 | ;; The parse tree actually needs to be refreshed | |
567 | (not (semantic-parse-tree-up-to-date-p)) | |
568 | ;; So do it! | |
569 | (let* ((gc-cons-threshold (max gc-cons-threshold 10000000)) | |
570 | (semantic-lex-block-streams nil) | |
571 | (res nil)) | |
572 | (garbage-collect) | |
573 | (cond | |
574 | ||
575 | ;;;; Try the incremental parser to do a fast update. | |
576 | ((semantic-parse-tree-needs-update-p) | |
577 | (setq res (semantic-parse-changes)) | |
578 | (if (semantic-parse-tree-needs-rebuild-p) | |
579 | ;; If the partial reparse fails, jump to a full reparse. | |
580 | (semantic-fetch-tags) | |
581 | ;; Clear the cache of unmatched syntax tokens | |
582 | ;; | |
583 | ;; NOTE TO SELF: | |
584 | ;; | |
585 | ;; Move this into the incremental parser. This is a bug. | |
586 | ;; | |
587 | (semantic-clear-unmatched-syntax-cache) | |
588 | (run-hook-with-args ;; Let hooks know the updated tags | |
589 | 'semantic-after-partial-cache-change-hook res)) | |
8bf997ef | 590 | (setq semantic--completion-cache nil)) |
d3d82e7b CY |
591 | |
592 | ;;;; Parse the whole system. | |
593 | ((semantic-parse-tree-needs-rebuild-p) | |
d3d82e7b CY |
594 | ;; Use Emacs' built-in progress-reporter |
595 | (let ((semantic--progress-reporter | |
596 | (and (>= (point-max) semantic-minimum-working-buffer-size) | |
597 | (eq semantic-working-type 'percent) | |
598 | (make-progress-reporter | |
599 | (semantic-parser-working-message (buffer-name)) | |
600 | 0 100)))) | |
601 | (setq res (semantic-parse-region (point-min) (point-max))) | |
59aec83e CY |
602 | (if semantic--progress-reporter |
603 | (progress-reporter-done semantic--progress-reporter))) | |
d3d82e7b CY |
604 | |
605 | ;; Clear the caches when we see there were no errors. | |
606 | ;; But preserve the unmatched syntax cache and warnings! | |
607 | (let (semantic-unmatched-syntax-cache | |
608 | semantic-unmatched-syntax-cache-check | |
609 | semantic-parser-warnings) | |
610 | (semantic-clear-toplevel-cache)) | |
611 | ;; Set up the new overlays | |
612 | (semantic--tag-link-list-to-buffer res) | |
613 | ;; Set up the cache with the new results | |
614 | (semantic--set-buffer-cache res) | |
615 | )))) | |
616 | ||
617 | ;; Always return the current parse tree. | |
618 | semantic--buffer-cache) | |
619 | ||
620 | (defun semantic-refresh-tags-safe () | |
621 | "Refreshes the current buffer's tags safely. | |
622 | ||
623 | Return non-nil if the refresh was successful. | |
624 | Return nil if there is some sort of syntax error preventing a reparse. | |
625 | ||
626 | Does nothing if the current buffer doesn't need reparsing." | |
627 | ||
628 | ;; These checks actually occur in `semantic-fetch-tags', but if we | |
629 | ;; do them here, then all the bovination hooks are not run, and | |
630 | ;; we save lots of time. | |
631 | (cond | |
632 | ;; If the buffer was previously marked unparseable, | |
633 | ;; then don't waste our time. | |
634 | ((semantic-parse-tree-unparseable-p) | |
635 | nil) | |
636 | ;; The parse tree is already ok. | |
637 | ((semantic-parse-tree-up-to-date-p) | |
638 | t) | |
639 | (t | |
640 | (let* ((inhibit-quit nil) | |
641 | (lexically-safe t) | |
642 | ) | |
643 | ||
644 | (unwind-protect | |
645 | ;; Perform the parsing. | |
646 | (progn | |
647 | (when (semantic-lex-catch-errors safe-refresh | |
648 | (save-excursion (semantic-fetch-tags)) | |
649 | nil) | |
650 | ;; If we are here, it is because the lexical step failed, | |
651 | ;; proably due to unterminated lists or something like that. | |
652 | ||
653 | ;; We do nothing, and just wait for the next idle timer | |
654 | ;; to go off. In the meantime, remember this, and make sure | |
655 | ;; no other idle services can get executed. | |
656 | (setq lexically-safe nil)) | |
657 | ) | |
658 | ) | |
659 | ;; Return if we are lexically safe | |
660 | lexically-safe)))) | |
661 | ||
662 | (defun semantic-bovinate-toplevel (&optional ignored) | |
663 | "Backward Compatibility Function." | |
664 | (semantic-fetch-tags)) | |
665 | (make-obsolete 'semantic-bovinate-toplevel 'semantic-fetch-tags) | |
666 | ||
667 | ;; Another approach is to let Emacs call the parser on idle time, when | |
668 | ;; needed, use `semantic-fetch-available-tags' to only retrieve | |
669 | ;; available tags, and setup the `semantic-after-*-hook' hooks to | |
670 | ;; synchronize with new tags when they become available. | |
671 | ||
672 | (defsubst semantic-fetch-available-tags () | |
673 | "Fetch available semantic tags from the current buffer. | |
674 | That is, return tags currently in the cache without parsing the | |
675 | current buffer. | |
676 | Parse operations happen asynchronously when needed on Emacs idle time. | |
677 | Use the `semantic-after-toplevel-cache-change-hook' and | |
678 | `semantic-after-partial-cache-change-hook' hooks to synchronize with | |
679 | new tags when they become available." | |
680 | semantic--buffer-cache) | |
681 | \f | |
682 | ;;; Iterative parser helper function | |
683 | ;; | |
684 | ;; Iterative parsers are better than rule-based iterative functions | |
685 | ;; in that they can handle obscure errors more cleanly. | |
686 | ;; | |
687 | ;; `semantic-repeat-parse-whole-stream' abstracts this action for | |
688 | ;; other parser centric routines. | |
689 | ;; | |
690 | (defun semantic-repeat-parse-whole-stream | |
691 | (stream nonterm &optional returnonerror) | |
692 | "Iteratively parse the entire stream STREAM starting with NONTERM. | |
693 | Optional argument RETURNONERROR indicates that the parser should exit | |
694 | with the current results on a parse error. | |
695 | This function returns semantic tags without overlays." | |
696 | (let ((result nil) | |
697 | (case-fold-search semantic-case-fold) | |
698 | nontermsym tag) | |
699 | (while stream | |
700 | (setq nontermsym (semantic-parse-stream stream nonterm) | |
701 | tag (car (cdr nontermsym))) | |
702 | (if (not nontermsym) | |
703 | (error "Parse error @ %d" (car (cdr (car stream))))) | |
704 | (if (eq (car nontermsym) stream) | |
705 | (error "Parser error: Infinite loop?")) | |
706 | (if tag | |
707 | (if (car tag) | |
708 | (setq tag (mapcar | |
709 | #'(lambda (tag) | |
710 | ;; Set the 'reparse-symbol property to | |
711 | ;; NONTERM unless it was already setup | |
712 | ;; by a tag expander | |
713 | (or (semantic--tag-get-property | |
714 | tag 'reparse-symbol) | |
715 | (semantic--tag-put-property | |
716 | tag 'reparse-symbol nonterm)) | |
717 | tag) | |
718 | (semantic--tag-expand tag)) | |
719 | result (append tag result)) | |
720 | ;; No error in this case, a purposeful nil means don't | |
721 | ;; store anything. | |
722 | ) | |
723 | (if returnonerror | |
724 | (setq stream nil) | |
725 | ;; The current item in the stream didn't match, so add it to | |
726 | ;; the list of syntax items which didn't match. | |
727 | (setq semantic-unmatched-syntax-cache | |
728 | (cons (car stream) semantic-unmatched-syntax-cache)) | |
729 | )) | |
730 | ;; Designated to ignore. | |
731 | (setq stream (car nontermsym)) | |
732 | (if stream | |
d3d82e7b CY |
733 | ;; Use Emacs' built-in progress reporter: |
734 | (and (boundp 'semantic--progress-reporter) | |
735 | semantic--progress-reporter | |
aa8724ae | 736 | (eq semantic-working-type 'percent) |
d3d82e7b CY |
737 | (progress-reporter-update |
738 | semantic--progress-reporter | |
739 | (/ (* 100 (semantic-lex-token-start (car stream))) | |
740 | (point-max)))))) | |
741 | result)) | |
742 | \f | |
743 | ;;; Parsing Warnings: | |
744 | ;; | |
745 | ;; Parsing a buffer may result in non-critical things that we should | |
746 | ;; alert the user to without interrupting the normal flow. | |
747 | ;; | |
748 | ;; Any parser can use this API to provide a list of warnings during a | |
749 | ;; parse which a user may want to investigate. | |
750 | (defvar semantic-parser-warnings nil | |
751 | "A list of parser warnings since the last full reparse.") | |
752 | (make-variable-buffer-local 'semantic-parser-warnings) | |
753 | ||
754 | (defun semantic-clear-parser-warnings () | |
755 | "Clear the current list of parser warnings for this buffer." | |
756 | (setq semantic-parser-warnings nil)) | |
757 | ||
758 | (defun semantic-push-parser-warning (warning start end) | |
759 | "Add a parser WARNING that covers text from START to END." | |
760 | (setq semantic-parser-warnings | |
761 | (cons (cons warning (cons start end)) | |
762 | semantic-parser-warnings))) | |
763 | ||
764 | (defun semantic-dump-parser-warnings () | |
765 | "Dump any parser warnings." | |
766 | (interactive) | |
767 | (if semantic-parser-warnings | |
768 | (let ((pw semantic-parser-warnings)) | |
769 | (pop-to-buffer "*Parser Warnings*") | |
770 | (require 'pp) | |
771 | (erase-buffer) | |
772 | (insert (pp-to-string pw)) | |
773 | (goto-char (point-min))) | |
774 | (message "No parser warnings."))) | |
775 | ||
776 | ||
777 | \f | |
778 | ;;; Compatibility: | |
779 | ;; | |
780 | ;; Semantic 1.x parser action helper functions, used by some parsers. | |
781 | ;; Please move away from these functions, and try using semantic 2.x | |
782 | ;; interfaces instead. | |
783 | ;; | |
784 | (defsubst semantic-bovinate-region-until-error | |
785 | (start end nonterm &optional depth) | |
786 | "NOTE: Use `semantic-parse-region' instead. | |
787 | ||
788 | Bovinate between START and END starting with NONTERM. | |
789 | Optional DEPTH specifies how many levels of parenthesis to enter. | |
790 | This command will parse until an error is encountered, and return | |
791 | the list of everything found until that moment. | |
792 | This is meant for finding variable definitions at the beginning of | |
793 | code blocks in methods. If `bovine-inner-scope' can also support | |
794 | commands, use `semantic-bovinate-from-nonterminal-full'." | |
795 | (semantic-parse-region start end nonterm depth t)) | |
796 | (make-obsolete 'semantic-bovinate-region-until-error | |
797 | 'semantic-parse-region) | |
798 | ||
799 | (defsubst semantic-bovinate-from-nonterminal | |
800 | (start end nonterm &optional depth length) | |
801 | "Bovinate from within a nonterminal lambda from START to END. | |
802 | Argument NONTERM is the nonterminal symbol to start with. | |
803 | Optional argument DEPTH is the depth of lists to dive into. When used | |
804 | in a `lambda' of a MATCH-LIST, there is no need to include a START and | |
805 | END part. | |
806 | Optional argument LENGTH specifies we are only interested in LENGTH | |
807 | tokens." | |
808 | (car-safe (cdr (semantic-parse-stream | |
809 | (semantic-lex start end (or depth 1) length) | |
810 | nonterm)))) | |
811 | ||
812 | (defsubst semantic-bovinate-from-nonterminal-full | |
813 | (start end nonterm &optional depth) | |
814 | "NOTE: Use `semantic-parse-region' instead. | |
815 | ||
816 | Bovinate from within a nonterminal lambda from START to END. | |
817 | Iterates until all the space between START and END is exhausted. | |
818 | Argument NONTERM is the nonterminal symbol to start with. | |
819 | If NONTERM is nil, use `bovine-block-toplevel'. | |
820 | Optional argument DEPTH is the depth of lists to dive into. | |
821 | When used in a `lambda' of a MATCH-LIST, there is no need to include | |
822 | a START and END part." | |
823 | (semantic-parse-region start end nonterm (or depth 1))) | |
824 | (make-obsolete 'semantic-bovinate-from-nonterminal-full | |
825 | 'semantic-parse-region) | |
826 | ||
b82525f2 CY |
827 | ;;; User interface |
828 | ||
8bf997ef CY |
829 | (defun semantic-force-refresh () |
830 | "Force a full refresh of the current buffer's tags. | |
831 | Throw away all the old tags, and recreate the tag database." | |
832 | (interactive) | |
833 | (semantic-clear-toplevel-cache) | |
715f35a5 CY |
834 | (semantic-fetch-tags) |
835 | (message "Buffer reparsed.")) | |
8bf997ef CY |
836 | |
837 | (defvar semantic-mode-map | |
715f35a5 | 838 | (let ((map (make-sparse-keymap))) |
8bf997ef | 839 | ;; Key bindings: |
8bf997ef CY |
840 | ;; (define-key km "f" 'senator-search-set-tag-class-filter) |
841 | ;; (define-key km "i" 'senator-isearch-toggle-semantic-mode) | |
842 | (define-key map "\C-c,j" 'semantic-complete-jump-local) | |
843 | (define-key map "\C-c,J" 'semantic-complete-jump) | |
844 | (define-key map "\C-c,g" 'semantic-symref-symbol) | |
845 | (define-key map "\C-c,G" 'semantic-symref) | |
846 | (define-key map "\C-c,p" 'senator-previous-tag) | |
847 | (define-key map "\C-c,n" 'senator-next-tag) | |
848 | (define-key map "\C-c,u" 'senator-go-to-up-reference) | |
849 | (define-key map "\C-c, " 'semantic-complete-analyze-inline) | |
850 | (define-key map "\C-c,\C-w" 'senator-kill-tag) | |
851 | (define-key map "\C-c,\M-w" 'senator-copy-tag) | |
852 | (define-key map "\C-c,\C-y" 'senator-yank-tag) | |
853 | (define-key map "\C-c,r" 'senator-copy-tag-to-register) | |
854 | (define-key map [?\C-c ?, up] 'senator-transpose-tags-up) | |
855 | (define-key map [?\C-c ?, down] 'senator-transpose-tags-down) | |
856 | (define-key map "\C-c,l" 'semantic-analyze-possible-completions) | |
715f35a5 CY |
857 | ;; This hack avoids showing the CEDET menu twice if ede-minor-mode |
858 | ;; and Semantic are both enabled. Is there a better way? | |
859 | (define-key map [menu-bar cedet-menu] | |
860 | (list 'menu-item "Development" cedet-menu-map | |
861 | :enable (quote (not (bound-and-true-p global-ede-mode))))) | |
8bf997ef CY |
862 | ;; (define-key km "-" 'senator-fold-tag) |
863 | ;; (define-key km "+" 'senator-unfold-tag) | |
864 | map)) | |
865 | ||
715f35a5 CY |
866 | ;; Activate the Semantic items in cedet-menu-map |
867 | (let ((navigate-menu (make-sparse-keymap "Navigate Tags")) | |
868 | (edit-menu (make-sparse-keymap "Edit Tags"))) | |
869 | ||
870 | ;; Edit Tags submenu: | |
871 | (define-key edit-menu [semantic-analyze-possible-completions] | |
872 | '(menu-item "List Completions" semantic-analyze-possible-completions | |
873 | :help "Display a list of completions for the tag at point")) | |
874 | (define-key edit-menu [semantic-complete-analyze-inline] | |
875 | '(menu-item "Complete Tag Inline" semantic-complete-analyze-inline | |
876 | :help "Display inline completion for the tag at point")) | |
877 | (define-key edit-menu [semantic-completion-separator] | |
878 | '("--")) | |
879 | (define-key edit-menu [senator-transpose-tags-down] | |
880 | '(menu-item "Transpose Tags Down" senator-transpose-tags-down | |
881 | :active (semantic-current-tag) | |
882 | :help "Transpose the current tag and the next tag")) | |
883 | (define-key edit-menu [senator-transpose-tags-up] | |
884 | '(menu-item "Transpose Tags Up" senator-transpose-tags-up | |
885 | :active (semantic-current-tag) | |
886 | :help "Transpose the current tag and the previous tag")) | |
887 | (define-key edit-menu [semantic-edit-separator] | |
888 | '("--")) | |
889 | (define-key edit-menu [senator-yank-tag] | |
890 | '(menu-item "Yank Tag" senator-yank-tag | |
891 | :active (not (ring-empty-p senator-tag-ring)) | |
892 | :help "Yank the head of the tag ring into the buffer")) | |
893 | (define-key edit-menu [senator-copy-tag-to-register] | |
894 | '(menu-item "Copy Tag To Register" senator-copy-tag-to-register | |
895 | :active (semantic-current-tag) | |
896 | :help "Yank the head of the tag ring into the buffer")) | |
897 | (define-key edit-menu [senator-copy-tag] | |
898 | '(menu-item "Copy Tag" senator-copy-tag | |
899 | :active (semantic-current-tag) | |
900 | :help "Copy the current tag to the tag ring")) | |
901 | (define-key edit-menu [senator-kill-tag] | |
902 | '(menu-item "Kill Tag" senator-kill-tag | |
903 | :active (semantic-current-tag) | |
904 | :help "Kill the current tag, and copy it to the tag ring")) | |
905 | ||
906 | ;; Navigate Tags submenu: | |
907 | (define-key navigate-menu [senator-narrow-to-defun] | |
908 | '(menu-item "Narrow to Tag" senator-narrow-to-defun | |
909 | :active (semantic-current-tag) | |
910 | :help "Narrow the buffer to the bounds of the current tag")) | |
911 | (define-key navigate-menu [semantic-narrow-to-defun-separator] | |
912 | '("--")) | |
913 | (define-key navigate-menu [semantic-symref-symbol] | |
914 | '(menu-item "Find Tag References..." semantic-symref-symbol | |
915 | :help "Read a tag and list the references to it")) | |
916 | (define-key navigate-menu [semantic-complete-jump] | |
917 | '(menu-item "Find Tag Globally..." semantic-complete-jump | |
918 | :help "Read a tag name and find it in the current project")) | |
919 | (define-key navigate-menu [semantic-complete-jump-local] | |
920 | '(menu-item "Find Tag in This Buffer..." semantic-complete-jump-local | |
921 | :help "Read a tag name and find it in this buffer")) | |
922 | (define-key navigate-menu [semantic-navigation-separator] | |
923 | '("--")) | |
924 | (define-key navigate-menu [senator-go-to-up-reference] | |
925 | '(menu-item "Parent Tag" senator-go-to-up-reference | |
926 | :help "Navigate up one reference by tag.")) | |
927 | (define-key navigate-menu [senator-next-tag] | |
928 | '(menu-item "Next Tag" senator-next-tag | |
929 | :help "Go to the next tag")) | |
930 | (define-key navigate-menu [senator-previous-tag] | |
931 | '(menu-item "Previous Tag" senator-previous-tag | |
932 | :help "Go to the previous tag")) | |
933 | ||
934 | ;; Top level menu items: | |
935 | (define-key cedet-menu-map [semantic-force-refresh] | |
936 | '(menu-item "Reparse Buffer" semantic-force-refresh | |
937 | :help "Force a full reparse of the current buffer.")) | |
938 | (define-key cedet-menu-map [semantic-edit-menu] | |
939 | (cons "Edit Tags" edit-menu)) | |
940 | (define-key cedet-menu-map [navigate-menu] | |
941 | (cons "Navigate Tags" navigate-menu)) | |
942 | (define-key cedet-menu-map [semantic-options-separator] | |
943 | '("--")) | |
944 | (define-key cedet-menu-map [global-semantic-highlight-func-mode] | |
945 | (menu-bar-make-mm-toggle | |
946 | global-semantic-highlight-func-mode | |
947 | "Highlight Current Function" | |
948 | "Highlight the tag at point")) | |
949 | (define-key cedet-menu-map [global-semantic-decoration-mode] | |
950 | (menu-bar-make-mm-toggle | |
951 | global-semantic-decoration-mode | |
952 | "Decorate Tags" | |
953 | "Decorate tags based on various attributes")) | |
954 | (define-key cedet-menu-map [global-semantic-idle-completions-mode] | |
955 | (menu-bar-make-mm-toggle | |
956 | global-semantic-idle-completions-mode | |
957 | "Show Tag Completions" | |
958 | "Show tag completions when idle")) | |
959 | (define-key cedet-menu-map [global-semantic-idle-summary-mode] | |
960 | (menu-bar-make-mm-toggle | |
961 | global-semantic-idle-summary-mode | |
962 | "Show Tag Summaries" | |
963 | "Show tag summaries when idle")) | |
964 | (define-key cedet-menu-map [global-semanticdb-minor-mode] | |
965 | '(menu-item "Semantic Database" global-semanticdb-minor-mode | |
966 | :help "Store tag information in a database" | |
967 | :button (:toggle . (semanticdb-minor-mode-p)))) | |
968 | (define-key cedet-menu-map [global-semantic-idle-scheduler-mode] | |
969 | (menu-bar-make-mm-toggle | |
970 | global-semantic-idle-scheduler-mode | |
971 | "Reparse When Idle" | |
972 | "Keep a buffer's parse tree up to date when idle")) | |
973 | (define-key cedet-menu-map [ede-menu-separator] 'undefined) | |
974 | (define-key cedet-menu-map [cedet-menu-separator] 'undefined) | |
975 | (define-key cedet-menu-map [semantic-menu-separator] '("--"))) | |
976 | ||
b82525f2 | 977 | ;; The `semantic-mode' command, in conjuction with the |
715f35a5 CY |
978 | ;; `semantic-default-submodes' variable, toggles Semantic's various |
979 | ;; auxilliary minor modes. | |
b82525f2 CY |
980 | |
981 | (defvar semantic-load-system-cache-loaded nil | |
982 | "Non nil when the Semantic system caches have been loaded. | |
983 | Prevent this load system from loading files in twice.") | |
984 | ||
985 | (defconst semantic-submode-list | |
986 | '(global-semantic-highlight-func-mode | |
987 | global-semantic-decoration-mode | |
988 | global-semantic-stickyfunc-mode | |
989 | global-semantic-idle-completions-mode | |
990 | global-semantic-idle-scheduler-mode | |
991 | global-semanticdb-minor-mode | |
992 | global-semantic-idle-summary-mode | |
993 | global-semantic-mru-bookmark-mode) | |
994 | "List of auxilliary minor modes in the Semantic package.") | |
995 | ||
996 | ;;;###autoload | |
997 | (defcustom semantic-default-submodes | |
998 | '(global-semantic-idle-scheduler-mode global-semanticdb-minor-mode) | |
999 | "List of auxilliary Semantic minor modes enabled by `semantic-mode'. | |
1000 | The possible elements of this list include the following: | |
1001 | ||
1002 | `semantic-highlight-func-mode' - Highlight the current tag. | |
1003 | `semantic-decoration-mode' - Decorate tags based on various attributes. | |
1004 | `semantic-stickyfunc-mode' - Track current function in the header-line. | |
1005 | `semantic-idle-completions-mode' - Provide smart symbol completion | |
1006 | automatically when idle. | |
1007 | `semantic-idle-scheduler-mode' - Keep a buffer's parse tree up to date. | |
1008 | `semanticdb-minor-mode' - Store tags when a buffer is not in memory. | |
1009 | `semantic-idle-summary-mode' - Show a summary for the code at point. | |
1010 | `semantic-mru-bookmark-mode' - Provide `switch-to-buffer'-like | |
1011 | keybinding for tag names." | |
1012 | :group 'semantic | |
1013 | :type `(set ,@(mapcar (lambda (c) (list 'const c)) | |
1014 | semantic-submode-list))) | |
1015 | ||
1016 | ;;;###autoload | |
1017 | (define-minor-mode semantic-mode | |
1018 | "Toggle Semantic mode. | |
1019 | With ARG, turn Semantic mode on if ARG is positive, off otherwise. | |
1020 | ||
1021 | In Semantic mode, Emacs parses the buffers you visit for their | |
1022 | semantic content. This information is used by a variety of | |
1023 | auxilliary minor modes, listed in `semantic-default-submodes'; | |
1024 | all the minor modes in this list are also enabled when you enable | |
8bf997ef CY |
1025 | Semantic mode. |
1026 | ||
1027 | \\{semantic-mode-map}" | |
1028 | :global t | |
b82525f2 CY |
1029 | :group 'semantic |
1030 | (if semantic-mode | |
1031 | ;; Turn on Semantic mode | |
1032 | (progn | |
8bf997ef CY |
1033 | ;; Enable all the global auxilliary minor modes in |
1034 | ;; `semantic-submode-list'. | |
b82525f2 CY |
1035 | (dolist (mode semantic-submode-list) |
1036 | (if (memq mode semantic-default-submodes) | |
1037 | (funcall mode 1))) | |
1038 | (unless semantic-load-system-cache-loaded | |
1039 | (setq semantic-load-system-cache-loaded t) | |
1040 | (when (and (boundp 'semanticdb-default-system-save-directory) | |
1041 | (stringp semanticdb-default-system-save-directory) | |
1042 | (file-exists-p semanticdb-default-system-save-directory)) | |
17e1f4bc | 1043 | (require 'semantic/db-ebrowse) |
b82525f2 CY |
1044 | (semanticdb-load-ebrowse-caches))) |
1045 | (add-hook 'mode-local-init-hook 'semantic-new-buffer-fcn) | |
1046 | ;; Add mode-local hooks | |
1047 | (add-hook 'javascript-mode-hook 'wisent-javascript-setup-parser) | |
1048 | (add-hook 'ecmascript-mode-hook 'wisent-javascript-setup-parser) | |
1049 | (add-hook 'java-mode-hook 'wisent-java-default-setup) | |
1050 | (add-hook 'scheme-mode-hook 'semantic-default-scheme-setup) | |
1051 | (add-hook 'makefile-mode-hook 'semantic-default-make-setup) | |
1052 | (add-hook 'c-mode-hook 'semantic-default-c-setup) | |
1053 | (add-hook 'c++-mode-hook 'semantic-default-c-setup) | |
1054 | (add-hook 'html-mode-hook 'semantic-default-html-setup)) | |
1055 | ;; Disable all Semantic features. | |
1056 | (remove-hook 'mode-local-init-hook 'semantic-new-buffer-fcn) | |
1057 | (remove-hook 'javascript-mode-hook 'wisent-javascript-setup-parser) | |
1058 | (remove-hook 'ecmascript-mode-hook 'wisent-javascript-setup-parser) | |
1059 | (remove-hook 'java-mode-hook 'wisent-java-default-setup) | |
1060 | (remove-hook 'scheme-mode-hook 'semantic-default-scheme-setup) | |
1061 | (remove-hook 'makefile-mode-hook 'semantic-default-make-setup) | |
1062 | (remove-hook 'c-mode-hook 'semantic-default-c-setup) | |
1063 | (remove-hook 'c++-mode-hook 'semantic-default-c-setup) | |
1064 | (remove-hook 'html-mode-hook 'semantic-default-html-setup) | |
1065 | ||
1066 | ;; FIXME: handle semanticdb-load-ebrowse-caches | |
1067 | ||
1068 | (dolist (mode semantic-submode-list) | |
1069 | (if (and (boundp mode) (eval mode)) | |
1070 | (funcall mode -1))))) | |
1071 | ||
af7b5a91 CY |
1072 | ;;; Autoload some functions that are not in semantic/loaddefs |
1073 | ||
1074 | (autoload 'global-semantic-idle-completions-mode "semantic/idle" | |
1075 | "Toggle global use of `semantic-idle-completions-mode'. | |
1076 | If ARG is positive, enable, if it is negative, disable. | |
1077 | If ARG is nil, then toggle." t nil) | |
1078 | ||
1079 | (autoload 'semantic-idle-completions-mode "semantic/idle" | |
1080 | "Display a list of possible completions in a tooltip. | |
1081 | ||
1082 | This is a minor mode which performs actions during idle time. | |
1083 | With prefix argument ARG, turn on if positive, otherwise off. The | |
1084 | minor mode can be turned on only if semantic feature is available and | |
1085 | the current buffer was set up for parsing. Return non-nil if the | |
1086 | minor mode is enabled." t nil) | |
1087 | ||
1088 | (autoload 'global-semantic-idle-summary-mode "semantic/idle" | |
1089 | "Toggle global use of `semantic-idle-summary-mode'. | |
1090 | If ARG is positive, enable, if it is negative, disable. | |
1091 | If ARG is nil, then toggle." t nil) | |
1092 | ||
1093 | (autoload 'semantic-idle-summary-mode "semantic/idle" | |
1094 | "Display a tag summary of the lexical token under the cursor. | |
1095 | Call `semantic-idle-summary-current-symbol-info' for getting the | |
1096 | current tag to display information. | |
1097 | ||
1098 | This is a minor mode which performs actions during idle time. | |
1099 | With prefix argument ARG, turn on if positive, otherwise off. The | |
1100 | minor mode can be turned on only if semantic feature is available and | |
1101 | the current buffer was set up for parsing. Return non-nil if the | |
1102 | minor mode is enabled." t nil) | |
b82525f2 | 1103 | |
d3d82e7b CY |
1104 | (provide 'semantic) |
1105 | ||
d3d82e7b CY |
1106 | ;; Semantic-util is a part of the semantic API. Include it last |
1107 | ;; because it depends on semantic. | |
9d389824 | 1108 | (require 'semantic/util) |
a60f2e7b | 1109 | |
b82525f2 CY |
1110 | ;; (require 'semantic/load) |
1111 | ||
a60f2e7b | 1112 | ;;; semantic.el ends here |