Spelling fixes.
[bpt/emacs.git] / lisp / cedet / semantic / symref.el
index acebac0..cbae9f8 100644 (file)
@@ -1,6 +1,6 @@
 ;;; semantic/symref.el --- Symbol Reference API
 
-;;; Copyright (C) 2008, 2009 Free Software Foundation, Inc.
+;; Copyright (C) 2008-2011  Free Software Foundation, Inc.
 
 ;; Author: Eric M. Ludlam <eric@siege-engine.com>
 
@@ -25,7 +25,7 @@
 ;;
 ;; Semantic's native parsing tools do not handle symbol references.
 ;; Tracking such information is a task that requires a huge amount of
-;; space and processing not apropriate for an Emacs Lisp program.
+;; space and processing not appropriate for an Emacs Lisp program.
 ;;
 ;; Many desired tools used in refactoring, however, need to have
 ;; such references available to them.  This API aims to provide a
 ;;
 ;; ADD A NEW EXTERNAL TOOL
 ;;
-;; To support a new external tool, sublcass `semantic-symref-tool-baseclass'
+;; To support a new external tool, subclass `semantic-symref-tool-baseclass'
 ;; and implement the methods.  The baseclass provides support for
 ;; managing external processes that produce parsable output.
 ;;
 ;; Your tool should then create an instance of `semantic-symref-result'.
 
-(require 'semantic/fw)
-(require 'ede)
-(eval-when-compile (require 'data-debug)
-                  (require 'eieio-datadebug))
+(require 'semantic)
+
+(defvar ede-minor-mode)
+(declare-function data-debug-new-buffer "data-debug")
+(declare-function data-debug-insert-object-slots "eieio-datadebug")
+(declare-function ede-toplevel "ede/base")
+(declare-function ede-project-root-directory "ede/files")
+(declare-function ede-up-directory "ede/files")
 
 ;;; Code:
 (defvar semantic-symref-tool 'detect
@@ -95,16 +99,27 @@ is supported.
 
 If no tools are supported, then 'grep is assumed.")
 
+(defun semantic-symref-calculate-rootdir ()
+  "Calculate the root directory for a symref search.
+Start with and EDE project, or use the default directory."
+  (let* ((rootproj (when (and (featurep 'ede) ede-minor-mode)
+                    (ede-toplevel)))
+        (rootdirbase (if rootproj
+                         (ede-project-root-directory rootproj)
+                       default-directory)))
+    (if (and rootproj (condition-case nil
+                         ;; Hack for subprojects.
+                         (oref rootproj :metasubproject)
+                       (error nil)))
+       (ede-up-directory rootdirbase)
+      rootdirbase)))
+
 (defun semantic-symref-detect-symref-tool ()
   "Detect the symref tool to use for the current buffer."
   (if (not (eq semantic-symref-tool 'detect))
       semantic-symref-tool
     ;; We are to perform a detection for the right tool to use.
-    (let* ((rootproj (when (and (featurep 'ede) ede-minor-mode)
-                      (ede-toplevel)))
-          (rootdir (if rootproj
-                       (ede-project-root-directory rootproj)
-                     default-directory))
+    (let* ((rootdir (semantic-symref-calculate-rootdir))
           (tools semantic-symref-tool-alist))
       (while (and tools (eq semantic-symref-tool 'detect))
        (when (funcall (car (car tools)) rootdir)
@@ -134,6 +149,7 @@ ARGS are the initialization arguments to pass to the created class."
 (defun semantic-symref-data-debug-last-result ()
   "Run the last symref data result in Data Debug."
   (interactive)
+  (require 'eieio-datadebug)
   (if semantic-symref-last-result
       (progn
        (data-debug-new-buffer "*Symbol Reference ADEBUG*")
@@ -143,6 +159,7 @@ ARGS are the initialization arguments to pass to the created class."
 ;;; EXTERNAL API
 ;;
 
+;;;###autoload
 (defun semantic-symref-find-references-by-name (name &optional scope tool-return)
   "Find a list of references to NAME in the current project.
 Optional SCOPE specifies which file set to search.  Defaults to 'project.
@@ -162,10 +179,11 @@ to perform the search.  This was added for use by a test harness."
       (set tool-return inst))
     (prog1
        (setq semantic-symref-last-result result)
-      (when (interactive-p)
+      (when (called-interactively-p 'interactive)
        (semantic-symref-data-debug-last-result))))
   )
 
+;;;###autoload
 (defun semantic-symref-find-tags-by-name (name &optional scope)
   "Find a list of references to NAME in the current project.
 Optional SCOPE specifies which file set to search.  Defaults to 'project.
@@ -181,10 +199,11 @@ Returns an object of class `semantic-symref-result'."
         (result (semantic-symref-get-result inst)))
     (prog1
        (setq semantic-symref-last-result result)
-      (when (interactive-p)
+      (when (called-interactively-p 'interactive)
        (semantic-symref-data-debug-last-result))))
   )
 
