Convert consecutive FSF copyright years to ranges.
[bpt/emacs.git] / lisp / cedet / semantic.el
index 9848d5d..c899988 100644 (file)
@@ -1,10 +1,10 @@
 ;;; semantic.el --- Semantic buffer evaluator.
 
-;;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
-;;; 2007, 2008, 2009 Free Software Foundation, Inc.
+;; Copyright (C) 1999-2011  Free Software Foundation, Inc.
 
 ;; Author: Eric M. Ludlam <zappo@gnu.org>
-;; Keywords: syntax
+;; Keywords: syntax tools
+;; Version: 2.0
 
 ;; This file is part of GNU Emacs.
 
 ;;
 ;; API for providing the semantic content of a buffer.
 ;;
-;; The semantic API provides an interface to a series of different parser
+;; The Semantic API provides an interface to a series of different parser
 ;; implementations.  Each parser outputs a parse tree in a similar format
 ;; designed to handle typical functional and object oriented languages.
+;;
+;; To enable Semantic, turn on `semantic-mode', a global minor mode
+;; (M-x semantic-mode RET, or "Source Code Parsers" from the Tools
+;; menu).  To enable it at startup, put (semantic-mode 1) in your init
+;; file.
 
-(require 'assoc)
+(require 'cedet)
 (require 'semantic/tag)
 (require 'semantic/lex)
 
-(defvar semantic-version "2.0pre7"
+(defvar semantic-version "2.0"
   "Current version of Semantic.")
 
 (declare-function inversion-test "inversion")
 (declare-function semanticdb-load-ebrowse-caches "semantic/db-ebrowse")
 
 (defun semantic-require-version (major minor &optional beta)
-  "Non-nil if this version of semantic does not satisfy a specific version.
+  "Non-nil if this version of Semantic does not satisfy a specific version.
 Arguments can be:
 
   (MAJOR MINOR &optional BETA)
@@ -58,7 +63,7 @@ introduced."
 
 (defgroup semantic nil
   "Parser Generator and parser framework."
-  :group 'lisp)
+  :group 'tools)
 
 (defgroup semantic-faces nil
   "Faces used for Semantic enabled tools."
@@ -77,7 +82,7 @@ This variable is for internal use only, and its content depends on the
 external parser used.")
 (make-variable-buffer-local 'semantic--parse-table)
 (semantic-varalias-obsolete 'semantic-toplevel-bovine-table
-                           'semantic--parse-table)
+                           'semantic--parse-table "23.2")
 
 (defvar semantic-symbol->name-assoc-list
   '((type     . "Types")
@@ -125,18 +130,18 @@ this is returned instead of re-parsing the buffer.
   DO NOT USE THIS VARIABLE IN PROGRAMS.
 
 If you need a tag list, use `semantic-fetch-tags'.  If you need the
