Function: reftex-nearest-match
reftex-nearest-match is a byte-compiled function defined in
reftex.el.gz.
Signature
(reftex-nearest-match REGEXP &optional MAX-LENGTH)
Source Code
;; Defined in /usr/src/emacs/lisp/textmodes/reftex.el.gz
(defun reftex-nearest-match (regexp &optional max-length)
;; Find the nearest match of REGEXP. Set the match data.
;; If POS is given, calculate distances relative to it.
;; Return nil if there is no match.
(let ((pos (point))
(dist (or max-length (length regexp)))
match1 match2 match)
(goto-char (min (+ pos dist) (point-max)))
(when (re-search-backward regexp nil t)
(setq match1 (match-data)))
(goto-char (max (- pos dist) (point-min)))
(when (re-search-forward regexp nil t)
(setq match2 (match-data)))
(goto-char pos)
(setq match
(cond
((not match1) match2)
((not match2) match1)
((< (abs (- pos (car match1))) (abs (- pos (car match2)))) match1)
(t match2)))
(if match (progn (set-match-data match) t) nil)))