emacs-pretest-bug
[Top][All Lists]
Advanced

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

Emacs 22: `bibtex-format-entry' deletes too many fields


From: Michael Ernst
Subject: Emacs 22: `bibtex-format-entry' deletes too many fields
Date: Sat, 1 Apr 2006 13:35:11 -0500

This bug appears in the Emacs 22 CVS version as of today.

`bibtex-format-entry' deletes empty non-required fields; it should only do
that for empty OPT and ALT fields.  In particular, its test for whether a
field is optional is faulty.

This is a problem when I have added a non-standard field to a BibTeX entry,
as many people do.  The code assumes that no such fields exist.

To reproduce the bug, consider the following BibTeX entry:

PhdThesis{Zellweger84,
  foo =          "",
  author =       "P. T. Zellweger",
  title =        "Interactive Source-Level Debugging for Optimized Programs",
  school =       University of California, Berkeley,
  year =         "1984",
  month =        may,
  note =         "Also available as Technical Report CSL-84-5, Xerox Palo Alto 
Research Center",
}

Assume that "foo" is a field for which an empty field is meaningful, or a
marker field whose value is not meaningful; such are not uncommon, and I
use many of them.  Running `bibtex-clean-entry' (say, by typing C-c C-c)
removes the "foo" field.  Emacs 21 did not remove such fields.

The following patch corrects the problem, by fixing the test for whether a
field is an optional field that was automatically inserted by Emacs and
then never modified by the user.

                    -Michael Ernst
                     address@hidden


2006-04-01  Michael Ernst  <address@hidden>

        * textmodes/bibtex.el (bibtex-format-entry): Improve the test for
        whether a field is an optional field.


--- bibtex.el   21 Mar 2006 15:54:52 -0500      1.111
+++ bibtex.el   01 Apr 2006 12:05:49 -0500      
@@ -1795,7 +1795,7 @@
                                   unify-case inherit-booktitle)
                       bibtex-entry-format))
             crossref-key bounds alternatives-there non-empty-alternative
-            entry-list req-field-list field-list)
+            entry-list req-field-list opt-field-list field-list)
 
         ;; identify entry type
         (goto-char (point-min))
@@ -1829,7 +1829,10 @@
                                   (cdr field))
                 req-field-list (if crossref-key
                                    (nth 0 (nth 2 entry-list)) ; crossref part
-                                 (nth 0 (nth 1 entry-list)))) ; required part
+                                 (nth 0 (nth 1 entry-list))) ; required part
+                opt-field-list (if crossref-key
+                                   (nth 1 (nth 2 entry-list)) ; crossref part
+                                 (nth 1 (nth 1 entry-list)))) ; required part
 
           (dolist (rfield req-field-list)
             (when (nth 3 rfield) ; we should have an alternative
@@ -1872,10 +1875,13 @@
             (if (memq 'opts-or-alts format)
                 (cond ((and empty-field
                             (or opt-alt
+                               ; OPT field
+                               (assoc-string field-name opt-field-list t)
+                               (assoc-string field-name 
bibtex-user-optional-fields t)
+                               ; ALT field
                                 (let ((field (assoc-string
                                               field-name req-field-list t)))
-                                  (or (not field)       ; OPT field
-                                      (nth 3 field))))) ; ALT field
+                                 (nth 3 field))))
                        ;; Either it is an empty ALT field.  Then we have 
checked
                        ;; already that we have one non-empty alternative.  Or 
it
                        ;; is an empty OPT field that we do not miss anyway.





reply via email to

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