-cached values for some reason, chances are you can, add a hook to
+cached values for some reason, chances are you can add a hook to
 `semantic-after-toplevel-cache-change-hook'.")
 (make-variable-buffer-local 'semantic--buffer-cache)
 (semantic-varalias-obsolete 'semantic-toplevel-bovine-cache
-                           'semantic--buffer-cache)
+                           'semantic--buffer-cache "23.2")
 
 (defvar semantic-unmatched-syntax-cache nil
   "A cached copy of unmatched syntax tokens.")
 (make-variable-buffer-local 'semantic-unmatched-syntax-cache)
 
 (defvar semantic-unmatched-syntax-cache-check nil
-  "Non nil if the unmatched syntax cache is out of date.
+  "Non-nil if the unmatched syntax cache is out of date.
 This is tracked with `semantic-change-function'.")
 (make-variable-buffer-local 'semantic-unmatched-syntax-cache-check)
 
@@ -149,24 +154,24 @@ will not change the tag structure, such as adding or updating
 `top-level' comments.")
 
 (defvar semantic-unmatched-syntax-hook nil
-  "Hooks run when semantic detects syntax not matched in a grammar.
+  "Hooks run when Semantic detects syntax not matched in a grammar.
 Each individual piece of syntax (such as a symbol or punctuation
 character) is called with this hook when it doesn't match in the
 grammar, and multiple unmatched syntax elements are not grouped
-together.  Each hook is called with one argument, which is a list of
-syntax tokens created by the semantic lexer.  Use the functions
+together.  Each hook is called with one argument, which is a list
+of syntax tokens created by the semantic lexer.  Use the functions
 `semantic-lex-token-start', `semantic-lex-token-end' and
-`semantic-lex-token-text' to get information about these tokens.  The
-current buffer is the buffer these tokens are derived from.")
+`semantic-lex-token-text' to get information about these tokens.
+The current buffer is the buffer these tokens are derived from.")
 
 (defvar semantic--before-fetch-tags-hook nil
-  "Hooks run before a buffer is parses for tags.
+  "Hooks run before a buffer is parsed for tags.
 It is called before any request for tags is made via the function
 `semantic-fetch-tags' by an application.
 If any hook returns a nil value, the cached value is returned
 immediately, even if it is empty.")
 (semantic-varalias-obsolete 'semantic-before-toplevel-bovination-hook
-                           'semantic--before-fetch-tags-hook)
+                           'semantic--before-fetch-tags-hook "23.2")
 
 (defvar semantic-after-toplevel-bovinate-hook nil
   "Hooks run after a toplevel parse.
@@ -176,7 +181,7 @@ For language specific hooks, make sure you define this as a local hook.
 
 This hook should not be used any more.
 Use `semantic-after-toplevel-cache-change-hook' instead.")
-(make-obsolete-variable 'semantic-after-toplevel-bovinate-hook nil)
+(make-obsolete-variable 'semantic-after-toplevel-bovinate-hook nil "23.2")
 
 (defvar semantic-after-toplevel-cache-change-hook nil
   "Hooks run after the buffer tag list has changed.
@@ -204,6 +209,10 @@ during a flush when the cache is given a new value of nil.")
 (defvar semantic-parser-name "LL"
   "Optional name of the parser used to parse input stream.")
 (make-variable-buffer-local 'semantic-parser-name)
+
+(defvar semantic--completion-cache nil
+  "Internal variable used by `semantic-complete-symbol'.")
+(make-variable-buffer-local 'semantic--completion-cache)
 \f
 ;;; Parse tree state management API
 ;;
@@ -256,6 +265,31 @@ setup to use Semantic."
   :group 'semantic
   :type 'hook)
 
+(defcustom semantic-new-buffer-setup-functions
+  '((c-mode . semantic-default-c-setup)
+    (c++-mode . semantic-default-c-setup)
+    (html-mode . semantic-default-html-setup)
+    (java-mode . wisent-java-default-setup)
+    (js-mode . wisent-javascript-setup-parser)
+    (python-mode . wisent-python-default-setup)
+    (scheme-mode . semantic-default-scheme-setup)
+    (srecode-template-mode . srecode-template-setup-parser)
+    (makefile-automake-mode . semantic-default-make-setup)
+    (makefile-gmake-mode . semantic-default-make-setup)
+    (makefile-makepp-mode . semantic-default-make-setup)
+    (makefile-bsdmake-mode . semantic-default-make-setup)
+    (makefile-imake-mode . semantic-default-make-setup)
+    (makefile-mode . semantic-default-make-setup))
+  "Alist of functions to call to set up Semantic parsing in the buffer.
+Each element has the form (MODE . FN), where MODE is a value of
+`major-mode' for the buffer and FN is the corresponding function
+to call, with no arguments, to set up the parser.
+
+These functions are called by `semantic-new-buffer-fcn', before
+`semantic-inhibit-functions'."
+  :group 'semantic
+  :type '(alist :key-type symbol :value-type function))
+
 (defvar semantic-init-hook nil
   "Hook run when a buffer is initialized with a parsing table.")
 
@@ -270,14 +304,14 @@ This guarantees that the DB will go before other modes that require
 a parse of the buffer.")
 
 (semantic-varalias-obsolete 'semantic-init-hooks
-                           'semantic-init-hook)
+                           'semantic-init-hook "23.2")
 (semantic-varalias-obsolete 'semantic-init-mode-hooks
-                           'semantic-init-mode-hook)
+                           'semantic-init-mode-hook "23.2")
 (semantic-varalias-obsolete 'semantic-init-db-hooks
-                           'semantic-init-db-hook)
+                           'semantic-init-db-hook "23.2")
 
 (defvar semantic-new-buffer-fcn-was-run nil
-  "Non nil after `semantic-new-buffer-fcn' has been executed.")
+  "Non-nil after `semantic-new-buffer-fcn' has been executed.")
 (make-variable-buffer-local 'semantic-new-buffer-fcn-was-run)
 
 (defsubst semantic-active-p ()
@@ -286,7 +320,7 @@ a parse of the buffer.")
 
 (defsubst semantic--umatched-syntax-needs-refresh-p  ()
   "Return non-nil if the unmatched syntax cache needs a refresh.
-That is if it is dirty or if the current parse tree isn't up to date."
+That is, if it is dirty or if the current parse tree isn't up to date."
   (or semantic-unmatched-syntax-cache-check
       (not (semantic-parse-tree-up-to-date-p))))
 
@@ -295,6 +329,11 @@ That is if it is dirty or if the current parse tree isn't up to date."
 If the major mode is ready for Semantic, and no
 `semantic-inhibit-functions' disabled it, the current buffer is setup
 to use Semantic, and `semantic-init-hook' is run."
+  ;; In upstream Semantic, the parser setup functions are called from
+  ;; mode hooks.  In the version bundled with Emacs, we do it here.
+  (let ((entry (assq major-mode semantic-new-buffer-setup-functions)))
+    (when entry
+      (funcall (cdr entry))))
   ;; Do stuff if semantic was activated by a mode hook in this buffer,
   ;; and not afterwards disabled.
   (when (and semantic--parse-table
@@ -338,7 +377,7 @@ to use Semantic, and `semantic-init-hook' is run."
 Do not set this yourself.  Call `semantic-debug'.")
 
 (defun semantic-elapsed-time (start end)
-  "Copied from elp.el.  Was elp-elapsed-time.
+  "Copied from elp.el.  Was `elp-elapsed-time'.
 Argument START and END bound the time being calculated."
   (+ (* (- (car end) (car start)) 65536.0)
      (- (car (cdr end)) (car (cdr start)))
@@ -371,14 +410,14 @@ the output buffer."
 (define-overloadable-function semantic-parse-stream (stream nonterminal)
   "Parse STREAM, starting at the first NONTERMINAL rule.
 For bovine and wisent based parsers, STREAM is from the output of
-`semantic-lex', and NONTERMINAL is a rule in the apropriate language
+`semantic-lex', and NONTERMINAL is a rule in the appropriate language
 specific rules file.
 The default parser table used for bovine or wisent based parsers is
 `semantic--parse-table'.
 
 Must return a list: (STREAM TAGS) where STREAM is the unused elements
-from STREAM, and TAGS is the list of semantic tags found, usually only
-one tag is returned with the exception of compound statements")
+from STREAM, and TAGS is the list of semantic tags found; usually only
+one tag is returned with the exception of compound statements.")
 
 (define-overloadable-function semantic-parse-changes ()
   "Reparse changes in the current buffer.
@@ -394,7 +433,7 @@ will be silently ignored.
 
 Optional arguments:
 NONTERMINAL is the rule to start parsing at.
-DEPTH specifies the lexical depth to decend for parser that use
+DEPTH specifies the lexical depth to descend for parser that use
 lexical analysis as their first step.
 RETURNONERROR specifies that parsing should stop on the first
 unmatched syntax encountered.  When nil, parsing skips the syntax,
@@ -408,8 +447,8 @@ to cook raw tags.")
 (defun semantic-parse-region-default
   (start end &optional nonterminal depth returnonerror)
   "Parse the area between START and END, and return any tags found.
-If END needs to be extended due to a lexical token being too large, it
-will be silently ignored.
+If END needs to be extended due to a lexical token being too large,
+it will be silently ignored.
 Optional arguments:
 NONTERMINAL is the rule to start parsing at if it is known.
 DEPTH specifies the lexical depth to scan.
@@ -487,12 +526,13 @@ is requested."
 
   (run-hook-with-args 'semantic-after-toplevel-cache-change-hook
                      semantic--buffer-cache)
-  )
+
+  (setq semantic--completion-cache nil))
 
 (defvar semantic-bovinate-nonterminal-check-obarray)
 
 (defun semantic--set-buffer-cache (tagtable)
-  "Set the toplevel cache cache to TAGTABLE."
+  "Set the toplevel tag cache to TAGTABLE."
   (setq semantic--buffer-cache tagtable
         semantic-unmatched-syntax-cache-check nil)
   ;; This is specific to the bovine parser.
@@ -503,6 +543,7 @@ is requested."
   (add-hook 'after-change-functions 'semantic-change-function nil t)
   (run-hook-with-args 'semantic-after-toplevel-cache-change-hook
                      semantic--buffer-cache)
+  (setq semantic--completion-cache nil)
   ;; Refresh the display of unmatched syntax tokens if enabled
   (run-hook-with-args 'semantic-unmatched-syntax-hook
                       semantic-unmatched-syntax-cache)
@@ -515,12 +556,12 @@ is requested."
 'percent means we are doing a linear parse through the buffer.
 'dynamic means we are reparsing specific tags.")
 (semantic-varalias-obsolete 'semantic-bovination-working-type
-                           'semantic-working-type)
+                           'semantic-working-type "23.2")
 
 (defvar semantic-minimum-working-buffer-size (* 1024 5)
   "*The minimum size of a buffer before working messages are displayed.
-Buffers smaller than will parse silently.
-Bufferse larger than this will display the working progress bar.")
+Buffers smaller than this will parse silently.
+Buffers larger than this will display the working progress bar.")
 
 (defsubst semantic-parser-working-message (&optional arg)
   "Return the message string displayed while parsing.
@@ -543,7 +584,7 @@ If the buffer cache is up to date, return that.
 If the buffer cache is out of date, attempt an incremental reparse.
 If the buffer has not been parsed before, or if the incremental reparse
 fails, then parse the entire buffer.
-If a lexcial error had been previously discovered and the buffer
+If a lexical error had been previously discovered and the buffer
 was marked unparseable, then do nothing, and return the cache."
   (and
    ;; Is this a semantic enabled buffer?
@@ -580,7 +621,7 @@ was marked unparseable, then do nothing, and return the cache."
         (semantic-clear-unmatched-syntax-cache)
         (run-hook-with-args ;; Let hooks know the updated tags
          'semantic-after-partial-cache-change-hook res))
-      )
+      (setq semantic--completion-cache nil))
 
 ;;;; Parse the whole system.
      ((semantic-parse-tree-needs-rebuild-p)
@@ -611,7 +652,7 @@ was marked unparseable, then do nothing, and return the cache."
   semantic--buffer-cache)
 
 (defun semantic-refresh-tags-safe ()
-  "Refreshes the current buffer's tags safely.
+  "Refresh the current buffer's tags safely.
 
 Return non-nil if the refresh was successful.
 Return nil if there is some sort of syntax error preventing a reparse.
@@ -653,9 +694,9 @@ Does nothing if the current buffer doesn't need reparsing."
       lexically-safe))))
 
 (defun semantic-bovinate-toplevel (&optional ignored)
-  "Backward Compatibility Function."
+  "Backward compatibility function."
   (semantic-fetch-tags))
-(make-obsolete 'semantic-bovinate-toplevel 'semantic-fetch-tags)
+(make-obsolete 'semantic-bovinate-toplevel 'semantic-fetch-tags "23.2")
 
 ;; Another approach is to let Emacs call the parser on idle time, when
 ;; needed, use `semantic-fetch-available-tags' to only retrieve
@@ -787,7 +828,7 @@ code blocks in methods.  If `bovine-inner-scope' can also support
 commands, use `semantic-bovinate-from-nonterminal-full'."
   (semantic-parse-region start end nonterm depth t))
 (make-obsolete 'semantic-bovinate-region-until-error
-               'semantic-parse-region)
+               'semantic-parse-region "23.2")
 
 (defsubst semantic-bovinate-from-nonterminal
   (start end nonterm &optional depth length)
@@ -815,16 +856,173 @@ When used in a `lambda' of a MATCH-LIST, there is no need to include
 a START and END part."
   (semantic-parse-region start end nonterm (or depth 1)))
 (make-obsolete 'semantic-bovinate-from-nonterminal-full
-               'semantic-parse-region)
+               'semantic-parse-region "23.2")
 
 ;;; User interface
 
+(defun semantic-force-refresh ()
+  "Force a full refresh of the current buffer's tags.
+Throw away all the old tags, and recreate the tag database."
+  (interactive)
+  (semantic-clear-toplevel-cache)
+  (semantic-fetch-tags)
+  (message "Buffer reparsed."))
+
+(defvar semantic-mode-map
+  (let ((map (make-sparse-keymap)))
+    ;; Key bindings:
+    ;; (define-key km "f"    'senator-search-set-tag-class-filter)
+    ;; (define-key km "i"    'senator-isearch-toggle-semantic-mode)
+    (define-key map "\C-c,j" 'semantic-complete-jump-local)
+    (define-key map "\C-c,J" 'semantic-complete-jump)
+    (define-key map "\C-c,m" 'semantic-complete-jump-local-members)
+    (define-key map "\C-c,g" 'semantic-symref-symbol)
+    (define-key map "\C-c,G" 'semantic-symref)
+    (define-key map "\C-c,p" 'senator-previous-tag)
+    (define-key map "\C-c,n" 'senator-next-tag)
+    (define-key map "\C-c,u" 'senator-go-to-up-reference)
+    (define-key map "\C-c, " 'semantic-complete-analyze-inline)
+    (define-key map "\C-c,\C-w" 'senator-kill-tag)
+    (define-key map "\C-c,\M-w" 'senator-copy-tag)
+    (define-key map "\C-c,\C-y" 'senator-yank-tag)
+    (define-key map "\C-c,r" 'senator-copy-tag-to-register)
+    (define-key map "\C-c,," 'semantic-force-refresh)
+    (define-key map [?\C-c ?, up] 'senator-transpose-tags-up)
+    (define-key map [?\C-c ?, down] 'senator-transpose-tags-down)
+    (define-key map "\C-c,l" 'semantic-analyze-possible-completions)
+    ;; This hack avoids showing the CEDET menu twice if ede-minor-mode
+    ;; and Semantic are both enabled.  Is there a better way?
+    (define-key map [menu-bar cedet-menu]
+      (list 'menu-item "Development" cedet-menu-map
+           :enable (quote (not (bound-and-true-p global-ede-mode)))))
+    ;; (define-key km "-"    'senator-fold-tag)
+    ;; (define-key km "+"    'senator-unfold-tag)
+    map))
+
+;; Activate the Semantic items in cedet-menu-map
+(let ((navigate-menu (make-sparse-keymap "Navigate Tags"))
+      (edit-menu (make-sparse-keymap "Edit Tags")))
+
+  ;; Edit Tags submenu:
+  (define-key edit-menu [semantic-analyze-possible-completions]
+    '(menu-item "List Completions" semantic-analyze-possible-completions
+               :help "Display a list of completions for the tag at point"))
+  (define-key edit-menu [semantic-complete-analyze-inline]
+    '(menu-item "Complete Tag Inline" semantic-complete-analyze-inline
+               :help "Display inline completion for the tag at point"))
+  (define-key edit-menu [semantic-completion-separator]
+    '("--"))
+  (define-key edit-menu [senator-transpose-tags-down]
+    '(menu-item "Transpose Tags Down" senator-transpose-tags-down
+               :active (semantic-current-tag)
+               :help "Transpose the current tag and the next tag"))
+  (define-key edit-menu [senator-transpose-tags-up]
+    '(menu-item "Transpose Tags Up" senator-transpose-tags-up
+               :active (semantic-current-tag)
+               :help "Transpose the current tag and the previous tag"))
+  (define-key edit-menu [semantic-edit-separator]
+    '("--"))
+  (define-key edit-menu [senator-yank-tag]
+    '(menu-item "Yank Tag" senator-yank-tag
+               :active (not (ring-empty-p senator-tag-ring))
+               :help "Yank the head of the tag ring into the buffer"))
+  (define-key edit-menu [senator-copy-tag-to-register]
+    '(menu-item "Copy Tag To Register" senator-copy-tag-to-register
+               :active (semantic-current-tag)
+               :help "Yank the head of the tag ring into the buffer"))
+  (define-key edit-menu [senator-copy-tag]
+    '(menu-item "Copy Tag" senator-copy-tag
+               :active (semantic-current-tag)
+               :help "Copy the current tag to the tag ring"))
+  (define-key edit-menu [senator-kill-tag]
+    '(menu-item "Kill Tag" senator-kill-tag
+               :active (semantic-current-tag)
+               :help "Kill the current tag, and copy it to the tag ring"))
+
+  ;; Navigate Tags submenu:
+  (define-key navigate-menu [senator-narrow-to-defun]
+    '(menu-item "Narrow to Tag" senator-narrow-to-defun
+               :active (semantic-current-tag)
+               :help "Narrow the buffer to the bounds of the current tag"))
+  (define-key navigate-menu [semantic-narrow-to-defun-separator]
+    '("--"))
+  (define-key navigate-menu [semantic-symref-symbol]
+    '(menu-item "Find Tag References..." semantic-symref-symbol
+               :help "Read a tag and list the references to it"))
+  (define-key navigate-menu [semantic-complete-jump]
+    '(menu-item "Find Tag Globally..." semantic-complete-jump
+               :help "Read a tag name and find it in the current project"))
+  (define-key navigate-menu [semantic-complete-jump-local-members]
+    '(menu-item "Find Local Members ..." semantic-complete-jump-local-members
+               :help "Read a tag name and find a local member with that name"))
+  (define-key navigate-menu [semantic-complete-jump-local]
+    '(menu-item "Find Tag in This Buffer..." semantic-complete-jump-local
+               :help "Read a tag name and find it in this buffer"))
+  (define-key navigate-menu [semantic-navigation-separator]
+    '("--"))
+  (define-key navigate-menu [senator-go-to-up-reference]
+    '(menu-item "Parent Tag" senator-go-to-up-reference
+               :help "Navigate up one reference by tag."))
+  (define-key navigate-menu [senator-next-tag]
+    '(menu-item "Next Tag" senator-next-tag
+               :help "Go to the next tag"))
+  (define-key navigate-menu [senator-previous-tag]
+    '(menu-item "Previous Tag" senator-previous-tag
+               :help "Go to the previous tag"))
+
+  ;; Top level menu items:
+  (define-key cedet-menu-map [semantic-force-refresh]
+    '(menu-item "Reparse Buffer" semantic-force-refresh
+               :help "Force a full reparse of the current buffer."
+               :visible semantic-mode))
+  (define-key cedet-menu-map [semantic-edit-menu]
+    `(menu-item "Edit Tags" ,edit-menu
+               :visible semantic-mode))
+  (define-key cedet-menu-map [navigate-menu]
+    `(menu-item "Navigate Tags" ,navigate-menu
+               :visible semantic-mode))
+  (define-key cedet-menu-map [semantic-options-separator]
+    '("--"))
+  (define-key cedet-menu-map [global-semantic-highlight-func-mode]
+    '(menu-item "Highlight Current Function" global-semantic-highlight-func-mode
+               :help "Highlight the tag at point"
+               :visible semantic-mode
+               :button (:toggle . global-semantic-highlight-func-mode)))
+  (define-key cedet-menu-map [global-semantic-decoration-mode]
+    '(menu-item "Decorate Tags" global-semantic-decoration-mode
+               :help "Decorate tags based on tag attributes"
+               :visible semantic-mode
+               :button (:toggle . (bound-and-true-p
+                                   global-semantic-decoration-mode))))
+  (define-key cedet-menu-map [global-semantic-idle-completions-mode]
+    '(menu-item "Show Tag Completions" global-semantic-idle-completions-mode
+               :help "Show tag completions when idle"
+               :visible semantic-mode
+               :enable global-semantic-idle-scheduler-mode
+               :button (:toggle . global-semantic-idle-completions-mode)))
+  (define-key cedet-menu-map [global-semantic-idle-summary-mode]
+    '(menu-item "Show Tag Summaries" global-semantic-idle-summary-mode
+               :help "Show tag summaries when idle"
+               :visible semantic-mode
+               :enable global-semantic-idle-scheduler-mode
+               :button (:toggle . global-semantic-idle-summary-mode)))
+  (define-key cedet-menu-map [global-semantic-idle-scheduler-mode]
+    '(menu-item "Reparse When Idle" global-semantic-idle-scheduler-mode
+               :help "Keep a buffer's parse tree up to date when idle"
+               :visible semantic-mode
+               :button (:toggle . global-semantic-idle-scheduler-mode)))
+  (define-key cedet-menu-map [global-semanticdb-minor-mode]
+    '(menu-item "Semantic Database" global-semanticdb-minor-mode
+               :help "Store tag information in a database"
+               :visible semantic-mode
+               :button (:toggle . global-semanticdb-minor-mode))))
+
 ;; The `semantic-mode' command, in conjuction with the
-;; `semantic-default-submodes' variable, are used to collectively
-;; toggle Semantic's various auxilliary minor modes.
+;; `semantic-default-submodes' variable, toggles Semantic's various
+;; auxiliary minor modes.
 
 (defvar semantic-load-system-cache-loaded nil
-  "Non nil when the Semantic system caches have been loaded.
+  "Non-nil when the Semantic system caches have been loaded.
 Prevent this load system from loading files in twice.")
 
 (defconst semantic-submode-list
@@ -836,24 +1034,23 @@ Prevent this load system from loading files in twice.")
     global-semanticdb-minor-mode
     global-semantic-idle-summary-mode
     global-semantic-mru-bookmark-mode)
-  "List of auxilliary minor modes in the Semantic package.")
+  "List of auxiliary minor modes in the Semantic package.")
 
 ;;;###autoload
 (defcustom semantic-default-submodes
   '(global-semantic-idle-scheduler-mode global-semanticdb-minor-mode)
-  "List of auxilliary Semantic minor modes enabled by `semantic-mode'.
+  "List of auxiliary Semantic minor modes enabled by `semantic-mode'.
 The possible elements of this list include the following:
 
- `semantic-highlight-func-mode'   - Highlight the current tag.
- `semantic-decoration-mode' - Decorate tags based on various attributes.
- `semantic-stickyfunc-mode' - Track current function in the header-line.
- `semantic-idle-completions-mode' - Provide smart symbol completion
-                                    automatically when idle.
- `semantic-idle-scheduler-mode'   - Keep a buffer's parse tree up to date.
- `semanticdb-minor-mode'    - Store tags when a buffer is not in memory.
- `semantic-idle-summary-mode'     - Show a summary for the code at point.
- `semantic-mru-bookmark-mode'     - Provide `switch-to-buffer'-like
-                                    keybinding for tag names."
+ `global-semanticdb-minor-mode'        - Maintain tag database.
+ `global-semantic-idle-scheduler-mode' - Reparse buffer when idle.
+ `global-semantic-idle-summary-mode'   - Show summary of tag at point.
+ `global-semantic-idle-completions-mode' - Show completions when idle.
+ `global-semantic-decoration-mode'     - Additional tag decorations.
+ `global-semantic-highlight-func-mode' - Highlight the current tag.
+ `global-semantic-stickyfunc-mode'     - Show current fun in header line.
+ `global-semantic-mru-bookmark-mode'   - Provide `switch-to-buffer'-like
+                                         keybinding for tag names."
   :group 'semantic
   :type `(set ,@(mapcar (lambda (c) (list 'const c))
                        semantic-submode-list)))
@@ -865,13 +1062,18 @@ With ARG, turn Semantic mode on if ARG is positive, off otherwise.
 
 In Semantic mode, Emacs parses the buffers you visit for their
 semantic content.  This information is used by a variety of
-auxilliary minor modes, listed in `semantic-default-submodes';
+auxiliary minor modes, listed in `semantic-default-submodes';
 all the minor modes in this list are also enabled when you enable
-Semantic mode."
+Semantic mode.
+
+\\{semantic-mode-map}"
+  :global t
   :group 'semantic
   (if semantic-mode
       ;; Turn on Semantic mode
       (progn
+       ;; Enable all the global auxiliary minor modes in
+       ;; `semantic-submode-list'.
        (dolist (mode semantic-submode-list)
          (if (memq mode semantic-default-submodes)
              (funcall mode 1)))
@@ -883,32 +1085,30 @@ Semantic mode."
            (require 'semantic/db-ebrowse)
            (semanticdb-load-ebrowse-caches)))
        (add-hook 'mode-local-init-hook 'semantic-new-buffer-fcn)
-       ;; Add mode-local hooks
-       (add-hook 'javascript-mode-hook 'wisent-javascript-setup-parser)
-       (add-hook 'ecmascript-mode-hook 'wisent-javascript-setup-parser)
-       (add-hook 'java-mode-hook 'wisent-java-default-setup)
-       (add-hook 'scheme-mode-hook 'semantic-default-scheme-setup)
-       (add-hook 'makefile-mode-hook 'semantic-default-make-setup)
-       (add-hook 'c-mode-hook 'semantic-default-c-setup)
-       (add-hook 'c++-mode-hook 'semantic-default-c-setup)
-       (add-hook 'html-mode-hook 'semantic-default-html-setup))
+       ;; Add semantic-ia-complete-symbol to
+       ;; completion-at-point-functions, so that it is run from
+       ;; M-TAB.
+       (add-hook 'completion-at-point-functions
+                 'semantic-completion-at-point-function)
+       (if global-ede-mode
+           (define-key cedet-menu-map [cedet-menu-separator] '("--")))
+       (dolist (b (buffer-list))
+         (with-current-buffer b
+           (semantic-new-buffer-fcn))))
     ;; Disable all Semantic features.
     (remove-hook 'mode-local-init-hook 'semantic-new-buffer-fcn)
-    (remove-hook 'javascript-mode-hook 'wisent-javascript-setup-parser)
-    (remove-hook 'ecmascript-mode-hook 'wisent-javascript-setup-parser)
-    (remove-hook 'java-mode-hook 'wisent-java-default-setup)
-    (remove-hook 'scheme-mode-hook 'semantic-default-scheme-setup)
-    (remove-hook 'makefile-mode-hook 'semantic-default-make-setup)
-    (remove-hook 'c-mode-hook 'semantic-default-c-setup)
-    (remove-hook 'c++-mode-hook 'semantic-default-c-setup)
-    (remove-hook 'html-mode-hook 'semantic-default-html-setup)
-
+    (remove-hook 'completion-at-point-functions
+                'semantic-completion-at-point-function)
+    (define-key cedet-menu-map [cedet-menu-separator] nil)
+    (define-key cedet-menu-map [semantic-options-separator] nil)
     ;; FIXME: handle semanticdb-load-ebrowse-caches
-
     (dolist (mode semantic-submode-list)
       (if (and (boundp mode) (eval mode))
          (funcall mode -1)))))
 
+(defun semantic-completion-at-point-function ()
+  'semantic-ia-complete-symbol)
+
 ;;; Autoload some functions that are not in semantic/loaddefs
 
 (autoload 'global-semantic-idle-completions-mode "semantic/idle"
@@ -941,6 +1141,9 @@ minor mode can be turned on only if semantic feature is available and
 the current buffer was set up for parsing.  Return non-nil if the
 minor mode is enabled." t nil)
 
+(autoload 'srecode-template-setup-parser "srecode/srecode-template"
+  "Set up buffer for parsing SRecode template files." t nil)
+
 (provide 'semantic)
 
 ;; Semantic-util is a part of the semantic API.  Include it last