emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r104497: lisp/textmodes/bibtex.el (bi


From: Roland Winkler
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r104497: lisp/textmodes/bibtex.el (bibtex-entry-format): new option sort-fields
Date: Sat, 04 Jun 2011 23:39:40 -0500
User-agent: Bazaar (2.3.1)

------------------------------------------------------------
revno: 104497
committer: Roland Winkler <address@hidden>
branch nick: trunk
timestamp: Sat 2011-06-04 23:39:40 -0500
message:
  lisp/textmodes/bibtex.el (bibtex-entry-format): new option sort-fields
modified:
  etc/NEWS
  lisp/ChangeLog
  lisp/textmodes/bibtex.el
=== modified file 'etc/NEWS'
--- a/etc/NEWS  2011-06-04 21:02:42 +0000
+++ b/etc/NEWS  2011-06-05 04:39:40 +0000
@@ -436,6 +436,10 @@
 
 ** Modula-2 mode provides auto-indentation.
 
+** BibTeX mode
+
+*** New `bibtex-entry-format' option `sort-fields', disabled by default.
+
 ** latex-electric-env-pair-mode keeps \begin..\end matched on the fly.
 
 ** FIXME: xdg-open for browse-url and reportbug, 2010/08.

=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2011-06-05 00:18:46 +0000
+++ b/lisp/ChangeLog    2011-06-05 04:39:40 +0000
@@ -1,3 +1,10 @@
+2011-06-05  Roland Winkler  <address@hidden>
+
+       * textmodes/bibtex.el (bibtex-entry-format): New option
+       sort-fields.
+       (bibtex-format-entry, bibtex-reformat): Honor this option.
+       (bibtex-parse-entry): Return fields in proper order.
+
 2011-06-05  Juanma Barranquero  <address@hidden>
 
        * doc-view.el (doc-view-remove-if): Move computation of result out

=== modified file 'lisp/textmodes/bibtex.el'
--- a/lisp/textmodes/bibtex.el  2011-05-24 02:45:50 +0000
+++ b/lisp/textmodes/bibtex.el  2011-06-05 04:39:40 +0000
@@ -126,6 +126,8 @@
                       `bibtex-field-braces-alist'.
 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-entry-field-alist'.
 
 The value t means do all of the above formatting actions.
 The value nil means do no formatting at all."
@@ -144,7 +146,8 @@
                       (const delimiters)
                       (const unify-case)
                       (const braces)
-                      (const strings))))
+                      (const strings)
+                      (const sort-fields))))
 (put 'bibtex-entry-format 'safe-local-variable
      (lambda (x)
        (or (eq x t)
@@ -153,7 +156,8 @@
                (unless (memq (pop x)
                              '(opts-or-alts required-fields numerical-fields
                                page-dashes whitespace inherit-booktitle realign
-                               last-comma delimiters unify-case braces 
strings))
+                               last-comma delimiters unify-case braces strings
+                               sort-fields))
                  (setq OK nil)))
              (unless (null x) (setq OK nil))
              OK))))
@@ -1906,7 +1910,7 @@
                     '(realign opts-or-alts required-fields numerical-fields
                               page-dashes whitespace inherit-booktitle
                               last-comma delimiters unify-case braces
-                              strings)
+                              strings sort-fields)
                   bibtex-entry-format))
         (left-delim-re (regexp-quote (bibtex-field-left-delimiter)))
         bounds crossref-key req-field-list default-field-list field-list
@@ -1962,7 +1966,21 @@
                       ;; default list of fields that may appear in this entry
                       default-field-list (append (nth 0 (nth 1 entry-list))
                                                  (nth 1 (nth 1 entry-list))
-                                                 bibtex-user-optional-fields)))
+                                                 bibtex-user-optional-fields))
+
+                (when (memq 'sort-fields format)
+                  (goto-char (point-min))
+                  (let ((beg-fields (save-excursion 
(bibtex-beginning-first-field)))
+                        (fields-alist (bibtex-parse-entry))
+                        bibtex-help-message elt)
+                    (delete-region beg-fields (point))
+                    (dolist (field default-field-list)
+                      (when (setq elt (assoc-string (car field) fields-alist 
t))
+                        (setq fields-alist (delete elt fields-alist))
+                        (bibtex-make-field (list (car elt) "" (cdr elt)) nil 
nil t)))
+                    (dolist (field fields-alist)
+                      (unless (member (car field) '("=key=" "=type="))
+                        (bibtex-make-field (list (car field) "" (cdr field)) 
nil nil t))))))
 
               ;; process all fields
               (bibtex-beginning-first-field (point-min))
@@ -3139,7 +3157,7 @@
                    (bibtex-text-in-field-bounds bounds content))
              alist)
        (goto-char (bibtex-end-of-field bounds))))
-    alist))
+    (nreverse alist)))
 
 (defun bibtex-autofill-entry ()
   "Try to fill fields of current BibTeX entry based on neighboring entries.
@@ -4397,14 +4415,15 @@
                                    ("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))))))
+                                   ("Replace parts of field entries by string 
constants? " . 'strings)
+                                   ("Sort fields? " . 'sort-fields))))))
                 ;; 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))
+                           whitespace braces strings sort-fields))
                 (t
                  (cons 'realign (remove 'required-fields 
bibtex-entry-format)))))
          (reformat-reference-keys


reply via email to

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