emacs/lisp/cedet/semantic/symref.el
David Engster 5d4da32d4e Update from CEDET trunk.
* grammars/c.by (template-type): Add :template-specifier and
:typevar to capture extra details about the template.
(opt-post-fcn-modifiers): Splice in the found symbol into the
return value correctly.
(QUESTION): New punctuation.
(expression): Add ternary conditional support.

* grammars/scheme.by (MODULE): New token.
(scheme): Handle expanding the MODULE tag.
(scheme-list): Remove closeparen required match.
(scheme-in-list): Remove extraneous matches for DEFINE.  Add
support for MODULE Simplify matching for code & make work.
(name-args, name-arg-list, name-arg-expand): Make it work.

* semantic.el (semantic-mode): Add/remove 3
completion-at-point-functions.
(semantic-completion-at-point-function): Removed.
(semantic-analyze-completion-at-point-function)
(semantic-analyze-notc-completion-at-point-function)
(semantic-analyze-nolongprefix-completion-at-point-function): New
completion at point functions.

* semantic/doc.el (semantic-doc-snarf-comment-for-tag): Fix case
when comment-end is empty string.

* semantic/debug.el
(semantic-debug-parser-debugger-source): New buffer local
variable.
(semantic-debug-interface): Add 'nil' initform to overlays.
(semantic-debug-mode): Remove read-only tags from buffers on exit.
(semantic-debug): Add autoload cookie.  Force the language
specific debugger to load.

* semantic/db.el (generic::semanticdb-full-filename): New generic
method to allow this method to be used on buffer names via an
associated database.

