summaryrefslogtreecommitdiff
path: root/lisp/textmodes/bibtex.el
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2006-05-29 01:35:53 +0000
committerStefan Monnier <monnier@iro.umontreal.ca>2006-05-29 01:35:53 +0000
commit7a0574f3e9489c9b87847a9beff18e7a485e1707 (patch)
tree2ad15d0c3e676ef7d269055d0b703fe6a1ff0152 /lisp/textmodes/bibtex.el
parent6d3906d52bba3dca4abd9c541850a5f30a673b95 (diff)
downloademacs-7a0574f3e9489c9b87847a9beff18e7a485e1707.tar.gz
(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.
Diffstat (limited to 'lisp/textmodes/bibtex.el')
-rw-r--r--lisp/textmodes/bibtex.el48
1 files changed, 34 insertions, 14 deletions
diff --git a/lisp/textmodes/bibtex.el b/lisp/textmodes/bibtex.el
index 74ec8beffa2..c82f2dcf3d0 100644
--- a/lisp/textmodes/bibtex.el
+++ b/lisp/textmodes/bibtex.el
@@ -183,6 +183,17 @@ to all entries not explicitly mentioned."
: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 @@ See `bibtex-generate-autokey' for details."
(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 @@ The CDRs of the elements are t for header keys and nil for crossref keys.")
(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 @@ of the head of the entry found. Return nil if no entry found."
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 @@ If its value is nil use plain sorting. Text outside of BibTeX entries is not
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 @@ If `bibtex-maintain-sorted-entries' is non-nil, perform a binary
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)