emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r104679: lisp/textmodes/bibtex.el: mi


From: Roland Winkler
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r104679: lisp/textmodes/bibtex.el: minor cleanup and bug fixes
Date: Wed, 22 Jun 2011 15:59:48 -0500
User-agent: Bazaar (2.3.1)

------------------------------------------------------------
revno: 104679
committer: Roland Winkler <address@hidden>
branch nick: trunk
timestamp: Wed 2011-06-22 15:59:48 -0500
message:
  lisp/textmodes/bibtex.el: minor cleanup and bug fixes
modified:
  lisp/ChangeLog
  lisp/textmodes/bibtex.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2011-06-22 19:24:51 +0000
+++ b/lisp/ChangeLog    2011-06-22 20:59:48 +0000
@@ -1,3 +1,13 @@
+2011-06-22  Roland Winkler  <address@hidden>
+
+       * textmodes/bibtex.el (bibtex-entry-update): Use mapc.
+       (bibtex-clean-entry): First delete the old key so that a
+       customized algorithm for generating the new key does not get
+       confused by the old key.
+       (bibtex-url): Obey regexp of first step.
+       (bibtex-search-entries): Do not use add-to-list with local
+       list-var.
+
 2011-06-22  Lars Magne Ingebrigtsen  <address@hidden>
 
        * mail/smtpmail.el (smtpmail-try-auth-methods): If the user has

=== modified file 'lisp/textmodes/bibtex.el'
--- a/lisp/textmodes/bibtex.el  2011-06-05 05:46:43 +0000
+++ b/lisp/textmodes/bibtex.el  2011-06-22 20:59:48 +0000
@@ -3154,8 +3154,8 @@
               (insert (bibtex-field-left-delimiter)))
             (goto-char end)))
         (skip-chars-backward " \t\n")
-        (dolist (field required) (bibtex-make-field field))
-        (dolist (field optional) (bibtex-make-optional-field field))))))
+        (mapc 'bibtex-make-field required)
+        (mapc 'bibtex-make-optional-field optional)))))
 
 (defun bibtex-parse-entry (&optional content)
   "Parse entry at point, return an alist.
@@ -4247,21 +4247,24 @@
           ;; (bibtex-format-string)
           (t (bibtex-format-entry)))
     ;; set key
-    (when (or new-key (not key))
-      (setq key (bibtex-generate-autokey))
-      ;; Sometimes `bibtex-generate-autokey' returns an empty string
-      (if (or bibtex-autokey-edit-before-use (string= "" key))
-          (setq key (if (eq entry-type 'string)
-                        (bibtex-read-string-key key)
-                      (bibtex-read-key "Key to use: " key))))
-      (save-excursion
-        (re-search-forward (if (eq entry-type 'string)
-                               bibtex-string-maybe-empty-head
-                             bibtex-entry-maybe-empty-head))
-        (if (match-beginning bibtex-key-in-head)
-            (delete-region (match-beginning bibtex-key-in-head)
-                           (match-end bibtex-key-in-head)))
-        (insert key)))
+    (if (or new-key (not key))
+        (save-excursion
+          ;; First delete the old key so that a customized algorithm
+          ;; for generating the new key does not get confused by the
+          ;; old key.
+          (re-search-forward (if (eq entry-type 'string)
+                                 bibtex-string-maybe-empty-head
+                               bibtex-entry-maybe-empty-head))
+          (if (match-beginning bibtex-key-in-head)
+              (delete-region (match-beginning bibtex-key-in-head)
+                             (match-end bibtex-key-in-head)))
+          (setq key (bibtex-generate-autokey))
+          ;; Sometimes `bibtex-generate-autokey' returns an empty string
+          (if (or bibtex-autokey-edit-before-use (string= "" key))
+              (setq key (if (eq entry-type 'string)
+                            (bibtex-read-string-key key)
+                          (bibtex-read-key "Key to use: " key))))
+          (insert key)))
 
     (unless called-by-reformat
       (let* ((end (save-excursion
@@ -4718,7 +4721,7 @@
           (fields-alist (save-excursion (bibtex-parse-entry t)))
           ;; Always ignore case,
           (case-fold-search t)
-          text url scheme obj fmt fl-match step)
+          text url scheme obj fmt fl-match)
       ;; The return value of `bibtex-parse-entry' (i.e., FIELDS-ALIST)
       ;; is always used to generate the URL.  However, if the BibTeX
       ;; entry contains more than one URL, we have multiple matches
@@ -4773,11 +4776,8 @@
         (setq url (if (null scheme) (match-string 0 text)
                     (if (stringp (car scheme))
                         (setq fmt (pop scheme)))
-                    (dotimes (i (length scheme))
-                      (setq step (nth i scheme))
-                      ;; The first step shall use TEXT as obtained earlier.
-                      (unless (= i 0)
-                        (setq text (cdr (assoc-string (car step) fields-alist 
t))))
+                    (dolist (step scheme)
+                      (setq text (cdr (assoc-string (car step) fields-alist 
t)))
                       (if (string-match (nth 1 step) text)
                           (push (cond ((functionp (nth 2 step))
                                        (funcall (nth 2 step) text))
@@ -4857,24 +4857,24 @@
                            (save-excursion
                              (goto-char beg)
                              (and (looking-at bibtex-entry-head)
-                                  (setq key (bibtex-key-in-head)))))
-                      (add-to-list 'entries
-                                   (list key file
-                                         (buffer-substring-no-properties
-                                          beg end))))))
+                                  (setq key (bibtex-key-in-head))))
+                           (not (assoc key entries)))
+                      (push (list key file
+                                  (buffer-substring-no-properties beg end))
+                            entries))))
             ;; The following is slow.  But it works reliably even in more
             ;; complicated cases with BibTeX string constants and crossrefed
             ;; entries.  If you prefer speed over reliability, perform an
             ;; unrestricted search.
             (bibtex-map-entries
              (lambda (key beg end)
-               (if (cond (funp (funcall regexp beg end))
-                         ((and (setq text (bibtex-text-in-field field t))
-                               (string-match regexp text))))
-                   (add-to-list 'entries
-                                (list key file
-                                      (buffer-substring-no-properties
-                                       beg end))))))))))
+               (if (and (cond (funp (funcall regexp beg end))
+                              ((and (setq text (bibtex-text-in-field field t))
+                                    (string-match regexp text))))
+                        (not (assoc key entries)))
+                   (push (list key file
+                               (buffer-substring-no-properties beg end))
+                         entries))))))))
     (if display
         (if entries
             (bibtex-display-entries entries)


reply via email to

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