+;;;###autoload
 (defun semantic-symref-find-tags-by-regexp (name &optional scope)
   "Find a list of references to NAME in the current project.
 Optional SCOPE specifies which file set to search.  Defaults to 'project.
@@ -200,10 +219,11 @@ Returns an object of class `semantic-symref-result'."
         (result (semantic-symref-get-result inst)))
     (prog1
        (setq semantic-symref-last-result result)
-      (when (interactive-p)
+      (when (called-interactively-p 'interactive)
        (semantic-symref-data-debug-last-result))))
   )
 
+;;;###autoload
 (defun semantic-symref-find-tags-by-completion (name &optional scope)
   "Find a list of references to NAME in the current project.
 Optional SCOPE specifies which file set to search.  Defaults to 'project.
@@ -219,10 +239,11 @@ Returns an object of class `semantic-symref-result'."
         (result (semantic-symref-get-result inst)))
     (prog1
        (setq semantic-symref-last-result result)
-      (when (interactive-p)
+      (when (called-interactively-p 'interactive)
        (semantic-symref-data-debug-last-result))))
   )
 
+;;;###autoload
 (defun semantic-symref-find-file-references-by-name (name &optional scope)
   "Find a list of references to NAME in the current project.
 Optional SCOPE specifies which file set to search.  Defaults to 'project.
@@ -238,12 +259,13 @@ Returns an object of class `semantic-symref-result'."
         (result (semantic-symref-get-result inst)))
     (prog1
        (setq semantic-symref-last-result result)
-      (when (interactive-p)
+      (when (called-interactively-p 'interactive)
        (semantic-symref-data-debug-last-result))))
   )
 
+;;;###autoload
 (defun semantic-symref-find-text (text &optional scope)
-  "Find a list of occurances of TEXT in the current project.
+  "Find a list of occurrences of TEXT in the current project.
 TEXT is a regexp formatted for use with egrep.
 Optional SCOPE specifies which file set to search.  Defaults to 'project.
 Refers to `semantic-symref-tool', to determine the reference tool to use
@@ -258,7 +280,7 @@ Returns an object of class `semantic-symref-result'."
         (result (semantic-symref-get-result inst)))
     (prog1
        (setq semantic-symref-last-result result)
-      (when (interactive-p)
+      (when (called-interactively-p 'interactive)
        (semantic-symref-data-debug-last-result))))
   )
 
@@ -302,7 +324,7 @@ Use the  `semantic-symref-hit-tags' method to get this list.")
       (setq ans (list (car files))
            files (cdr files))
       (dolist (F files)
-       ;; This algorithm for uniqing the file list depends on the
+       ;; This algorithm for uniquifying the file list depends on the
        ;; tool in question providing all the hits in the same file
        ;; grouped together.
        (when (not (string= F (car ans)))
@@ -466,8 +488,7 @@ The symref TOOL should already contain the search criteria."
   "Parse the entire OUTPUTBUFFER of a symref tool.
 Calls the method `semantic-symref-parse-tool-output-one-line' over and
 over until it returns nil."
-  (save-excursion
-    (set-buffer outputbuffer)
+  (with-current-buffer outputbuffer
     (goto-char (point-min))
     (let ((result nil)
          (hit nil))
@@ -482,4 +503,9 @@ over until it returns nil."
 
 (provide 'semantic/symref)
 
+;; Local variables:
+;; generated-autoload-file: "loaddefs.el"
+;; generated-autoload-load-name: "semantic/symref"
+;; End:
+
 ;;; semantic/symref.el ends here