123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346 |
- (require 'semantic/db)
- (eval-when-compile
-
- (require 'eieio)
- (require 'eieio-opt)
- (require 'eieio-base))
- (declare-function semantic-elisp-desymbolify "semantic/bovine/el")
- (defclass semanticdb-table-emacs-lisp (semanticdb-abstract-table)
- ((major-mode :initform emacs-lisp-mode)
- )
- "A table for returning search results from Emacs.")
- (defmethod semanticdb-refresh-table ((obj semanticdb-table-emacs-lisp) &optional force)
- "Do not refresh Emacs Lisp table.
- It does not need refreshing."
- nil)
- (defmethod semanticdb-needs-refresh-p ((obj semanticdb-table-emacs-lisp))
- "Return nil, we never need a refresh."
- nil)
- (defclass semanticdb-project-database-emacs-lisp
- (semanticdb-project-database eieio-singleton)
- ((new-table-class :initform semanticdb-table-emacs-lisp
- :type class
- :documentation
- "New tables created for this database are of this class.")
- )
- "Database representing Emacs core.")
- (defvar-mode-local emacs-lisp-mode semanticdb-project-system-databases
- (list
- (semanticdb-project-database-emacs-lisp "Emacs"))
- "Search Emacs core for symbols.")
- (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 do system or recursive searching because of
- the omniscience database.")
- (defmethod semanticdb-get-database-tables ((obj semanticdb-project-database-emacs-lisp))
- "For an Emacs Lisp database, there are no explicit tables.
- Create one of our special tables that can act as an intermediary."
-
-
- (when (not (slot-boundp obj 'tables))
- (let ((newtable (semanticdb-table-emacs-lisp "Emacs System 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-emacs-lisp) filename)
- "From OBJ, return FILENAME's associated table object.
- For Emacs Lisp, creates a specialized table."
- (car (semanticdb-get-database-tables obj))
- )
- (defmethod semanticdb-get-tags ((table semanticdb-table-emacs-lisp ))
- "Return the list of tags belonging to TABLE."
-
- nil)
- (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 the `semantic-equivalent-major-modes'
- local variable."
- (with-current-buffer buffer
- (eq (or mode-local-active-mode major-mode) 'emacs-lisp-mode)))
- (defmethod semanticdb-full-filename ((obj semanticdb-table-emacs-lisp))
- "Fetch the full filename that OBJ refers to.
- For Emacs Lisp system DB, there isn't one."
- nil)
- (defmethod semanticdb-normalize-tags ((obj semanticdb-table-emacs-lisp) tags)
- "Convert tags, originating from Emacs OBJ, into standardized form."
- (let ((newtags nil))
- (dolist (T tags)
- (let* ((ot (semanticdb-normalize-one-tag obj T))
- (tag (cdr ot)))
- (setq newtags (cons tag newtags))))
-
- (nreverse newtags)))
- (defmethod semanticdb-normalize-one-tag ((obj semanticdb-table-emacs-lisp) tag)
- "Convert one TAG, originating from Emacs OBJ, into standardized form.
- If Emacs cannot resolve this symbol to a particular file, then return nil."
-
-
-
-
- (let* ((type (cond ((semantic-tag-of-class-p tag 'function)
- 'defun)
- ((semantic-tag-of-class-p tag 'variable)
- 'defvar)
- ))
- (sym (intern (semantic-tag-name tag)))
- (file (condition-case err
- (symbol-file sym type)
-
- (error (symbol-file sym))))
- )
- (if (or (not file) (not (file-exists-p file)))
-
-
- (cons obj tag)
- (when (string-match "\\.elc" file)
- (setq file (concat (file-name-sans-extension file)
- ".el"))
- (when (and (not (file-exists-p file))
- (file-exists-p (concat file ".gz")))
-
- (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)))
- (match nil))
-
- (dolist (T newtags)
- (when (semantic-tag-similar-p T tag)
- (setq match T)))
-
- (when (not match)
- (setq match (car newtags)))
-
- (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)
-
-
- (eieio-compiled-function-arglist def))
- ((eq (car-safe def) 'lambda)
- (nth 1 def))
- (t nil))))
- arglist))
- (defun semanticdb-elisp-sym->tag (sym &optional toktype)
- "Convert SYM into a semantic tag.
- TOKTYPE is a hint to the type of tag desired."
- (if (stringp sym)
- (setq sym (intern-soft sym)))
- (when sym
- (cond ((and (eq toktype 'function) (fboundp sym))
- (require 'semantic/bovine/el)
- (semantic-tag-new-function
- (symbol-name sym)
- nil
- (semantic-elisp-desymbolify
- (semanticdb-elisp-sym-function-arglist sym))
- :user-visible-flag (condition-case nil
- (interactive-form sym)
- (error nil))
- ))
- ((and (eq toktype 'variable) (boundp sym))
- (semantic-tag-new-variable
- (symbol-name sym)
- nil
- nil
- ))
- ((and (eq toktype 'type) (class-p sym))
- (semantic-tag-new-type
- (symbol-name sym)
- "class"
- (semantic-elisp-desymbolify
- (aref (class-v semanticdb-project-database)
- class-public-a))
- (semantic-elisp-desymbolify (class-parents sym))
- ))
- ((not toktype)
-
- (cond ((class-p sym)
- (semanticdb-elisp-sym->tag sym 'type))
- ((fboundp sym)
- (semanticdb-elisp-sym->tag sym 'function))
- ((boundp sym)
- (semanticdb-elisp-sym->tag sym 'variable))
- (t nil))
- )
- (t nil))))
- (defvar semanticdb-elisp-mapatom-collector nil
- "Variable used to collect `mapatoms' output.")
- (defmethod semanticdb-find-tags-by-name-method
- ((table semanticdb-table-emacs-lisp) name &optional tags)
- "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)
-
- (let* ((sym (intern-soft name))
- (fun (semanticdb-elisp-sym->tag sym 'function))
- (var (semanticdb-elisp-sym->tag sym 'variable))
- (typ (semanticdb-elisp-sym->tag sym 'type))
- (taglst nil)
- )
- (when (or fun var typ)
-
- (when var (setq taglst (cons var taglst)))
- (when typ (setq taglst (cons typ taglst)))
- (when fun (setq taglst (cons fun taglst)))
- taglst
- ))))
- (defmethod semanticdb-find-tags-by-name-regexp-method
- ((table semanticdb-table-emacs-lisp) regex &optional tags)
- "Find all tags with name matching REGEX in TABLE.
- Optional argument TAGS is a list of tags to search.
- Uses `apropos-internal' to find matches.
- Return a list of tags."
- (if tags (call-next-method)
- (delq nil (mapcar 'semanticdb-elisp-sym->tag
- (apropos-internal regex)))))
- (defmethod semanticdb-find-tags-for-completion-method
- ((table semanticdb-table-emacs-lisp) 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)
- (delq nil (mapcar 'semanticdb-elisp-sym->tag
- (all-completions prefix obarray)))))
- (defmethod semanticdb-find-tags-by-class-method
- ((table semanticdb-table-emacs-lisp) class &optional tags)
- "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)
-
- nil))
- (defmethod semanticdb-deep-find-tags-by-name-method
- ((table semanticdb-table-emacs-lisp) 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 Emacs Lisp."
- (semanticdb-find-tags-by-name-method table name tags))
- (defmethod semanticdb-deep-find-tags-by-name-regexp-method
- ((table semanticdb-table-emacs-lisp) 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 Emacs Lisp."
- (semanticdb-find-tags-by-name-regexp-method table regex tags))
- (defmethod semanticdb-deep-find-tags-for-completion-method
- ((table semanticdb-table-emacs-lisp) 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 Emacs Lisp."
- (semanticdb-find-tags-for-completion-method table prefix tags))
- (defmethod semanticdb-find-tags-external-children-of-type-method
- ((table semanticdb-table-emacs-lisp) type &optional tags)
- "Find all nonterminals which are child elements of TYPE
- Optional argument TAGS is a list of tags to search.
- Return a list of tags."
- (if tags (call-next-method)
-
- (when (featurep 'eieio)
- (let* ((class (intern-soft type))
- (taglst (when class
- (delq nil
- (mapcar 'semanticdb-elisp-sym->tag
-
-
- (eieio-all-generic-functions class)))))
- )
- taglst))))
- (provide 'semantic/db-el)
|