Mercurial > emacs
comparison lisp/textmodes/bibtex.el @ 90428:a8190f7e546e
Merge from emacs--devo--0
Patches applied:
* emacs--devo--0 (patch 285-296)
- Update from CVS
- Merge from gnus--rel--5.10
- Update from CVS: admin/FOR-RELEASE: Update refcard section.
* gnus--rel--5.10 (patch 102-104)
- Update from CVS
Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-64
author | Miles Bader <miles@gnu.org> |
---|---|
date | Wed, 07 Jun 2006 18:05:10 +0000 |
parents | 2ecafc6d5db7 da5fa425123d |
children | 02cf29720f31 |
comparison
equal
deleted
inserted
replaced
90427:ddb25860d044 | 90428:a8190f7e546e |
---|---|
85 If this is a function, call it to generate the initial field text." | 85 If this is a function, call it to generate the initial field text." |
86 :group 'bibtex | 86 :group 'bibtex |
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 |
94 '(("annote" "Personal annotation (ignored)")) | 94 '(("annote" "Personal annotation (ignored)")) |
95 "List of optional fields the user wants to have always present. | 95 "List of optional fields the user wants to have always present. |
151 :type 'hook) | 151 :type 'hook) |
152 | 152 |
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. |
160 entry-class The entries are divided into classes according to their | 160 entry-class The entries are divided into classes according to their |
161 entry name, see `bibtex-sort-entry-class'. Within each class | 161 entry name, see `bibtex-sort-entry-class'. Within each class |
163 See also `bibtex-sort-ignore-string-entries'." | 163 See also `bibtex-sort-ignore-string-entries'." |
164 :group 'bibtex | 164 :group 'bibtex |
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") |
172 (catch-all) | 175 (catch-all) |
173 ("Book" "Proceedings")) | 176 ("Book" "Proceedings")) |
178 to all entries not explicitly mentioned." | 181 to all entries not explicitly mentioned." |
179 :group 'BibTeX | 182 :group 'BibTeX |
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. |
186 That means they are ignored when determining ordering of the buffer | 200 That means they are ignored when determining ordering of the buffer |
187 \(e.g., sorting, locating alphabetical position for new entries, etc.)." | 201 \(e.g., sorting, locating alphabetical position for new entries, etc.)." |
605 :type '(choice (const :tag "Preserve case" identity) | 619 :type '(choice (const :tag "Preserve case" identity) |
606 (const :tag "Downcase" downcase) | 620 (const :tag "Downcase" downcase) |
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 |
613 (defcustom bibtex-autokey-name-length 'infty | 629 (defcustom bibtex-autokey-name-length 'infty |
614 "Number of characters from name to incorporate into key. | 630 "Number of characters from name to incorporate into key. |
1183 "Regexp for `bibtex-font-lock-url'.") | 1199 "Regexp for `bibtex-font-lock-url'.") |
1184 | 1200 |
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'.") |
1198 | 1208 |
1199 | 1209 |
1798 crossref-key bounds alternatives-there non-empty-alternative | 1808 crossref-key bounds alternatives-there non-empty-alternative |
1799 entry-list req-field-list field-list) | 1809 entry-list req-field-list field-list) |
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 |
1807 beg-type end-type) | 1818 beg-type end-type) |
1808 bibtex-entry-field-alist | 1819 bibtex-entry-field-alist |
3182 (list key | 3193 (list key |
3183 (if bounds (bibtex-text-in-field-bounds bounds t)) | 3194 (if bounds (bibtex-text-in-field-bounds bounds t)) |
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). |
3190 The predicate depends on the variable `bibtex-maintain-sorted-entries'. | 3212 The predicate depends on the variable `bibtex-maintain-sorted-entries'. |
3191 If its value is nil use plain sorting." | 3213 If its value is nil use plain sorting." |
3219 The predicate for sorting is defined via `bibtex-maintain-sorted-entries'. | 3241 The predicate for sorting is defined via `bibtex-maintain-sorted-entries'. |
3220 If its value is nil use plain sorting. Text outside of BibTeX entries is not | 3242 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. |
3234 If `bibtex-files' is non-nil, search all these files. | 3257 If `bibtex-files' is non-nil, search all these files. |
3235 Otherwise the search is limited to the current buffer. | 3258 Otherwise the search is limited to the current buffer. |
3326 Move point where the entry KEY should be placed. | 3349 Move point where the entry KEY should be placed. |
3327 If `bibtex-maintain-sorted-entries' is non-nil, perform a binary | 3350 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) |
3334 (and (stringp key) | 3358 (and (stringp key) |
3335 (string-equal key "")) | 3359 (string-equal key "")) |
3874 ;; Opt. arg called-by-reformat is t if bibtex-clean-entry | 3898 ;; Opt. arg called-by-reformat is t if bibtex-clean-entry |
3875 ;; is called by bibtex-reformat | 3899 ;; is called by bibtex-reformat |
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 |
3883 (cond ((bibtex-string= entry-type "preamble") | 3908 (cond ((bibtex-string= entry-type "preamble") |
3884 ;; (bibtex-format-preamble) | 3909 ;; (bibtex-format-preamble) |