* src/gfilenotify.c (Fgfile_add_watch):
[emacs.git] / lisp / cedet / semantic.el
blob290cd907bebaff31e70e9498012bf3a832672df9
1 ;;; semantic.el --- Semantic buffer evaluator.
3 ;; Copyright (C) 1999-2015 Free Software Foundation, Inc.
5 ;; Author: Eric M. Ludlam <zappo@gnu.org>
6 ;; Keywords: syntax tools
7 ;; Version: 2.2
9 ;; This file is part of GNU Emacs.
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.
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.
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/>.
24 ;;; Commentary:
26 ;; API for providing the semantic content of a buffer.
28 ;; The Semantic API provides an interface to a series of different parser
29 ;; implementations. Each parser outputs a parse tree in a similar format
30 ;; designed to handle typical functional and object oriented languages.
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.
37 (require 'cedet)
38 (require 'semantic/tag)
39 (require 'semantic/lex)
41 (defvar semantic-version "2.2"
42 "Current version of Semantic.")
44 (declare-function inversion-test "inversion")
45 (declare-function semanticdb-load-ebrowse-caches "semantic/db-ebrowse")
47 (defun semantic-require-version (major minor &optional beta)
48 "Non-nil if this version of Semantic does not satisfy a specific version.
49 Arguments can be:
51 (MAJOR MINOR &optional BETA)
53 Values MAJOR and MINOR must be integers. BETA can be an integer, or
54 excluded if a released version is required.
56 It is assumed that if the current version is newer than that specified,
57 everything passes. Exceptions occur when known incompatibilities are
58 introduced."
59 (require 'inversion)
60 (inversion-test 'semantic
61 (concat major "." minor
62 (when beta (concat "beta" beta)))))
64 (defgroup semantic nil
65 "Parser Generator and parser framework."
66 :group 'tools)
68 (defgroup semantic-faces nil
69 "Faces used for Semantic enabled tools."
70 :group 'semantic)
72 (require 'semantic/fw)
74 ;;; Code:
77 ;;; Variables and Configuration
79 (defvar semantic--parse-table nil
80 "Variable that defines how to parse top level items in a buffer.
81 This variable is for internal use only, and its content depends on the
82 external parser used.")
83 (make-variable-buffer-local 'semantic--parse-table)
84 (semantic-varalias-obsolete 'semantic-toplevel-bovine-table
85 'semantic--parse-table "23.2")
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.
94 The string is used to represent a group of objects of the given type.
95 It is sometimes useful for a language to use a different string
96 in place of the default, even though that language will still
97 return a symbol. For example, Java return's includes, but the
98 string can be replaced with `Imports'.")
99 (make-variable-buffer-local 'semantic-symbol->name-assoc-list)
101 (defvar semantic-symbol->name-assoc-list-for-type-parts nil
102 "Like `semantic-symbol->name-assoc-list' for type parts.
103 Some tags that have children (see `semantic-tag-children-compatibility')
104 will want to define the names of classes of tags differently than at
105 the top level. For example, in C++, a Function may be called a
106 Method. In addition, there may be new types of tags that exist only
107 in classes, such as protection labels.")
108 (make-variable-buffer-local 'semantic-symbol->name-assoc-list-for-type-parts)
110 (defvar semantic-case-fold nil
111 "Value for `case-fold-search' when parsing.")
112 (make-variable-buffer-local 'semantic-case-fold)
114 (defvar semantic-expand-nonterminal nil
115 "Function to call for each nonterminal production.
116 Return a list of non-terminals derived from the first argument, or nil
117 if it does not need to be expanded.
118 Languages with compound definitions should use this function to expand
119 from one compound symbol into several. For example, in C the definition
120 int a, b;
121 is easily parsed into one tag. This function should take this
122 compound tag and turn it into two tags, one for A, and the other for B.")
123 (make-variable-buffer-local 'semantic-expand-nonterminal)
125 (defvar semantic--buffer-cache nil
126 "A cache of the fully parsed buffer.
127 If no significant changes have been made (based on the state) then
128 this is returned instead of re-parsing the buffer.
130 DO NOT USE THIS VARIABLE IN PROGRAMS.
132 If you need a tag list, use `semantic-fetch-tags'. If you need the
133 cached 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
137 'semantic--buffer-cache "23.2")
139 (defvar semantic-unmatched-syntax-cache nil
140 "A cached copy of unmatched syntax tokens.")
141 (make-variable-buffer-local 'semantic-unmatched-syntax-cache)
143 (defvar semantic-unmatched-syntax-cache-check nil
144 "Non-nil if the unmatched syntax cache is out of date.
145 This is tracked with `semantic-change-function'.")
146 (make-variable-buffer-local 'semantic-unmatched-syntax-cache-check)
148 (defvar semantic-edits-are-safe nil
149 "When non-nil, modifications do not require a reparse.
150 This prevents tags from being marked dirty, and it prevents top level
151 edits from causing a cache check.
152 Use this when writing programs that could cause a full reparse, but
153 will not change the tag structure, such as adding or updating
154 `top-level' comments.")
156 (defvar semantic-unmatched-syntax-hook nil
157 "Hooks run when Semantic detects syntax not matched in a grammar.
158 Each individual piece of syntax (such as a symbol or punctuation
159 character) is called with this hook when it doesn't match in the
160 grammar, and multiple unmatched syntax elements are not grouped
161 together. Each hook is called with one argument, which is a list
162 of syntax 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.
165 The current buffer is the buffer these tokens are derived from.")
167 (defvar semantic--before-fetch-tags-hook nil
168 "Hooks run before a buffer is parsed for tags.
169 It is called before any request for tags is made via the function
170 `semantic-fetch-tags' by an application.
171 If any hook returns a nil value, the cached value is returned
172 immediately, even if it is empty.")
173 (semantic-varalias-obsolete 'semantic-before-toplevel-bovination-hook
174 'semantic--before-fetch-tags-hook "23.2")
176 (defvar semantic-after-toplevel-bovinate-hook nil
177 "Hooks run after a toplevel parse.
178 It is not run if the toplevel parse command is called, and buffer does
179 not need to be fully reparsed.
180 For language specific hooks, make sure you define this as a local hook.
182 This hook should not be used any more.
183 Use `semantic-after-toplevel-cache-change-hook' instead.")
184 (make-obsolete-variable 'semantic-after-toplevel-bovinate-hook nil "23.2")
186 (defvar semantic-after-toplevel-cache-change-hook nil
187 "Hooks run after the buffer tag list has changed.
188 This list will change when a buffer is reparsed, or when the tag list
189 in a buffer is cleared. It is *NOT* called if the current tag list is
190 partially reparsed.
192 Hook functions must take one argument, which is the new list of tags
193 associated with this buffer.
195 For language specific hooks, make sure you define this as a local hook.")
197 (defvar semantic-before-toplevel-cache-flush-hook nil
198 "Hooks run before the toplevel tag cache is flushed.
199 For language specific hooks, make sure you define this as a local
200 hook. This hook is called before a corresponding
201 `semantic-after-toplevel-cache-change-hook' which is also called
202 during a flush when the cache is given a new value of nil.")
204 (defcustom semantic-dump-parse nil
205 "When non-nil, dump parsing information."
206 :group 'semantic
207 :type 'boolean)
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)
213 (defvar semantic--completion-cache nil
214 "Internal variable used by `semantic-complete-symbol'.")
215 (make-variable-buffer-local 'semantic--completion-cache)
217 ;;; Parse tree state management API
219 (defvar semantic-parse-tree-state 'needs-rebuild
220 "State of the current parse tree.")
221 (make-variable-buffer-local 'semantic-parse-tree-state)
223 (defmacro semantic-parse-tree-unparseable ()
224 "Indicate that the current buffer is unparseable.
225 It is also true that the parse tree will need either updating or
226 a rebuild. This state will be changed when the user edits the buffer."
227 `(setq semantic-parse-tree-state 'unparseable))
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))
233 (defmacro semantic-parse-tree-set-needs-update ()
234 "Indicate that the current parse tree needs to be updated.
235 The parse tree can be updated by `semantic-parse-changes'."
236 `(setq semantic-parse-tree-state 'needs-update))
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))
242 (defmacro semantic-parse-tree-set-needs-rebuild ()
243 "Indicate that the current parse tree needs to be rebuilt.
244 The parse tree must be rebuilt by `semantic-parse-region'."
245 `(setq semantic-parse-tree-state 'needs-rebuild))
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))
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))
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))
259 ;;; Interfacing with the system
261 (defcustom semantic-inhibit-functions nil
262 "List of functions to call with no arguments before Semantic is setup.
263 If any of these functions returns non-nil, the current buffer is not
264 setup to use Semantic."
265 :group 'semantic
266 :type 'hook)
268 (defcustom semantic-new-buffer-setup-functions
269 '((c-mode . semantic-default-c-setup)
270 (c++-mode . semantic-default-c-setup)
271 (html-mode . semantic-default-html-setup)
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)
276 (srecode-template-mode . srecode-template-setup-parser)
277 (texinfo-mode . semantic-default-texi-setup)
278 (makefile-automake-mode . semantic-default-make-setup)
279 (makefile-gmake-mode . semantic-default-make-setup)
280 (makefile-makepp-mode . semantic-default-make-setup)
281 (makefile-bsdmake-mode . semantic-default-make-setup)
282 (makefile-imake-mode . semantic-default-make-setup)
283 (makefile-mode . semantic-default-make-setup))
284 "Alist of functions to call to set up Semantic parsing in the buffer.
285 Each element has the form (MODE . FN), where MODE is a value of
286 `major-mode' for the buffer and FN is the corresponding function
287 to call, with no arguments, to set up the parser.
289 These functions are called by `semantic-new-buffer-fcn', before
290 `semantic-inhibit-functions'."
291 :group 'semantic
292 :type '(alist :key-type symbol :value-type function))
294 (defvar semantic-init-hook nil
295 "Hook run when a buffer is initialized with a parsing table.")
297 (defvar semantic-init-mode-hook nil
298 "Hook run when a buffer of a particular mode is initialized.")
299 (make-variable-buffer-local 'semantic-init-mode-hook)
301 (defvar semantic-init-db-hook nil
302 "Hook run when a buffer is initialized with a parsing table for DBs.
303 This hook is for database functions which intend to swap in a tag table.
304 This guarantees that the DB will go before other modes that require
305 a parse of the buffer.")
307 (semantic-varalias-obsolete 'semantic-init-hooks
308 'semantic-init-hook "23.2")
309 (semantic-varalias-obsolete 'semantic-init-mode-hooks
310 'semantic-init-mode-hook "23.2")
311 (semantic-varalias-obsolete 'semantic-init-db-hooks
312 'semantic-init-db-hook "23.2")
314 (defsubst semantic-error-if-unparsed ()
315 "Raise an error if current buffer was not parsed by Semantic."
316 (unless semantic-new-buffer-fcn-was-run
317 (error "Buffer was not parsed by Semantic.")))
319 (defsubst semantic--umatched-syntax-needs-refresh-p ()
320 "Return non-nil if the unmatched syntax cache needs a refresh.
321 That is, if it is dirty or if the current parse tree isn't up to date."
322 (or semantic-unmatched-syntax-cache-check
323 (not (semantic-parse-tree-up-to-date-p))))
325 (defun semantic-new-buffer-fcn ()
326 "Setup the current buffer to use Semantic.
327 If the major mode is ready for Semantic, and no
328 `semantic-inhibit-functions' disabled it, the current buffer is setup
329 to use Semantic, and `semantic-init-hook' is run."
330 ;; In upstream Semantic, the parser setup functions are called from
331 ;; mode hooks. In the version bundled with Emacs, we do it here.
332 (let ((entry (assq major-mode semantic-new-buffer-setup-functions)))
333 (when entry
334 (funcall (cdr entry))))
335 ;; Do stuff if semantic was activated by a mode hook in this buffer,
336 ;; and not afterwards disabled.
337 (when (and semantic--parse-table
338 (not (semantic-active-p))
339 (not (run-hook-with-args-until-success
340 'semantic-inhibit-functions)))
341 ;; Make sure that if this buffer is cloned, our tags and overlays
342 ;; don't go along for the ride.
343 (add-hook 'clone-indirect-buffer-hook 'semantic-clear-toplevel-cache
344 nil t)
345 ;; Specify that this function has done its work. At this point
346 ;; we can consider that semantic is active in this buffer.
347 (setq semantic-new-buffer-fcn-was-run t)
348 ;; Here are some buffer local variables we can initialize ourselves
349 ;; of a mode does not choose to do so.
350 (semantic-lex-init)
351 ;; Force this buffer to have its cache refreshed.
352 (semantic-clear-toplevel-cache)
353 ;; Call DB hooks before regular init hooks
354 (run-hooks 'semantic-init-db-hook)
355 ;; Set up semantic modes
356 (run-hooks 'semantic-init-hook)
357 ;; Set up major-mode specific semantic modes
358 (run-hooks 'semantic-init-mode-hook)))
360 (defun semantic-fetch-tags-fast ()
361 "For use in a hook. When only a partial reparse is needed, reparse."
362 (condition-case nil
363 (if (semantic-parse-tree-needs-update-p)
364 (semantic-fetch-tags))
365 (error nil))
366 semantic--buffer-cache)
368 ;;; Parsing Commands
370 (eval-when-compile
371 (condition-case nil (require 'pp) (error nil)))
373 (defvar semantic-edebug nil
374 "When non-nil, activate the interactive parsing debugger.
375 Do not set this yourself. Call `semantic-debug'.")
377 (defsubst semantic-elapsed-time (start end)
378 "Copied from elp.el. Was `elp-elapsed-time'.
379 Arguments START and END bound the time being calculated."
380 (float-time (time-subtract end start)))
382 (defun bovinate (&optional clear)
383 "Parse the current buffer. Show output in a temp buffer.
384 Optional argument CLEAR will clear the cache before parsing.
385 If CLEAR is negative, it will do a full reparse, and also display
386 the output buffer."
387 (interactive "P")
388 (if clear (semantic-clear-toplevel-cache))
389 (if (eq clear '-) (setq clear -1))
390 (let* ((start (current-time))
391 (out (semantic-fetch-tags))
392 (end (current-time)))
393 (message "Retrieving tags took %.2f seconds."
394 (semantic-elapsed-time start end))
395 (when (or (null clear) (not (listp clear))
396 (and (numberp clear) (< 0 clear)))
397 (pop-to-buffer "*Parser Output*")
398 (require 'pp)
399 (erase-buffer)
400 (insert (pp-to-string out))
401 (goto-char (point-min)))))
403 ;;; Functions of the parser plug-in API
405 ;; Overload these functions to create new types of parsers.
407 (define-overloadable-function semantic-parse-stream (stream nonterminal)
408 "Parse STREAM, starting at the first NONTERMINAL rule.
409 For bovine and wisent based parsers, STREAM is from the output of
410 `semantic-lex', and NONTERMINAL is a rule in the appropriate language
411 specific rules file.
412 The default parser table used for bovine or wisent based parsers is
413 `semantic--parse-table'.
415 Must return a list: (STREAM TAGS) where STREAM is the unused elements
416 from STREAM, and TAGS is the list of semantic tags found; usually only
417 one tag is returned with the exception of compound statements.")
419 (define-overloadable-function semantic-parse-changes ()
420 "Reparse changes in the current buffer.
421 The list of changes are tracked as a series of overlays in the buffer.
422 When overloading this function, use `semantic-changes-in-region' to
423 analyze.")
425 (define-overloadable-function semantic-parse-region
426 (start end &optional nonterminal depth returnonerror)
427 "Parse the area between START and END, and return any tags found.
428 If END needs to be extended due to a lexical token being too large, it
429 will be silently ignored.
431 Optional arguments:
432 NONTERMINAL is the rule to start parsing at.
433 DEPTH specifies the lexical depth to descend for parsers that use
434 lexical analysis as their first step.
435 RETURNONERROR specifies that parsing should stop on the first
436 unmatched syntax encountered. When nil, parsing skips the syntax,
437 adding it to the unmatched syntax cache.
439 Must return a list of semantic tags which have been cooked
440 \(repositioned properly) but which DO NOT HAVE OVERLAYS associated
441 with them. When overloading this function, use `semantic--tag-expand'
442 to cook raw tags.")
444 (defun semantic-parse-region-default
445 (start end &optional nonterminal depth returnonerror)
446 "Parse the area between START and END, and return any tags found.
447 If END needs to be extended due to a lexical token being too large,
448 it will be silently ignored.
449 Optional arguments:
450 NONTERMINAL is the rule to start parsing at if it is known.
451 DEPTH specifies the lexical depth to scan.
452 RETURNONERROR specifies that parsing should end when encountering
453 unterminated syntax."
454 (when (or (null semantic--parse-table) (eq semantic--parse-table t))
455 ;; If there is no table, or it was set to t, then we are here by
456 ;; some other mistake. Do not throw an error deep in the parser.
457 (error "No support found to parse buffer %S" (buffer-name)))
458 (save-restriction
459 (widen)
460 (when (or (< end start) (> end (point-max)))
461 (error "Invalid parse region bounds %S, %S" start end))
462 (semantic-repeat-parse-whole-stream
463 (or (cdr (assq start semantic-lex-block-streams))
464 (semantic-lex start end depth))
465 nonterminal returnonerror)))
467 ;;; Parsing functions
469 (defun semantic-set-unmatched-syntax-cache (unmatched-syntax)
470 "Set the unmatched syntax cache.
471 Argument UNMATCHED-SYNTAX is the syntax to set into the cache."
472 ;; This function is not actually called by the main parse loop.
473 ;; This is intended for use by semanticdb.
474 (setq semantic-unmatched-syntax-cache unmatched-syntax
475 semantic-unmatched-syntax-cache-check nil)
476 ;; Refresh the display of unmatched syntax tokens if enabled
477 (run-hook-with-args 'semantic-unmatched-syntax-hook
478 semantic-unmatched-syntax-cache))
480 (defun semantic-clear-unmatched-syntax-cache ()
481 "Clear the cache of unmatched syntax tokens."
482 (setq semantic-unmatched-syntax-cache nil
483 semantic-unmatched-syntax-cache-check t))
485 (defun semantic-unmatched-syntax-tokens ()
486 "Return the list of unmatched syntax tokens."
487 ;; If the cache need refresh then do a full re-parse.
488 (if (semantic--umatched-syntax-needs-refresh-p)
489 ;; To avoid a recursive call, temporarily disable
490 ;; `semantic-unmatched-syntax-hook'.
491 (let (semantic-unmatched-syntax-hook)
492 (condition-case nil
493 (progn
494 (semantic-clear-toplevel-cache)
495 (semantic-fetch-tags))
496 (quit
497 (message "semantic-unmatched-syntax-tokens:\
498 parsing of buffer canceled"))
500 semantic-unmatched-syntax-cache)
502 (defun semantic-clear-toplevel-cache ()
503 "Clear the toplevel tag cache for the current buffer.
504 Clearing the cache will force a complete reparse next time a tag list
505 is requested."
506 (interactive)
507 (run-hooks 'semantic-before-toplevel-cache-flush-hook)
508 (setq semantic--buffer-cache nil)
509 (semantic-clear-unmatched-syntax-cache)
510 (semantic-clear-parser-warnings)
511 ;; Nuke all semantic overlays. This is faster than deleting based
512 ;; on our data structure.
513 (let ((l (semantic-overlay-lists)))
514 (mapc 'semantic-delete-overlay-maybe (car l))
515 (mapc 'semantic-delete-overlay-maybe (cdr l))
517 (semantic-parse-tree-set-needs-rebuild)
518 ;; Remove this hook which tracks if a buffer is up to date or not.
519 (remove-hook 'after-change-functions 'semantic-change-function t)
520 ;; Old model. Delete someday.
521 ;;(run-hooks 'semantic-after-toplevel-bovinate-hook)
523 (run-hook-with-args 'semantic-after-toplevel-cache-change-hook
524 semantic--buffer-cache)
526 (setq semantic--completion-cache nil))
528 (defvar semantic-bovinate-nonterminal-check-obarray)
530 (defun semantic--set-buffer-cache (tagtable)
531 "Set the toplevel tag cache to TAGTABLE."
532 (setq semantic--buffer-cache tagtable
533 semantic-unmatched-syntax-cache-check nil)
534 ;; This is specific to the bovine parser.
535 (set (make-local-variable 'semantic-bovinate-nonterminal-check-obarray)
536 nil)
537 (semantic-parse-tree-set-up-to-date)
538 (semantic-make-local-hook 'after-change-functions)
539 (add-hook 'after-change-functions 'semantic-change-function nil t)
540 (run-hook-with-args 'semantic-after-toplevel-cache-change-hook
541 semantic--buffer-cache)
542 (setq semantic--completion-cache nil)
543 ;; Refresh the display of unmatched syntax tokens if enabled
544 (run-hook-with-args 'semantic-unmatched-syntax-hook
545 semantic-unmatched-syntax-cache)
546 ;; Old Semantic 1.3 hook API. Maybe useful forever?
547 (run-hooks 'semantic-after-toplevel-bovinate-hook)
550 (defvar semantic-working-type 'percent
551 "The type of working message to use when parsing.
552 'percent means we are doing a linear parse through the buffer.
553 'dynamic means we are reparsing specific tags.")
554 (semantic-varalias-obsolete 'semantic-bovination-working-type
555 'semantic-working-type "23.2")
557 (defvar semantic-minimum-working-buffer-size (* 1024 5)
558 "The minimum size of a buffer before working messages are displayed.
559 Buffers smaller than this will parse silently.
560 Buffers larger than this will display the working progress bar.")
562 (defsubst semantic-parser-working-message (&optional arg)
563 "Return the message string displayed while parsing.
564 If optional argument ARG is non-nil it is appended to the message
565 string."
566 (concat "Parsing"
567 (if arg (format " %s" arg))
568 (if semantic-parser-name (format " (%s)" semantic-parser-name))
569 "..."))
571 ;;; Application Parser Entry Points
573 ;; The best way to call the parser from programs is via
574 ;; `semantic-fetch-tags'. This, in turn, uses other internal
575 ;; API functions which plug-in parsers can take advantage of.
576 (defvar semantic-parser-warnings)
578 (defun semantic-fetch-tags ()
579 "Fetch semantic tags from the current buffer.
580 If the buffer cache is up to date, return that.
581 If the buffer cache is out of date, attempt an incremental reparse.
582 If the buffer has not been parsed before, or if the incremental reparse
583 fails, then parse the entire buffer.
584 If a lexical error had been previously discovered and the buffer
585 was marked unparseable, then do nothing, and return the cache."
586 (and
587 ;; Is this a semantic enabled buffer?
588 (semantic-active-p)
589 ;; Application hooks say the buffer is safe for parsing
590 (run-hook-with-args-until-failure
591 'semantic-before-toplevel-bovination-hook)
592 (run-hook-with-args-until-failure
593 'semantic--before-fetch-tags-hook)
594 ;; If the buffer was previously marked unparseable,
595 ;; then don't waste our time.
596 (not (semantic-parse-tree-unparseable-p))
597 ;; The parse tree actually needs to be refreshed
598 (not (semantic-parse-tree-up-to-date-p))
599 ;; So do it!
600 (let* ((gc-cons-threshold (max gc-cons-threshold 10000000))
601 (semantic-lex-block-streams nil)
602 (res nil))
603 (garbage-collect)
604 (cond
606 ;; Try the incremental parser to do a fast update.
607 ((semantic-parse-tree-needs-update-p)
608 (setq res (semantic-parse-changes))
609 (if (semantic-parse-tree-needs-rebuild-p)
610 ;; If the partial reparse fails, jump to a full reparse.
611 (semantic-fetch-tags)
612 ;; Clear the cache of unmatched syntax tokens
614 ;; NOTE TO SELF:
616 ;; Move this into the incremental parser. This is a bug.
618 (semantic-clear-unmatched-syntax-cache)
619 (run-hook-with-args ;; Let hooks know the updated tags
620 'semantic-after-partial-cache-change-hook res))
621 (setq semantic--completion-cache nil))
623 ;; Parse the whole system.
624 ((semantic-parse-tree-needs-rebuild-p)
625 ;; Use Emacs's built-in progress-reporter (only interactive).
626 (if noninteractive
627 (setq res (semantic-parse-region (point-min) (point-max)))
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)))
635 (if semantic--progress-reporter
636 (progress-reporter-done semantic--progress-reporter))))
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 ))))
650 ;; Always return the current parse tree.
651 semantic--buffer-cache)
653 (defun semantic-refresh-tags-safe ()
654 "Refresh the current buffer's tags safely.
656 Return non-nil if the refresh was successful.
657 Return nil if there is some sort of syntax error preventing a reparse.
659 Does nothing if the current buffer doesn't need reparsing."
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)
673 (let* ((inhibit-quit nil)
674 (lexically-safe t)
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 ;; probably due to unterminated lists or something like that.
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))
692 ;; Return if we are lexically safe
693 lexically-safe))))
695 (defun semantic-bovinate-toplevel (&optional ignored)
696 "Backward compatibility function."
697 (semantic-fetch-tags))
698 (make-obsolete 'semantic-bovinate-toplevel 'semantic-fetch-tags "23.2")
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.
705 (defsubst semantic-fetch-available-tags ()
706 "Fetch available semantic tags from the current buffer.
707 That is, return tags currently in the cache without parsing the
708 current buffer.
709 Parse operations happen asynchronously when needed on Emacs idle time.
710 Use the `semantic-after-toplevel-cache-change-hook' and
711 `semantic-after-partial-cache-change-hook' hooks to synchronize with
712 new tags when they become available."
713 semantic--buffer-cache)
715 ;;; Iterative parser helper function
717 ;; Iterative parsers are better than rule-based iterative functions
718 ;; in that they can handle obscure errors more cleanly.
720 ;; `semantic-repeat-parse-whole-stream' abstracts this action for
721 ;; other parser centric routines.
723 (defun semantic-repeat-parse-whole-stream
724 (stream nonterm &optional returnonerror)
725 "Iteratively parse the entire stream STREAM starting with NONTERM.
726 Optional argument RETURNONERROR indicates that the parser should exit
727 with the current results on a parse error.
728 This 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 result tag))
753 ;; No error in this case, a purposeful nil means don't
754 ;; store anything.
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))
763 ;; Designated to ignore.
764 (setq stream (car nontermsym))
765 (if stream
766 ;; Use Emacs's built-in progress reporter:
767 (and (boundp 'semantic--progress-reporter)
768 semantic--progress-reporter
769 (eq semantic-working-type 'percent)
770 (progress-reporter-update
771 semantic--progress-reporter
772 (floor (* 100.0 (semantic-lex-token-start (car stream)))
773 (point-max))))))
774 result))
776 ;;; Parsing Warnings:
778 ;; Parsing a buffer may result in non-critical things that we should
779 ;; alert the user to without interrupting the normal flow.
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)
787 (defun semantic-clear-parser-warnings ()
788 "Clear the current list of parser warnings for this buffer."
789 (setq semantic-parser-warnings nil))
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)))
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.")))
811 ;;; Compatibility:
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.
817 (defsubst semantic-bovinate-region-until-error
818 (start end nonterm &optional depth)
819 "NOTE: Use `semantic-parse-region' instead.
821 Bovinate between START and END starting with NONTERM.
822 Optional DEPTH specifies how many levels of parenthesis to enter.
823 This command will parse until an error is encountered, and return
824 the list of everything found until that moment.
825 This is meant for finding variable definitions at the beginning of
826 code blocks in methods. If `bovine-inner-scope' can also support
827 commands, use `semantic-bovinate-from-nonterminal-full'."
828 (semantic-parse-region start end nonterm depth t))
829 (make-obsolete 'semantic-bovinate-region-until-error
830 'semantic-parse-region "23.2")
832 (defsubst semantic-bovinate-from-nonterminal
833 (start end nonterm &optional depth length)
834 "Bovinate from within a nonterminal lambda from START to END.
835 Argument NONTERM is the nonterminal symbol to start with.
836 Optional argument DEPTH is the depth of lists to dive into. When used
837 in a `lambda' of a MATCH-LIST, there is no need to include a START and
838 END part.
839 Optional argument LENGTH specifies we are only interested in LENGTH
840 tokens."
841 (car-safe (cdr (semantic-parse-stream
842 (semantic-lex start end (or depth 1) length)
843 nonterm))))
845 (defsubst semantic-bovinate-from-nonterminal-full
846 (start end nonterm &optional depth)
847 "NOTE: Use `semantic-parse-region' instead.
849 Bovinate from within a nonterminal lambda from START to END.
850 Iterates until all the space between START and END is exhausted.
851 Argument NONTERM is the nonterminal symbol to start with.
852 If NONTERM is nil, use `bovine-block-toplevel'.
853 Optional argument DEPTH is the depth of lists to dive into.
854 When used in a `lambda' of a MATCH-LIST, there is no need to include
855 a START and END part."
856 (semantic-parse-region start end nonterm (or depth 1)))
857 (make-obsolete 'semantic-bovinate-from-nonterminal-full
858 'semantic-parse-region "23.2")
860 ;;; User interface
862 (defun semantic-force-refresh ()
863 "Force a full refresh of the current buffer's tags.
864 Throw away all the old tags, and recreate the tag database."
865 (interactive)
866 (semantic-clear-toplevel-cache)
867 (semantic-fetch-tags)
868 (message "Buffer reparsed."))
870 (defvar semantic-mode-map
871 (let ((map (make-sparse-keymap)))
872 ;; Key bindings:
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,m" 'semantic-complete-jump-local-members)
878 (define-key map "\C-c,g" 'semantic-symref-symbol)
879 (define-key map "\C-c,G" 'semantic-symref)
880 (define-key map "\C-c,p" 'senator-previous-tag)
881 (define-key map "\C-c,n" 'senator-next-tag)
882 (define-key map "\C-c,u" 'senator-go-to-up-reference)
883 (define-key map "\C-c, " 'semantic-complete-analyze-inline)
884 (define-key map "\C-c,\C-w" 'senator-kill-tag)
885 (define-key map "\C-c,\M-w" 'senator-copy-tag)
886 (define-key map "\C-c,\C-y" 'senator-yank-tag)
887 (define-key map "\C-c,r" 'senator-copy-tag-to-register)
888 (define-key map "\C-c,," 'semantic-force-refresh)
889 (define-key map [?\C-c ?, up] 'senator-transpose-tags-up)
890 (define-key map [?\C-c ?, down] 'senator-transpose-tags-down)
891 (define-key map "\C-c,l" 'semantic-analyze-possible-completions)
892 ;; This hack avoids showing the CEDET menu twice if ede-minor-mode
893 ;; and Semantic are both enabled. Is there a better way?
894 (define-key map [menu-bar cedet-menu]
895 (list 'menu-item "Development" cedet-menu-map
896 :enable (quote (not (and menu-bar-mode
897 (bound-and-true-p global-ede-mode))))))
898 ;; (define-key km "-" 'senator-fold-tag)
899 ;; (define-key km "+" 'senator-unfold-tag)
900 map))
902 ;; Activate the Semantic items in cedet-menu-map
903 (let ((navigate-menu (make-sparse-keymap "Navigate Tags"))
904 (edit-menu (make-sparse-keymap "Edit Tags")))
906 ;; Edit Tags submenu:
907 (define-key edit-menu [semantic-analyze-possible-completions]
908 '(menu-item "List Completions" semantic-analyze-possible-completions
909 :enable (semantic-active-p)
910 :help "Display a list of completions for the tag at point"))
911 (define-key edit-menu [semantic-complete-analyze-inline]
912 '(menu-item "Complete Tag Inline" semantic-complete-analyze-inline
913 :enable (semantic-active-p)
914 :help "Display inline completion for the tag at point"))
915 (define-key edit-menu [semantic-completion-separator]
916 '("--"))
917 (define-key edit-menu [senator-transpose-tags-down]
918 '(menu-item "Transpose Tags Down" senator-transpose-tags-down
919 :enable (and (semantic-active-p)
920 (semantic-current-tag))
921 :help "Transpose the current tag and the next tag"))
922 (define-key edit-menu [senator-transpose-tags-up]
923 '(menu-item "Transpose Tags Up" senator-transpose-tags-up
924 :enable (and (semantic-active-p)
925 (semantic-current-tag))
926 :help "Transpose the current tag and the previous tag"))
927 (define-key edit-menu [semantic-edit-separator]
928 '("--"))
929 (define-key edit-menu [senator-yank-tag]
930 '(menu-item "Yank Tag" senator-yank-tag
931 :enable (and (boundp 'senator-tag-ring)
932 (not (ring-empty-p senator-tag-ring)))
933 :help "Yank the head of the tag ring into the buffer"))
934 (define-key edit-menu [senator-copy-tag-to-register]
935 '(menu-item "Copy Tag To Register" senator-copy-tag-to-register
936 :enable (and (semantic-active-p)
937 (semantic-current-tag))
938 :help "Yank the head of the tag ring into the buffer"))
939 (define-key edit-menu [senator-copy-tag]
940 '(menu-item "Copy Tag" senator-copy-tag
941 :enable (and (semantic-active-p)
942 (semantic-current-tag))
943 :help "Copy the current tag to the tag ring"))
944 (define-key edit-menu [senator-kill-tag]
945 '(menu-item "Kill Tag" senator-kill-tag
946 :enable (and (semantic-active-p)
947 (semantic-current-tag))
948 :help "Kill the current tag, and copy it to the tag ring"))
950 ;; Navigate Tags submenu:
951 (define-key navigate-menu [senator-narrow-to-defun]
952 '(menu-item "Narrow to Tag" senator-narrow-to-defun
953 :enable (and (semantic-active-p)
954 (semantic-current-tag))
955 :help "Narrow the buffer to the bounds of the current tag"))
956 (define-key navigate-menu [semantic-narrow-to-defun-separator]
957 '("--"))
958 (define-key navigate-menu [semantic-symref-symbol]
959 '(menu-item "Find Tag References..." semantic-symref-symbol
960 :enable (semantic-active-p)
961 :help "Read a tag and list the references to it"))
962 (define-key navigate-menu [semantic-complete-jump]
963 '(menu-item "Find Tag Globally..." semantic-complete-jump
964 :enable (semantic-active-p)
965 :help "Read a tag name and find it in the current project"))
966 (define-key navigate-menu [semantic-complete-jump-local-members]
967 '(menu-item "Find Local Members ..." semantic-complete-jump-local-members
968 :enable (semantic-active-p)
969 :help "Read a tag name and find a local member with that name"))
970 (define-key navigate-menu [semantic-complete-jump-local]
971 '(menu-item "Find Tag in This Buffer..." semantic-complete-jump-local
972 :enable (semantic-active-p)
973 :help "Read a tag name and find it in this buffer"))
974 (define-key navigate-menu [semantic-navigation-separator]
975 '("--"))
976 (define-key navigate-menu [senator-go-to-up-reference]
977 '(menu-item "Parent Tag" senator-go-to-up-reference
978 :enable (semantic-active-p)
979 :help "Navigate up one reference by tag"))
980 (define-key navigate-menu [senator-next-tag]
981 '(menu-item "Next Tag" senator-next-tag
982 :enable (semantic-active-p)
983 :help "Go to the next tag"))
984 (define-key navigate-menu [senator-previous-tag]
985 '(menu-item "Previous Tag" senator-previous-tag
986 :enable (semantic-active-p)
987 :help "Go to the previous tag"))
989 ;; Top level menu items:
990 (define-key cedet-menu-map [semantic-force-refresh]
991 '(menu-item "Reparse Buffer" semantic-force-refresh
992 :help "Force a full reparse of the current buffer"
993 :visible semantic-mode
994 :enable (semantic-active-p)))
995 (define-key cedet-menu-map [semantic-edit-menu]
996 `(menu-item "Edit Tags" ,edit-menu
997 :visible semantic-mode))
998 (define-key cedet-menu-map [navigate-menu]
999 `(menu-item "Navigate Tags" ,navigate-menu
1000 :visible semantic-mode))
1001 (define-key cedet-menu-map [semantic-options-separator]
1002 '("--"))
1003 (define-key cedet-menu-map [global-semantic-highlight-func-mode]
1004 '(menu-item "Highlight Current Function" global-semantic-highlight-func-mode
1005 :help "Highlight the tag at point"
1006 :visible semantic-mode
1007 :button (:toggle . global-semantic-highlight-func-mode)))
1008 (define-key cedet-menu-map [global-semantic-stickyfunc-mode]
1009 '(menu-item "Stick Top Tag to Headerline" global-semantic-stickyfunc-mode
1010 :help "Stick the tag scrolled off the top of the buffer into the header line"
1011 :visible semantic-mode
1012 :button (:toggle . (bound-and-true-p
1013 global-semantic-stickyfunc-mode))))
1014 (define-key cedet-menu-map [global-semantic-decoration-mode]
1015 '(menu-item "Decorate Tags" global-semantic-decoration-mode
1016 :help "Decorate tags based on tag attributes"
1017 :visible semantic-mode
1018 :button (:toggle . (bound-and-true-p
1019 global-semantic-decoration-mode))))
1020 (define-key cedet-menu-map [global-semantic-idle-completions-mode]
1021 '(menu-item "Show Tag Completions" global-semantic-idle-completions-mode
1022 :help "Show tag completions when idle"
1023 :visible semantic-mode
1024 :enable global-semantic-idle-scheduler-mode
1025 :button (:toggle . global-semantic-idle-completions-mode)))
1026 (define-key cedet-menu-map [global-semantic-idle-summary-mode]
1027 '(menu-item "Show Tag Summaries" global-semantic-idle-summary-mode
1028 :help "Show tag summaries when idle"
1029 :visible semantic-mode
1030 :enable global-semantic-idle-scheduler-mode
1031 :button (:toggle . global-semantic-idle-summary-mode)))
1032 (define-key cedet-menu-map [global-semantic-idle-scheduler-mode]
1033 '(menu-item "Reparse When Idle" global-semantic-idle-scheduler-mode
1034 :help "Keep a buffer's parse tree up to date when idle"
1035 :visible semantic-mode
1036 :button (:toggle . global-semantic-idle-scheduler-mode)))
1037 (define-key cedet-menu-map [global-semanticdb-minor-mode]
1038 '(menu-item "Semantic Database" global-semanticdb-minor-mode
1039 :help "Store tag information in a database"
1040 :visible semantic-mode
1041 :button (:toggle . global-semanticdb-minor-mode))))
1043 ;; The `semantic-mode' command, in conjunction with the
1044 ;; `semantic-default-submodes' variable, toggles Semantic's various
1045 ;; auxiliary minor modes.
1047 (defvar semantic-load-system-cache-loaded nil
1048 "Non-nil when the Semantic system caches have been loaded.
1049 Prevent this load system from loading files in twice.")
1051 (defconst semantic-submode-list
1052 '(global-semantic-highlight-func-mode
1053 global-semantic-decoration-mode
1054 global-semantic-stickyfunc-mode
1055 global-semantic-idle-completions-mode
1056 global-semantic-idle-scheduler-mode
1057 global-semanticdb-minor-mode
1058 global-semantic-idle-summary-mode
1059 global-semantic-mru-bookmark-mode
1060 global-cedet-m3-minor-mode
1061 global-semantic-idle-local-symbol-highlight-mode
1062 global-semantic-highlight-edits-mode
1063 global-semantic-show-unmatched-syntax-mode
1064 global-semantic-show-parser-state-mode)
1065 "List of auxiliary minor modes in the Semantic package.")
1067 ;;;###autoload
1068 (defcustom semantic-default-submodes
1069 '(global-semantic-idle-scheduler-mode global-semanticdb-minor-mode)
1070 "List of auxiliary Semantic minor modes enabled by `semantic-mode'.
1071 The possible elements of this list include the following:
1073 `global-semanticdb-minor-mode' - Maintain tag database.
1074 `global-semantic-idle-scheduler-mode' - Reparse buffer when idle.
1075 `global-semantic-idle-summary-mode' - Show summary of tag at point.
1076 `global-semantic-idle-completions-mode' - Show completions when idle.
1077 `global-semantic-decoration-mode' - Additional tag decorations.
1078 `global-semantic-highlight-func-mode' - Highlight the current tag.
1079 `global-semantic-stickyfunc-mode' - Show current fun in header line.
1080 `global-semantic-mru-bookmark-mode' - Provide `switch-to-buffer'-like
1081 keybinding for tag names.
1082 `global-cedet-m3-minor-mode' - A mouse 3 context menu.
1083 `global-semantic-idle-local-symbol-highlight-mode' - Highlight references
1084 of the symbol under point.
1085 The following modes are more targeted at people who want to see
1086 some internal information of the semantic parser in action:
1087 `global-semantic-highlight-edits-mode' - Visualize incremental parser by
1088 highlighting not-yet parsed changes.
1089 `global-semantic-show-unmatched-syntax-mode' - Highlight unmatched lexical
1090 syntax tokens.
1091 `global-semantic-show-parser-state-mode' - Display the parser cache state."
1092 :group 'semantic
1093 :type `(set ,@(mapcar (lambda (c) (list 'const c))
1094 semantic-submode-list)))
1096 ;;;###autoload
1097 (define-minor-mode semantic-mode
1098 "Toggle parser features (Semantic mode).
1099 With a prefix argument ARG, enable Semantic mode if ARG is
1100 positive, and disable it otherwise. If called from Lisp, enable
1101 Semantic mode if ARG is omitted or nil.
1103 In Semantic mode, Emacs parses the buffers you visit for their
1104 semantic content. This information is used by a variety of
1105 auxiliary minor modes, listed in `semantic-default-submodes';
1106 all the minor modes in this list are also enabled when you enable
1107 Semantic mode.
1109 \\{semantic-mode-map}"
1110 :global t
1111 :group 'semantic
1112 (if semantic-mode
1113 ;; Turn on Semantic mode
1114 (progn
1115 ;; Enable all the global auxiliary minor modes in
1116 ;; `semantic-submode-list'.
1117 (dolist (mode semantic-submode-list)
1118 (if (memq mode semantic-default-submodes)
1119 (funcall mode 1)))
1120 (unless semantic-load-system-cache-loaded
1121 (setq semantic-load-system-cache-loaded t)
1122 (when (and (boundp 'semanticdb-default-system-save-directory)
1123 (stringp semanticdb-default-system-save-directory)
1124 (file-exists-p semanticdb-default-system-save-directory))
1125 (require 'semantic/db-ebrowse)
1126 (semanticdb-load-ebrowse-caches)))
1127 (add-hook 'mode-local-init-hook 'semantic-new-buffer-fcn)
1128 ;; Add semantic-ia-complete-symbol to
1129 ;; completion-at-point-functions, so that it is run from
1130 ;; M-TAB.
1132 ;; Note: The first entry added is the last entry run, so the
1133 ;; most specific entry should be last.
1134 (add-hook 'completion-at-point-functions
1135 'semantic-analyze-nolongprefix-completion-at-point-function)
1136 (add-hook 'completion-at-point-functions
1137 'semantic-analyze-notc-completion-at-point-function)
1138 (add-hook 'completion-at-point-functions
1139 'semantic-analyze-completion-at-point-function)
1141 (if global-ede-mode
1142 (define-key cedet-menu-map [cedet-menu-separator] '("--")))
1143 (dolist (b (buffer-list))
1144 (with-current-buffer b
1145 (semantic-new-buffer-fcn))))
1146 ;; Disable Semantic features. Removing everything Semantic has
1147 ;; introduced in the buffer is pretty much futile, but we have to
1148 ;; clean the hooks and delete Semantic-related overlays, so that
1149 ;; Semantic can be re-activated cleanly.
1150 (remove-hook 'mode-local-init-hook 'semantic-new-buffer-fcn)
1151 (remove-hook 'completion-at-point-functions
1152 'semantic-analyze-completion-at-point-function)
1153 (remove-hook 'completion-at-point-functions
1154 'semantic-analyze-notc-completion-at-point-function)
1155 (remove-hook 'completion-at-point-functions
1156 'semantic-analyze-nolongprefix-completion-at-point-function)
1158 (remove-hook 'after-change-functions
1159 'semantic-change-function)
1160 (define-key cedet-menu-map [cedet-menu-separator] nil)
1161 (define-key cedet-menu-map [semantic-options-separator] nil)
1162 ;; FIXME: handle semanticdb-load-ebrowse-caches
1163 (dolist (mode semantic-submode-list)
1164 (if (and (boundp mode) (eval mode))
1165 (funcall mode -1)))
1166 ;; Unlink buffer and clear cache
1167 (semantic--tag-unlink-cache-from-buffer)
1168 (setq semantic--buffer-cache nil)
1169 ;; Make sure we run the setup function if Semantic gets
1170 ;; re-activated.
1171 (setq semantic-new-buffer-fcn-was-run nil)))
1173 ;;; Completion At Point functions
1174 (defun semantic-analyze-completion-at-point-function ()
1175 "Return possible analysis completions at point.
1176 The completions provided are via `semantic-analyze-possible-completions'.
1177 This function can be used by `completion-at-point-functions'."
1178 (when (semantic-active-p)
1179 (let* ((ctxt (semantic-analyze-current-context))
1180 (possible (semantic-analyze-possible-completions ctxt)))
1182 ;; The return from this is either:
1183 ;; nil - not applicable here.
1184 ;; A list: (START END COLLECTION . PROPS)
1185 (when possible
1186 (list (car (oref ctxt bounds))
1187 (cdr (oref ctxt bounds))
1188 possible))
1191 (defun semantic-analyze-notc-completion-at-point-function ()
1192 "Return possible analysis completions at point.
1193 The completions provided are via `semantic-analyze-possible-completions',
1194 but with the 'no-tc option passed in, which means constraints based
1195 on what is being assigned to are ignored.
1196 This function can be used by `completion-at-point-functions'."
1197 (when (semantic-active-p)
1198 (let* ((ctxt (semantic-analyze-current-context))
1199 (possible (semantic-analyze-possible-completions ctxt 'no-tc)))
1201 (when possible
1202 (list (car (oref ctxt bounds))
1203 (cdr (oref ctxt bounds))
1204 possible))
1207 (defun semantic-analyze-nolongprefix-completion-at-point-function ()
1208 "Return possible analysis completions at point.
1209 The completions provided are via `semantic-analyze-possible-completions',
1210 but with the 'no-tc and 'no-longprefix option passed in, which means
1211 constraints resulting in a long multi-symbol dereference are ignored.
1212 This function can be used by `completion-at-point-functions'."
1213 (when (semantic-active-p)
1214 (let* ((ctxt (semantic-analyze-current-context))
1215 (possible (semantic-analyze-possible-completions
1216 ctxt 'no-tc 'no-longprefix)))
1218 (when possible
1219 (list (car (oref ctxt bounds))
1220 (cdr (oref ctxt bounds))
1221 possible))
1224 ;;; Autoload some functions that are not in semantic/loaddefs
1226 (autoload 'global-semantic-idle-completions-mode "semantic/idle"
1227 "Toggle global use of `semantic-idle-completions-mode'.
1228 If ARG is positive, enable, if it is negative, disable.
1229 If ARG is nil, then toggle." t nil)
1231 (autoload 'semantic-idle-completions-mode "semantic/idle"
1232 "Display a list of possible completions in a tooltip.
1234 This is a minor mode which performs actions during idle time.
1235 With prefix argument ARG, turn on if positive, otherwise off. The
1236 minor mode can be turned on only if semantic feature is available and
1237 the current buffer was set up for parsing. Return non-nil if the
1238 minor mode is enabled." t nil)
1240 (autoload 'global-semantic-idle-summary-mode "semantic/idle"
1241 "Toggle global use of `semantic-idle-summary-mode'.
1242 If ARG is positive, enable, if it is negative, disable.
1243 If ARG is nil, then toggle." t nil)
1245 (autoload 'semantic-idle-summary-mode "semantic/idle"
1246 "Display a tag summary of the lexical token under the cursor.
1247 Call `semantic-idle-summary-current-symbol-info' for getting the
1248 current tag to display information.
1250 This is a minor mode which performs actions during idle time.
1251 With prefix argument ARG, turn on if positive, otherwise off. The
1252 minor mode can be turned on only if semantic feature is available and
1253 the current buffer was set up for parsing. Return non-nil if the
1254 minor mode is enabled." t nil)
1256 (autoload 'global-semantic-idle-local-symbol-highlight-mode "semantic/idle"
1257 "Highlight the tag and symbol references of the symbol under point.
1258 Call `semantic-analyze-current-context' to find the reference tag.
1259 Call `semantic-symref-hits-in-region' to identify local references." t nil)
1261 (autoload 'srecode-template-setup-parser "srecode/srecode-template"
1262 "Set up buffer for parsing SRecode template files." t nil)
1264 (provide 'semantic)
1266 ;; Semantic-util is a part of the semantic API. Include it last
1267 ;; because it depends on semantic.
1268 (require 'semantic/util)
1270 ;; (require 'semantic/load)
1272 ;;; semantic.el ends here