Function: reftex-query-index-phrase
reftex-query-index-phrase is a byte-compiled function defined in
reftex-index.el.gz.
Signature
(reftex-query-index-phrase PHRASE MACRO-FMT &optional INDEX-KEY REPEAT AS-WORDS)
Documentation
Search through buffer for PHRASE, and offer to replace it with an indexed
version. The index version is derived by applying format with MACRO-FMT
to INDEX-KEY or PHRASE. When REPEAT is non-nil, the PHRASE is inserted
again after the macro.
AS-WORDS means, the search for PHRASE should require word boundaries at
both ends.
Source Code
;; Defined in /usr/src/emacs/lisp/textmodes/reftex-index.el.gz
(defun reftex-query-index-phrase (phrase macro-fmt &optional
index-key repeat as-words)
"Search through buffer for PHRASE, and offer to replace it with an indexed
version. The index version is derived by applying `format' with MACRO-FMT
to INDEX-KEY or PHRASE. When REPEAT is non-nil, the PHRASE is inserted
again after the macro.
AS-WORDS means, the search for PHRASE should require word boundaries at
both ends."
(let* ((re (reftex-index-make-phrase-regexp phrase as-words 'allow-newline))
(case-fold-search reftex-index-phrases-case-fold-search)
(index-keys (split-string
(or index-key phrase)
reftex-index-phrases-logical-or-regexp))
(nkeys (length index-keys))
(ckey (nth 0 index-keys))
(all-yes nil)
match rpl char (beg (make-marker)) (end (make-marker)) mathp)
(move-marker beg 1)
(move-marker end 1)
(unwind-protect
(while (re-search-forward re nil t)
(catch 'next-match
(if (reftex-in-comment)
(throw 'next-match nil))
(if (and (fboundp reftex-index-verify-function)
(not (funcall reftex-index-verify-function)))
(throw 'next-match nil))
(setq match (match-string 0))
(setq mathp
(save-match-data
(condition-case nil (texmathp) (error nil))))
(setq beg (move-marker beg (match-beginning 0))
end (move-marker end (match-end 0)))
(if (and reftex-index-phrases-skip-indexed-matches
(save-match-data
(reftex-index-phrase-match-is-indexed beg
end)))
(throw 'next-match nil))
(reftex-highlight 0 (match-beginning 0) (match-end 0))
(setq rpl
(save-match-data
(reftex-index-make-replace-string
macro-fmt (match-string 0) ckey repeat mathp)))
(while
(not
(catch 'loop
(message "REPLACE: %s? (yn!qoe%s?)"
rpl
(if (> nkeys 1)
(concat "1-" (int-to-string nkeys))
""))
(setq char (if all-yes ?y (read-char-exclusive)))
(cond ((member char '(?y ?Y ?\ ))
;; Yes!
(replace-match rpl t t)
(incf replace-count)
;; See if we should insert newlines to shorten lines
(and reftex-index-phrases-wrap-long-lines
(reftex-index-phrases-fixup-line beg end))
(throw 'loop t))
((member char '(?n ?N ?\C-h ?\C-?));; FIXME: DEL
;; No
(throw 'loop t))
((equal char ?!)
;; Yes for all in this buffer
(setq all-yes t))
((equal char ?q)
;; Stop this one in this file
(goto-char (point-max))
(throw 'loop t))
((equal char ?Q)
;; Stop this one
(throw 'no-more-files t))
((equal char ?s)
(save-buffer))
((equal char ?S)
(reftex-save-all-document-buffers))
((equal char ?\C-g)
(keyboard-quit))
((member char '(?o ?O))
;; Select a different macro
(let* ((nc (reftex-index-select-phrases-macro 2))
(macro-data
(cdr (assoc nc reftex-index-phrases-macro-data)))
(macro-fmt (car macro-data))
(repeat (nth 1 macro-data)))
(if macro-data
(setq rpl (save-match-data
(reftex-index-make-replace-string
macro-fmt match
ckey repeat mathp)))
(ding))))
((equal char ?\?)
;; Help
(with-output-to-temp-buffer "*Help*"
(princ reftex-index-phrases-help)))
((equal char ?\C-r)
;; Recursive edit
(save-match-data
(save-excursion
(message "%s"
(substitute-command-keys
"Recursive edit. Resume with \\[exit-recursive-edit]"))
(recursive-edit))))
((equal char ?e)
(setq rpl (read-string "Edit: " rpl)))
((equal char ?0)
(setq ckey (or index-key phrase)
rpl (save-match-data
(reftex-index-make-replace-string
macro-fmt match ckey repeat mathp))))
((and (> char ?0)
(<= char (+ ?0 nkeys)))
(setq ckey (nth (1- (- char ?0)) index-keys)
rpl (save-match-data
(reftex-index-make-replace-string
macro-fmt match ckey repeat mathp))))
(t (ding)))
nil)))))
(message "")
(move-marker beg nil)
(move-marker end nil)
(setq all-yes nil)
(reftex-unhighlight 0))))