Function: change-log-goto-source-1

change-log-goto-source-1 is a byte-compiled function defined in add-log.el.gz.

Signature

(change-log-goto-source-1 TAG REGEXP FILE BUFFER &optional WINDOW FIRST LAST)

Documentation

Search for tag TAG in buffer BUFFER visiting file FILE.

REGEXP is a regular expression for TAG. The remaining arguments are optional: WINDOW denotes the window to display the results of the search. FIRST is a position in BUFFER denoting the first match from previous searches for TAG. LAST is the position in BUFFER denoting the last match for TAG in the last search.

Source Code

;; Defined in /usr/src/emacs/lisp/vc/add-log.el.gz
(defun change-log-goto-source-1 (tag regexp file buffer
				     &optional window first last)
  "Search for tag TAG in buffer BUFFER visiting file FILE.
REGEXP is a regular expression for TAG.  The remaining arguments
are optional: WINDOW denotes the window to display the results of
the search.  FIRST is a position in BUFFER denoting the first
match from previous searches for TAG.  LAST is the position in
BUFFER denoting the last match for TAG in the last search."
  (with-current-buffer buffer
    (save-excursion
      (save-restriction
	(widen)
	(if last
	    (progn
	      ;; When LAST is set make sure we continue from the next
	      ;; line end to not find the same tag again.
	      (goto-char last)
	      (end-of-line)
	      (condition-case nil
		  ;; Try to go to the end of the current defun to avoid
		  ;; false positives within the current defun's body
		  ;; since these would match `add-log-current-defun'.
		  (end-of-defun)
		;; Don't fall behind when `end-of-defun' fails.
		(error (progn (goto-char last) (end-of-line))))
	      (setq last nil))
	  ;; When LAST was not set start at beginning of BUFFER.
	  (goto-char (point-min)))
	(let (current-defun)
	  (while (and (not last) (re-search-forward regexp nil t))
	      ;; Verify that `add-log-current-defun' invoked at the end
	      ;; of the match returns TAG.  This heuristic works well
	      ;; whenever the name of the defun occurs within the first
	      ;; line of the defun.
	      (setq current-defun (add-log-current-defun))
	      (when (and current-defun (string-equal current-defun tag))
		;; Record this as last match.
		(setq last (line-beginning-position))
		;; Record this as first match when there's none.
		(unless first (setq first last)))))))
    (if (or last first)
	(with-selected-window
	    (setq change-log-find-window (or window (display-buffer buffer)))
	  (if last
	      (progn
		(when (or (< last (point-min)) (> last (point-max)))
		  ;; Widen to show TAG.
		  (widen))
		(push-mark)
		(goto-char last))
	    ;; When there are no more matches go (back) to FIRST.
	    (message "No more matches for tag `%s' in file `%s'" tag file)
	    (setq last first)
	    (goto-char first))
	  ;; Return new "tail".
	  (list (selected-window) first last))
      (message "Source location of tag `%s' not found in file `%s'" tag file)
      nil)))