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