Function: semantic-go-to-tag

semantic-go-to-tag is an autoloaded and byte-compiled function defined in tag-file.el.gz.

Signature

(semantic-go-to-tag TAG &optional PARENT)

Documentation

Go to the location of TAG.

TAG may be a stripped element, in which case PARENT specifies a parent tag that has position information. PARENT can also be a semanticdb-table(var)/semanticdb-table(fun) object.

Source Code

;; Defined in /usr/src/emacs/lisp/cedet/semantic/tag-file.el.gz
;;;###autoload
(defun semantic-go-to-tag (tag &optional parent)
  "Go to the location of TAG.
TAG may be a stripped element, in which case PARENT specifies a
parent tag that has position information.
PARENT can also be a `semanticdb-table' object."
  (save-match-data
    (set-buffer
     (cond ((semantic-tag-in-buffer-p tag)
	    ;; We have a linked tag, go to that buffer.
	    (semantic-tag-buffer tag))
	   ((semantic-tag-file-name tag)
	    ;; If it didn't have a buffer, but does have a file
	    ;; name, then we need to get to that file so the tag
	    ;; location is made accurate.
	    (find-file-noselect (semantic-tag-file-name tag)))
	   ((and parent (semantic-tag-parent-buffer parent)))
	   ;; Well, just assume things are in the current buffer.
	   (t (current-buffer)))))
  ;; We should be in the correct buffer now, try and figure out
  ;; where the tag is.
  (cond ((semantic-tag-with-position-p tag)
	 ;; If it's a number, go there
	 (goto-char (semantic-tag-start tag)))
	((semantic-tag-with-position-p parent)
	 ;; Otherwise, it's a trimmed vector, such as a parameter,
	 ;; or a structure part.  If there is a parent, we can use it
	 ;; as a bounds for searching.
	 (goto-char (semantic-tag-start parent))
	 ;; Here we make an assumption that the text returned by
	 ;; the parser and concocted by us actually exists
	 ;; in the buffer.
	 (re-search-forward (semantic-tag-name tag)
			    (semantic-tag-end parent)
			    t))
	((semantic-tag-get-attribute tag :line)
	 ;; The tag has a line number in it.  Go there.
	 (goto-char (point-min))
	 (forward-line (1- (semantic-tag-get-attribute tag :line))))
	((and (semantic-tag-p parent) (semantic-tag-get-attribute parent :line))
	 ;; The tag has a line number in it.  Go there.
	 (goto-char (point-min))
	 (forward-line (1- (semantic-tag-get-attribute parent :line)))
	 (re-search-forward (semantic-tag-name tag) nil t))
	(t
	 ;; Take a guess that the tag has a unique name, and just
	 ;; search for it from the beginning of the buffer.
	 (goto-char (point-min))
	 (re-search-forward (semantic-tag-name tag) nil t)))
  )