diff options
Diffstat (limited to 'lisp/textmodes/bibtex.el')
| -rw-r--r-- | lisp/textmodes/bibtex.el | 63 |
1 files changed, 44 insertions, 19 deletions
diff --git a/lisp/textmodes/bibtex.el b/lisp/textmodes/bibtex.el index e4f0a3db545..c82f2dcf3d0 100644 --- a/lisp/textmodes/bibtex.el +++ b/lisp/textmodes/bibtex.el | |||
| @@ -87,7 +87,7 @@ If this is a function, call it to generate the initial field text." | |||
| 87 | :type '(choice (const :tag "None" nil) | 87 | :type '(choice (const :tag "None" nil) |
| 88 | (string :tag "Initial text") | 88 | (string :tag "Initial text") |
| 89 | (function :tag "Initialize Function" :value fun) | 89 | (function :tag "Initialize Function" :value fun) |
| 90 | (other :tag "Default" t))) | 90 | (const :tag "Default" t))) |
| 91 | (put 'bibtex-include-OPTkey 'risky-local-variable t) | 91 | (put 'bibtex-include-OPTkey 'risky-local-variable t) |
| 92 | 92 | ||
| 93 | (defcustom bibtex-user-optional-fields | 93 | (defcustom bibtex-user-optional-fields |
| @@ -153,7 +153,7 @@ narrowed to just the entry." | |||
| 153 | (defcustom bibtex-maintain-sorted-entries nil | 153 | (defcustom bibtex-maintain-sorted-entries nil |
| 154 | "If non-nil, BibTeX mode maintains all entries in sorted order. | 154 | "If non-nil, BibTeX mode maintains all entries in sorted order. |
| 155 | Allowed non-nil values are: | 155 | Allowed non-nil values are: |
| 156 | plain All entries are sorted alphabetically. | 156 | plain or t All entries are sorted alphabetically. |
| 157 | crossref All entries are sorted alphabetically unless an entry has a | 157 | crossref All entries are sorted alphabetically unless an entry has a |
| 158 | crossref field. These crossrefed entries are placed in | 158 | crossref field. These crossrefed entries are placed in |
| 159 | alphabetical order immediately preceding the main entry. | 159 | alphabetical order immediately preceding the main entry. |
| @@ -165,7 +165,10 @@ See also `bibtex-sort-ignore-string-entries'." | |||
| 165 | :type '(choice (const nil) | 165 | :type '(choice (const nil) |
| 166 | (const plain) | 166 | (const plain) |
| 167 | (const crossref) | 167 | (const crossref) |
| 168 | (const entry-class))) | 168 | (const entry-class) |
| 169 | (const t))) | ||
| 170 | (put 'bibtex-maintain-sorted-entries 'safe-local-variable | ||
| 171 | '(lambda (a) (memq a '(nil t plain crossref entry-class)))) | ||
| 169 | 172 | ||
| 170 | (defcustom bibtex-sort-entry-class | 173 | (defcustom bibtex-sort-entry-class |
| 171 | '(("String") | 174 | '(("String") |
| @@ -180,6 +183,17 @@ to all entries not explicitly mentioned." | |||
| 180 | :type '(repeat (choice :tag "Class" | 183 | :type '(repeat (choice :tag "Class" |
| 181 | (const :tag "catch-all" (catch-all)) | 184 | (const :tag "catch-all" (catch-all)) |
| 182 | (repeat :tag "Entry name" string)))) | 185 | (repeat :tag "Entry name" string)))) |
| 186 | (put 'bibtex-sort-entry-class 'safe-local-variable | ||
| 187 | (lambda (x) (let ((OK t)) | ||
| 188 | (while (consp x) | ||
| 189 | (let ((y (pop x))) | ||
| 190 | (while (consp y) | ||
| 191 | (let ((z (pop y))) | ||
| 192 | (unless (or (stringp z) (eq z 'catch-all)) | ||
| 193 | (setq OK nil)))) | ||
| 194 | (unless (null y) (setq OK nil)))) | ||
| 195 | (unless (null x) (setq OK nil)) | ||
| 196 | OK))) | ||
| 183 | 197 | ||
| 184 | (defcustom bibtex-sort-ignore-string-entries t | 198 | (defcustom bibtex-sort-ignore-string-entries t |
| 185 | "If non-nil, BibTeX @String entries are not sort-significant. | 199 | "If non-nil, BibTeX @String entries are not sort-significant. |
| @@ -607,6 +621,8 @@ See `bibtex-generate-autokey' for details." | |||
| 607 | (const :tag "Capitalize" capitalize) | 621 | (const :tag "Capitalize" capitalize) |
| 608 | (const :tag "Upcase" upcase) | 622 | (const :tag "Upcase" upcase) |
| 609 | (function :tag "Conversion function"))) | 623 | (function :tag "Conversion function"))) |
| 624 | (put 'bibtex-autokey-name-case-convert-function 'safe-local-variable | ||
| 625 | (lambda (x) (memq x '(upcase downcase capitalize identity)))) | ||
| 610 | (defvaralias 'bibtex-autokey-name-case-convert | 626 | (defvaralias 'bibtex-autokey-name-case-convert |
| 611 | 'bibtex-autokey-name-case-convert-function) | 627 | 'bibtex-autokey-name-case-convert-function) |
| 612 | 628 | ||
| @@ -1185,13 +1201,7 @@ The CDRs of the elements are t for header keys and nil for crossref keys.") | |||
| 1185 | (defvar bibtex-string-empty-key nil | 1201 | (defvar bibtex-string-empty-key nil |
| 1186 | "If non-nil, `bibtex-parse-string' accepts empty key.") | 1202 | "If non-nil, `bibtex-parse-string' accepts empty key.") |
| 1187 | 1203 | ||
| 1188 | (defvar bibtex-sort-entry-class-alist | 1204 | (defvar bibtex-sort-entry-class-alist nil |
| 1189 | (let ((i -1) alist) | ||
| 1190 | (dolist (class bibtex-sort-entry-class alist) | ||
| 1191 | (setq i (1+ i)) | ||
| 1192 | (dolist (entry class) | ||
| 1193 | ;; all entry names should be downcase (for ease of comparison) | ||
| 1194 | (push (cons (if (stringp entry) (downcase entry) entry) i) alist)))) | ||
| 1195 | "Alist mapping entry types to their sorting index. | 1205 | "Alist mapping entry types to their sorting index. |
| 1196 | Auto-generated from `bibtex-sort-entry-class'. | 1206 | Auto-generated from `bibtex-sort-entry-class'. |
| 1197 | Used when `bibtex-maintain-sorted-entries' is `entry-class'.") | 1207 | Used when `bibtex-maintain-sorted-entries' is `entry-class'.") |
| @@ -1800,7 +1810,8 @@ Formats current entry according to variable `bibtex-entry-format'." | |||
| 1800 | 1810 | ||
| 1801 | ;; identify entry type | 1811 | ;; identify entry type |
| 1802 | (goto-char (point-min)) | 1812 | (goto-char (point-min)) |
| 1803 | (re-search-forward bibtex-entry-type) | 1813 | (or (re-search-forward bibtex-entry-type nil t) |
| 1814 | (error "Not inside a BibTeX entry")) | ||
| 1804 | (let ((beg-type (1+ (match-beginning 0))) | 1815 | (let ((beg-type (1+ (match-beginning 0))) |
| 1805 | (end-type (match-end 0))) | 1816 | (end-type (match-end 0))) |
| 1806 | (setq entry-list (assoc-string (buffer-substring-no-properties | 1817 | (setq entry-list (assoc-string (buffer-substring-no-properties |
| @@ -3184,6 +3195,17 @@ of the head of the entry found. Return nil if no entry found." | |||
| 3184 | entry-name)) | 3195 | entry-name)) |
| 3185 | (list key nil entry-name)))))) | 3196 | (list key nil entry-name)))))) |
| 3186 | 3197 | ||
| 3198 | (defun bibtex-init-sort-entry-class-alist () | ||
| 3199 | (unless (local-variable-p 'bibtex-sort-entry-class-alist) | ||
| 3200 | (set (make-local-variable 'bibtex-sort-entry-class-alist) | ||
| 3201 | (let ((i -1) alist) | ||
| 3202 | (dolist (class bibtex-sort-entry-class alist) | ||
| 3203 | (setq i (1+ i)) | ||
| 3204 | (dolist (entry class) | ||
| 3205 | ;; All entry names should be downcase (for ease of comparison). | ||
| 3206 | (push (cons (if (stringp entry) (downcase entry) entry) i) | ||
| 3207 | alist))))))) | ||
| 3208 | |||
| 3187 | (defun bibtex-lessp (index1 index2) | 3209 | (defun bibtex-lessp (index1 index2) |
| 3188 | "Predicate for sorting BibTeX entries with indices INDEX1 and INDEX2. | 3210 | "Predicate for sorting BibTeX entries with indices INDEX1 and INDEX2. |
| 3189 | Each index is a list (KEY CROSSREF-KEY ENTRY-NAME). | 3211 | Each index is a list (KEY CROSSREF-KEY ENTRY-NAME). |
| @@ -3221,13 +3243,14 @@ If its value is nil use plain sorting. Text outside of BibTeX entries is not | |||
| 3221 | affected. If `bibtex-sort-ignore-string-entries' is non-nil, @String entries | 3243 | affected. If `bibtex-sort-ignore-string-entries' is non-nil, @String entries |
| 3222 | are ignored." | 3244 | are ignored." |
| 3223 | (interactive) | 3245 | (interactive) |
| 3224 | (bibtex-beginning-of-first-entry) ;; needed by `sort-subr' | 3246 | (bibtex-beginning-of-first-entry) ; Needed by `sort-subr' |
| 3225 | (sort-subr nil | 3247 | (bibtex-init-sort-entry-class-alist) ; Needed by `bibtex-lessp'. |
| 3226 | 'bibtex-skip-to-valid-entry ; NEXTREC function | 3248 | (sort-subr nil |
| 3227 | 'bibtex-end-of-entry ; ENDREC function | 3249 | 'bibtex-skip-to-valid-entry ; NEXTREC function |
| 3228 | 'bibtex-entry-index ; STARTKEY function | 3250 | 'bibtex-end-of-entry ; ENDREC function |
| 3229 | nil ; ENDKEY function | 3251 | 'bibtex-entry-index ; STARTKEY function |
| 3230 | 'bibtex-lessp)) ; PREDICATE | 3252 | nil ; ENDKEY function |
| 3253 | 'bibtex-lessp)) ; PREDICATE | ||
| 3231 | 3254 | ||
| 3232 | (defun bibtex-find-crossref (crossref-key &optional pnt split) | 3255 | (defun bibtex-find-crossref (crossref-key &optional pnt split) |
| 3233 | "Move point to the beginning of BibTeX entry CROSSREF-KEY. | 3256 | "Move point to the beginning of BibTeX entry CROSSREF-KEY. |
| @@ -3328,6 +3351,7 @@ If `bibtex-maintain-sorted-entries' is non-nil, perform a binary | |||
| 3328 | search to look for place for KEY. This requires that buffer is sorted, | 3351 | search to look for place for KEY. This requires that buffer is sorted, |
| 3329 | see `bibtex-validate'. | 3352 | see `bibtex-validate'. |
| 3330 | Return t if preparation was successful or nil if entry KEY already exists." | 3353 | Return t if preparation was successful or nil if entry KEY already exists." |
| 3354 | (bibtex-init-sort-entry-class-alist) ; Needed by `bibtex-lessp'. | ||
| 3331 | (let ((key (nth 0 index)) | 3355 | (let ((key (nth 0 index)) |
| 3332 | key-exist) | 3356 | key-exist) |
| 3333 | (cond ((or (null key) | 3357 | (cond ((or (null key) |
| @@ -3876,7 +3900,8 @@ At end of the cleaning process, the functions in | |||
| 3876 | (interactive "P") | 3900 | (interactive "P") |
| 3877 | (let ((case-fold-search t) | 3901 | (let ((case-fold-search t) |
| 3878 | (start (bibtex-beginning-of-entry)) | 3902 | (start (bibtex-beginning-of-entry)) |
| 3879 | (_ (looking-at bibtex-any-entry-maybe-empty-head)) | 3903 | (_ (or (looking-at bibtex-any-entry-maybe-empty-head) |
| 3904 | (error "Not inside a BibTeX entry"))) | ||
| 3880 | (entry-type (bibtex-type-in-head)) | 3905 | (entry-type (bibtex-type-in-head)) |
| 3881 | (key (bibtex-key-in-head))) | 3906 | (key (bibtex-key-in-head))) |
| 3882 | ;; formatting | 3907 | ;; formatting |