changeset 71044:da5fa425123d

(bibtex-autokey-name-case-convert-function) (bibtex-sort-entry-class): Add safe-local-variable predicate. (bibtex-sort-entry-class-alist): Don't set the global value. (bibtex-init-sort-entry-class-alist): New fun. (bibtex-sort-buffer, bibtex-prepare-new-entry): Call it to compute bibtex-init-sort-entry-class-alist from the buffer-local value (if any) of bibtex-init-sort-entry-class.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Mon, 29 May 2006 01:35:53 +0000
parents aabd8a623e0c
children ddc3087f4c41
files lisp/ChangeLog lisp/textmodes/bibtex.el
diffstat 2 files changed, 45 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Mon May 29 01:24:05 2006 +0000
+++ b/lisp/ChangeLog	Mon May 29 01:35:53 2006 +0000
@@ -1,3 +1,13 @@
+2006-05-28  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+	* textmodes/bibtex.el (bibtex-autokey-name-case-convert-function)
+	(bibtex-sort-entry-class): Add safe-local-variable predicate.
+	(bibtex-sort-entry-class-alist): Don't set the global value.
+	(bibtex-init-sort-entry-class-alist): New fun.
+	(bibtex-sort-buffer, bibtex-prepare-new-entry): Call it to compute
+	bibtex-init-sort-entry-class-alist from the buffer-local value (if any)
+	of bibtex-init-sort-entry-class.
+
 2006-05-28  Richard Stallman  <rms@gnu.org>
 
 	* subr.el (load-history-regexp): If FILE is relative, insist
@@ -6,7 +16,7 @@
 
 2006-05-29  Kim F. Storm  <storm@cua.dk>
 
-	* emacs-lisp/bindat.el (bindat-idx, bindat-raw): Rename dynamic variables
+	* emacs-lisp/bindat.el (bindat-idx, bindat-raw): Rename dynamic vars
 	`pos' and `raw-data' for clarity, as eval forms may access these.
 
 2006-05-28  Kim F. Storm  <storm@cua.dk>
--- a/lisp/textmodes/bibtex.el	Mon May 29 01:24:05 2006 +0000
+++ b/lisp/textmodes/bibtex.el	Mon May 29 01:35:53 2006 +0000
@@ -183,6 +183,17 @@
   :type '(repeat (choice :tag "Class"
                          (const :tag "catch-all" (catch-all))
                          (repeat :tag "Entry name" string))))
+(put 'bibtex-sort-entry-class 'safe-local-variable
+     (lambda (x) (let ((OK t))
+              (while (consp x)
+                (let ((y (pop x)))
+                  (while (consp y)
+                    (let ((z (pop y)))
+                      (unless (or (stringp z) (eq z 'catch-all))
+                        (setq OK nil))))
+                  (unless (null y) (setq OK nil))))
+              (unless (null x) (setq OK nil))
+              OK)))
 
 (defcustom bibtex-sort-ignore-string-entries t
   "If non-nil, BibTeX @String entries are not sort-significant.
@@ -610,6 +621,8 @@
                  (const :tag "Capitalize" capitalize)
                  (const :tag "Upcase" upcase)
                  (function :tag "Conversion function")))
+(put 'bibtex-autokey-name-case-convert-function 'safe-local-variable
+     (lambda (x) (memq x '(upcase downcase capitalize identity))))
 (defvaralias 'bibtex-autokey-name-case-convert
   'bibtex-autokey-name-case-convert-function)
 
@@ -1188,13 +1201,7 @@
 (defvar bibtex-string-empty-key nil
   "If non-nil, `bibtex-parse-string' accepts empty key.")
 
-(defvar bibtex-sort-entry-class-alist
-  (let ((i -1) alist)
-    (dolist (class bibtex-sort-entry-class alist)
-      (setq i (1+ i))
-      (dolist (entry class)
-        ;; all entry names should be downcase (for ease of comparison)
-        (push (cons (if (stringp entry) (downcase entry) entry) i) alist))))
+(defvar bibtex-sort-entry-class-alist nil
   "Alist mapping entry types to their sorting index.
 Auto-generated from `bibtex-sort-entry-class'.
 Used when `bibtex-maintain-sorted-entries' is `entry-class'.")
@@ -3188,6 +3195,17 @@
                       entry-name))
             (list key nil entry-name))))))
 
+(defun bibtex-init-sort-entry-class-alist ()
+  (unless (local-variable-p 'bibtex-sort-entry-class-alist)
+    (set (make-local-variable 'bibtex-sort-entry-class-alist)
+         (let ((i -1) alist)
+           (dolist (class bibtex-sort-entry-class alist)
+             (setq i (1+ i))
+             (dolist (entry class)
+               ;; All entry names should be downcase (for ease of comparison).
+               (push (cons (if (stringp entry) (downcase entry) entry) i)
+                     alist)))))))
+
 (defun bibtex-lessp (index1 index2)
   "Predicate for sorting BibTeX entries with indices INDEX1 and INDEX2.
 Each index is a list (KEY CROSSREF-KEY ENTRY-NAME).
@@ -3225,13 +3243,14 @@
 affected.  If `bibtex-sort-ignore-string-entries' is non-nil, @String entries
 are ignored."
   (interactive)
-    (bibtex-beginning-of-first-entry) ;; needed by `sort-subr'
-    (sort-subr nil
-               'bibtex-skip-to-valid-entry ; NEXTREC function
-               'bibtex-end-of-entry        ; ENDREC function
-               'bibtex-entry-index         ; STARTKEY function
-               nil                         ; ENDKEY function
-               'bibtex-lessp))             ; PREDICATE
+  (bibtex-beginning-of-first-entry)     ; Needed by `sort-subr'
+  (bibtex-init-sort-entry-class-alist)  ; Needed by `bibtex-lessp'.
+  (sort-subr nil
+             'bibtex-skip-to-valid-entry   ; NEXTREC function
+             'bibtex-end-of-entry          ; ENDREC function
+             'bibtex-entry-index           ; STARTKEY function
+             nil                           ; ENDKEY function
+             'bibtex-lessp))               ; PREDICATE
 
 (defun bibtex-find-crossref (crossref-key &optional pnt split)
   "Move point to the beginning of BibTeX entry CROSSREF-KEY.
@@ -3332,6 +3351,7 @@
 search to look for place for KEY.  This requires that buffer is sorted,
 see `bibtex-validate'.
 Return t if preparation was successful or nil if entry KEY already exists."
+  (bibtex-init-sort-entry-class-alist)  ; Needed by `bibtex-lessp'.
   (let ((key (nth 0 index))
         key-exist)
     (cond ((or (null key)