emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 5c519cd 1/3: bibtex-format-entry: Preserve opt-alt


From: Roland Winkler
Subject: [Emacs-diffs] master 5c519cd 1/3: bibtex-format-entry: Preserve opt-alt if possible.
Date: Wed, 30 May 2018 11:25:44 -0400 (EDT)

branch: master
commit 5c519cd95f573c380ef66243933348e69df6d3c5
Author: Roland Winkler <address@hidden>
Commit: Roland Winkler <address@hidden>

    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.
---
 lisp/textmodes/bibtex.el | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/lisp/textmodes/bibtex.el b/lisp/textmodes/bibtex.el
index 0111d48..65d0675 100644
--- a/lisp/textmodes/bibtex.el
+++ b/lisp/textmodes/bibtex.el
@@ -2345,7 +2345,8 @@ Formats current entry according to variable 
`bibtex-entry-format'."
                 (when (memq 'sort-fields format)
                   (goto-char (point-min))
                   (let ((beg-fields (save-excursion 
(bibtex-beginning-first-field)))
-                        (fields-alist (bibtex-parse-entry))
+                        (fields-alist (bibtex-parse-entry
+                                       nil (not (memq 'opts-or-alts format))))
                         bibtex-help-message elt)
                     (delete-region beg-fields (point))
                     (dolist (field default-field-list)
@@ -2367,7 +2368,8 @@ Formats current entry according to variable 
`bibtex-entry-format'."
                        (end-text  (copy-marker (bibtex-end-of-text-in-field 
bounds) t))
                        (empty-field (equal "" (bibtex-text-in-field-bounds 
bounds t)))
                        (field-name (buffer-substring-no-properties beg-name 
end-name))
-                       (opt-alt   (and (string-match "\\`\\(OPT\\|ALT\\)" 
field-name)
+                       (opt-alt   (and (memq 'opts-or-alts format)
+                                       (string-match "\\`\\(OPT\\|ALT\\)" 
field-name)
                                        (not (and bibtex-no-opt-remove-re
                                                  (string-match 
bibtex-no-opt-remove-re
                                                                field-name)))))
@@ -3641,20 +3643,20 @@ When called interactively with a prefix arg, query for 
a value of ENTRY-TYPE."
         (mapc 'bibtex-make-field required)
         (mapc 'bibtex-make-optional-field optional)))))
 
-(defun bibtex-parse-entry (&optional content)
+(defun bibtex-parse-entry (&optional content keep-opt-alt)
   "Parse entry at point, return an alist.
 The alist elements have the form (FIELD . TEXT), where FIELD can also be
 the special strings \"=type=\" and \"=key=\".  For the FIELD \"=key=\"
-TEXT may be nil.  Remove \"OPT\" and \"ALT\" from FIELD.
-Move point to the end of the last field.
-If optional arg CONTENT is non-nil extract content of text fields."
+TEXT may be nil.  Move point to the end of the last field.
+If optional arg CONTENT is non-nil extract content of text fields.
+Remove \"OPT\" and \"ALT\" from FIELD unless KEEP-OPT-ALT is non-nil."
   (let (alist bounds)
     (when (looking-at bibtex-entry-maybe-empty-head)
       (push (cons "=type=" (bibtex-type-in-head)) alist)
       (push (cons "=key=" (bibtex-key-in-head)) alist)
       (goto-char (match-end 0))
       (while (setq bounds (bibtex-parse-field))
-       (push (cons (bibtex-name-in-field bounds t)
+       (push (cons (bibtex-name-in-field bounds (not keep-opt-alt))
                    (bibtex-text-in-field-bounds bounds content))
              alist)
        (goto-char (bibtex-end-of-field bounds))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]