The built-in `bibtex-mode` provides a function `bibtex-next-field` which does what you'd expect: if we use "|" to represent point, calling `bibtex-next-field` from the following configuration:
@article{key,
author = {D|oe, Jane},
title = {A paper},
...
will take you to this configuration:
@article{key,
author = {D|oe, Jane},
title = {A paper|},
...
I'm trying to define a `bibtex-previous-field` function that does the reverse, so I decided to look into the definition of `bibtex-next-field`, which is this:
(defun bibtex-next-field (begin &optional comma)
"Move point to end of text of next BibTeX field or entry head.
With prefix BEGIN non-nil, move point to its beginning. Optional arg COMMA
is as in `bibtex-enclosing-field'. It is t for interactive calls."
(interactive (list current-prefix-arg t))
(let ((bounds (bibtex-find-text-internal t nil comma))
end-of-entry)
(if (not bounds)
(setq end-of-entry t)
(goto-char (nth 3 bounds))
(if (assoc-string (car bounds) '("@String" "@Preamble") t)
(setq end-of-entry t)
;; BibTeX key or field
(if (looking-at ",[ \t\n]*") (goto-char (match-end 0)))
;; end of entry
(if (looking-at "[)}][ \t\n]*") (setq end-of-entry t))))
(if (and end-of-entry
(re-search-forward bibtex-any-entry-maybe-empty-head nil t))
(goto-char (match-beginning 0)))
(bibtex-find-text begin nil bibtex-help-message)))
Unfortunately, I'm having trouble parsing this. What is the expression `end-of-entry` doing? I thought `let` expressions would take the following form:
(let ((VAR-1 VALUE-1)
(VAR-2 VALUE-2)
...
(VAR-n VALUE-n))
BODY)
but the first argument of `let` in the definition of `bibtex-next-field` seems to have a different form:
...
(let ((bounds (bibtex-find-text-internal t nil comma))
end-of-entry)
BODY
...
Any help making sense of this would be much appreciated.