Function: Info-get-token

Info-get-token is a byte-compiled function defined in info.el.gz.

Signature

(Info-get-token POS START ALL &optional ERRORSTRING)

Documentation

Return the token around POS.

POS must be somewhere inside the token. START is a regular expression which will match the
    beginning of the tokens delimited string.
ALL is a regular expression with a single
    parenthesized subpattern which is the token to be
    returned. E.g. {(.*)} would return any string
    enclosed in braces around POS.
ERRORSTRING optional fourth argument, controls action on no match:
    nil: return nil
    t: beep
    a string: signal an error, using that string.

Source Code

;; Defined in /usr/src/emacs/lisp/info.el.gz
(defun Info-get-token (pos start all &optional errorstring)
  "Return the token around POS.
POS must be somewhere inside the token.
START is a regular expression which will match the
    beginning of the tokens delimited string.
ALL is a regular expression with a single
    parenthesized subpattern which is the token to be
    returned.  E.g. `{(.*)}' would return any string
    enclosed in braces around POS.
ERRORSTRING optional fourth argument, controls action on no match:
    nil: return nil
    t: beep
    a string: signal an error, using that string."
  (let ((case-fold-search t))
    (save-excursion
      (goto-char pos)
      ;; First look for a match for START that goes across POS.
      (while (and (not (bobp)) (> (point) (- pos (length start)))
		  (not (looking-at start)))
	(forward-char -1))
      ;; If we did not find one, search back for START
      ;; (this finds only matches that end at or before POS).
      (or (looking-at start)
	  (progn
	    (goto-char pos)
	    (re-search-backward start (max (point-min) (- pos 200)) 'yes)))
      (let (found)
	(while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
		    (not (setq found (and (<= (match-beginning 0) pos)
					  (> (match-end 0) pos))))))
	(if (and found (<= (match-beginning 0) pos)
		 (> (match-end 0) pos))
	    (match-string-no-properties 1)
	  (cond ((null errorstring)
		 nil)
		((eq errorstring t)
		 (beep)
		 nil)
		(t
		 (error "No %s around position %d" errorstring pos))))))))