* man.el (Man-goto-section): Signal error if section not found (Bug#5317).
[bpt/emacs.git] / lisp / cedet / semantic.el
CommitLineData
d3d82e7b
CY
1;;; semantic.el --- Semantic buffer evaluator.
2
bd2afec2
GM
3;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
4;; 2008, 2009 Free Software Foundation, Inc.
d3d82e7b
CY
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;;
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
00999a2e
CY
41(defvar semantic-version "2.0pre7"
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)
48 "Non-nil if this version of semantic does not satisfy a specific version.
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."
66 :group 'lisp)
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
133cached values for some reason, chances are you can, add a hook to
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
144 "Non nil if the unmatched syntax cache is out of date.
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
157 "Hooks run when semantic detects syntax not matched in a grammar.
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
161together. Each hook is called with one argument, which is a list of
162syntax tokens created by the semantic lexer. Use the functions
163`semantic-lex-token-start', `semantic-lex-token-end' and
164`semantic-lex-token-text' to get information about these tokens. The
165current buffer is the buffer these tokens are derived from.")
166
167(defvar semantic--before-fetch-tags-hook nil
168 "Hooks run before a buffer is parses for tags.
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
CY
268(defcustom semantic-new-buffer-setup-functions
269 '((js-mode . wisent-javascript-setup-parser)
270 (java-mode . wisent-java-default-setup)
271 (scheme-mode . semantic-default-scheme-setup)
272 (c-mode . semantic-default-c-setup)
273 (c++-mode . semantic-default-c-setup)
274 (html-mode . semantic-default-html-setup)
275 (srecode-template-mode . srecode-template-setup-parser)
276 (makefile-automake-mode . semantic-default-make-setup)
277 (makefile-gmake-mode . semantic-default-make-setup)
278 (makefile-makepp-mode . semantic-default-make-setup)
279 (makefile-bsdmake-mode . semantic-default-make-setup)
280 (makefile-imake-mode . semantic-default-make-setup)
281 (makefile-mode . semantic-default-make-setup))
282 "Alist of functions to call to set up Semantic parsing in the buffer.
283Each element has the form (MODE . FN), where MODE is a value of
284`major-mode' for the buffer and FN is the corresponding function
285to call, with no arguments, to set up the parser.
286
287These functions are called by `semantic-new-buffer-fcn', before
288`semantic-inhibit-functions'."
289 :group 'semantic
290 :type '(alist :key-type symbol :value-type function))
291
b82525f2
CY
292(defvar semantic-init-hook nil
293 "Hook run when a buffer is initialized with a parsing table.")
d3d82e7b 294
b82525f2
CY
295(defvar semantic-init-mode-hook nil
296 "Hook run when a buffer of a particular mode is initialized.")
297(make-variable-buffer-local 'semantic-init-mode-hook)
d3d82e7b 298
b82525f2
CY
299(defvar semantic-init-db-hook nil
300 "Hook run when a buffer is initialized with a parsing table for DBs.
d3d82e7b
CY
301This hook is for database functions which intend to swap in a tag table.
302This guarantees that the DB will go before other modes that require
303a parse of the buffer.")
304
1ac9ebc8 305(semantic-varalias-obsolete 'semantic-init-hooks
eefa91db 306 'semantic-init-hook "23.2")
1ac9ebc8 307(semantic-varalias-obsolete 'semantic-init-mode-hooks
eefa91db 308 'semantic-init-mode-hook "23.2")
1ac9ebc8 309(semantic-varalias-obsolete 'semantic-init-db-hooks
eefa91db 310 'semantic-init-db-hook "23.2")
b82525f2 311
d3d82e7b
CY
312(defvar semantic-new-buffer-fcn-was-run nil
313 "Non nil after `semantic-new-buffer-fcn' has been executed.")
314(make-variable-buffer-local 'semantic-new-buffer-fcn-was-run)
315
316(defsubst semantic-active-p ()
317 "Return non-nil if the current buffer was set up for parsing."
318 semantic-new-buffer-fcn-was-run)
319
320(defsubst semantic--umatched-syntax-needs-refresh-p ()
321 "Return non-nil if the unmatched syntax cache needs a refresh.
322That is if it is dirty or if the current parse tree isn't up to date."
323 (or semantic-unmatched-syntax-cache-check
324 (not (semantic-parse-tree-up-to-date-p))))
325
326(defun semantic-new-buffer-fcn ()
327 "Setup the current buffer to use Semantic.
328If the major mode is ready for Semantic, and no
329`semantic-inhibit-functions' disabled it, the current buffer is setup
330to use Semantic, and `semantic-init-hook' is run."
82481502
CY
331 ;; In upstream Semantic, the parser setup functions are called from
332 ;; mode hooks. In the version bundled with Emacs, we do it here.
333 (let ((entry (assq major-mode semantic-new-buffer-setup-functions)))
334 (when entry
335 (funcall (cdr entry))))
d3d82e7b
CY
336 ;; Do stuff if semantic was activated by a mode hook in this buffer,
337 ;; and not afterwards disabled.
338 (when (and semantic--parse-table
339 (not (semantic-active-p))
340 (not (run-hook-with-args-until-success
341 'semantic-inhibit-functions)))
342 ;; Make sure that if this buffer is cloned, our tags and overlays
343 ;; don't go along for the ride.
344 (add-hook 'clone-indirect-buffer-hook 'semantic-clear-toplevel-cache
345 nil t)
346 ;; Specify that this function has done it's work. At this point
347 ;; we can consider that semantic is active in this buffer.
348 (setq semantic-new-buffer-fcn-was-run t)
349 ;; Here are some buffer local variables we can initialize ourselves
350 ;; of a mode does not choose to do so.
351 (semantic-lex-init)
352 ;; Force this buffer to have its cache refreshed.
353 (semantic-clear-toplevel-cache)
354 ;; Call DB hooks before regular init hooks
b82525f2 355 (run-hooks 'semantic-init-db-hook)
d3d82e7b 356 ;; Set up semantic modes
b82525f2 357 (run-hooks 'semantic-init-hook)
d3d82e7b 358 ;; Set up major-mode specific semantic modes
b82525f2 359 (run-hooks 'semantic-init-mode-hook)))
d3d82e7b
CY
360
361(defun semantic-fetch-tags-fast ()
362 "For use in a hook. When only a partial reparse is needed, reparse."
363 (condition-case nil
364 (if (semantic-parse-tree-needs-update-p)
365 (semantic-fetch-tags))
366 (error nil))
367 semantic--buffer-cache)
d3d82e7b
CY
368\f
369;;; Parsing Commands
370;;
371(eval-when-compile
372 (condition-case nil (require 'pp) (error nil)))
373
374(defvar semantic-edebug nil
375 "When non-nil, activate the interactive parsing debugger.
376Do not set this yourself. Call `semantic-debug'.")
377
378(defun semantic-elapsed-time (start end)
379 "Copied from elp.el. Was elp-elapsed-time.
380Argument START and END bound the time being calculated."
381 (+ (* (- (car end) (car start)) 65536.0)
382 (- (car (cdr end)) (car (cdr start)))
383 (/ (- (car (cdr (cdr end))) (car (cdr (cdr start)))) 1000000.0)))
384
385(defun bovinate (&optional clear)
386 "Parse the current buffer. Show output in a temp buffer.
387Optional argument CLEAR will clear the cache before parsing.
388If CLEAR is negative, it will do a full reparse, and also not display
389the output buffer."
390 (interactive "P")
391 (if clear (semantic-clear-toplevel-cache))
392 (if (eq clear '-) (setq clear -1))
393 (let* ((start (current-time))
394 (out (semantic-fetch-tags))
395 (end (current-time)))
396 (message "Retrieving tags took %.2f seconds."
397 (semantic-elapsed-time start end))
398 (when (or (null clear) (not (listp clear)))
399 (pop-to-buffer "*Parser Output*")
400 (require 'pp)
401 (erase-buffer)
402 (insert (pp-to-string out))
403 (goto-char (point-min)))))
404\f
405;;; Functions of the parser plug-in API
406;;
407;; Overload these functions to create new types of parsers.
408;;
409(define-overloadable-function semantic-parse-stream (stream nonterminal)
410 "Parse STREAM, starting at the first NONTERMINAL rule.
411For bovine and wisent based parsers, STREAM is from the output of
412`semantic-lex', and NONTERMINAL is a rule in the apropriate language
413specific rules file.
414The default parser table used for bovine or wisent based parsers is
415`semantic--parse-table'.
416
417Must return a list: (STREAM TAGS) where STREAM is the unused elements
418from STREAM, and TAGS is the list of semantic tags found, usually only
419one tag is returned with the exception of compound statements")
420
421(define-overloadable-function semantic-parse-changes ()
422 "Reparse changes in the current buffer.
423The list of changes are tracked as a series of overlays in the buffer.
424When overloading this function, use `semantic-changes-in-region' to
425analyze.")
426
427(define-overloadable-function semantic-parse-region
428 (start end &optional nonterminal depth returnonerror)
429 "Parse the area between START and END, and return any tags found.
430If END needs to be extended due to a lexical token being too large, it
431will be silently ignored.
432
433Optional arguments:
434NONTERMINAL is the rule to start parsing at.
435DEPTH specifies the lexical depth to decend for parser that use
436lexical analysis as their first step.
437RETURNONERROR specifies that parsing should stop on the first
438unmatched syntax encountered. When nil, parsing skips the syntax,
439adding it to the unmatched syntax cache.
440
441Must return a list of semantic tags wich have been cooked
442\(repositioned properly) but which DO NOT HAVE OVERLAYS associated
443with them. When overloading this function, use `semantic--tag-expand'
444to cook raw tags.")
445
446(defun semantic-parse-region-default
447 (start end &optional nonterminal depth returnonerror)
448 "Parse the area between START and END, and return any tags found.
449If END needs to be extended due to a lexical token being too large, it
450will be silently ignored.
451Optional arguments:
452NONTERMINAL is the rule to start parsing at if it is known.
453DEPTH specifies the lexical depth to scan.
454RETURNONERROR specifies that parsing should end when encountering
455unterminated syntax."
456 (when (or (null semantic--parse-table) (eq semantic--parse-table t))
457 ;; If there is no table, or it was set to t, then we are here by
458 ;; some other mistake. Do not throw an error deep in the parser.
459 (error "No support found to parse buffer %S" (buffer-name)))
460 (save-restriction
461 (widen)
462 (when (or (< end start) (> end (point-max)))
463 (error "Invalid parse region bounds %S, %S" start end))
464 (nreverse
465 (semantic-repeat-parse-whole-stream
466 (or (cdr (assq start semantic-lex-block-streams))
467 (semantic-lex start end depth))
468 nonterminal returnonerror))))
469\f
470;;; Parsing functions
471;;
472(defun semantic-set-unmatched-syntax-cache (unmatched-syntax)
473 "Set the unmatched syntax cache.
474Argument UNMATCHED-SYNTAX is the syntax to set into the cache."
475 ;; This function is not actually called by the main parse loop.
476 ;; This is intended for use by semanticdb.
477 (setq semantic-unmatched-syntax-cache unmatched-syntax
478 semantic-unmatched-syntax-cache-check nil)
479 ;; Refresh the display of unmatched syntax tokens if enabled
480 (run-hook-with-args 'semantic-unmatched-syntax-hook
481 semantic-unmatched-syntax-cache))
482
483(defun semantic-clear-unmatched-syntax-cache ()
484 "Clear the cache of unmatched syntax tokens."
485 (setq semantic-unmatched-syntax-cache nil
486 semantic-unmatched-syntax-cache-check t))
487
488(defun semantic-unmatched-syntax-tokens ()
489 "Return the list of unmatched syntax tokens."
490 ;; If the cache need refresh then do a full re-parse.
491 (if (semantic--umatched-syntax-needs-refresh-p)
492 ;; To avoid a recursive call, temporarily disable
493 ;; `semantic-unmatched-syntax-hook'.
494 (let (semantic-unmatched-syntax-hook)
495 (condition-case nil
496 (progn
497 (semantic-clear-toplevel-cache)
498 (semantic-fetch-tags))
499 (quit
500 (message "semantic-unmatched-syntax-tokens:\
501 parsing of buffer canceled"))
502 )))
503 semantic-unmatched-syntax-cache)
504
505(defun semantic-clear-toplevel-cache ()
506 "Clear the toplevel tag cache for the current buffer.
507Clearing the cache will force a complete reparse next time a tag list
508is requested."
509 (interactive)
510 (run-hooks 'semantic-before-toplevel-cache-flush-hook)
511 (setq semantic--buffer-cache nil)
512 (semantic-clear-unmatched-syntax-cache)
513 (semantic-clear-parser-warnings)
514 ;; Nuke all semantic overlays. This is faster than deleting based
515 ;; on our data structure.
516 (let ((l (semantic-overlay-lists)))
517 (mapc 'semantic-delete-overlay-maybe (car l))
518 (mapc 'semantic-delete-overlay-maybe (cdr l))
519 )
520 (semantic-parse-tree-set-needs-rebuild)
521 ;; Remove this hook which tracks if a buffer is up to date or not.
522 (remove-hook 'after-change-functions 'semantic-change-function t)
523 ;; Old model. Delete someday.
524 ;;(run-hooks 'semantic-after-toplevel-bovinate-hook)
525
526 (run-hook-with-args 'semantic-after-toplevel-cache-change-hook
527 semantic--buffer-cache)
8bf997ef
CY
528
529 (setq semantic--completion-cache nil))
d3d82e7b
CY
530
531(defvar semantic-bovinate-nonterminal-check-obarray)
532
533(defun semantic--set-buffer-cache (tagtable)
534 "Set the toplevel cache cache to TAGTABLE."
535 (setq semantic--buffer-cache tagtable
06511291
CY
536 semantic-unmatched-syntax-cache-check nil)
537 ;; This is specific to the bovine parser.
538 (set (make-local-variable 'semantic-bovinate-nonterminal-check-obarray)
539 nil)
d3d82e7b
CY
540 (semantic-parse-tree-set-up-to-date)
541 (semantic-make-local-hook 'after-change-functions)
542 (add-hook 'after-change-functions 'semantic-change-function nil t)
543 (run-hook-with-args 'semantic-after-toplevel-cache-change-hook
544 semantic--buffer-cache)
8bf997ef 545 (setq semantic--completion-cache nil)
d3d82e7b
CY
546 ;; Refresh the display of unmatched syntax tokens if enabled
547 (run-hook-with-args 'semantic-unmatched-syntax-hook
548 semantic-unmatched-syntax-cache)
549 ;; Old Semantic 1.3 hook API. Maybe useful forever?
550 (run-hooks 'semantic-after-toplevel-bovinate-hook)
551 )
552
553(defvar semantic-working-type 'percent
554 "*The type of working message to use when parsing.
555'percent means we are doing a linear parse through the buffer.
556'dynamic means we are reparsing specific tags.")
557(semantic-varalias-obsolete 'semantic-bovination-working-type
eefa91db 558 'semantic-working-type "23.2")
d3d82e7b
CY
559
560(defvar semantic-minimum-working-buffer-size (* 1024 5)
561 "*The minimum size of a buffer before working messages are displayed.
562Buffers smaller than will parse silently.
bd2afec2 563Buffers larger than this will display the working progress bar.")
d3d82e7b
CY
564
565(defsubst semantic-parser-working-message (&optional arg)
566 "Return the message string displayed while parsing.
567If optional argument ARG is non-nil it is appended to the message
568string."
17e1f4bc
CY
569 (concat "Parsing"
570 (if arg (format " %s" arg))
571 (if semantic-parser-name (format " (%s)" semantic-parser-name))
572 "..."))
d3d82e7b
CY
573\f
574;;; Application Parser Entry Points
575;;
576;; The best way to call the parser from programs is via
577;; `semantic-fetch-tags'. This, in turn, uses other internal
578;; API functions which plug-in parsers can take advantage of.
579
580(defun semantic-fetch-tags ()
581 "Fetch semantic tags from the current buffer.
582If the buffer cache is up to date, return that.
583If the buffer cache is out of date, attempt an incremental reparse.
584If the buffer has not been parsed before, or if the incremental reparse
585fails, then parse the entire buffer.
bd2afec2 586If a lexical error had been previously discovered and the buffer
d3d82e7b
CY
587was marked unparseable, then do nothing, and return the cache."
588 (and
589 ;; Is this a semantic enabled buffer?
590 (semantic-active-p)
591 ;; Application hooks say the buffer is safe for parsing
592 (run-hook-with-args-until-failure
593 'semantic-before-toplevel-bovination-hook)
594 (run-hook-with-args-until-failure
595 'semantic--before-fetch-tags-hook)
596 ;; If the buffer was previously marked unparseable,
597 ;; then don't waste our time.
598 (not (semantic-parse-tree-unparseable-p))
599 ;; The parse tree actually needs to be refreshed
600 (not (semantic-parse-tree-up-to-date-p))
601 ;; So do it!
602 (let* ((gc-cons-threshold (max gc-cons-threshold 10000000))
603 (semantic-lex-block-streams nil)
604 (res nil))
605 (garbage-collect)
606 (cond
607
608;;;; Try the incremental parser to do a fast update.
609 ((semantic-parse-tree-needs-update-p)
610 (setq res (semantic-parse-changes))
611 (if (semantic-parse-tree-needs-rebuild-p)
612 ;; If the partial reparse fails, jump to a full reparse.
613 (semantic-fetch-tags)
614 ;; Clear the cache of unmatched syntax tokens
615 ;;
616 ;; NOTE TO SELF:
617 ;;
618 ;; Move this into the incremental parser. This is a bug.
619 ;;
620 (semantic-clear-unmatched-syntax-cache)
621 (run-hook-with-args ;; Let hooks know the updated tags
622 'semantic-after-partial-cache-change-hook res))
8bf997ef 623 (setq semantic--completion-cache nil))
d3d82e7b
CY
624
625;;;; Parse the whole system.
626 ((semantic-parse-tree-needs-rebuild-p)
d3d82e7b
CY
627 ;; Use Emacs' built-in progress-reporter
628 (let ((semantic--progress-reporter
629 (and (>= (point-max) semantic-minimum-working-buffer-size)
630 (eq semantic-working-type 'percent)
631 (make-progress-reporter
632 (semantic-parser-working-message (buffer-name))
633 0 100))))
634 (setq res (semantic-parse-region (point-min) (point-max)))
59aec83e
CY
635 (if semantic--progress-reporter
636 (progress-reporter-done semantic--progress-reporter)))
d3d82e7b
CY
637
638 ;; Clear the caches when we see there were no errors.
639 ;; But preserve the unmatched syntax cache and warnings!
640 (let (semantic-unmatched-syntax-cache
641 semantic-unmatched-syntax-cache-check
642 semantic-parser-warnings)
643 (semantic-clear-toplevel-cache))
644 ;; Set up the new overlays
645 (semantic--tag-link-list-to-buffer res)
646 ;; Set up the cache with the new results
647 (semantic--set-buffer-cache res)
648 ))))
649
650 ;; Always return the current parse tree.
651 semantic--buffer-cache)
652
653(defun semantic-refresh-tags-safe ()
654 "Refreshes the current buffer's tags safely.
655
656Return non-nil if the refresh was successful.
657Return nil if there is some sort of syntax error preventing a reparse.
658
659Does nothing if the current buffer doesn't need reparsing."
660
661 ;; These checks actually occur in `semantic-fetch-tags', but if we
662 ;; do them here, then all the bovination hooks are not run, and
663 ;; we save lots of time.
664 (cond
665 ;; If the buffer was previously marked unparseable,
666 ;; then don't waste our time.
667 ((semantic-parse-tree-unparseable-p)
668 nil)
669 ;; The parse tree is already ok.
670 ((semantic-parse-tree-up-to-date-p)
671 t)
672 (t
673 (let* ((inhibit-quit nil)
674 (lexically-safe t)
675 )
676
677 (unwind-protect
678 ;; Perform the parsing.
679 (progn
680 (when (semantic-lex-catch-errors safe-refresh
681 (save-excursion (semantic-fetch-tags))
682 nil)
683 ;; If we are here, it is because the lexical step failed,
684 ;; proably due to unterminated lists or something like that.
685
686 ;; We do nothing, and just wait for the next idle timer
687 ;; to go off. In the meantime, remember this, and make sure
688 ;; no other idle services can get executed.
689 (setq lexically-safe nil))
690 )
691 )
692 ;; Return if we are lexically safe
693 lexically-safe))))
694
695(defun semantic-bovinate-toplevel (&optional ignored)
696 "Backward Compatibility Function."
697 (semantic-fetch-tags))
e6e267fc 698(make-obsolete 'semantic-bovinate-toplevel 'semantic-fetch-tags "23.2")
d3d82e7b
CY
699
700;; Another approach is to let Emacs call the parser on idle time, when
701;; needed, use `semantic-fetch-available-tags' to only retrieve
702;; available tags, and setup the `semantic-after-*-hook' hooks to
703;; synchronize with new tags when they become available.
704
705(defsubst semantic-fetch-available-tags ()
706 "Fetch available semantic tags from the current buffer.
707That is, return tags currently in the cache without parsing the
708current buffer.
709Parse operations happen asynchronously when needed on Emacs idle time.
710Use the `semantic-after-toplevel-cache-change-hook' and
711`semantic-after-partial-cache-change-hook' hooks to synchronize with
712new tags when they become available."
713 semantic--buffer-cache)
714\f
715;;; Iterative parser helper function
716;;
717;; Iterative parsers are better than rule-based iterative functions
718;; in that they can handle obscure errors more cleanly.
719;;
720;; `semantic-repeat-parse-whole-stream' abstracts this action for
721;; other parser centric routines.
722;;
723(defun semantic-repeat-parse-whole-stream
724 (stream nonterm &optional returnonerror)
725 "Iteratively parse the entire stream STREAM starting with NONTERM.
726Optional argument RETURNONERROR indicates that the parser should exit
727with the current results on a parse error.
728This function returns semantic tags without overlays."
729 (let ((result nil)
730 (case-fold-search semantic-case-fold)
731 nontermsym tag)
732 (while stream
733 (setq nontermsym (semantic-parse-stream stream nonterm)
734 tag (car (cdr nontermsym)))
735 (if (not nontermsym)
736 (error "Parse error @ %d" (car (cdr (car stream)))))
737 (if (eq (car nontermsym) stream)
738 (error "Parser error: Infinite loop?"))
739 (if tag
740 (if (car tag)
741 (setq tag (mapcar
742 #'(lambda (tag)
743 ;; Set the 'reparse-symbol property to
744 ;; NONTERM unless it was already setup
745 ;; by a tag expander
746 (or (semantic--tag-get-property
747 tag 'reparse-symbol)
748 (semantic--tag-put-property
749 tag 'reparse-symbol nonterm))
750 tag)
751 (semantic--tag-expand tag))
752 result (append tag result))
753 ;; No error in this case, a purposeful nil means don't
754 ;; store anything.
755 )
756 (if returnonerror
757 (setq stream nil)
758 ;; The current item in the stream didn't match, so add it to
759 ;; the list of syntax items which didn't match.
760 (setq semantic-unmatched-syntax-cache
761 (cons (car stream) semantic-unmatched-syntax-cache))
762 ))
763 ;; Designated to ignore.
764 (setq stream (car nontermsym))
765 (if stream
d3d82e7b
CY
766 ;; Use Emacs' built-in progress reporter:
767 (and (boundp 'semantic--progress-reporter)
768 semantic--progress-reporter
aa8724ae 769 (eq semantic-working-type 'percent)
d3d82e7b
CY
770 (progress-reporter-update
771 semantic--progress-reporter
772 (/ (* 100 (semantic-lex-token-start (car stream)))
773 (point-max))))))
774 result))
775\f
776;;; Parsing Warnings:
777;;
778;; Parsing a buffer may result in non-critical things that we should
779;; alert the user to without interrupting the normal flow.
780;;
781;; Any parser can use this API to provide a list of warnings during a
782;; parse which a user may want to investigate.
783(defvar semantic-parser-warnings nil
784 "A list of parser warnings since the last full reparse.")
785(make-variable-buffer-local 'semantic-parser-warnings)
786
787(defun semantic-clear-parser-warnings ()
788 "Clear the current list of parser warnings for this buffer."
789 (setq semantic-parser-warnings nil))
790
791(defun semantic-push-parser-warning (warning start end)
792 "Add a parser WARNING that covers text from START to END."
793 (setq semantic-parser-warnings
794 (cons (cons warning (cons start end))
795 semantic-parser-warnings)))
796
797(defun semantic-dump-parser-warnings ()
798 "Dump any parser warnings."
799 (interactive)
800 (if semantic-parser-warnings
801 (let ((pw semantic-parser-warnings))
802 (pop-to-buffer "*Parser Warnings*")
803 (require 'pp)
804 (erase-buffer)
805 (insert (pp-to-string pw))
806 (goto-char (point-min)))
807 (message "No parser warnings.")))
808
809
810\f
811;;; Compatibility:
812;;
813;; Semantic 1.x parser action helper functions, used by some parsers.
814;; Please move away from these functions, and try using semantic 2.x
815;; interfaces instead.
816;;
817(defsubst semantic-bovinate-region-until-error
818 (start end nonterm &optional depth)
819 "NOTE: Use `semantic-parse-region' instead.
820
821Bovinate between START and END starting with NONTERM.
822Optional DEPTH specifies how many levels of parenthesis to enter.
823This command will parse until an error is encountered, and return
824the list of everything found until that moment.
825This is meant for finding variable definitions at the beginning of
826code blocks in methods. If `bovine-inner-scope' can also support
827commands, use `semantic-bovinate-from-nonterminal-full'."
828 (semantic-parse-region start end nonterm depth t))
829(make-obsolete 'semantic-bovinate-region-until-error
e6e267fc 830 'semantic-parse-region "23.2")
d3d82e7b
CY
831
832(defsubst semantic-bovinate-from-nonterminal
833 (start end nonterm &optional depth length)
834 "Bovinate from within a nonterminal lambda from START to END.
835Argument NONTERM is the nonterminal symbol to start with.
836Optional argument DEPTH is the depth of lists to dive into. When used
837in a `lambda' of a MATCH-LIST, there is no need to include a START and
838END part.
839Optional argument LENGTH specifies we are only interested in LENGTH
840tokens."
841 (car-safe (cdr (semantic-parse-stream
842 (semantic-lex start end (or depth 1) length)
843 nonterm))))
844
845(defsubst semantic-bovinate-from-nonterminal-full
846 (start end nonterm &optional depth)
847 "NOTE: Use `semantic-parse-region' instead.
848
849Bovinate from within a nonterminal lambda from START to END.
850Iterates until all the space between START and END is exhausted.
851Argument NONTERM is the nonterminal symbol to start with.
852If NONTERM is nil, use `bovine-block-toplevel'.
853Optional argument DEPTH is the depth of lists to dive into.
854When used in a `lambda' of a MATCH-LIST, there is no need to include
855a START and END part."
856 (semantic-parse-region start end nonterm (or depth 1)))
857(make-obsolete 'semantic-bovinate-from-nonterminal-full
e6e267fc 858 'semantic-parse-region "23.2")
d3d82e7b 859
b82525f2
CY
860;;; User interface
861
8bf997ef
CY
862(defun semantic-force-refresh ()
863 "Force a full refresh of the current buffer's tags.
864Throw away all the old tags, and recreate the tag database."
865 (interactive)
866 (semantic-clear-toplevel-cache)
715f35a5
CY
867 (semantic-fetch-tags)
868 (message "Buffer reparsed."))
8bf997ef
CY
869
870(defvar semantic-mode-map
715f35a5 871 (let ((map (make-sparse-keymap)))
8bf997ef 872 ;; Key bindings:
8bf997ef
CY
873 ;; (define-key km "f" 'senator-search-set-tag-class-filter)
874 ;; (define-key km "i" 'senator-isearch-toggle-semantic-mode)
875 (define-key map "\C-c,j" 'semantic-complete-jump-local)
876 (define-key map "\C-c,J" 'semantic-complete-jump)
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)
887 (define-key map [?\C-c ?, up] 'senator-transpose-tags-up)
888 (define-key map [?\C-c ?, down] 'senator-transpose-tags-down)
889 (define-key map "\C-c,l" 'semantic-analyze-possible-completions)
715f35a5
CY
890 ;; This hack avoids showing the CEDET menu twice if ede-minor-mode
891 ;; and Semantic are both enabled. Is there a better way?
892 (define-key map [menu-bar cedet-menu]
893 (list 'menu-item "Development" cedet-menu-map
894 :enable (quote (not (bound-and-true-p global-ede-mode)))))
8bf997ef
CY
895 ;; (define-key km "-" 'senator-fold-tag)
896 ;; (define-key km "+" 'senator-unfold-tag)
897 map))
898
715f35a5
CY
899;; Activate the Semantic items in cedet-menu-map
900(let ((navigate-menu (make-sparse-keymap "Navigate Tags"))
901 (edit-menu (make-sparse-keymap "Edit Tags")))
902
903 ;; Edit Tags submenu:
904 (define-key edit-menu [semantic-analyze-possible-completions]
905 '(menu-item "List Completions" semantic-analyze-possible-completions
906 :help "Display a list of completions for the tag at point"))
907 (define-key edit-menu [semantic-complete-analyze-inline]
908 '(menu-item "Complete Tag Inline" semantic-complete-analyze-inline
909 :help "Display inline completion for the tag at point"))
910 (define-key edit-menu [semantic-completion-separator]
911 '("--"))
912 (define-key edit-menu [senator-transpose-tags-down]
913 '(menu-item "Transpose Tags Down" senator-transpose-tags-down
914 :active (semantic-current-tag)
915 :help "Transpose the current tag and the next tag"))
916 (define-key edit-menu [senator-transpose-tags-up]
917 '(menu-item "Transpose Tags Up" senator-transpose-tags-up
918 :active (semantic-current-tag)
919 :help "Transpose the current tag and the previous tag"))
920 (define-key edit-menu [semantic-edit-separator]
921 '("--"))
922 (define-key edit-menu [senator-yank-tag]
923 '(menu-item "Yank Tag" senator-yank-tag
924 :active (not (ring-empty-p senator-tag-ring))
925 :help "Yank the head of the tag ring into the buffer"))
926 (define-key edit-menu [senator-copy-tag-to-register]
927 '(menu-item "Copy Tag To Register" senator-copy-tag-to-register
928 :active (semantic-current-tag)
929 :help "Yank the head of the tag ring into the buffer"))
930 (define-key edit-menu [senator-copy-tag]
931 '(menu-item "Copy Tag" senator-copy-tag
932 :active (semantic-current-tag)
933 :help "Copy the current tag to the tag ring"))
934 (define-key edit-menu [senator-kill-tag]
935 '(menu-item "Kill Tag" senator-kill-tag
936 :active (semantic-current-tag)
937 :help "Kill the current tag, and copy it to the tag ring"))
938
939 ;; Navigate Tags submenu:
940 (define-key navigate-menu [senator-narrow-to-defun]
941 '(menu-item "Narrow to Tag" senator-narrow-to-defun
942 :active (semantic-current-tag)
943 :help "Narrow the buffer to the bounds of the current tag"))
944 (define-key navigate-menu [semantic-narrow-to-defun-separator]
945 '("--"))
946 (define-key navigate-menu [semantic-symref-symbol]
947 '(menu-item "Find Tag References..." semantic-symref-symbol
948 :help "Read a tag and list the references to it"))
949 (define-key navigate-menu [semantic-complete-jump]
950 '(menu-item "Find Tag Globally..." semantic-complete-jump
951 :help "Read a tag name and find it in the current project"))
952 (define-key navigate-menu [semantic-complete-jump-local]
953 '(menu-item "Find Tag in This Buffer..." semantic-complete-jump-local
954 :help "Read a tag name and find it in this buffer"))
955 (define-key navigate-menu [semantic-navigation-separator]
956 '("--"))
957 (define-key navigate-menu [senator-go-to-up-reference]
958 '(menu-item "Parent Tag" senator-go-to-up-reference
959 :help "Navigate up one reference by tag."))
960 (define-key navigate-menu [senator-next-tag]
961 '(menu-item "Next Tag" senator-next-tag
962 :help "Go to the next tag"))
963 (define-key navigate-menu [senator-previous-tag]
964 '(menu-item "Previous Tag" senator-previous-tag
965 :help "Go to the previous tag"))
966
967 ;; Top level menu items:
968 (define-key cedet-menu-map [semantic-force-refresh]
969 '(menu-item "Reparse Buffer" semantic-force-refresh
a2095e2e
CY
970 :help "Force a full reparse of the current buffer."
971 :visible semantic-mode))
715f35a5 972 (define-key cedet-menu-map [semantic-edit-menu]
a2095e2e
CY
973 `(menu-item "Edit Tags" ,edit-menu
974 :visible semantic-mode))
715f35a5 975 (define-key cedet-menu-map [navigate-menu]
a2095e2e
CY
976 `(menu-item "Navigate Tags" ,navigate-menu
977 :visible semantic-mode))
715f35a5
CY
978 (define-key cedet-menu-map [semantic-options-separator]
979 '("--"))
980 (define-key cedet-menu-map [global-semantic-highlight-func-mode]
a2095e2e
CY
981 '(menu-item "Highlight Current Function" global-semantic-highlight-func-mode
982 :help "Highlight the tag at point"
983 :visible semantic-mode
984 :button (:toggle . global-semantic-highlight-func-mode)))
715f35a5 985 (define-key cedet-menu-map [global-semantic-decoration-mode]
a2095e2e
CY
986 '(menu-item "Decorate Tags" global-semantic-decoration-mode
987 :help "Decorate tags based on tag attributes"
988 :visible semantic-mode
989 :button (:toggle . (bound-and-true-p
990 global-semantic-decoration-mode))))
715f35a5 991 (define-key cedet-menu-map [global-semantic-idle-completions-mode]
a2095e2e
CY
992 '(menu-item "Show Tag Completions" global-semantic-idle-completions-mode
993 :help "Show tag completions when idle"
994 :visible semantic-mode
725bff06 995 :enable global-semantic-idle-scheduler-mode
a2095e2e 996 :button (:toggle . global-semantic-idle-completions-mode)))
715f35a5 997 (define-key cedet-menu-map [global-semantic-idle-summary-mode]
a2095e2e
CY
998 '(menu-item "Show Tag Summaries" global-semantic-idle-summary-mode
999 :help "Show tag summaries when idle"
1000 :visible semantic-mode
725bff06 1001 :enable global-semantic-idle-scheduler-mode
a2095e2e 1002 :button (:toggle . global-semantic-idle-summary-mode)))
715f35a5 1003 (define-key cedet-menu-map [global-semantic-idle-scheduler-mode]
a2095e2e
CY
1004 '(menu-item "Reparse When Idle" global-semantic-idle-scheduler-mode
1005 :help "Keep a buffer's parse tree up to date when idle"
1006 :visible semantic-mode
725bff06
CY
1007 :button (:toggle . global-semantic-idle-scheduler-mode)))
1008 (define-key cedet-menu-map [global-semanticdb-minor-mode]
1009 '(menu-item "Semantic Database" global-semanticdb-minor-mode
1010 :help "Store tag information in a database"
1011 :visible semantic-mode
1012 :button (:toggle . global-semanticdb-minor-mode))))
715f35a5 1013
b82525f2 1014;; The `semantic-mode' command, in conjuction with the
715f35a5
CY
1015;; `semantic-default-submodes' variable, toggles Semantic's various
1016;; auxilliary minor modes.
b82525f2
CY
1017
1018(defvar semantic-load-system-cache-loaded nil
1019 "Non nil when the Semantic system caches have been loaded.
1020Prevent this load system from loading files in twice.")
1021
1022(defconst semantic-submode-list
1023 '(global-semantic-highlight-func-mode
1024 global-semantic-decoration-mode
1025 global-semantic-stickyfunc-mode
1026 global-semantic-idle-completions-mode
1027 global-semantic-idle-scheduler-mode
1028 global-semanticdb-minor-mode
1029 global-semantic-idle-summary-mode
1030 global-semantic-mru-bookmark-mode)
bd2afec2 1031 "List of auxiliary minor modes in the Semantic package.")
b82525f2
CY
1032
1033;;;###autoload
1034(defcustom semantic-default-submodes
1035 '(global-semantic-idle-scheduler-mode global-semanticdb-minor-mode)
bd2afec2 1036 "List of auxiliary Semantic minor modes enabled by `semantic-mode'.
b82525f2
CY
1037The possible elements of this list include the following:
1038
725bff06
CY
1039 `global-semanticdb-minor-mode' - Maintain tag database.
1040 `global-semantic-idle-scheduler-mode' - Reparse buffer when idle.
1041 `global-semantic-idle-summary-mode' - Show summary of tag at point.
1042 `global-semantic-idle-completions-mode' - Show completions when idle.
1043 `global-semantic-decoration-mode' - Additional tag decorations.
1044 `global-semantic-highlight-func-mode' - Highlight the current tag.
1045 `global-semantic-stickyfunc-mode' - Show current fun in header line.
1046 `global-semantic-mru-bookmark-mode' - Provide `switch-to-buffer'-like
b82525f2
CY
1047 keybinding for tag names."
1048 :group 'semantic
1049 :type `(set ,@(mapcar (lambda (c) (list 'const c))
1050 semantic-submode-list)))
1051
1052;;;###autoload
1053(define-minor-mode semantic-mode
1054 "Toggle Semantic mode.
1055With ARG, turn Semantic mode on if ARG is positive, off otherwise.
1056
1057In Semantic mode, Emacs parses the buffers you visit for their
1058semantic content. This information is used by a variety of
1059auxilliary minor modes, listed in `semantic-default-submodes';
1060all the minor modes in this list are also enabled when you enable
8bf997ef
CY
1061Semantic mode.
1062
1063\\{semantic-mode-map}"
1064 :global t
b82525f2
CY
1065 :group 'semantic
1066 (if semantic-mode
1067 ;; Turn on Semantic mode
1068 (progn
8bf997ef
CY
1069 ;; Enable all the global auxilliary minor modes in
1070 ;; `semantic-submode-list'.
b82525f2
CY
1071 (dolist (mode semantic-submode-list)
1072 (if (memq mode semantic-default-submodes)
1073 (funcall mode 1)))
1074 (unless semantic-load-system-cache-loaded
1075 (setq semantic-load-system-cache-loaded t)
1076 (when (and (boundp 'semanticdb-default-system-save-directory)
1077 (stringp semanticdb-default-system-save-directory)
1078 (file-exists-p semanticdb-default-system-save-directory))
17e1f4bc 1079 (require 'semantic/db-ebrowse)
b82525f2 1080 (semanticdb-load-ebrowse-caches)))
d436f538 1081 (add-hook 'mode-local-init-hook 'semantic-new-buffer-fcn)
ebf5c4f5
CY
1082 (if global-ede-mode
1083 (define-key cedet-menu-map [cedet-menu-separator] '("--")))
d436f538
CY
1084 (dolist (b (buffer-list))
1085 (with-current-buffer b
1086 (semantic-new-buffer-fcn))))
b82525f2
CY
1087 ;; Disable all Semantic features.
1088 (remove-hook 'mode-local-init-hook 'semantic-new-buffer-fcn)
ebf5c4f5
CY
1089 (define-key cedet-menu-map [cedet-menu-separator] nil)
1090 (define-key cedet-menu-map [semantic-options-separator] nil)
b82525f2 1091 ;; FIXME: handle semanticdb-load-ebrowse-caches
b82525f2
CY
1092 (dolist (mode semantic-submode-list)
1093 (if (and (boundp mode) (eval mode))
1094 (funcall mode -1)))))
1095
af7b5a91
CY
1096;;; Autoload some functions that are not in semantic/loaddefs
1097
1098(autoload 'global-semantic-idle-completions-mode "semantic/idle"
1099 "Toggle global use of `semantic-idle-completions-mode'.
1100If ARG is positive, enable, if it is negative, disable.
1101If ARG is nil, then toggle." t nil)
1102
1103(autoload 'semantic-idle-completions-mode "semantic/idle"
1104 "Display a list of possible completions in a tooltip.
1105
1106This is a minor mode which performs actions during idle time.
1107With prefix argument ARG, turn on if positive, otherwise off. The
1108minor mode can be turned on only if semantic feature is available and
1109the current buffer was set up for parsing. Return non-nil if the
1110minor mode is enabled." t nil)
1111
1112(autoload 'global-semantic-idle-summary-mode "semantic/idle"
1113 "Toggle global use of `semantic-idle-summary-mode'.
1114If ARG is positive, enable, if it is negative, disable.
1115If ARG is nil, then toggle." t nil)
1116
1117(autoload 'semantic-idle-summary-mode "semantic/idle"
1118 "Display a tag summary of the lexical token under the cursor.
1119Call `semantic-idle-summary-current-symbol-info' for getting the
1120current tag to display information.
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)
b82525f2 1127
e6e267fc
CY
1128(autoload 'srecode-template-setup-parser "srecode/srecode-template"
1129 "Set up buffer for parsing SRecode template files." t nil)
1130
d3d82e7b
CY
1131(provide 'semantic)
1132
d3d82e7b
CY
1133;; Semantic-util is a part of the semantic API. Include it last
1134;; because it depends on semantic.
9d389824 1135(require 'semantic/util)
a60f2e7b 1136
b82525f2
CY
1137;; (require 'semantic/load)
1138
3999968a 1139;; arch-tag: 31583e10-6508-41a9-be40-f83d0ae0a4ed
a60f2e7b 1140;;; semantic.el ends here