Function: etags-goto-tag-location
etags-goto-tag-location is a byte-compiled function defined in
etags.el.gz.
Signature
(etags-goto-tag-location TAG-INFO)
Documentation
Go to location of tag specified by TAG-INFO.
TAG-INFO is a cons (TEXT LINE . POSITION). TEXT is the initial part of a line containing the tag. LINE is the line number. POSITION is the (one-based) char position of TEXT within the file.
If TEXT is t, it means the tag refers to exactly LINE or POSITION, whichever is present, LINE having preference, no searching. Either LINE or POSITION can be nil. POSITION is used if present.
If the tag isn't exactly at the given position, then look near that position using a search window that expands progressively until it hits the start of file.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/etags.el.gz
(defun etags-goto-tag-location (tag-info)
"Go to location of tag specified by TAG-INFO.
TAG-INFO is a cons (TEXT LINE . POSITION).
TEXT is the initial part of a line containing the tag.
LINE is the line number.
POSITION is the (one-based) char position of TEXT within the file.
If TEXT is t, it means the tag refers to exactly LINE or POSITION,
whichever is present, LINE having preference, no searching.
Either LINE or POSITION can be nil. POSITION is used if present.
If the tag isn't exactly at the given position, then look near that
position using a search window that expands progressively until it
hits the start of file."
(let ((startpos (cdr (cdr tag-info)))
(line (car (cdr tag-info)))
offset found pat)
(if (eq (car tag-info) t)
;; Direct file tag.
(cond (line (progn (goto-char (point-min))
(forward-line (1- line))))
(startpos (goto-char startpos))
(t (error "etags.el BUG: bogus direct file tag")))
;; This constant is 1/2 the initial search window.
;; There is no sense in making it too small,
;; since just going around the loop once probably
;; costs about as much as searching 2000 chars.
(setq offset 1000
found nil
pat (concat (if (eq selective-display t)
"\\(^\\|\^m\\)" "^")
(regexp-quote (car tag-info))))
;; The character position in the tags table is 0-origin and counts CRs.
;; Convert it to a 1-origin Emacs character position.
(when startpos
(setq startpos (1+ startpos))
(when (and line
(eq 1 (coding-system-eol-type buffer-file-coding-system)))
;; Act as if CRs were elided from all preceding lines.
;; Although this doesn't always give exactly the correct position,
;; it does typically improve the guess.
(setq startpos (- startpos (1- line)))))
;; If no char pos was given, try the given line number.
(or startpos
(if line
(setq startpos (progn (goto-char (point-min))
(forward-line (1- line))
(point)))))
(or startpos
(setq startpos (point-min)))
;; First see if the tag is right at the specified location.
(goto-char startpos)
(setq found (looking-at pat))
(while (and (not found)
(progn
(goto-char (- startpos offset))
(not (bobp))))
(setq found
(re-search-forward pat (+ startpos offset) t)
offset (* 3 offset))) ; expand search window
(or found
(re-search-forward pat nil t)
(user-error "Rerun etags: `%s' not found in %s"
pat buffer-file-name)))
;; Position point at the right place
;; if the search string matched an extra Ctrl-m at the beginning.
(and (eq selective-display t)
(looking-at "\^m")
(forward-char 1))
(beginning-of-line)))