* semantic/symref.el
(semantic-symref-cleanup-recent-buffers-fcn): When cleaning up
buffers, don't clean up buffers that are being used (i.e., in a
window) when the hook fires.
(semantic-symref-recently-opened-buffers): New tracking variable.
(semantic-symref-cleanup-recent-buffers-fcn): New hook fcn.
(semantic-symref-result-get-tags): Move logic into
`semantic-symref-hit-to-tag-via-buffer', and cleanup buffers via
the symref cleanup function in post-command-hook.
(semantic-symref-hit-to-tag-via-buffer): Logic that used to be
from above.
(semantic-symref-hit-to-tag-via-db): New.

* semantic/analyze.el:
(semantic-analyze-find-tag-sequence-default): If first entry in
sequence is the only one, apply tagclass filter.
(semantic-analyze-princ-sequence): Show slot even if empty.
(semantic-analyze-find-tag-sequence)
(semantic-analyze-find-tag-sequence-default): Add flags argument.
Add support for forcing the final entry of the sequence to be of
class variable.
(semantic-analyze-find-tag): Fix bug where input class filter was
ignored if there was a typecache match.
(semantic-analyze-current-context-default): For assignments, the
assignee now must be of class variable.

* semantic/analyze/complete.el
(semantic-analyze-possible-completions-default): Add
'no-longprefix' flag.  When used, the prefix and prefixtypes are
shortened to just the last symbol.

* semantic/bovine/c.el (semantic-c-do-lex-if): Catch errors from
'hideif', and push to the parser warning stack.
(semantic-lex-cpp-define): When a comment is at the end of a
macro, do not subtract an extra 1 from the found position.  Fixes
bug with: #define foo (a)/**/ adding an extra ')' to the stream.

* semantic/bovine/scm.el (semantic-lex-scheme-symbol): Allow
symbols to be one char long.

* semantic/bovine/grammar.el
(bovine-grammar-calculate-source-on-path): New.
(bovine-grammar-setupcode-builder): Use it.

* ede.el (ede/detect): New require.
(ede-version): Bump version
(ede-initialize-state-current-buffer): Use new
`ede-detect-directory-for-project' to detect projects first
instead of depending on currente dir only.
(ede-delete-project-from-global-list): New.
(ede-flush-deleted-projects): Use above.
(ede-check-project-query-fcn): New variable
(ede-check-project-directory): Use above when querying the user.
Added to support unit testing of this security measure.
(ede-initialize-state-current-buffer): Use
`ede-directory-project-cons' instead of the -detect- fcn to take
advantage of the cache.  Pass found project into
`ede-load-project-file'.
(ede-load-project-file): Add new input DETECTIN.
(ede-rescan-toplevel): Get the proj root a better way.
(ede-load-project-file): Return the loaded object.  When asking
for existing project, ask for an exact match.
(ede-initialize-state-current-buffer): Simplify some conditional
logic.
(ede-load-project-file): Simplify conditional logic.
(ede-global-list-sanity-check): New Testing fcn.
(ede-parent-project): Replace old code with call to faster
`ede-find-subproject-for-directory'.
(ede-load-project-file): Use
`ede-directory-get-toplevel-open-project' instead of above
deleted.  Rename "pfc" to "autoloader".  Use
`ede-directory-project-cons' to detect a project.  Delete no
project found case where we search up the tree.

* ede/auto.el (ede-project-autoload): Fix doc typo.  Add
`:root-only' slot.
(ede-auto-load-project): Doc update: warn to not use.
(ede-dir-to-projectfile): Deleted.
(ede-project-autoload-dirmatch): Add subdir-only slot.  Make
configdatastash unbound by default.
(ede-do-dirmatch): If subdir-only is true, then don't allow exact
matches.  Account for configdatastash as unbound.  Assume value of
nil means no tool installed.  Make sure loaded path matches from
beginning.  Stash the regexp, not the raw string.
(ede-project-class-files): Note that makefile and automake are not
root only.
(ede-auto-detect-in-dir): New (for use with `ede/detect.el').
(ede-project-dirmatch-p): Deleted.
(ede-project-root-directory): Remove body, return nil.
(ede-project-autoload): :proj-root-dirmatch can be null & doc fix.
(ede-auto-detect-in-dir): If there is no :proj-file, check for a
dirmatch.

* ede/generic.el (ede/config): Replace require of ede.
(ede-generic-new-autoloader): Generic projects are now safe by
default.  Note this is NOT a root only project.
(project-rescan, ede-project-root, ede-generic-target-java)
(ede-java-classpath, ede-find-subproject-for-directory): New.
(ede-enable-generic-projects): Add new autoloaders for git, bzr,
hg, sv, CVS.
(ede-generic-vc-project)
(ede-generic-vc-project::ede-generic-setup-configuration): New.
(ede-generic-config): Remove slots: c-include-path,
c-preprocessor-table, c-preprocessor-files, classpath,
build-command, debug-command, run command.  Inherit from
ede-extra-config-build, ede-extra-config-program.  Make
run-command :value match :custom so only strings are accepted.
Add some more :group slot specifiers.
(ede-generic-project): Add mixins `ede-project-with-config-c' and
`ede-project-with-config-java'. Inherit from
`ede-project-with-config-build',
`ede-project-with-config-program'.  Subclass
`ede-project-with-config'.  Remove duplication from new baseclass.
(ede-generic-target): Inherit from `ede-target-with-config-build',
`ede-target-with-config-program'. Subclass `ede-target-with-config'.
(ede-generic-target-c-cpp): Add mixin `ede-target-with-config-c'.
(ede-generic-target-java): Add mixin `ede-target-with-config-java'.
(ede-preprocessor-map, ede-system-include-path)
(edejava-classpath): Deleted, moved to config.el.
(project-compile-project, project-compile-target)
(project-debug-target, project-run-target): Deleted.
(ede-generic-get-configuration, ede-generic-setup-configuration)
(ede-commit-project, project-rescan)
(ede-generic-project::ede-customize)
(ede-generic-target::ede-customize)
(ede-generic-config::eieio-done-customizing)
(ede-generic-config::ede-commit): Deleted.  Subsumed by new
baseclass.
(ede-preprocessor-map, ede-system-include-path)
(project-debug-target, project-run-target): Call new
`ede-config-get-configuration' instead of old version.
(ede-generic-load): Do not add to global list here.

* ede/files.el (ede-find-project-root)
(ede-files-find-existing)
(ede-directory-get-toplevel-open-project-new): Deleted.
(ede-project-root-directory): Use `ede-project-root' first.
(ede-project-directory-remove-hash)
(ede--directory-project-from-hash)
(ede--directory-project-add-description-to-hash): Rename to make
internal symbols (via --).  Expand input dir first.
(ede-directory-project-p): Doc fix (note obsoleted.)
(ede-toplevel-project-or-nil): Alias to `ede-toplevel-project'.
(ede-toplevel-project): Doc Fix.  Delete commented out old code.
Simplify returning result from ede-detect-directory-for-project.
(ede-directory-get-open-project): Support when
inodes are disabled.  If disabled to str compare on root project.
(ede-directory-get-toplevel-open-project): Enabled nested
projects.  When doing directory name matching, save the 'short'
version of an answer (non-exact match) and eventually select the
shortest answer at the end.  Expand the filename of tested
projects.  Better support for when inodes are disabled.  Add
'exact' option so that it will return a project that is an exact
match.
(ede-find-subproject-for-directory): Small optimization to run
`file-truename' less often.
(ede-directory-project-p): Move content, then use
`ede-directory-project-cons'.  Use
`ede-detect-directory-for-project', replacing old detection loop.
(ede-directory-project-cons): New, from above.
(ede-toplevel-project): Toss old scanning code.  Use
`ede-detect-directory-for-project' instead.
(ede-directory-get-toplevel-open-project-new): New.

* ede/linux.el (ede-linux-project-root): Deleted.
(ede-project-autoload): Remove dirmatch entry - it is no longer
needed.

* lisp/cedet/ede/proj.el (project-rescan): Replace direct
manipulation of `ede-projects' with equivalent and better
functions.
(ede-proj-load): Replace call to test if dir has project to
explicity ask filesystem if Project.ede is there.

* ede/config.el:
* ede/detect.el: New files.

* ede/project-am.el (project-run-target): Add "./" to program to
run for systems where '.' isn't in PATH.
(project-am-load): Remove old code regarding `ede-constructing'.
Just read in the makefiles.

* ede/linux.el (ede-linux-load): Do not add to global list here.
Don't check for existing anymore.
(project-rescan): New.
(ede-linux-project-list, ede-linux-file-existing): Deleted.
(ede-linux-project-root): Delete body.  Need symbol for autoloads
for now.
(ede-linux-project): No longer instance tracker.
(ede-project-autoload): Don't provide :proj-root

* ede/emacs.el (ede-emacs-load): Do not add project to global list
here.  Don't look for existing first.
(ede-project-autoload): Remove dirmatch entry - it is no longer
needed.  Don't provide proj-root anymore.
(ede-emacs-project-list, ede-emacs-file-existing): Delete.
(ede-emacs-project-root): Remove body (need symbol for loaddefs
still).
(ede-emacs-project): Do not instance track anymore.

* ede/cpp-root.el (initialize-instance): Remove commented code.
Add note about why we are adding the project to the master list.
Make sure if we are replacing a prev version, remove from global
list.
(ede-cpp-root-file-existing)
(ede-cpp-root-project-file-for-dir)
(ede-cpp-root-count, ede-cpp-root-project-root, ede-cpp-root-load)
(ede-project-autoload cpp-root): Deleted.
(ede-project-root-directory): Return :directory instead of
calculating from :file.
(project-rescan): New.

* ede/base.el (ede-toplevel): Only use buffer cached value if
subproj not passed in.

* srecode/java.el (srecode-semantic-handle-:java): Fix case when
an EDE project didn't support java paths.

* lisp/cedet/ede/proj-elisp.el
(ede-proj-target-elisp::ede-proj-tweak-autoconf): Kill buffer
after saving modified elisp-comp script, as to avoid "file has
changed on disk; really edit the buffer" questions when script
gets rewritten.

* emacs-lisp/eieio-custom.el (eieio-customize-object): Set
eieio-cog (current group) to g, which is an improved form of input
group.

* srecode/doc-cpp.srt (mode): Set to c mode so this works with
both C and C++.
2014-11-10 01:04:30 +01:00

581 lines
21 KiB
EmacsLisp

;;; semantic/symref.el --- Symbol Reference API
;; Copyright (C) 2008-2014 Free Software Foundation, Inc.
;; Author: Eric M. Ludlam <eric@siege-engine.com>
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;; Semantic Symbol Reference API.
;;
;; 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 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
;; range of functions that can be used to identify references. The
;; API is backed by an OO system that is used to allow multiple
;; external tools to provide the information.
;;
;; The default implementation uses a find/grep combination to do a
;; search. This works ok in small projects. For larger projects, it
;; is important to find an alternate tool to use as a back-end to
;; symref.
;;
;; See the command: `semantic-symref' for an example app using this api.
;;
;; TO USE THIS TOOL
;;
;; The following functions can be used to find different kinds of
;; references.
;;
;; `semantic-symref-find-references-by-name'
;; `semantic-symref-find-file-references-by-name'
;; `semantic-symref-find-text'
;;
;; All the search routines return a class of type
;; `semantic-symref-result'. You can reference the various slots, but
;; you will need the following methods to get extended information.
;;
;; `semantic-symref-result-get-files'
;; `semantic-symref-result-get-tags'
;;
;; ADD A NEW EXTERNAL TOOL
;;
;; 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)
(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
"*The active symbol reference tool name.
The tool symbol can be 'detect, or a symbol that is the name of
a tool that can be used for symbol referencing.")
(make-variable-buffer-local 'semantic-symref-tool)
;;; TOOL SETUP
;;
(defvar semantic-symref-tool-alist
'( ( (lambda (rootdir) (file-exists-p (expand-file-name "GPATH" rootdir))) .
global)
( (lambda (rootdir) (file-exists-p (expand-file-name "ID" rootdir))) .
idutils)
( (lambda (rootdir) (file-exists-p (expand-file-name "cscope.out" rootdir))) .
cscope )
)
"Alist of tools usable by `semantic-symref'.
Each entry is of the form:
( PREDICATE . KEY )
Where PREDICATE is a function that takes a directory name for the
root of a project, and returns non-nil if the tool represented by KEY
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* ((rootdir (semantic-symref-calculate-rootdir))
(tools semantic-symref-tool-alist))
(while (and tools (eq semantic-symref-tool 'detect))
(when (funcall (car (car tools)) rootdir)
(setq semantic-symref-tool (cdr (car tools))))
(setq tools (cdr tools)))
(when (eq semantic-symref-tool 'detect)
(setq semantic-symref-tool 'grep))
semantic-symref-tool)))
(defun semantic-symref-instantiate (&rest args)
"Instantiate a new symref search object.
ARGS are the initialization arguments to pass to the created class."
(let* ((srt (symbol-name (semantic-symref-detect-symref-tool)))
(class (intern-soft (concat "semantic-symref-tool-" srt)))
(inst nil)
)
(when (not (class-p class))
(error "Unknown symref tool %s" semantic-symref-tool))
(setq inst (apply 'make-instance class args))
inst))
(defvar semantic-symref-last-result nil
"The last calculated symref result.")
(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*")
(data-debug-insert-object-slots semantic-symref-last-result "]"))
(message "Empty results.")))
;;; 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.
Refers to `semantic-symref-tool', to determine the reference tool to use
for the current buffer.
Returns an object of class `semantic-symref-result'.
TOOL-RETURN is an optional symbol, which will be assigned the tool used
to perform the search. This was added for use by a test harness."
(interactive "sName: ")
(let* ((inst (semantic-symref-instantiate
:searchfor name
:searchtype 'symbol
:searchscope (or scope 'project)
:resulttype 'line))
(result (semantic-symref-get-result inst)))
(when tool-return
(set tool-return inst))
(prog1
(setq semantic-symref-last-result result)
(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 tags by NAME in the current project.
Optional SCOPE specifies which file set to search. Defaults to 'project.
Refers to `semantic-symref-tool', to determine the reference tool to use
for the current buffer.
Returns an object of class `semantic-symref-result'."
(interactive "sName: ")
(let* ((inst (semantic-symref-instantiate
:searchfor name
:searchtype 'tagname
:searchscope (or scope 'project)
:resulttype 'line))
(result (semantic-symref-get-result inst)))
(prog1
(setq semantic-symref-last-result result)
(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.
Refers to `semantic-symref-tool', to determine the reference tool to use
for the current buffer.
Returns an object of class `semantic-symref-result'."
(interactive "sName: ")
(let* ((inst (semantic-symref-instantiate
:searchfor name
:searchtype 'tagregexp
:searchscope (or scope 'project)
:resulttype 'line))
(result (semantic-symref-get-result inst)))
(prog1
(setq semantic-symref-last-result result)
(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.
Refers to `semantic-symref-tool', to determine the reference tool to use
for the current buffer.
Returns an object of class `semantic-symref-result'."
(interactive "sName: ")
(let* ((inst (semantic-symref-instantiate
:searchfor name
:searchtype 'tagcompletions
:searchscope (or scope 'project)
:resulttype 'line))
(result (semantic-symref-get-result inst)))
(prog1
(setq semantic-symref-last-result result)
(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.
Refers to `semantic-symref-tool', to determine the reference tool to use
for the current buffer.
Returns an object of class `semantic-symref-result'."
(interactive "sName: ")
(let* ((inst (semantic-symref-instantiate
:searchfor name
:searchtype 'regexp
:searchscope (or scope 'project)
:resulttype 'file))
(result (semantic-symref-get-result inst)))
(prog1
(setq semantic-symref-last-result result)
(when (called-interactively-p 'interactive)
(semantic-symref-data-debug-last-result))))
)
;;;###autoload
(defun semantic-symref-find-text (text &optional scope)
"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
for the current buffer.
Returns an object of class `semantic-symref-result'."
(interactive "sEgrep style Regexp: ")
(let* ((inst (semantic-symref-instantiate
:searchfor text
:searchtype 'regexp
:searchscope (or scope 'project)
:resulttype 'line))
(result (semantic-symref-get-result inst)))
(prog1
(setq semantic-symref-last-result result)
(when (called-interactively-p 'interactive)
(semantic-symref-data-debug-last-result))))
)
;;; RESULTS
;;
;; The results class and methods provide features for accessing hits.
(defclass semantic-symref-result ()
((created-by :initarg :created-by
:type semantic-symref-tool-baseclass
:documentation
"Back-pointer to the symref tool creating these results.")
(hit-files :initarg :hit-files
:type list
:documentation
"The list of files hit.")
(hit-text :initarg :hit-text
:type list
:documentation
"If the result doesn't provide full lines, then fill in hit-text.
GNU Global does completion search this way.")
(hit-lines :initarg :hit-lines
:type list
:documentation
"The list of line hits.
Each element is a cons cell of the form (LINE . FILENAME).")
(hit-tags :initarg :hit-tags
:type list
:documentation
"The list of tags with hits in them.
Use the `semantic-symref-hit-tags' method to get this list.")
)
"The results from a symbol reference search.")
(defmethod semantic-symref-result-get-files ((result semantic-symref-result))
"Get the list of files from the symref result RESULT."
(if (slot-boundp result :hit-files)
(oref result hit-files)
(let* ((lines (oref result :hit-lines))
(files (mapcar (lambda (a) (cdr a)) lines))
(ans nil))
(setq ans (list (car files))
files (cdr files))
(dolist (F files)
;; 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)))
(setq ans (cons F ans))))
(oset result hit-files (nreverse ans))
)
))
(defvar semantic-symref-recently-opened-buffers nil
"List of buffers opened by `semantic-symref-result-get-tags'.")
(defun semantic-symref-cleanup-recent-buffers-fcn ()
"Hook function to be used in 'post-command-hook' to cleanup buffers.
Buffers collected during symref can result in some files being
opened multiple times for one operation. This will keep buffers open
until the next command is executed."
;;(message "To Clean Up: %S" semantic-symref-recently-opened-buffers)
(mapc (lambda (buff)
;; Don't delete any buffers which are being used
;; upon completion of some command.
(when (not (get-buffer-window buff))
(kill-buffer buff)))
semantic-symref-recently-opened-buffers)
(setq semantic-symref-recently-opened-buffers nil)
(remove-hook 'post-command-hook 'semantic-symref-cleanup-recent-buffers-fcn)
)
(defmethod semantic-symref-result-get-tags ((result semantic-symref-result)
&optional open-buffers)
"Get the list of tags from the symref result RESULT.
Optional OPEN-BUFFERS indicates that the buffers that the hits are
in should remain open after scanning.
Note: This can be quite slow if most of the hits are not in buffers
already."
(if (and (slot-boundp result :hit-tags) (oref result hit-tags))
(oref result hit-tags)
;; Calculate the tags.
(let ((lines (oref result :hit-lines))
(txt (oref (oref result :created-by) :searchfor))
(searchtype (oref (oref result :created-by) :searchtype))
(ans nil)
(out nil))
(save-excursion
(setq ans (mapcar
(lambda (hit)
(semantic-symref-hit-to-tag-via-buffer
hit txt searchtype open-buffers))
lines)))
;; Kill off dead buffers, unless we were requested to leave them open.
(if (not open-buffers)
(add-hook 'post-command-hook 'semantic-symref-cleanup-recent-buffers-fcn)
;; Else, just clear the saved buffers so they aren't deleted later.
(setq semantic-symref-recently-opened-buffers nil)
)
;; Strip out duplicates.
(dolist (T ans)
(if (and T (not (semantic-equivalent-tag-p (car out) T)))
(setq out (cons T out))
(when T
;; Else, add this line into the existing list of lines.
(let ((lines (append (semantic--tag-get-property (car out) :hit)
(semantic--tag-get-property T :hit))))
(semantic--tag-put-property (car out) :hit lines)))
))
;; Out is reversed... twice
(oset result :hit-tags (nreverse out)))))
(defun semantic-symref-hit-to-tag-via-db (hit searchtxt searchtype)
"Convert the symref HIT into a TAG by looking up the tag via a database.
Return the Semantic tag associated with HIT.
SEARCHTXT is the text that is being searched for.
Used to narrow the in-buffer search.
SEARCHTYPE is the type of search (such as 'symbol or 'tagname).
If there is no database, of if the searchtype is wrong, return nil."
;; Allowed search types for this mechanism:
;; tagname, tagregexp, tagcompletions
(if (not (memq searchtype '(tagname tagregexp tagcompletions)))
nil
(let* ((line (car hit))
(file (cdr hit))
;; FAIL here vv - don't load is not obeyed if no table found.
(db (semanticdb-file-table-object file t))
(found nil)
(hit nil)
)
(cond ((eq searchtype 'tagname)
(setq found (semantic-find-tags-by-name searchtxt db)))
((eq searchtype 'tagregexp)
(setq found (semantic-find-tags-by-name-regexp searchtxt db)))
((eq searchtype 'tagcompletions)
(setq found (semantic-find-tags-for-completion searchtxt db)))
)
;; Loop over FOUND to see if we can line up a match with a line number.
(when (= (length found) 1)
(setq hit (car found)))
;; FAIL here ^^ - symref finds line numbers, but our DB uses character locations.
;; as such, this is a cheat and we will need to give up.
hit)))
(defun semantic-symref-hit-to-tag-via-buffer (hit searchtxt searchtype &optional open-buffers)
"Convert the symref HIT into a TAG by looking up the tag via a buffer.
Return the Semantic tag associated with HIT.
SEARCHTXT is the text that is being searched for.
Used to narrow the in-buffer search.
SEARCHTYPE is the type of search (such as 'symbol or 'tagname).
Optional OPEN-BUFFERS, when nil will use a faster version of
`find-file' when a file needs to be opened. If non-nil, then
normal buffer initialization will be used.
This function will leave buffers loaded from a file open, but
will add buffers that must be opened to `semantic-symref-recently-opened-buffers'.
Any caller MUST deal with that variable, either clearing it, or deleting the
buffers that were opened."
(let* ((line (car hit))
(file (cdr hit))
(buff (find-buffer-visiting file))
(tag nil)
)
(cond
;; We have a buffer already. Check it out.
(buff
(set-buffer buff))
;; We have a table, but it needs a refresh.
;; This means we should load in that buffer.
(t
(let ((kbuff
(if open-buffers
;; Even if we keep the buffers open, don't
;; let EDE ask lots of questions.
(let ((ede-auto-add-method 'never))
(find-file-noselect file t))
;; When not keeping the buffers open, then
;; don't setup all the fancy froo-froo features
;; either.
(semantic-find-file-noselect file t))))
(set-buffer kbuff)
(push kbuff semantic-symref-recently-opened-buffers)
(semantic-fetch-tags)
))
)
;; Too much baggage in goto-line
;; (goto-line line)
(goto-char (point-min))
(forward-line (1- line))
;; Search forward for the matching text
(when (re-search-forward (regexp-quote searchtxt)
(point-at-eol)
t)
(goto-char (match-beginning 0))
)
(setq tag (semantic-current-tag))
;; If we are searching for a tag, but bound the tag we are looking
;; for, see if it resides in some other parent tag.
;;
;; If there is no parent tag, then we still need to hang the originator
;; in our list.
(when (and (eq searchtype 'symbol)
(string= (semantic-tag-name tag) searchtxt))
(setq tag (or (semantic-current-tag-parent) tag)))
;; Copy the tag, which adds a :filename property.
(when tag
(setq tag (semantic-tag-copy tag nil t))
;; Ad this hit to the tag.
(semantic--tag-put-property tag :hit (list line)))
tag))
;;; SYMREF TOOLS
;;
;; The base symref tool provides something to hang new tools off of
;; for finding symbol references.
(defclass semantic-symref-tool-baseclass ()
((searchfor :initarg :searchfor
:type string
:documentation "The thing to search for.")
(searchtype :initarg :searchtype
:type symbol
:documentation "The type of search to do.
Values could be `symbol, `regexp, 'tagname, or 'completion.")
(searchscope :initarg :searchscope
:type symbol
:documentation
"The scope to search for.
Can be 'project, 'target, or 'file.")
(resulttype :initarg :resulttype
:type symbol
:documentation
"The kind of search results desired.
Can be 'line, 'file, or 'tag.
The type of result can be converted from 'line to 'file, or 'line to 'tag,
but not from 'file to 'line or 'tag.")
)
"Baseclass for all symbol references tools.
A symbol reference tool supplies functionality to identify the locations of
where different symbols are used.
Subclasses should be named `semantic-symref-tool-NAME', where
NAME is the name of the tool used in the configuration variable
`semantic-symref-tool'"
:abstract t)
(defmethod semantic-symref-get-result ((tool semantic-symref-tool-baseclass))
"Calculate the results of a search based on TOOL.
The symref TOOL should already contain the search criteria."
(let ((answer (semantic-symref-perform-search tool))
)
(when answer
(let ((answersym (if (eq (oref tool :resulttype) 'file)
:hit-files
(if (stringp (car answer))
:hit-text
:hit-lines))))
(semantic-symref-result (oref tool searchfor)
answersym
answer
:created-by tool))
)
))
(defmethod semantic-symref-perform-search ((tool semantic-symref-tool-baseclass))
"Base search for symref tools should throw an error."
(error "Symref tool objects must implement `semantic-symref-perform-search'"))
(defmethod semantic-symref-parse-tool-output ((tool semantic-symref-tool-baseclass)
outputbuffer)
"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."
(with-current-buffer outputbuffer
(goto-char (point-min))
(let ((result nil)
(hit nil))
(while (setq hit (semantic-symref-parse-tool-output-one-line tool))
(setq result (cons hit result)))
(nreverse result)))
)
(defmethod semantic-symref-parse-tool-output-one-line ((tool semantic-symref-tool-baseclass))
"Base tool output parser is not implemented."
(error "Symref tool objects must implement `semantic-symref-parse-tool-output-one-line'"))
(provide 'semantic/symref)
;; Local variables:
;; generated-autoload-file: "loaddefs.el"
;; generated-autoload-load-name: "semantic/symref"
;; End:
;;; semantic/symref.el ends here