aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoland Winkler2018-05-30 10:21:57 -0500
committerRoland Winkler2018-05-30 10:21:57 -0500
commit5c519cd95f573c380ef66243933348e69df6d3c5 (patch)
tree94e389b02ebe00000e7f5e399d8c88bb764017bb
parent58d0642e1ca006fa550bff50fd328bc166c572da (diff)
downloademacs-5c519cd95f573c380ef66243933348e69df6d3c5.tar.gz
emacs-5c519cd95f573c380ef66243933348e69df6d3c5.zip
bibtex-format-entry: Preserve opt-alt if possible.
* textmodes/bibtex.el (bibtex-format-entry): Preserve opt-alt unless its removal is selected. (bibtex-parse-entry): New optional arg keep-opt-alt.
-rw-r--r--lisp/textmodes/bibtex.el16
1 files changed, 9 insertions, 7 deletions
diff --git a/lisp/textmodes/bibtex.el b/lisp/textmodes/bibtex.el
index 0111d48ba77..65d0675d0e3 100644
--- a/lisp/textmodes/bibtex.el
+++ b/lisp/textmodes/bibtex.el
@@ -2345,7 +2345,8 @@ Formats current entry according to variable `bibtex-entry-format'."
2345 (when (memq 'sort-fields format) 2345 (when (memq 'sort-fields format)
2346 (goto-char (point-min)) 2346 (goto-char (point-min))
2347 (let ((beg-fields (save-excursion (bibtex-beginning-first-field))) 2347 (let ((beg-fields (save-excursion (bibtex-beginning-first-field)))
2348 (fields-alist (bibtex-parse-entry)) 2348 (fields-alist (bibtex-parse-entry
2349 nil (not (memq 'opts-or-alts format))))
2349 bibtex-help-message elt) 2350 bibtex-help-message elt)
2350 (delete-region beg-fields (point)) 2351 (delete-region beg-fields (point))
2351 (dolist (field default-field-list) 2352 (dolist (field default-field-list)
@@ -2367,7 +2368,8 @@ Formats current entry according to variable `bibtex-entry-format'."
2367 (end-text (copy-marker (bibtex-end-of-text-in-field bounds) t)) 2368 (end-text (copy-marker (bibtex-end-of-text-in-field bounds) t))
2368 (empty-field (equal "" (bibtex-text-in-field-bounds bounds t))) 2369 (empty-field (equal "" (bibtex-text-in-field-bounds bounds t)))
2369 (field-name (buffer-substring-no-properties beg-name end-name)) 2370 (field-name (buffer-substring-no-properties beg-name end-name))
2370 (opt-alt (and (string-match "\\`\\(OPT\\|ALT\\)" field-name) 2371 (opt-alt (and (memq 'opts-or-alts format)
2372 (string-match "\\`\\(OPT\\|ALT\\)" field-name)
2371 (not (and bibtex-no-opt-remove-re 2373 (not (and bibtex-no-opt-remove-re
2372 (string-match bibtex-no-opt-remove-re 2374 (string-match bibtex-no-opt-remove-re
2373 field-name))))) 2375 field-name)))))
@@ -3641,20 +3643,20 @@ When called interactively with a prefix arg, query for a value of ENTRY-TYPE."
3641 (mapc 'bibtex-make-field required) 3643 (mapc 'bibtex-make-field required)
3642 (mapc 'bibtex-make-optional-field optional))))) 3644 (mapc 'bibtex-make-optional-field optional)))))
3643 3645
3644(defun bibtex-parse-entry (&optional content) 3646(defun bibtex-parse-entry (&optional content keep-opt-alt)
3645 "Parse entry at point, return an alist. 3647 "Parse entry at point, return an alist.
3646The alist elements have the form (FIELD . TEXT), where FIELD can also be 3648The alist elements have the form (FIELD . TEXT), where FIELD can also be
3647the special strings \"=type=\" and \"=key=\". For the FIELD \"=key=\" 3649the special strings \"=type=\" and \"=key=\". For the FIELD \"=key=\"
3648TEXT may be nil. Remove \"OPT\" and \"ALT\" from FIELD. 3650TEXT may be nil. Move point to the end of the last field.
3649Move point to the end of the last field. 3651If optional arg CONTENT is non-nil extract content of text fields.
3650If optional arg CONTENT is non-nil extract content of text fields." 3652Remove \"OPT\" and \"ALT\" from FIELD unless KEEP-OPT-ALT is non-nil."
3651 (let (alist bounds) 3653 (let (alist bounds)
3652 (when (looking-at bibtex-entry-maybe-empty-head) 3654 (when (looking-at bibtex-entry-maybe-empty-head)
3653 (push (cons "=type=" (bibtex-type-in-head)) alist) 3655 (push (cons "=type=" (bibtex-type-in-head)) alist)
3654 (push (cons "=key=" (bibtex-key-in-head)) alist) 3656 (push (cons "=key=" (bibtex-key-in-head)) alist)
3655 (goto-char (match-end 0)) 3657 (goto-char (match-end 0))
3656 (while (setq bounds (bibtex-parse-field)) 3658 (while (setq bounds (bibtex-parse-field))
3657 (push (cons (bibtex-name-in-field bounds t) 3659 (push (cons (bibtex-name-in-field bounds (not keep-opt-alt))
3658 (bibtex-text-in-field-bounds bounds content)) 3660 (bibtex-text-in-field-bounds bounds content))
3659 alist) 3661 alist)
3660 (goto-char (bibtex-end-of-field bounds)))) 3662 (goto-char (bibtex-end-of-field bounds))))