]> code.delx.au - gnu-emacs/blobdiff - lisp/cedet/semantic/db-global.el
Merge from origin/emacs-24
[gnu-emacs] / lisp / cedet / semantic / db-global.el
index 7f3d616203e581660ffd43e94f8f146a2e2863c2..b95fa34cb3c89d82f8b7572c1a790cc9f4906f98 100644 (file)
@@ -1,6 +1,6 @@
 ;;; semantic/db-global.el --- Semantic database extensions for GLOBAL
 
-;; Copyright (C) 2002-2006, 2008-201 Free Software Foundation, Inc.
+;; Copyright (C) 2002-2006, 2008-2015 Free Software Foundation, Inc.
 
 ;; Author: Eric M. Ludlam <zappo@gnu.org>
 ;; Keywords: tags
 ;;; Code:
 
 ;;;###autoload
-(defun semanticdb-enable-gnu-global-databases (mode)
+(defun semanticdb-enable-gnu-global-databases (mode &optional noerror)
   "Enable the use of the GNU Global SemanticDB back end for all files of MODE.
 This will add an instance of a GNU Global database to each buffer
-in a GNU Global supported hierarchy."
+in a GNU Global supported hierarchy.
+
+Two sanity checks are performed to assure (a) that GNU global program exists
+and (b) that the GNU global program version is compatibility with the database
+version.  If optional NOERROR is nil, then an error may be signalled on version
+mismatch.  If NOERROR is not nil, then no error will be signaled.  Instead
+return value will indicate success or failure with non-nil or nil respective
+values."
   (interactive
    (list (completing-read
           "Enable in Mode: " obarray
@@ -51,17 +58,18 @@ in a GNU Global supported hierarchy."
           t (symbol-name major-mode))))
 
   ;; First, make sure the version is ok.
-  (cedet-gnu-global-version-check)
-
-  ;; Make sure mode is a symbol.
-  (when (stringp mode)
-    (setq mode (intern mode)))
-
-  (let ((ih (mode-local-value mode 'semantic-init-mode-hook)))
-    (eval `(setq-mode-local
-           ,mode semantic-init-mode-hook
-           (cons 'semanticdb-enable-gnu-global-hook ih))))
-
+  (if (not (cedet-gnu-global-version-check noerror))
+      nil
+    ;; Make sure mode is a symbol.
+    (when (stringp mode)
+      (setq mode (intern mode)))
+
+    (let ((ih (mode-local-value mode 'semantic-init-mode-hook)))
+      (eval `(setq-mode-local
+              ,mode semantic-init-mode-hook
+              (cons 'semanticdb-enable-gnu-global-hook ih))))
+    t
+    )
   )
 
 (defun semanticdb-enable-gnu-global-hook ()
@@ -72,6 +80,8 @@ MODE is the major mode to support."
 (defclass semanticdb-project-database-global
   ;; @todo - convert to one DB per directory.
   (semanticdb-project-database eieio-instance-tracker)
+
+  ;; @todo - use instance tracker symbol.
   ()
   "Database representing a GNU Global tags file.")
 
@@ -102,7 +112,12 @@ if optional DONT-ERR-IF-NOT-AVAILABLE is non-nil; else throw an error."
    )
   "A table for returning search results from GNU Global.")
 
-(defmethod semanticdb-equivalent-mode ((table semanticdb-table-global) &optional buffer)
+(cl-defmethod object-print ((obj semanticdb-table-global) &rest strings)
+  "Pretty printer extension for `semanticdb-table-global'.
+Adds the number of tags in this file to the object print name."
+  (apply 'call-next-method obj (cons " (proxy)" strings)))
+
+(cl-defmethod semanticdb-equivalent-mode ((table semanticdb-table-global) &optional buffer)
   "Return t, pretend that this table's mode is equivalent to BUFFER.
 Equivalent modes are specified by the `semantic-equivalent-major-modes'
 local variable."
@@ -111,7 +126,7 @@ local variable."
 
 ;;; Filename based methods
 ;;
-(defmethod semanticdb-get-database-tables ((obj semanticdb-project-database-global))
+(cl-defmethod semanticdb-get-database-tables ((obj semanticdb-project-database-global))
   "For a global database, there are no explicit tables.
 For each file hit, get the traditional semantic table from that file."
   ;; We need to return something since there is always the "master table"
@@ -123,9 +138,9 @@ For each file hit, get the traditional semantic table from that file."
       (oset newtable tags nil)
       ))
 
-  (call-next-method))
+  (cl-call-next-method))
 
-(defmethod semanticdb-file-table ((obj semanticdb-project-database-global) filename)
+(cl-defmethod semanticdb-file-table ((obj semanticdb-project-database-global) filename)
   "From OBJ, return FILENAME's associated table object."
   ;; We pass in "don't load".  I wonder if we need to avoid that or not?
   (car (semanticdb-get-database-tables obj))
@@ -135,13 +150,13 @@ For each file hit, get the traditional semantic table from that file."
 ;;
 ;; Only NAME based searches work with GLOBAL as that is all it tracks.
 ;;
-(defmethod semanticdb-find-tags-by-name-method
+(cl-defmethod semanticdb-find-tags-by-name-method
   ((table semanticdb-table-global) name &optional tags)
   "Find all tags named NAME in TABLE.
 Return a list of tags."
   (if tags
       ;; If TAGS are passed in, then we don't need to do work here.
-      (call-next-method)
+      (cl-call-next-method)
     ;; Call out to GNU Global for some results.
     (let* ((semantic-symref-tool 'global)
           (result (semantic-symref-find-tags-by-name name 'project))
@@ -152,12 +167,12 @@ Return a list of tags."
        (semantic-symref-result-get-tags result))
       )))
 
-(defmethod semanticdb-find-tags-by-name-regexp-method
+(cl-defmethod semanticdb-find-tags-by-name-regexp-method
   ((table semanticdb-table-global) regex &optional tags)
   "Find all tags with name matching REGEX in TABLE.
 Optional argument TAGS is a list of tags to search.
 Return a list of tags."
-  (if tags (call-next-method)
+  (if tags (cl-call-next-method)
     (let* ((semantic-symref-tool 'global)
           (result (semantic-symref-find-tags-by-regexp regex 'project))
           )
@@ -165,12 +180,12 @@ Return a list of tags."
        (semantic-symref-result-get-tags result))
       )))
 
-(defmethod semanticdb-find-tags-for-completion-method
+(cl-defmethod semanticdb-find-tags-for-completion-method
   ((table semanticdb-table-global) prefix &optional tags)
   "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)
+  (if tags (cl-call-next-method)
     (let* ((semantic-symref-tool 'global)
           (result (semantic-symref-find-tags-by-completion prefix 'project))
           (faketags nil)
@@ -191,21 +206,21 @@ Returns a table of all matching tags."
 ;; alone, otherwise replace with implementations similar to those
 ;; above.
 ;;
-(defmethod semanticdb-deep-find-tags-by-name-method
+(cl-defmethod semanticdb-deep-find-tags-by-name-method
   ((table semanticdb-table-global) name &optional tags)
   "Find all tags name NAME in TABLE.
 Optional argument TAGS is a list of tags to search.
 Like `semanticdb-find-tags-by-name-method' for global."
   (semanticdb-find-tags-by-name-method table name tags))
 
-(defmethod semanticdb-deep-find-tags-by-name-regexp-method
+(cl-defmethod semanticdb-deep-find-tags-by-name-regexp-method
   ((table semanticdb-table-global) regex &optional tags)
   "Find all tags with name matching REGEX in TABLE.
 Optional argument TAGS is a list of tags to search.
 Like `semanticdb-find-tags-by-name-method' for global."
   (semanticdb-find-tags-by-name-regexp-method table regex tags))
 
-(defmethod semanticdb-deep-find-tags-for-completion-method
+(cl-defmethod semanticdb-deep-find-tags-for-completion-method
   ((table semanticdb-table-global) prefix &optional tags)
   "In TABLE, find all occurrences of tags matching PREFIX.
 Optional argument TAGS is a list of tags to search.