123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- (require 'cedet-global)
- (require 'semantic/db-find)
- (require 'semantic/symref/global)
- (eval-when-compile
-
- (require 'eieio)
- (require 'eieio-opt)
- )
- (defun semanticdb-enable-gnu-global-databases (mode)
- "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."
- (interactive
- (list (completing-read
- "Enable in Mode: " obarray
- #'(lambda (s) (get s 'mode-local-symbol-table))
- t (symbol-name major-mode))))
-
- (cedet-gnu-global-version-check)
-
- (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))))
- )
- (defun semanticdb-enable-gnu-global-hook ()
- "Add support for GNU Global in the current buffer via `semantic-init-hook'.
- MODE is the major mode to support."
- (semanticdb-enable-gnu-global-in-buffer t))
- (defclass semanticdb-project-database-global
-
- (semanticdb-project-database eieio-instance-tracker)
- ()
- "Database representing a GNU Global tags file.")
- (defun semanticdb-enable-gnu-global-in-buffer (&optional dont-err-if-not-available)
- "Enable a GNU Global database in the current buffer.
- When GNU Global is not available for this directory, display a message
- if optional DONT-ERR-IF-NOT-AVAILABLE is non-nil; else throw an error."
- (interactive "P")
- (if (cedet-gnu-global-root)
- (setq
-
- semanticdb-project-system-databases
- (cons (semanticdb-project-database-global "global")
- semanticdb-project-system-databases)
-
- semanticdb-find-default-throttle
- (append semanticdb-find-default-throttle
- '(omniscience))
- )
- (if dont-err-if-not-available
- nil
- (error "No Global support in %s" default-directory))
- ))
- (defclass semanticdb-table-global (semanticdb-search-results-table)
- ((major-mode :initform nil)
- )
- "A table for returning search results from GNU Global.")
- (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."
-
- t)
- (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."
-
-
- (when (not (slot-boundp obj 'tables))
- (let ((newtable (semanticdb-table-global "GNU Global Search Table")))
- (oset obj tables (list newtable))
- (oset newtable parent-db obj)
- (oset newtable tags nil)
- ))
- (call-next-method))
- (defmethod semanticdb-file-table ((obj semanticdb-project-database-global) filename)
- "From OBJ, return FILENAME's associated table object."
-
- (car (semanticdb-get-database-tables obj))
- )
- (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
-
- (call-next-method)
-
- (let* ((semantic-symref-tool 'global)
- (result (semantic-symref-find-tags-by-name name 'project))
- )
- (when result
-
-
- (semantic-symref-result-get-tags result))
- )))
- (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)
- (let* ((semantic-symref-tool 'global)
- (result (semantic-symref-find-tags-by-regexp regex 'project))
- )
- (when result
- (semantic-symref-result-get-tags result))
- )))
- (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)
- (let* ((semantic-symref-tool 'global)
- (result (semantic-symref-find-tags-by-completion prefix 'project))
- (faketags nil)
- )
- (when result
- (dolist (T (oref result :hit-text))
-
-
- (setq faketags (cons
- (semantic-tag T 'function :faux t)
- faketags))
- )
- faketags))))
- (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
- ((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
- ((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.
- Like `semanticdb-find-tags-for-completion-method' for global."
- (semanticdb-find-tags-for-completion-method table prefix tags))
- (provide 'semantic/db-global)
|