Function: bibtex-reformat
bibtex-reformat is an interactive and byte-compiled function defined
in bibtex.el.gz.
Signature
(bibtex-reformat &optional READ-OPTIONS)
Documentation
Reformat all BibTeX entries in buffer or region.
Without prefix argument, reformatting is based on bibtex-entry-format.
With prefix argument, read options for reformatting from minibuffer.
With C-u (universal-argument) C-u (universal-argument) prefix argument, reuse previous answers (if any) again.
If mark is active reformat entries in region, if not in whole buffer.
Probably introduced at or before Emacs version 20.1.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/textmodes/bibtex.el.gz
(defun bibtex-reformat (&optional read-options)
"Reformat all BibTeX entries in buffer or region.
Without prefix argument, reformatting is based on `bibtex-entry-format'.
With prefix argument, read options for reformatting from minibuffer.
With \\[universal-argument] \\[universal-argument] prefix argument, reuse previous answers (if any) again.
If mark is active reformat entries in region, if not in whole buffer."
(interactive "*P")
(let* ((pnt (point))
(use-previous-options
(and (equal (prefix-numeric-value read-options) 16)
(or bibtex-reformat-previous-options
bibtex-reformat-previous-reference-keys)))
(bibtex-entry-format
(cond (read-options
(if use-previous-options
bibtex-reformat-previous-options
(let (answers)
(map-y-or-n-p
#'car
(lambda (option)
(push (cdr option) answers))
`(("Realign entries (recommended)? " . realign)
("Remove empty optional and alternative fields? " . opts-or-alts)
("Remove delimiters around pure numerical fields? " . numerical-fields)
(,(concat (if bibtex-comma-after-last-field "Insert" "Remove")
" comma at end of entry? ")
. last-comma)
("Replace double page dashes by single ones? " . page-dashes)
("Delete whitespace at the beginning and end of fields? " . whitespace)
("Inherit booktitle? " . inherit-booktitle)
("Force delimiters? " . delimiters)
("Unify case of entry types and field names? " . unify-case)
("Enclose parts of field entries by braces? " . braces)
("Replace parts of field entries by string constants? " . strings)
("Sort fields? " . sort-fields))
'("formatting action" "formatting actions" "perform"))
(setq bibtex-reformat-previous-options (nreverse answers)))))
;; Do not include required-fields because `bibtex-reformat'
;; cannot handle the error messages of `bibtex-format-entry'.
;; Use `bibtex-validate' to check for required fields.
((eq t bibtex-entry-format)
'(realign opts-or-alts numerical-fields delimiters
last-comma page-dashes unify-case inherit-booktitle
whitespace braces strings sort-fields))
(t
(cons 'realign (remove 'required-fields bibtex-entry-format)))))
(reformat-reference-keys
(if read-options
(if use-previous-options
bibtex-reformat-previous-reference-keys
(setq bibtex-reformat-previous-reference-keys
(y-or-n-p "Generate new reference keys automatically? ")))))
(bibtex-sort-ignore-string-entries t)
bibtex-autokey-edit-before-use)
(save-restriction
(if mark-active (narrow-to-region (region-beginning) (region-end)))
(if (memq 'realign bibtex-entry-format)
(bibtex-realign))
(bibtex-progress-message "Formatting" 1)
(bibtex-map-entries (lambda (_key _beg _end)
(bibtex-progress-message)
(bibtex-clean-entry reformat-reference-keys t)))
(bibtex-progress-message 'done))
(when reformat-reference-keys
(kill-local-variable 'bibtex-reference-keys)
(when bibtex-maintain-sorted-entries
(bibtex-progress-message "Sorting" 1)
(bibtex-sort-buffer)
(bibtex-progress-message 'done)))
(goto-char pnt)))