Source

semantic / semantic-load.el

Diff from to

semantic-load.el

 ;;; semantic-load.el --- Autoload definitions for Semantic
 
-;;; Copyright (C) 1999, 2000, 2001, 2002, 2003 Eric M. Ludlam
+;;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Eric M. Ludlam
 
 ;; Author: Eric M. Ludlam <zappo@gnu.org>
 ;; X-RCS: $Id$
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 ;;
 ;; Initialize semantic for all supported conditions.
 
 ;;; Code:
+;;
 
-;;; Parser setup
+(require 'semantic-fw)
+
+;;; Add parser and doc directories
 ;;
-(autoload 'semantic-bnf-mode "semantic-bnf" "Mode for Bovine Normal Form." t)
-(add-to-list 'auto-mode-alist '("\\.bnf$" . semantic-bnf-mode))
-(eval-after-load "speedbar" '(speedbar-add-supported-extension ".bnf"))
-
-(autoload 'semantic-default-c-setup "semantic-c")
-(add-hook 'c-mode-hook 'semantic-default-c-setup)
-(add-hook 'c++-mode-hook 'semantic-default-c-setup)
-
-(autoload 'semantic-default-elisp-setup "semantic-el")
-(add-hook 'emacs-lisp-mode-hook 'semantic-default-elisp-setup)
-
-(autoload 'semantic-default-scheme-setup "semantic-scm")
-(add-hook 'scheme-mode-hook 'semantic-default-scheme-setup)
-
-(autoload 'semantic-default-make-setup "semantic-make")
-(add-hook 'makefile-mode-hook 'semantic-default-make-setup)
-
-(autoload 'semantic-default-texi-setup "semantic-texi")
-(add-hook 'texinfo-mode-hook 'semantic-default-texi-setup)
-
-(autoload 'semantic-default-java-setup "semantic-java")
-(add-hook 'java-mode-hook 'semantic-default-java-setup)
-
-;;; Charts
-;;
-(autoload 'semantic-chart-nonterminals-by-token "semantic-chart" nil t)
-(autoload 'semantic-chart-nonterminal-complexity-token "semantic-chart" nil t)
-(autoload 'semantic-chart-database-size "semantic-chart" nil t)
-
-;;; Class browser data
-(autoload 'semantic-cb-speedbar-mode "semantic-cb")
-
-;;; Context analysis
-(autoload 'semantic-analyze-current-context "semantic-analyze")
-(autoload 'semantic-analyze-possible-completions "semantic-analyze")
-(autoload 'semantic-speedbar-analysis "semantic-ia-sb")
+(let ((dir (file-name-directory (locate-library "semantic"))))
+  (add-to-list 'load-path (expand-file-name "bovine" dir))
+  (add-to-list 'load-path (expand-file-name "wisent" dir))
+  (add-to-list 'Info-default-directory-list (expand-file-name "doc" dir))
+  )
 
 ;;; Some speedbar major modes
 (eval-after-load "speedbar"
   '(progn
      (require 'semantic-cb)
      (require 'semantic-ia-sb)))
-
 
-;;; Minor modes
+;;; Useful predefined setup
 ;;
-
-;; semanticdb
-(autoload 'global-semanticdb-minor-mode "semanticdb" nil t)
-
-;; senator
-(autoload 'senator-minor-mode "senator"
-  "Toggle senator minor mode.
-With prefix argument ARG, turn on if positive, otherwise off.  The
-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.
-
-\\{senator-mode-map}"
-  t nil)
-
-(defvar global-senator-minor-mode nil
-  "*If non-nil enable global use of senator minor mode.")
-
-(custom-add-to-group 'senator
-                     'global-senator-minor-mode
-                     'custom-variable)
-
-(custom-add-load 'global-senator-minor-mode 'senator)
-
-(autoload 'global-senator-minor-mode "senator"
-  "Toggle global use of senator minor mode.
-If ARG is positive, enable, if it is negative, disable.
-If ARG is nil, then toggle."
-  t nil)
-
-(autoload 'senator-try-expand-semantic "senator"
-  "Attempt inline completion at the cursor.
-Use Semantic, or the semantic database to look up possible
-completions.  The argument OLD has to be nil the first call of this
-function.  It returns t if a unique, possibly partial, completion is
-found, nil otherwise."
-  t nil)
-
-(autoload 'senator-complete-symbol "senator"
-  "Complete the current symbol under point.
-If optional argument CYCLE-ONCE is non-nil, only cycle through the list
-of completions once, doing nothing where there are no more matches."
-  t nil)
-
-;; semantic-show-dirty
-(autoload 'semantic-show-dirty-mode
-  "semantic-util-modes"
-  "Minor mode to display of dirty tokens.
-With prefix argument ARG, turn on if positive, otherwise off.  The
-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.
-
-\\{semantic-show-dirty-mode-map}"
-  t nil)
-
-(defvar global-semantic-show-dirty-mode nil
-  "*If non-nil enable global use of show-dirty mode.")
-
-(custom-add-to-group 'semantic
-                     'global-semantic-show-dirty-mode
-                     'custom-variable)
-
-(custom-add-load 'global-semantic-show-dirty-mode
-                 'semantic-util-modes)
-
-(autoload 'global-semantic-show-dirty-mode
-  "semantic-util-modes"
-  "Toggle global use of show-dirty mode.
-If ARG is positive, enable, if it is negative, disable.
-If ARG is nil, then toggle."
-  t nil)
-
-;; semantic-show-unmatched-syntax
-(autoload 'semantic-show-unmatched-syntax-mode
-  "semantic-util-modes"
-  "Minor mode to display of unmatched-syntax tokens.
-With prefix argument ARG, turn on if positive, otherwise off.  The
-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.
-
-\\{semantic-show-unmatched-syntax-mode-map}"
-  t nil)
-
-(defvar global-semantic-show-unmatched-syntax-mode nil
-  "*If non-nil enable global use of show-unmatched-syntax mode.")
-
-(custom-add-to-group 'semantic
-                     'global-semantic-show-unmatched-syntax-mode
-                     'custom-variable)
-
-(custom-add-load 'global-semantic-show-unmatched-syntax-mode
-                 'semantic-util-modes)
-
-(autoload 'global-semantic-show-unmatched-syntax-mode
-  "semantic-util-modes"
-  "Toggle global use of show-unmatched-syntax mode'.
-If ARG is positive, enable, if it is negative, disable.
-If ARG is nil, then toggle."
-  t nil)
-
-;; semantic-auto-parse
-(autoload 'semantic-auto-parse-mode
-  "semantic-util-modes"
-  "Minor mode to auto parse buffer following changes.
-With prefix argument ARG, turn on if positive, otherwise off.  The
-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)
-
-(defvar global-semantic-auto-parse-mode nil
-  "*If non-nil enable global use of auto-parse mode.")
-
-(custom-add-to-group 'semantic
-                     'global-semantic-auto-parse-mode
-                     'custom-variable)
-
-(custom-add-load 'global-semantic-auto-parse-mode
-                 'semantic-util-modes)
-
-(autoload 'global-semantic-auto-parse-mode
-  "semantic-util-modes"
-  "Toggle global use of `semantic-auto-parse-mode'.
-If ARG is positive, enable, if it is negative, disable.
-If ARG is nil, then toggle."
-  t nil)
-
-;; semantic-summary
-(autoload 'semantic-summary-mode
-  "semantic-util-modes"
-  "Minor mode to show useful things about tokens in echo area.
-Enables/disables `eldoc-mode' which supplies the support functions for
-this minor mode.
-With prefix argument ARG, turn on if positive, otherwise off.  The
-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.
-
-\\{semantic-summary-mode-map}"
-  t nil)
-
-(defvar global-semantic-summary-mode nil
-  "*If non-nil enable global use of summary mode.")
-
-(custom-add-to-group 'semantic
-                     'global-semantic-summary-mode
-                     'custom-variable)
-
-(custom-add-load 'global-semantic-summary-mode
-                 'semantic-util-modes)
-
-(autoload 'global-semantic-summary-mode
-  "semantic-util-modes"
-  "Toggle global use of `semantic-summary-mode'.
-If ARG is positive, enable, if it is negative, disable.
-If ARG is nil, then toggle."
-  t nil)
-
-
-;; This turns on semantic partial reparsing
-(add-hook 'semantic-change-hooks #'semantic-change-function-mark-dirty)
+(defvar semantic-load-imenu-string "TAGS"
+  "String used in `semantic-load' startup for the Imenu menu item.")
 
 (defvar semantic-load-turn-everything-on nil
   "Non-nil means turn on all features in the semantic package.")
 Sadly `useful' here means things Eric wants on as opposed to some
 other criteria.")
 
-(when (or semantic-load-turn-everything-on
-	  semantic-load-turn-useful-things-on)
+(defvar semantic-load-system-cache-loaded nil
+  "Non nil when the system caches have been loaded.
+Prevent this load system from loading files in twice.")
 
-  (if (and semantic-load-turn-everything-on
-	   (fboundp #'which-func-mode))
-      (add-hook 'semantic-init-hooks (lambda ()
-				       (which-func-mode 1))))
+(defun semantic-load-enable-minimum-features ()
+  "Enable the minimum number of semantic features for basic usage.
+This includes:
+ `semantic-idle-scheduler-mode' - Keeps a buffer's parse tree up to date.
+ `semanticdb-minor-mode' - Stores tags when a buffer is not in memory.
+ `semanticdb-load-system-caches' - Loads any systemdbs created earlier.
+ `semanticdb-load-ebrowse-caches' - Loads any ebrowse dbs created earlier."
+  (interactive)
+
+  (global-semantic-idle-scheduler-mode 1)
+
+  (global-semanticdb-minor-mode 1)
+
+  ;; Don't do the loads from semantic-load twice.
+  (when (null semantic-load-system-cache-loaded)
+
+    ;; This loads any created system databases which get linked into
+    ;; any searches performed.
+    (setq semantic-load-system-cache-loaded t)
+    (when (and (boundp 'semanticdb-default-system-save-directory)
+	       (stringp semanticdb-default-system-save-directory)
+	       (file-exists-p semanticdb-default-system-save-directory))
+      (semanticdb-load-system-caches))
+
+    ;; This loads any created ebrowse databases which get linked into
+    ;; any searches performed.
+    (when (and (not (featurep 'xemacs))
+	       (boundp 'semanticdb-default-system-save-directory)
+	       (stringp semanticdb-default-system-save-directory)
+	       (file-exists-p semanticdb-default-system-save-directory))
+      (semanticdb-load-ebrowse-caches))
+    )
+  )
+
+(defun semantic-load-enable-code-helpers ()
+  "Enable some semantic features that provide coding assistance.
+This includes `semantic-load-enable-minimum-features' plus:
+  `imenu' - Lists Semantic generated tags in the menubar.
+  `semantic-idle-summary-mode' - Show a summary for the tag indicated by
+                                 code under point.  (intellisense)
+  `senator-minor-mode' - Semantic Navigator, and global menu for all
+                         features semantic.
+  `semantic-mru-bookmark-mode' - Provides a `switch-to-buffer' like
+                       keybinding for tag names."
+  (interactive)
+
+  (semantic-load-enable-minimum-features)
 
   (when (and (eq window-system 'x)
 	     (locate-library "imenu"))
     (add-hook 'semantic-init-hooks (lambda ()
-				     (imenu-add-to-menubar "TOKENS"))))
+				     (condition-case nil
+					 (imenu-add-to-menubar
+					  semantic-load-imenu-string)
+				       (error nil)))))
 
-  (when semantic-load-turn-everything-on
-    (global-semantic-show-dirty-mode 1))
+  (global-semantic-idle-summary-mode 1)
 
+  ;; Do this last.  This allows other minor modes to get loaded
+  ;; in so they appear in the menu properly.
   (global-senator-minor-mode 1)
+
+  )
+
+(defun semantic-load-enable-gaudy-code-helpers ()
+  "Enable semantic features that provide gaudy coding assistance.
+This includes `semantic-load-enable-code-helpers'.
+  `semantic-stickyfunc-mode' - Tracks current function in header-line
+                               (when available).
+  `semantic-idle-completions-mode' - Provide smart symbol completion
+                                 automatically at idle time.
+  `semantic-decoration-mode' - Decorate tags based on various attributes."
+  (interactive)
+
+  (global-semantic-decoration-mode 1)
+
+  (when (boundp 'header-line-format)
+    (global-semantic-stickyfunc-mode 1))
+
+  ;; Idle Completions mode is more annoying than useful
+  ;; when it keeps splitting the window to show you completions.
+  ;; Using speedbar for this would be better.
+  (condition-case nil
+      (when (and (featurep 'tooltip) tooltip-mode)
+	(global-semantic-idle-completions-mode 1))
+    (error nil))
+
+  (semantic-load-enable-code-helpers)
+  )
+
+(semantic-alias-obsolete 'semantic-load-enable-guady-code-helpers
+                         'semantic-load-enable-gaudy-code-helpers)
+
+(defun semantic-load-enable-excessive-code-helpers ()
+  "Enable all semantic features that provide coding assistance.
+This includes all features of `semantic-load-enable-code-helpers' plus:
+  `which-func-mode' - Display the current function in the mode line."
+  (interactive)
+
+  (semantic-load-enable-code-helpers)
+
+  (if (fboundp #'which-func-mode)
+      (add-hook 'semantic-init-hooks (lambda ()
+				       (which-func-mode 1))))
+  )
+
+(defun semantic-load-enable-semantic-debugging-helpers ()
+  "Enable all semantic features that assist with debugging semantic.
+These modes include:
+  `semantic-highlight-edits-mode' - Highlight text that has been edited
+                            since the last parse step.
+  `semantic-show-unmatched-syntax-mode' - Highlight lexical tokens which
+                            failed to be parsed.
+  `semantic-show-parser-state-mode' - Show the current buffer state via
+                            small indicators in the mode line."
+  (interactive)
+
+  (global-semantic-highlight-edits-mode 1)
+
+  ;; This ought to be a code helper, but it is still
+  ;; a bit on the lame side.  Opinions?
   (global-semantic-show-unmatched-syntax-mode 1)
-  (global-semantic-auto-parse-mode 1)
-  (global-semanticdb-minor-mode 1)
-  (global-semantic-summary-mode 1)
 
-  (if (boundp 'default-header-line-format)
-      (global-semantic-stickyfunc-mode 1))
- )
+  (global-semantic-show-parser-state-mode 1)
+
+  ;; This enables debug output from the incremental parser.
+  ;; Perhaps a mode for that dumps stuff in a `messages' like buffer
+  ;; would be better?
+  (setq semantic-edits-verbose-flag t)
+
+  )
+
+;; Old style variables.  Use only if we are not in batch mode.
+(when (not noninteractive)
+  (cond
+   (semantic-load-turn-everything-on
+    (semantic-load-enable-excessive-code-helpers))
+   (semantic-load-turn-useful-things-on
+    (semantic-load-enable-code-helpers))
+   ))
 
 (provide 'semantic-load)