diff options
| author | Roland Winkler | 2018-05-30 10:21:57 -0500 |
|---|---|---|
| committer | Roland Winkler | 2018-05-30 10:21:57 -0500 |
| commit | 5c519cd95f573c380ef66243933348e69df6d3c5 (patch) | |
| tree | 94e389b02ebe00000e7f5e399d8c88bb764017bb | |
| parent | 58d0642e1ca006fa550bff50fd328bc166c572da (diff) | |
| download | emacs-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.el | 16 |
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. |
| 3646 | The alist elements have the form (FIELD . TEXT), where FIELD can also be | 3648 | The alist elements have the form (FIELD . TEXT), where FIELD can also be |
| 3647 | the special strings \"=type=\" and \"=key=\". For the FIELD \"=key=\" | 3649 | the special strings \"=type=\" and \"=key=\". For the FIELD \"=key=\" |
| 3648 | TEXT may be nil. Remove \"OPT\" and \"ALT\" from FIELD. | 3650 | TEXT may be nil. Move point to the end of the last field. |
| 3649 | Move point to the end of the last field. | 3651 | If optional arg CONTENT is non-nil extract content of text fields. |
| 3650 | If optional arg CONTENT is non-nil extract content of text fields." | 3652 | Remove \"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)))) |