Function: bibtex-pop
bibtex-pop is a byte-compiled function defined in bibtex.el.gz.
Signature
(bibtex-pop ARG DIRECTION)
Documentation
Fill current field from the ARGth same field's text in DIRECTION.
Generic function used by bibtex-pop-previous and bibtex-pop-next.
Source Code
;; Defined in /usr/src/emacs/lisp/textmodes/bibtex.el.gz
(defun bibtex-pop (arg direction)
"Fill current field from the ARGth same field's text in DIRECTION.
Generic function used by `bibtex-pop-previous' and `bibtex-pop-next'."
;; parse current field
(let* ((bounds (bibtex-enclosing-field t))
(start-old-field (bibtex-start-of-field bounds))
(start-old-text (bibtex-start-of-text-in-field bounds))
(end-old-text (bibtex-end-of-text-in-field bounds))
(field-name (bibtex-name-in-field bounds t))
failure)
(save-excursion
;; if executed several times in a row, start each search where
;; the last one was finished
(cond ((eq last-command 'bibtex-pop)
(goto-char (if (eq direction 'previous)
bibtex-pop-previous-search-point
bibtex-pop-next-search-point)))
((eq direction 'previous)
(bibtex-beginning-of-entry))
(t (bibtex-end-of-entry)))
;; Search for arg'th previous/next similar field
(while (and (not failure)
(>= (setq arg (1- arg)) 0))
;; The search of BibTeX fields is not bounded by entry boundaries
(if (eq direction 'previous)
(if (setq bounds (bibtex-search-backward-field field-name))
(goto-char (bibtex-start-of-field bounds))
(setq failure t))
(if (setq bounds (bibtex-search-forward-field field-name))
(goto-char (bibtex-end-of-field bounds))
(setq failure t))))
(if failure
(user-error "No %s matching BibTeX field"
(if (eq direction 'previous) "previous" "next"))
;; Found a matching field. Remember boundaries.
(let ((new-text (bibtex-text-in-field-bounds bounds))
(nbeg (copy-marker (bibtex-start-of-field bounds)))
(nend (copy-marker (bibtex-end-of-field bounds))))
(bibtex-flash-head "From: ")
;; Go back to where we started, delete old text, and pop new.
(goto-char end-old-text)
(delete-region start-old-text end-old-text)
(if (= nbeg start-old-field)
(insert (bibtex-field-left-delimiter)
(bibtex-field-right-delimiter))
(insert new-text))
(setq bibtex-pop-previous-search-point (marker-position nbeg)
bibtex-pop-next-search-point (marker-position nend))))))
(bibtex-find-text nil nil nil t)
(setq this-command 'bibtex-pop))