emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] emacs/lisp/textmodes bibtex.el


From: Roland Winkler
Subject: [Emacs-diffs] emacs/lisp/textmodes bibtex.el
Date: Sat, 14 Feb 2009 16:57:06 +0000

CVSROOT:        /sources/emacs
Module name:    emacs
Changes by:     Roland Winkler <winkler>        09/02/14 16:57:06

Modified files:
        lisp/textmodes : bibtex.el 

Log message:
        (bibtex-global-key-alist, bibtex-initialize): Exclude current buffer
        if it does not use bibtex-mode.
        (bibtex-parse-strings, bibtex-strings, bibtex-initialize)
        (bibtex-sort-buffer, bibtex-search-entry)
        (bibtex-prepare-new-entry, bibtex-clean-entry): Use functionp to
        test whether bibtex-strings and bibtex-reference-keys have their
        initial values.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/emacs/lisp/textmodes/bibtex.el?cvsroot=emacs&r1=1.144&r2=1.145

Patches:
Index: bibtex.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/textmodes/bibtex.el,v
retrieving revision 1.144
retrieving revision 1.145
diff -u -b -r1.144 -r1.145
--- bibtex.el   17 Jan 2009 14:58:53 -0000      1.144
+++ bibtex.el   14 Feb 2009 16:57:05 -0000      1.145
@@ -2440,8 +2440,10 @@
       (apply 'append
              (mapcar (lambda (buf)
                        (with-current-buffer buf bibtex-reference-keys))
-                     (bibtex-initialize t)))
-    bibtex-reference-keys))
+                     ;; include current buffer only if it uses `bibtex-mode'
+                     (bibtex-initialize (eq major-mode 'bibtex-mode))))
+    (if (eq major-mode 'bibtex-mode)
+        bibtex-reference-keys)))
 
 (defun bibtex-read-key (prompt &optional key global)
   "Read BibTeX key from minibuffer using PROMPT and default KEY.
@@ -2531,8 +2533,7 @@
   (save-excursion
     (save-match-data
       (goto-char (point-min))
-      (let ((strings (if (and add
-                              (listp bibtex-strings))
+      (let ((strings (if (and add (not (functionp bibtex-strings)))
                          bibtex-strings))
             bounds key)
         (if (listp add)
@@ -2555,8 +2556,9 @@
 
 (defun bibtex-strings ()
   "Return `bibtex-strings'.  Initialize this variable if necessary."
-  (if (listp bibtex-strings) bibtex-strings
-    (bibtex-parse-strings (bibtex-string-files-init))))
+  (if (functionp bibtex-strings)
+      (bibtex-parse-strings (bibtex-string-files-init))
+    bibtex-strings))
 
 (defun bibtex-string-files-init ()
   "Return initialization for `bibtex-strings'.
@@ -2668,7 +2670,11 @@
     (dolist (file file-list)
       (if (file-readable-p file)
         (push (find-file-noselect file) buffer-list)))
-    ;; include current buffer iff we want it
+    ;; Include current buffer iff we want it.
+    ;; Exclude current buffer if it doesn't use `bibtex-mode'.
+    ;; Thus calling `bibtex-initialize' gives meaningful results for
+    ;; any current buffer.
+    (unless (and current (eq major-mode 'bibtex-mode)) (setq current nil))
     (cond ((and current (not (memq (current-buffer) buffer-list)))
            (push (current-buffer) buffer-list))
           ((and (not current) (memq (current-buffer) buffer-list))
@@ -2676,7 +2682,7 @@
     ;; parse keys
     (dolist (buffer buffer-list)
       (with-current-buffer buffer
-        (if (or force (nlistp bibtex-reference-keys))
+        (if (or force (functionp bibtex-reference-keys))
             (bibtex-parse-keys))))
     ;; select BibTeX buffer
     (if select
@@ -3484,7 +3490,7 @@
   (bibtex-beginning-of-first-entry)     ; Needed by `sort-subr'
   (bibtex-init-sort-entry-class-alist)  ; Needed by `bibtex-lessp'.
   (if (and (eq bibtex-maintain-sorted-entries 'crossref)
-           (nlistp bibtex-reference-keys))
+           (functionp bibtex-reference-keys))
       (bibtex-parse-keys))              ; Needed by `bibtex-lessp'.
   (sort-subr nil
              'bibtex-skip-to-valid-entry   ; NEXTREC function
@@ -3591,8 +3597,7 @@
         (while (and (not found)
                     (setq buffer (pop buffer-list)))
           (with-current-buffer buffer
-            (if (and (listp bibtex-reference-keys)
-                     (cdr (assoc-string key bibtex-reference-keys)))
+            (if (cdr (assoc-string key bibtex-reference-keys))
                 ;; `bibtex-search-entry' moves point if key found
                 (setq found (bibtex-search-entry key)))))
         (cond ((and found display)
@@ -3632,7 +3637,7 @@
 Return t if preparation was successful or nil if entry KEY already exists."
   (bibtex-init-sort-entry-class-alist)  ; Needed by `bibtex-lessp'.
   (if (and (eq bibtex-maintain-sorted-entries 'crossref)
-           (nlistp bibtex-reference-keys))
+           (functionp bibtex-reference-keys))
       (bibtex-parse-keys))              ; Needed by `bibtex-lessp'.
   (let ((key (nth 0 index))
         key-exist)
@@ -4247,23 +4252,27 @@
             (if (cdr (assoc-string key bibtex-reference-keys))
                 (error "Duplicate key in %s" (buffer-file-name)))))
 
-        ;; Only update the list of keys if it has been built already.
+        ;; Only update `bibtex-strings' and `bibtex-reference-keys'
+        ;; if they have been built already.
         (cond ((eq entry-type 'string)
-               (if (and (listp bibtex-strings)
-                        (not (assoc key bibtex-strings)))
+               ;; We have a @String entry.
+               (unless (or (functionp bibtex-strings)
+                           (assoc key bibtex-strings))
                    (push (cons key (bibtex-text-in-string
                                     (bibtex-parse-string) t))
                            bibtex-strings)))
               ;; We have a normal entry.
-              ((listp bibtex-reference-keys)
-               (cond ((not (assoc key bibtex-reference-keys))
+              ((not (functionp bibtex-reference-keys))
+               (let ((found (assoc key bibtex-reference-keys)))
+                 (cond ((not found)
                       (push (cons key t) bibtex-reference-keys))
-                     ((not (cdr (assoc key bibtex-reference-keys)))
+                       ((not (cdr found))
                       ;; Turn a crossref key into a header key
                       (setq bibtex-reference-keys
                             (cons (cons key t)
-                                  (delete (list key) bibtex-reference-keys)))))
-               ;; Handle crossref key.
+                                    (delete (list key) 
bibtex-reference-keys))))))
+               ;; If entry has a crossref key, it goes into the list
+               ;; `bibtex-reference-keys', too.
                (if (and (nth 1 index)
                         (not (assoc (nth 1 index) bibtex-reference-keys)))
                    (push (list (nth 1 index)) bibtex-reference-keys)))))




reply via email to

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