Hi, I would like to suggest a patch for 'bibtex-mode'. The 'bibtex-fill-entry' command always runs 'fill-region-as-paragraph' at field texts, but it is inconvenient sometimes. This patch prevents this command from being executed using a new formatting option in 'bibtex-entry-format'. Although the modifications were simple, it was necessary to change several functions due to the 't' option for 'bibtex-entry-format'. Since 't' is a way to include all possible symbols, the new 'no-fill-fields' symbol had to be added to all functions where the 't' option was permitted.
Best regards, João Sena
From bb7a9bb6f9b074c92c4ee435ce119ff22c383215 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Sena?= <[email protected]> Date: Fri, 25 Sep 2026 22:18:09 -0300 Subject: [PATCH] bibtex-mode: Add formatting option to 'bibtex-entry-format' --- lisp/textmodes/bibtex.el | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/lisp/textmodes/bibtex.el b/lisp/textmodes/bibtex.el index 470b20d..882d14b 100644 --- a/lisp/textmodes/bibtex.el +++ b/lisp/textmodes/bibtex.el @@ -123,7 +123,9 @@ bibtex-entry-format strings Replace parts of field entries by string constants according to `bibtex-field-strings-alist'. sort-fields Sort fields to match the field order in - `bibtex-BibTeX-entry-alist'. + `bibtex-BibTeX-entry-alist'. +no-fill-fields Preserve existing breaks inside field texts (do not run + `fill-region-as-paragraph' on field texts). The value t means do all of the above formatting actions. The value nil means do no formatting at all." @@ -143,7 +145,8 @@ bibtex-entry-format (const unify-case) (const braces) (const strings) - (const sort-fields))) + (const sort-fields) + (const no-fill-fields))) :safe (lambda (x) (or (eq x t) (let ((ok t)) @@ -152,7 +155,7 @@ bibtex-entry-format '( opts-or-alts required-fields numerical-fields page-dashes whitespace inherit-booktitle realign last-comma delimiters unify-case - braces strings sort-fields )) + braces strings sort-fields no-fill-fields )) (setq ok nil))) (unless x ok))))) @@ -2509,7 +2512,7 @@ bibtex-format-entry '(realign opts-or-alts required-fields numerical-fields page-dashes whitespace inherit-booktitle last-comma delimiters unify-case braces - strings sort-fields) + strings sort-fields no-fill-fields) bibtex-entry-format)) (left-delim-re (regexp-quote (bibtex-field-left-delimiter))) bounds crossref-key req-field-list opt-field-list @@ -5253,7 +5256,9 @@ bibtex-fill-field-bounds "Fill BibTeX field delimited by BOUNDS. If JUSTIFY is non-nil justify as well. If optional arg MOVE is non-nil move point to end of field." - (let ((end-field (copy-marker (bibtex-end-of-field bounds)))) + (let ((end-field (copy-marker (bibtex-end-of-field bounds))) + (no-fill (and (listp bibtex-entry-format) + (memq 'no-fill-fields bibtex-entry-format)))) (if (not justify) (goto-char (bibtex-start-of-text-in-field bounds)) (goto-char (bibtex-start-of-field bounds)) @@ -5275,8 +5280,10 @@ bibtex-fill-field-bounds (insert " ") (indent-to-column bibtex-text-indentation))) ;; Paragraphs within fields are not preserved. Bother? - (fill-region-as-paragraph (line-beginning-position) end-field - default-justification nil (point)) + ;; Yes, you should + (unless no-fill + (fill-region-as-paragraph (line-beginning-position) end-field + default-justification nil (point))) (if move (goto-char end-field)))) (defun bibtex-fill-field (&optional justify) @@ -5366,7 +5373,8 @@ bibtex-reformat ("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)) + ("Sort fields? " . sort-fields) + ("Preserve existing breaks inside field texts?" . no-fill-fields)) '("formatting action" "formatting actions" "perform")) (setq bibtex-reformat-previous-options (nreverse answers))))) ;; Do not include required-fields because `bibtex-reformat' @@ -5375,7 +5383,7 @@ bibtex-reformat ((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)) + whitespace braces strings sort-fields no-fill-fields)) (t (cons 'realign (remove 'required-fields bibtex-entry-format))))) (reformat-reference-keys -- 2.43.0
