]> code.delx.au - gnu-emacs/blobdiff - lisp/cedet/semantic/db-el.el
Update copyright year to 2014 by running admin/update-copyright.
[gnu-emacs] / lisp / cedet / semantic / db-el.el
index 4b232278a397063d55d08620ec0ffa016b4118d7..7ff1538dd2b587bd796ac9ecd8fed1b5f9e680f1 100644 (file)
@@ -1,7 +1,6 @@
 ;;; semantic/db-el.el --- Semantic database extensions for Emacs Lisp
 
-;;; Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
-;;; Free Software Foundation, Inc.
+;;; Copyright (C) 2002-2014 Free Software Foundation, Inc.
 
 ;; Author: Eric M. Ludlam <zappo@gnu.org>
 ;; Keywords: tags
 ;;
 
 (require 'semantic/db)
-
-(eval-when-compile
-  ;; For generic function searching.
-  (require 'eieio)
-  (require 'eieio-opt)
-  (require 'eieio-base))
+(require 'eieio-opt)
 
 (declare-function semantic-elisp-desymbolify "semantic/bovine/el")
+(declare-function semantic-tag-similar-p "semantic/tag-ls")
 
 ;;; Code:
 
@@ -58,6 +53,11 @@ It does not need refreshing."
   "Return nil, we never need a refresh."
   nil)
 
+(defmethod object-print ((obj semanticdb-table-emacs-lisp) &rest strings)
+  "Pretty printer extension for `semanticdb-table-emacs-lisp'.
+Adds the number of tags in this file to the object print name."
+  (apply 'call-next-method obj (cons " (proxy)" strings)))
+
 (defclass semanticdb-project-database-emacs-lisp
   (semanticdb-project-database eieio-singleton)
   ((new-table-class :initform semanticdb-table-emacs-lisp
@@ -67,6 +67,15 @@ It does not need refreshing."
    )
   "Database representing Emacs core.")
 
+(defmethod object-print ((obj semanticdb-project-database-emacs-lisp) &rest strings)
+  "Pretty printer extension for `semanticdb-table-emacs-lisp'.
+Adds the number of tags in this file to the object print name."
+  (let ((count 0))
+    (mapatoms (lambda (sym) (setq count (1+ count))))
+    (apply 'call-next-method obj (cons 
+                                 (format " (%d known syms)" count)
+                                 strings))))
+
 ;; Create the database, and add it to searchable databases for Emacs Lisp mode.
 (defvar-mode-local emacs-lisp-mode semanticdb-project-system-databases
   (list
@@ -76,7 +85,7 @@ It does not need refreshing."
 (defvar-mode-local emacs-lisp-mode semanticdb-find-default-throttle
   '(project omniscience)
   "Search project files, then search this omniscience database.
-It is not necessary to to system or recursive searching because of
+It is not necessary to do system or recursive searching because of
 the omniscience database.")
 
 ;;; Filename based methods
@@ -107,7 +116,7 @@ For Emacs Lisp, creates a specialized table."
 
 (defmethod semanticdb-equivalent-mode ((table semanticdb-table-emacs-lisp) &optional buffer)
   "Return non-nil if TABLE's mode is equivalent to BUFFER.
-Equivalent modes are specified by by `semantic-equivalent-major-modes'
+Equivalent modes are specified by the `semantic-equivalent-major-modes'
 local variable."
   (with-current-buffer buffer
     (eq (or mode-local-active-mode major-mode) 'emacs-lisp-mode)))
@@ -133,7 +142,7 @@ For Emacs Lisp system DB, there isn't one."
   "Convert one TAG, originating from Emacs OBJ, into standardized form.
 If Emacs cannot resolve this symbol to a particular file, then return nil."
   ;; Here's the idea.  For each tag, get the name, then use
-  ;; Emacs' `symbol-file' to get the source.  Once we have that,
+  ;; Emacs's `symbol-file' to get the source.  Once we have that,
   ;; we can use more typical semantic searching techniques to
   ;; get a regularly parsed tag.
   (let* ((type (cond ((semantic-tag-of-class-p tag 'function)
@@ -160,44 +169,28 @@ If Emacs cannot resolve this symbol to a particular file, then return nil."
          (setq file (concat file ".gz"))))
 
       (let* ((tab (semanticdb-file-table-object file))
-            (alltags (semanticdb-get-tags tab))
-            (newtags (semanticdb-find-tags-by-name-method
-                      tab (semantic-tag-name tag)))
+            (alltags (when tab (semanticdb-get-tags tab)))
+            (newtags (when tab (semanticdb-find-tags-by-name-method
+                                tab (semantic-tag-name tag))))
             (match nil))
-       ;; Find the best match.
-       (dolist (T newtags)
-         (when (semantic-tag-similar-p T tag)
-           (setq match T)))
-       ;; Backup system.
-       (when (not match)
-           (setq match (car newtags)))
+       ;; We might not have a parsed tag in this file, because it
+       ;; might be generated through a macro like defstruct.
+       (if (null newtags)
+           (setq match tag)
+         ;; Find the best match.
+         (dolist (T newtags)
+           (when (semantic-tag-similar-p T tag)
+             (setq match T)))
+         ;; Backup system.
+         (when (not match)
+           (setq match (car newtags))))
        ;; Return it.
-       (cons tab match)))))
-
-(defun semanticdb-elisp-sym-function-arglist (sym)
-  "Get the argument list for SYM.
-Deal with all different forms of function.
-This was snarfed out of eldoc."
-  (let* ((prelim-def
-         (let ((sd (and (fboundp sym)
-                        (symbol-function sym))))
-           (and (symbolp sd)
-                (condition-case err
-                    (setq sd (indirect-function sym))
-                  (error (setq sd nil))))
-           sd))
-         (def (if (eq (car-safe prelim-def) 'macro)
-                  (cdr prelim-def)
-                prelim-def))
-         (arglist (cond ((null def) nil)
-                       ((byte-code-function-p def)
-                        ;; This is an eieio compatibility function.
-                        ;; We depend on EIEIO, so use this.
-                        (eieio-compiled-function-arglist def))
-                        ((eq (car-safe def) 'lambda)
-                         (nth 1 def))
-                        (t nil))))
-    arglist))
+       (when tab (cons tab match))))))
+
+(autoload 'help-function-arglist "help-fns")
+(defalias 'semanticdb-elisp-sym-function-arglist 'help-function-arglist)
+(make-obsolete 'semanticdb-elisp-sym-function-arglist
+              'help-function-arglist "CEDET 1.1")
 
 (defun semanticdb-elisp-sym->tag (sym &optional toktype)
   "Convert SYM into a semantic tag.
@@ -207,15 +200,18 @@ TOKTYPE is a hint to the type of tag desired."
   (when sym
     (cond ((and (eq toktype 'function) (fboundp sym))
           (require 'semantic/bovine/el)
-          (semantic-tag-new-function
-           (symbol-name sym)
-           nil ;; return type
-           (semantic-elisp-desymbolify
-            (semanticdb-elisp-sym-function-arglist sym)) ;; arg-list
-           :user-visible-flag (condition-case nil
-                                  (interactive-form sym)
-                                (error nil))
-           ))
+          (let ((arglist (help-function-arglist sym)))
+            (when (not (listp arglist))
+              ;; Function might be autoloaded, in which case
+              ;; the arglist is not available yet.
+              (setq arglist nil))
+            (semantic-tag-new-function
+             (symbol-name sym)
+             nil       ;; return type
+             (semantic-elisp-desymbolify arglist)
+             :user-visible-flag (condition-case nil
+                                    (interactive-form sym)
+                                  (error nil)))))
          ((and (eq toktype 'variable) (boundp sym))
           (semantic-tag-new-variable
            (symbol-name sym)
@@ -227,9 +223,8 @@ TOKTYPE is a hint to the type of tag desired."
            (symbol-name sym)
            "class"
            (semantic-elisp-desymbolify
-            (aref (class-v semanticdb-project-database)
-                  class-public-a)) ;; slots
-           (semantic-elisp-desymbolify (class-parents sym)) ;; parents
+            (eieio--class-public-a (class-v semanticdb-project-database))) ;; slots
+           (semantic-elisp-desymbolify (eieio-class-parents sym)) ;; parents
            ))
          ((not toktype)
           ;; Figure it out on our own.
@@ -246,12 +241,12 @@ TOKTYPE is a hint to the type of tag desired."
 ;;; Search Overrides
 ;;
 (defvar semanticdb-elisp-mapatom-collector nil
-  "Variable used to collect mapatoms output.")
+  "Variable used to collect `mapatoms' output.")
 
 (defmethod semanticdb-find-tags-by-name-method
   ((table semanticdb-table-emacs-lisp) name &optional tags)
-  "Find all tags name NAME in TABLE.
-Uses `inter-soft' to match NAME to emacs symbols.
+  "Find all tags named NAME in TABLE.
+Uses `intern-soft' to match NAME to Emacs symbols.
 Return a list of tags."
   (if tags (call-next-method)
     ;; No need to search.  Use `intern-soft' which does the same thing for us.
@@ -281,7 +276,7 @@ Return a list of tags."
 
 (defmethod semanticdb-find-tags-for-completion-method
   ((table semanticdb-table-emacs-lisp) prefix &optional tags)
-  "In TABLE, find all occurances of tags matching PREFIX.
+  "In TABLE, find all occurrences of tags matching PREFIX.
 Optional argument TAGS is a list of tags to search.
 Returns a table of all matching tags."
   (if tags (call-next-method)
@@ -290,7 +285,7 @@ Returns a table of all matching tags."
 
 (defmethod semanticdb-find-tags-by-class-method
   ((table semanticdb-table-emacs-lisp) class &optional tags)
-  "In TABLE, find all occurances of tags of CLASS.
+  "In TABLE, find all occurrences of tags of CLASS.
 Optional argument TAGS is a list of tags to search.
 Returns a table of all matching tags."
   (if tags (call-next-method)
@@ -316,7 +311,7 @@ Like `semanticdb-find-tags-by-name-method' for Emacs Lisp."
 
 (defmethod semanticdb-deep-find-tags-for-completion-method
   ((table semanticdb-table-emacs-lisp) prefix &optional tags)
-  "In TABLE, find all occurances of tags matching PREFIX.
+  "In TABLE, find all occurrences of tags matching PREFIX.
 Optional argument TAGS is a list of tags to search.
 Like `semanticdb-find-tags-for-completion-method' for Emacs Lisp."
   (semanticdb-find-tags-for-completion-method table prefix tags))
@@ -343,5 +338,4 @@ Return a list of tags."
 
 (provide 'semantic/db-el)
 
-;; arch-tag: e54f556e-fa3f-4bc5-9b15-744a659a6e65
 ;;; semantic/db-el.el ends here