Mercurial > emacs
comparison lisp/textmodes/bibtex.el @ 13728:4b7903cfa7ee
(bibtex-auto-fill-function): Adapted for use with
changed autofill policy of emacs-19.30 (uses now fill-prefix
instead of indent-line-function).
(bibtex-indent-line-function): Removed (not used any more).
(bibtex-make-field): Was broken when called
non-interactively.
(bibtex-make-field): Point is now placed on closing
brace or quote (suggested by Karl Eichwalder <ke@ke.Central.DE>).
(bibtex-clean-entry): Comma after last field isn't
deleted anymore (new standard in BibTeX 0.99 and 1.xx).
(bibtex-enclosing-reference-maybe-empty-head): Works with entries
with comma after last field.
(bibtex-reference): Permits entries with comma after last field.
(bibtex-font-lock-keywords): Enhanced to support new field-name
characters (suggested by Martin Maechler
<maechler@stat.math.ethz.ch>).
(bibtex-field-name): Now numbers (not as the first sign), dashes,
and underscores are allowed (suggested by Martin Maechler
<maechler@stat.math.ethz.ch> and Oren Patashnik
<opbibtex@labrea.Stanford.EDU>).
(bibtex-make-field): Was broken on lines containing
non-parenthesized entries (reported by Karl Eichwalder
<ke@ke.Central.DE>).
(bibtex-validate-buffer): Changed so that preamble
references are ignored (same as string entries) (reported by
Martin Maechler <maechler@stat.math.ethz.ch>).
(bibtex-enclosing-reference-maybe-empty-head):
New function to be used in case reference head may be empty.
(bibtex-clean-entry, bibtex-pop-previous, bibtex-pop-next): Uses
now bibtex-enclosing-reference-maybe-empty-head.
(bibtex-mode): Added support for font-lock mode.
(bibtex-font-lock-keywords): New variable with font-lock keywords
for BibTeX mode.
(bibtex-make-optional-field): Not longer interactive
(suggested by Karl Eichwalder <karl@pertron.central.de>).
(bibtex-maintain-sorted-entries): Set to nil, since it
requires more user attention and more restricted files to have
this set to t.
(bibtex-maintain-sorted-entries,
bibtex-sort-ignore-string-entries): Made buffer local, since it
may depend on the buffer which preferences to use.
(bibtex-validate-buffer): Looking for correct sort order only when
bibtex-maintain-sorted-entries is non-nil.
Put a comment in the `KNOWN BUGS' section about the
quote-inside-quotes problem.
(whole file): Changed string `true' in some documentation strings
to `non-nil' (e.g. `if variable has a true/non-nil value').
(bibtex-mode-map): Changed `move/edit' to `bibtex-edit'.
(bibtex-sort-entries): Now works correctly with
`@String' entries inside BibTeX files (i.e. after the occurence of
other references).
(bibtex-validate-buffer): Inserted code which looks if entries are
balanced (a single non-escaped quote inside braces was not
detected till now, but bibtex-sort-entries stumbles about it).
(bibtex-entry): bibtex-move-outside-of-entry is only
called when bibtex-maintain-sorted-entries is nil (otherwise
bibtex-find-entry-location determines the correct location).
(bibtex-find-entry-location): Now uses binary search. As before,
it assumes that the buffer is sorted without duplicates (but as
before it is only called when bibtex-maintain-sorted-entries is
t). Ignores `@String' entries if told so via variable
bibtex-sort-ignore-string-entries.
(bibtex-clean-entry): Respect
bibtex-maintain-sorted-entries when inserting autokey.
(bibtex-validate-buffer): Searching whole buffer for duplicates
and correct order is now done directly instead of calling
bibtex-find-entry-location (since this is to be reprogrammed to
use a binary search instead a sequential one).
(bibtex-parse-keys): May now be called with an
optional parameter which (if t) tells bibtex-parse-keys that it
should abort if input is pending.
(bibtex-mode): The instance of bibtex-parse-keys called in
auto-save-mode-hook is now called with this new parameter set to
t, so an auto-save caused by exceeding auto-save-interval is now
aborted immediately if user is still typing.
(bibtex-print-help-message, bibtex-clean-entry): Use
now constant strings instead of custom ones.
(bibtex-clean-entry): Changed the call of
bibtex-enclosing-reference to a more specific call so entries
without a key (here allowed) can be handled.
(bibtex-reference-key): Cleared off parentheses (caused string
entries enclosed by parentheses instead of braces to be not added
to bibtex-completion-candidates).
(bibtex-complete-string): Made it use bibtex-string.
(bibtex-keys,
bibtex-buffer-last-parsed-for-keys-tick): New buffer-local
variables to make parsing of BibTeX buffer for reference keys
(needed by TAB completion in minibuffer when entering key) more
occasional.
(bibtex-parse-keys): New function to parse for keys (functionality
was partially included in bibtex-entry).
(bibtex-entry): Changed to use bibtex-parse-keys.
(bibtex-mode): Installs bibtex-parse-keys as an
auto-save-mode-hook, so whole buffer is parsed at most when it is
autosaved.
(bibtex-clean-entry): Calls bibtex-parse-keys on the new entry, so
bibtex-keys remains consistent for new entries that are finished
by calling this function (most should).
(bibtex-inside-field): Be independent on current
setting of bibtex-field-right-delimiter (allows more intermixing
between quotes and braces).
(bibtex-make-field): Last change didn't make it work correctly
when called non-interactively by bibtex-entry (fixed).
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Wed, 13 Dec 1995 20:26:13 +0000 |
parents | 5488d9efa7de |
children | cc71d8efd948 |
comparison
equal
deleted
inserted
replaced
13727:9eb09adbcb38 | 13728:4b7903cfa7ee |
---|---|
41 ;; on long entries (e.g. those containing abstracts) since | 41 ;; on long entries (e.g. those containing abstracts) since |
42 ;; the length of regular expression matches is fairly limited. | 42 ;; the length of regular expression matches is fairly limited. |
43 ;; 2. Calling bibtex-find-text in a string entry results in the | 43 ;; 2. Calling bibtex-find-text in a string entry results in the |
44 ;; error message "Can't find enclosing Bibtex field" instead of | 44 ;; error message "Can't find enclosing Bibtex field" instead of |
45 ;; moving to the empty string. [reported by gernot@cs.unsw.oz.au] | 45 ;; moving to the empty string. [reported by gernot@cs.unsw.oz.au] |
46 ;; 3. Quotes inside quote-parenthesized fields (like | |
47 ;; `author = "Stefan Sch{\"o}f"') break bibtex-validate-buffer. | |
48 ;; Further, you must use braces here, if you want to set | |
49 ;; bibtex-maintain-sorted-entries to a non-nil value. | |
46 | 50 |
47 ;; (current keeper: schoef@informatik.uni-oldenburg.de | 51 ;; (current keeper: schoef@informatik.uni-oldenburg.de |
48 ;; previous: alarson@src.honeywell.com) | 52 ;; previous: alarson@src.honeywell.com) |
49 | 53 |
50 ;;; Code: | 54 ;;; Code: |
76 | 80 |
77 (defvar bibtex-clean-entry-zap-empty-opts t | 81 (defvar bibtex-clean-entry-zap-empty-opts t |
78 "*If non-nil, bibtex-clean-entry will delete all empty optional fields.") | 82 "*If non-nil, bibtex-clean-entry will delete all empty optional fields.") |
79 | 83 |
80 (defvar bibtex-sort-ignore-string-entries t | 84 (defvar bibtex-sort-ignore-string-entries t |
81 "*If true, BibTeX @STRING entries are not sort-significant. | 85 "*If non-nil, BibTeX @STRING entries are not sort-significant. |
82 That means they are ignored when determining ordering of the buffer | 86 That means they are ignored when determining ordering of the buffer |
83 (e.g. sorting, locating alphabetical position for new entries, etc.).") | 87 (e.g. sorting, locating alphabetical position for new entries, etc.). |
88 This variable is buffer local.") | |
89 (make-variable-buffer-local 'bibtex-sort-ignore-string-entries) | |
84 | 90 |
85 (defvar bibtex-maintain-sorted-entries nil | 91 (defvar bibtex-maintain-sorted-entries nil |
86 "*If true, bibtex-mode maintains all BibTeX entries in sorted order. | 92 "*If non-nil, bibtex-mode maintains all BibTeX entries in sorted order. |
87 Setting this variable to nil will strip off some comfort (e.g. TAB | 93 Setting this variable to nil will strip off some comfort (e.g. TAB |
88 completion for reference keys) from bibtex-mode.") | 94 completion for reference keys in minibuffer, automatic detection of |
95 duplicates) from bibtex-mode. See also bibtex-sort-ignore-string-entries. | |
96 This variable is buffer local.") | |
97 (make-variable-buffer-local 'bibtex-maintain-sorted-entries) | |
89 | 98 |
90 (defvar bibtex-entry-field-alist | 99 (defvar bibtex-entry-field-alist |
91 '( | 100 '( |
92 ("Article" . (((("author" "Author1 [and Author2 ...] [and others]") | 101 ("Article" . (((("author" "Author1 [and Author2 ...] [and others]") |
93 ("title" "Title of the article (will be converted to lowercase)") | 102 ("title" "Title of the article (BibTeX converts it to lowercase)") |
94 ("journal" "Name of the journal (use string, remove braces)") | 103 ("journal" "Name of the journal (use string, remove braces)") |
95 ("year" "Year of publication")) | 104 ("year" "Year of publication")) |
96 (("volume" "Volume of the journal") | 105 (("volume" "Volume of the journal") |
97 ("number" "Number of the journal") | 106 ("number" "Number of the journal") |
98 ("month" "Month of the publication as a string (remove braces)") | 107 ("month" "Month of the publication as a string (remove braces)") |
99 ("pages" "Pages in the journal") | 108 ("pages" "Pages in the journal") |
100 ("note" "Remarks to be put at the end of the \\bibitem"))) | 109 ("note" "Remarks to be put at the end of the \\bibitem"))) |
101 ((("author" "Author1 [and Author2 ...] [and others]") | 110 ((("author" "Author1 [and Author2 ...] [and others]") |
102 ("title" "Title of the article (will be converted to lowercase)")) | 111 ("title" "Title of the article (BibTeX converts it to lowercase)")) |
103 (("journal" "Name of the journal (use string, remove braces)") | 112 (("journal" "Name of the journal (use string, remove braces)") |
104 ("year" "Year of publication") | 113 ("year" "Year of publication") |
105 ("volume" "Volume of the journal") | 114 ("volume" "Volume of the journal") |
106 ("number" "Number of the journal") | 115 ("number" "Number of the journal") |
107 ("month" "Month of the publication as a string (remove braces)") | 116 ("month" "Month of the publication as a string (remove braces)") |
117 ("series" "Series in which the book appeared") | 126 ("series" "Series in which the book appeared") |
118 ("address" "Address of the publisher") | 127 ("address" "Address of the publisher") |
119 ("edition" "Edition of the book as a capitalized English word") | 128 ("edition" "Edition of the book as a capitalized English word") |
120 ("month" "Month of the publication as a string (remove braces)") | 129 ("month" "Month of the publication as a string (remove braces)") |
121 ("note" "Remarks to be put at the end of the \\bibitem"))))) | 130 ("note" "Remarks to be put at the end of the \\bibitem"))))) |
122 ("Booklet" . (((("title" "Title of the booklet (will be converted to lowercase)")) | 131 ("Booklet" . (((("title" "Title of the booklet (BibTeX converts it to lowercase)")) |
123 (("author" "Author1 [and Author2 ...] [and others]") | 132 (("author" "Author1 [and Author2 ...] [and others]") |
124 ("howpublished" "The way in which the booklet was published") | 133 ("howpublished" "The way in which the booklet was published") |
125 ("address" "Address of the publisher") | 134 ("address" "Address of the publisher") |
126 ("year" "Year of publication") | 135 ("year" "Year of publication") |
127 ("month" "Month of the publication as a string (remove braces)") | 136 ("month" "Month of the publication as a string (remove braces)") |
155 ("month" "Month of the publication as a string (remove braces)") | 164 ("month" "Month of the publication as a string (remove braces)") |
156 ("pages" "Pages in the book") | 165 ("pages" "Pages in the book") |
157 ("type" "Word to use instead of \"chapter\"") | 166 ("type" "Word to use instead of \"chapter\"") |
158 ("note" "Remarks to be put at the end of the \\bibitem"))))) | 167 ("note" "Remarks to be put at the end of the \\bibitem"))))) |
159 ("InCollection" . (((("author" "Author1 [and Author2 ...] [and others]") | 168 ("InCollection" . (((("author" "Author1 [and Author2 ...] [and others]") |
160 ("title" "Title of the article in book (will be converted to lowercase)") | 169 ("title" "Title of the article in book (BibTeX converts it to lowercase)") |
161 ("booktitle" "Name of the book") | 170 ("booktitle" "Name of the book") |
162 ("publisher" "Publishing company") | 171 ("publisher" "Publishing company") |
163 ("year" "Year of publication")) | 172 ("year" "Year of publication")) |
164 (("editor" "Editor1 [and Editor2 ...] [and others]") | 173 (("editor" "Editor1 [and Editor2 ...] [and others]") |
165 ("volume" "Volume of the book in the series") | 174 ("volume" "Volume of the book in the series") |
171 ("edition" "Edition of the book as a capitalized English word") | 180 ("edition" "Edition of the book as a capitalized English word") |
172 ("month" "Month of the publication as a string (remove braces)") | 181 ("month" "Month of the publication as a string (remove braces)") |
173 ("pages" "Pages in the book") | 182 ("pages" "Pages in the book") |
174 ("note" "Remarks to be put at the end of the \\bibitem"))) | 183 ("note" "Remarks to be put at the end of the \\bibitem"))) |
175 ((("author" "Author1 [and Author2 ...] [and others]") | 184 ((("author" "Author1 [and Author2 ...] [and others]") |
176 ("title" "Title of the article in book (will be converted to lowercase)") | 185 ("title" "Title of the article in book (BibTeX converts it to lowercase)") |
177 ("booktitle" "Name of the book")) | 186 ("booktitle" "Name of the book")) |
178 (("publisher" "Publishing company") | 187 (("publisher" "Publishing company") |
179 ("year" "Year of publication") | 188 ("year" "Year of publication") |
180 ("editor" "Editor1 [and Editor2 ...] [and others]") | 189 ("editor" "Editor1 [and Editor2 ...] [and others]") |
181 ("volume" "Volume of the book in the series") | 190 ("volume" "Volume of the book in the series") |
187 ("edition" "Edition of the book as a capitalized English word") | 196 ("edition" "Edition of the book as a capitalized English word") |
188 ("month" "Month of the publication as a string (remove braces)") | 197 ("month" "Month of the publication as a string (remove braces)") |
189 ("pages" "Pages in the book") | 198 ("pages" "Pages in the book") |
190 ("note" "Remarks to be put at the end of the \\bibitem"))))) | 199 ("note" "Remarks to be put at the end of the \\bibitem"))))) |
191 ("InProceedings" . (((("author" "Author1 [and Author2 ...] [and others]") | 200 ("InProceedings" . (((("author" "Author1 [and Author2 ...] [and others]") |
192 ("title" "Title of the article in proceedings (will be converted to lowercase)") | 201 ("title" "Title of the article in proceedings (BibTeX converts it to lowercase)") |
193 ("booktitle" "Name of the conference proceedings") | 202 ("booktitle" "Name of the conference proceedings") |
194 ("year" "Year of publication")) | 203 ("year" "Year of publication")) |
195 (("editor" "Editor1 [and Editor2 ...] [and others]") | 204 (("editor" "Editor1 [and Editor2 ...] [and others]") |
196 ("volume" "Volume of the conference proceedings in the series") | 205 ("volume" "Volume of the conference proceedings in the series") |
197 ("number" "Number of the conference proceedings in a small series (overwritten by volume)") | 206 ("number" "Number of the conference proceedings in a small series (overwritten by volume)") |
201 ("address" "Location of the Proceedings") | 210 ("address" "Location of the Proceedings") |
202 ("month" "Month of the publication as a string (remove braces)") | 211 ("month" "Month of the publication as a string (remove braces)") |
203 ("pages" "Pages in the conference proceedings") | 212 ("pages" "Pages in the conference proceedings") |
204 ("note" "Remarks to be put at the end of the \\bibitem"))) | 213 ("note" "Remarks to be put at the end of the \\bibitem"))) |
205 ((("author" "Author1 [and Author2 ...] [and others]") | 214 ((("author" "Author1 [and Author2 ...] [and others]") |
206 ("title" "Title of the article in proceedings (will be converted to lowercase)") | 215 ("title" "Title of the article in proceedings (BibTeX converts it to lowercase)") |
207 ("booktitle" "Name of the conference proceedings")) | 216 ("booktitle" "Name of the conference proceedings")) |
208 (("editor" "Editor1 [and Editor2 ...] [and others]") | 217 (("editor" "Editor1 [and Editor2 ...] [and others]") |
209 ("volume" "Volume of the conference proceedings in the series") | 218 ("volume" "Volume of the conference proceedings in the series") |
210 ("number" "Number of the conference proceedings in a small series (overwritten by volume)") | 219 ("number" "Number of the conference proceedings in a small series (overwritten by volume)") |
211 ("series" "Series in which the conference proceedings appeared") | 220 ("series" "Series in which the conference proceedings appeared") |
224 ("year" "Year of publication") | 233 ("year" "Year of publication") |
225 ("month" "Month of the publication as a string (remove braces)") | 234 ("month" "Month of the publication as a string (remove braces)") |
226 ("note" "Remarks to be put at the end of the \\bibitem"))))) | 235 ("note" "Remarks to be put at the end of the \\bibitem"))))) |
227 | 236 |
228 ("MastersThesis" . (((("author" "Author1 [and Author2 ...] [and others]") | 237 ("MastersThesis" . (((("author" "Author1 [and Author2 ...] [and others]") |
229 ("title" "Title of the master\'s thesis (will be converted to lowercase)") | 238 ("title" "Title of the master\'s thesis (BibTeX converts it to lowercase)") |
230 ("school" "School where the master\'s thesis was written") | 239 ("school" "School where the master\'s thesis was written") |
231 ("year" "Year of publication")) | 240 ("year" "Year of publication")) |
232 (("address" "Address of the school (if not part of field \"school\") or country") | 241 (("address" "Address of the school (if not part of field \"school\") or country") |
233 ("type" "Type of the master\'s thesis") | 242 ("type" "Type of the master\'s thesis") |
234 ("month" "Month of the publication as a string (remove braces)") | 243 ("month" "Month of the publication as a string (remove braces)") |
235 ("note" "Remarks to be put at the end of the \\bibitem"))))) | 244 ("note" "Remarks to be put at the end of the \\bibitem"))))) |
236 ("Misc" . ((() | 245 ("Misc" . ((() |
237 (("author" "Author1 [and Author2 ...] [and others]") | 246 (("author" "Author1 [and Author2 ...] [and others]") |
238 ("title" "Title of the reference (will be converted to lowercase)") | 247 ("title" "Title of the reference (BibTeX converts it to lowercase)") |
239 ("howpublished" "The way in which the reference was published") | 248 ("howpublished" "The way in which the reference was published") |
240 ("year" "Year of publication") | 249 ("year" "Year of publication") |
241 ("month" "Month of the publication as a string (remove braces)") | 250 ("month" "Month of the publication as a string (remove braces)") |
242 ("note" "Remarks to be put at the end of the \\bibitem"))))) | 251 ("note" "Remarks to be put at the end of the \\bibitem"))))) |
243 ("PhdThesis" . (((("author" "Author1 [and Author2 ...] [and others]") | 252 ("PhdThesis" . (((("author" "Author1 [and Author2 ...] [and others]") |
258 ("organization" "Sponsoring organization of the conference") | 267 ("organization" "Sponsoring organization of the conference") |
259 ("address" "Location of the Proceedings") | 268 ("address" "Location of the Proceedings") |
260 ("month" "Month of the publication as a string (remove braces)") | 269 ("month" "Month of the publication as a string (remove braces)") |
261 ("note" "Remarks to be put at the end of the \\bibitem"))))) | 270 ("note" "Remarks to be put at the end of the \\bibitem"))))) |
262 ("TechReport" . (((("author" "Author1 [and Author2 ...] [and others]") | 271 ("TechReport" . (((("author" "Author1 [and Author2 ...] [and others]") |
263 ("title" "Title of the technical report (will be converted to lowercase)") | 272 ("title" "Title of the technical report (BibTeX converts it to lowercase)") |
264 ("institution" "Sponsoring institution of the report") | 273 ("institution" "Sponsoring institution of the report") |
265 ("year" "Year of publication")) | 274 ("year" "Year of publication")) |
266 (("type" "Type of the report (if other than \"technical report\")") | 275 (("type" "Type of the report (if other than \"technical report\")") |
267 ("number" "Number of the technical report") | 276 ("number" "Number of the technical report") |
268 ("address" "Address of the institution (if not part of field \"institution\") or country") | 277 ("address" "Address of the institution (if not part of field \"institution\") or country") |
269 ("month" "Month of the publication as a string (remove braces)") | 278 ("month" "Month of the publication as a string (remove braces)") |
270 ("note" "Remarks to be put at the end of the \\bibitem"))))) | 279 ("note" "Remarks to be put at the end of the \\bibitem"))))) |
271 ("Unpublished" . (((("author" "Author1 [and Author2 ...] [and others]") | 280 ("Unpublished" . (((("author" "Author1 [and Author2 ...] [and others]") |
272 ("title" "Title of the unpublished reference (will be converted to lowercase)") | 281 ("title" "Title of the unpublished reference (BibTeX converts it to lowercase)") |
273 ("note" "Remarks to be put at the end of the \\bibitem")) | 282 ("note" "Remarks to be put at the end of the \\bibitem")) |
274 (("year" "Year of publication") | 283 (("year" "Year of publication") |
275 ("month" "Month of the publication as a string (remove braces)"))))) | 284 ("month" "Month of the publication as a string (remove braces)"))))) |
276 ) | 285 ) |
277 | 286 |
395 See the documentation of function bibtex-generate-autokey for further detail.") | 404 See the documentation of function bibtex-generate-autokey for further detail.") |
396 | 405 |
397 (defvar bibtex-autokey-edit-before-use t | 406 (defvar bibtex-autokey-edit-before-use t |
398 "*If non-nil, user is allowed to edit the generated key before it is used.") | 407 "*If non-nil, user is allowed to edit the generated key before it is used.") |
399 | 408 |
409 (defvar bibtex-font-lock-keywords | |
410 (list | |
411 "^@[A-Za-z]*[({]" | |
412 ;; reference type | |
413 '("^\\([ \t]*OPT[A-Za-z_-][A-Za-z0-9_-]*\\)[ \t]*=" | |
414 1 font-lock-comment-face) | |
415 ;; optional field names | |
416 '("^\\([ \t]*[A-Za-z_-][A-Za-z0-9_-]*\\)[ \t]*=" | |
417 1 font-lock-function-name-face) | |
418 ;; field names | |
419 '("^@[A-Za-z]*[({]\\([^\n,]*\\)," | |
420 1 font-lock-string-face) | |
421 ;; reference labels | |
422 ) | |
423 "*Fonts to use in BibTeX mode") | |
400 | 424 |
401 | 425 |
402 ;; Syntax Table, Keybindings and BibTeX Entry List | 426 ;; Syntax Table, Keybindings and BibTeX Entry List |
403 (defvar bibtex-mode-syntax-table | 427 (defvar bibtex-mode-syntax-table |
404 (let ((st (make-syntax-table))) | 428 (let ((st (make-syntax-table))) |
432 (define-key km "\C-c$" 'bibtex-ispell-entry) | 456 (define-key km "\C-c$" 'bibtex-ispell-entry) |
433 (define-key km "\M-\C-a" 'bibtex-beginning-of-entry) | 457 (define-key km "\M-\C-a" 'bibtex-beginning-of-entry) |
434 (define-key km "\M-\C-e" 'bibtex-end-of-entry) | 458 (define-key km "\M-\C-e" 'bibtex-end-of-entry) |
435 (define-key km "\C-c\C-b" 'bibtex-entry) | 459 (define-key km "\C-c\C-b" 'bibtex-entry) |
436 (define-key km "\C-c\C-q" 'bibtex-hide-entry-bodies) | 460 (define-key km "\C-c\C-q" 'bibtex-hide-entry-bodies) |
437 (define-key km "\C-c\C-a" 'show-all) | |
438 (define-key km "\C-c\C-rn" 'bibtex-narrow-to-entry) | 461 (define-key km "\C-c\C-rn" 'bibtex-narrow-to-entry) |
439 (define-key km "\C-c\C-rw" 'widen) | 462 (define-key km "\C-c\C-rw" 'widen) |
440 (define-key km "\C-c\C-o" 'bibtex-remove-OPT) | 463 (define-key km "\C-c\C-o" 'bibtex-remove-OPT) |
441 | 464 |
442 (define-key km "\C-c\C-e\C-i" 'bibtex-InProceedings) | 465 (define-key km "\C-c\C-e\C-i" 'bibtex-InProceedings) |
457 (define-key km "\C-c\C-e\C-s" 'bibtex-string) | 480 (define-key km "\C-c\C-e\C-s" 'bibtex-string) |
458 (define-key km "\C-c\C-e\C-t" 'bibtex-TechReport) | 481 (define-key km "\C-c\C-e\C-t" 'bibtex-TechReport) |
459 (define-key km "\C-c\C-e\C-u" 'bibtex-Unpublished) | 482 (define-key km "\C-c\C-e\C-u" 'bibtex-Unpublished) |
460 km)) | 483 km)) |
461 | 484 |
462 (define-key bibtex-mode-map [menu-bar move/edit] | 485 (define-key bibtex-mode-map [menu-bar bibtex-edit] |
463 (cons "BibTeX-Edit" (make-sparse-keymap "BibTeX-Edit"))) | 486 (cons "BibTeX-Edit" (make-sparse-keymap "BibTeX-Edit"))) |
464 (define-key bibtex-mode-map [menu-bar move/edit bibtex-print-help-message] | 487 (define-key bibtex-mode-map [menu-bar bibtex-edit bibtex-print-help-message] |
465 '("Help about Current Field" . bibtex-print-help-message)) | 488 '("Help about Current Field" . bibtex-print-help-message)) |
466 (define-key bibtex-mode-map [menu-bar move/edit bibtex-complete-string] | 489 (define-key bibtex-mode-map [menu-bar bibtex-edit bibtex-complete-string] |
467 '("String Complete" . bibtex-complete-string)) | 490 '("String Complete" . bibtex-complete-string)) |
468 (define-key bibtex-mode-map [menu-bar move/edit bibtex-next-field] | 491 (define-key bibtex-mode-map [menu-bar bibtex-edit bibtex-next-field] |
469 '("Next Field" . bibtex-next-field)) | 492 '("Next Field" . bibtex-next-field)) |
470 (define-key bibtex-mode-map [menu-bar move/edit bibtex-find-text] | 493 (define-key bibtex-mode-map [menu-bar bibtex-edit bibtex-find-text] |
471 '("End of Field" . bibtex-find-text)) | 494 '("End of Field" . bibtex-find-text)) |
472 (define-key bibtex-mode-map [menu-bar move/edit bibtex-pop-previous] | 495 (define-key bibtex-mode-map [menu-bar bibtex-edit bibtex-pop-previous] |
473 '("Snatch from Similar Preceding Field" . bibtex-pop-previous)) | 496 '("Snatch from Similar Preceding Field" . bibtex-pop-previous)) |
474 (define-key bibtex-mode-map [menu-bar move/edit bibtex-pop-next] | 497 (define-key bibtex-mode-map [menu-bar bibtex-edit bibtex-pop-next] |
475 '("Snatch from Similar Following Field" . bibtex-pop-next)) | 498 '("Snatch from Similar Following Field" . bibtex-pop-next)) |
476 (define-key bibtex-mode-map [menu-bar move/edit bibtex-remove-OPT] | 499 (define-key bibtex-mode-map [menu-bar bibtex-edit bibtex-remove-OPT] |
477 '("Remove OPT" . bibtex-remove-OPT)) | 500 '("Remove OPT" . bibtex-remove-OPT)) |
478 (define-key bibtex-mode-map [menu-bar move/edit bibtex-remove-double-quotes-or-braces] | 501 (define-key bibtex-mode-map [menu-bar bibtex-edit bibtex-remove-double-quotes-or-braces] |
479 '("Remove Quotes or Braces" . bibtex-remove-double-quotes-or-braces)) | 502 '("Remove Quotes or Braces" . bibtex-remove-double-quotes-or-braces)) |
480 (define-key bibtex-mode-map [menu-bar move/edit bibtex-clean-entry] | 503 (define-key bibtex-mode-map [menu-bar bibtex-edit bibtex-clean-entry] |
481 '("Clean Up Entry" . bibtex-clean-entry)) | 504 '("Clean Up Entry" . bibtex-clean-entry)) |
482 (define-key bibtex-mode-map [menu-bar move/edit bibtex-sort-entries] | 505 (define-key bibtex-mode-map [menu-bar bibtex-edit bibtex-sort-entries] |
483 '("Sort Entries" . bibtex-sort-entries)) | 506 '("Sort Entries" . bibtex-sort-entries)) |
484 (define-key bibtex-mode-map [menu-bar move/edit bibtex-validate-buffer] | 507 (define-key bibtex-mode-map [menu-bar bibtex-edit bibtex-validate-buffer] |
485 '("Validate Entries" . bibtex-validate-buffer)) | 508 '("Validate Entries" . bibtex-validate-buffer)) |
486 | 509 |
487 (define-key bibtex-mode-map [menu-bar entry-types] | 510 (define-key bibtex-mode-map [menu-bar entry-types] |
488 (cons "Entry-Types" (make-sparse-keymap "Entry-Types"))) | 511 (cons "Entry-Types" (make-sparse-keymap "Entry-Types"))) |
489 (define-key bibtex-mode-map [menu-bar entry-types bibtex-preamble] | 512 (define-key bibtex-mode-map [menu-bar entry-types bibtex-preamble] |
532 ;; Candidates for bibtex-complete-string. Initialized from | 555 ;; Candidates for bibtex-complete-string. Initialized from |
533 ;; bibtex-predefined-strings and bibtex-string-files. This variable is | 556 ;; bibtex-predefined-strings and bibtex-string-files. This variable is |
534 ;; buffer-local. | 557 ;; buffer-local. |
535 (make-variable-buffer-local 'bibtex-completion-candidates) | 558 (make-variable-buffer-local 'bibtex-completion-candidates) |
536 | 559 |
560 (defvar bibtex-keys nil) | |
561 ;; Candidates for TAB completion when entering a reference key using | |
562 ;; the minibuffer. Initialized in bibtex-mode and updated for each | |
563 ;; new entry. This variable is buffer-local. | |
564 (make-variable-buffer-local 'bibtex-keys) | |
565 | |
566 (defvar bibtex-buffer-last-parsed-for-keys-tick nil) | |
567 ;; Remembers the value returned by buffer-modified-tick when buffer | |
568 ;; was parsed for keys the last time. | |
569 (make-variable-buffer-local 'bibtex-keys) | |
570 | |
571 | |
537 | 572 |
538 ;; Functions to Parse the BibTeX Entries | 573 ;; Functions to Parse the BibTeX Entries |
539 | 574 |
540 (defun bibtex-cfield (name text) | 575 (defun bibtex-cfield (name text) |
541 ;; Create a regexp for a BibTeX field of name NAME and text TEXT. | 576 ;; Create a regexp for a BibTeX field of name NAME and text TEXT. |
548 ;; The regexp subexpression number of the name part in bibtex-cfield. | 583 ;; The regexp subexpression number of the name part in bibtex-cfield. |
549 | 584 |
550 (defconst bibtex-text-in-cfield 2) | 585 (defconst bibtex-text-in-cfield 2) |
551 ;; The regexp subexpression number of the text part in bibtex-cfield. | 586 ;; The regexp subexpression number of the text part in bibtex-cfield. |
552 | 587 |
553 (defconst bibtex-field-name "[A-Za-z][]A-Za-z0-9.:;?!`'()/*@_+=-]*") | 588 (defconst bibtex-field-name "[A-Za-z_-][A-Za-z0-9_-]*") |
554 ;; Regexp defining the name part of a BibTeX field. | 589 ;; Regexp defining the name part of a BibTeX field. |
555 | 590 |
556 (defconst bibtex-field-const "[0-9A-Za-z][A-Za-z0-9:_+-]*" | 591 (defconst bibtex-field-const "[0-9A-Za-z][A-Za-z0-9:_+-]*" |
557 "Format of a bibtex field constant.") | 592 "Format of a bibtex field constant.") |
558 | 593 |
560 (concat | 595 (concat |
561 "\\(" | 596 "\\(" |
562 "{\\(\\({\\(\\({[^}]*}\\)\\|\\([^{}]\\)\\)*}\\)\\|\\([^{}]\\)\\)*}" | 597 "{\\(\\({\\(\\({[^}]*}\\)\\|\\([^{}]\\)\\)*}\\)\\|\\([^{}]\\)\\)*}" |
563 ;; maximal twice nested {} | 598 ;; maximal twice nested {} |
564 "\\)\\|\\(" | 599 "\\)\\|\\(" |
565 "\"[^\"]*[^\\\\]\"\\|\"\"\\)")) | 600 "\"[^\"]*[^\\\\]\"\\|\"\"" |
601 "\\)")) | |
566 ;; Match either a string or an empty string. | 602 ;; Match either a string or an empty string. |
567 | 603 |
568 (defconst bibtex-field-string-or-const | 604 (defconst bibtex-field-string-or-const |
569 (concat bibtex-field-const "\\|" bibtex-field-string)) | 605 (concat bibtex-field-const "\\|" bibtex-field-string)) |
570 ;; Match either bibtex-field-string or bibtex-field-const. | 606 ;; Match either bibtex-field-string or bibtex-field-const. |
571 | 607 |
572 (defconst bibtex-field-text | 608 (defconst bibtex-field-text |
573 (concat | 609 (concat |
574 "\\(" bibtex-field-string-or-const "\\)" | 610 "\\(" bibtex-field-string-or-const "\\)" |
575 "\\([ \t\n]+#[ \t\n]+\\(" bibtex-field-string-or-const "\\)\\)*\\|" | 611 "\\([ \t\n]+#[ \t\n]+\\(" bibtex-field-string-or-const "\\)\\)*")) |
576 "{[^{}]*[^\\\\]}")) | |
577 ;; Regexp defining the text part of a BibTeX field: either a string, | 612 ;; Regexp defining the text part of a BibTeX field: either a string, |
578 ;; or an empty string, or a constant followed by one or more # / | 613 ;; or an empty string, or a constant followed by one or more # / |
579 ;; constant pairs. Also matches simple {...} patterns. | 614 ;; constant pairs. |
580 | 615 |
581 (defconst bibtex-field | 616 (defconst bibtex-field |
582 (bibtex-cfield bibtex-field-name bibtex-field-text)) | 617 (bibtex-cfield bibtex-field-name bibtex-field-text)) |
583 ;; Regexp defining the format of a BibTeX field. | 618 ;; Regexp defining the format of a BibTeX field. |
584 | 619 |
586 ;; The regexp subexpression number of the name part in BibTeX-field. | 621 ;; The regexp subexpression number of the name part in BibTeX-field. |
587 | 622 |
588 (defconst bibtex-text-in-field bibtex-text-in-cfield) | 623 (defconst bibtex-text-in-field bibtex-text-in-cfield) |
589 ;; The regexp subexpression number of the text part in BibTeX-field. | 624 ;; The regexp subexpression number of the text part in BibTeX-field. |
590 | 625 |
591 (defconst bibtex-reference-type | 626 (defconst bibtex-reference-type "@[A-Za-z]+") |
592 "@[A-Za-z]+") | |
593 ;; Regexp defining the type part of a BibTeX reference entry. | 627 ;; Regexp defining the type part of a BibTeX reference entry. |
628 | |
629 (defconst bibtex-reference-key "[A-Za-z][A-Za-z0-9.:;?!`'/*@_+-]*") | |
630 ;; Regexp defining the label part of a BibTeX reference entry. | |
594 | 631 |
595 (defconst bibtex-reference-head | 632 (defconst bibtex-reference-head |
596 (concat "^\\( \\|\t\\)*\\(" | 633 (concat "^\\( \\|\t\\)*\\(" |
597 bibtex-reference-type | 634 bibtex-reference-type |
598 "\\)[ \t]*[({]\\(" | 635 "\\)[ \t]*[({]\\(" |
599 bibtex-field-name | 636 bibtex-reference-key |
600 "\\)")) | 637 "\\)")) |
601 ;; Regexp defining format of the header line of a BibTeX reference | 638 ;; Regexp defining format of the header line of a BibTeX reference |
602 ;; entry. | 639 ;; entry. |
603 | 640 |
641 (defconst bibtex-reference-maybe-empty-head | |
642 (concat bibtex-reference-head "?")) | |
643 ;; Regexp defining format of the header line of a maybe empty | |
644 ;; BibTeX reference entry (without reference key). | |
645 | |
604 (defconst bibtex-type-in-head 2) | 646 (defconst bibtex-type-in-head 2) |
605 ;; The regexp subexpression number of the type part in | 647 ;; The regexp subexpression number of the type part in |
606 ;; bibtex-reference-head. | 648 ;; bibtex-reference-head. |
607 | 649 |
608 (defconst bibtex-key-in-head 3) | 650 (defconst bibtex-key-in-head 3) |
610 ;; bibtex-reference-head. | 652 ;; bibtex-reference-head. |
611 | 653 |
612 (defconst bibtex-reference | 654 (defconst bibtex-reference |
613 (concat bibtex-reference-head | 655 (concat bibtex-reference-head |
614 "\\([ \t\n]*" bibtex-field "\\)*" | 656 "\\([ \t\n]*" bibtex-field "\\)*" |
615 "[ \t\n]*[})]")) | 657 "[ \t\n]*,?[ \t\n]*[})]")) |
616 ;; Regexp defining the format of a BibTeX reference entry. | 658 ;; Regexp defining the format of a BibTeX reference entry. |
617 | 659 |
618 (defconst bibtex-type-in-reference bibtex-type-in-head) | 660 (defconst bibtex-type-in-reference bibtex-type-in-head) |
619 ;; The regexp subexpression number of the type part in | 661 ;; The regexp subexpression number of the type part in |
620 ;; bibtex-reference. | 662 ;; bibtex-reference. |
623 ;; The regexp subexpression number of the key part in | 665 ;; The regexp subexpression number of the key part in |
624 ;; bibtex-reference. | 666 ;; bibtex-reference. |
625 | 667 |
626 (defconst bibtex-string | 668 (defconst bibtex-string |
627 (concat "^[ \t]*@[sS][tT][rR][iI][nN][gG][ \t\n]*[({][ \t\n]*\\(" | 669 (concat "^[ \t]*@[sS][tT][rR][iI][nN][gG][ \t\n]*[({][ \t\n]*\\(" |
628 bibtex-field-name | 670 bibtex-reference-key |
629 "\\)[ \t\n]*=[ \t\n]*\\(" | 671 "\\)[ \t\n]*=[ \t\n]*\\(" |
630 bibtex-field-text | 672 bibtex-field-text |
631 "\\)[ \t\n]*[})]")) | 673 "\\)[ \t\n]*[})]")) |
632 ;; Regexp defining the format of a BibTeX string entry. | 674 ;; Regexp defining the format of a BibTeX string entry. |
633 | 675 |
634 (defconst bibtex-name-in-string 1) | 676 (defconst bibtex-key-in-string 1) |
635 ;; The regexp subexpression of the name part in bibtex-string. | 677 ;; The regexp subexpression of the name part in bibtex-string. |
636 | 678 |
637 (defconst bibtex-text-in-string 2) | 679 (defconst bibtex-text-in-string 2) |
638 ;; The regexp subexpression of the text part in bibtex-string. | 680 ;; The regexp subexpression of the text part in bibtex-string. |
639 | 681 |
707 | 749 |
708 (defun map-bibtex-entries (fun) | 750 (defun map-bibtex-entries (fun) |
709 ;; Call FUN for each BibTeX entry starting with the current. Do this | 751 ;; Call FUN for each BibTeX entry starting with the current. Do this |
710 ;; to the end of the file. FUN is called with one argument, the key | 752 ;; to the end of the file. FUN is called with one argument, the key |
711 ;; of the entry, and with point inside the entry. If | 753 ;; of the entry, and with point inside the entry. If |
712 ;; bibtex-sort-ignore-string-entries is true, FUN will not be called | 754 ;; bibtex-sort-ignore-string-entries is non-nil, FUN will not be called |
713 ;; for @string entries. | 755 ;; for @string entries. |
714 (bibtex-beginning-of-entry) | 756 (bibtex-beginning-of-entry) |
715 (while (re-search-forward "^@[^{]*{[ \t]*\\([^, ]*\\)" nil t) | 757 (while (re-search-forward bibtex-reference-head nil t) |
716 (if (and bibtex-sort-ignore-string-entries | 758 (if (and bibtex-sort-ignore-string-entries |
717 (string-equal "@string{" | 759 (string-equal "@string" |
718 (downcase (buffer-substring-no-properties | 760 (downcase (buffer-substring-no-properties |
719 (match-beginning 0) | 761 (match-beginning bibtex-type-in-head) |
720 (match-beginning 1))))) | 762 (match-end bibtex-type-in-head))))) |
721 nil | 763 nil |
722 (funcall fun (buffer-substring-no-properties | 764 (funcall fun (buffer-substring-no-properties |
723 (match-beginning 1) (match-end 1)))))) | 765 (match-beginning bibtex-key-in-head) |
766 (match-end bibtex-key-in-head)))))) | |
724 | 767 |
725 (defun bibtex-flash-head () | 768 (defun bibtex-flash-head () |
726 ;; Flash at BibTeX reference head before point, if exists. | 769 ;; Flash at BibTeX reference head before point, if exists. |
727 (let ((flash)) | 770 (let ((flash)) |
728 (cond ((re-search-backward bibtex-reference-head (point-min) t) | 771 (cond ((re-search-backward bibtex-reference-head (point-min) t) |
753 (re-search-forward "[ \t\n]*" (point-max) t)) | 796 (re-search-forward "[ \t\n]*" (point-max) t)) |
754 | 797 |
755 (defun beginning-of-first-bibtex-entry () | 798 (defun beginning-of-first-bibtex-entry () |
756 ;; Go to the beginning of the first BibTeX entry in buffer. | 799 ;; Go to the beginning of the first BibTeX entry in buffer. |
757 (goto-char (point-min)) | 800 (goto-char (point-min)) |
758 (cond | 801 (cond |
759 ((re-search-forward "^@" nil 'move) | 802 ((re-search-forward "^@" nil 'move) |
760 (beginning-of-line)) | 803 (beginning-of-line)) |
761 ((and (bobp) (eobp)) | 804 ((and (bobp) (eobp)) |
762 nil) | 805 nil) |
763 (t | 806 (t |
764 (message "Warning: No BibTeX entries found!")))) | 807 (message "Warning: No BibTeX entries found!")))) |
765 | 808 |
766 (defun bibtex-inside-field () | 809 (defun bibtex-inside-field () |
767 ;; Try to avoid point being at end of a BibTeX field. | 810 ;; Try to avoid point being at end of a BibTeX field. |
768 (end-of-line) | 811 (end-of-line) |
769 (skip-chars-backward " \t") ;MON - maybe delete these chars? | 812 (skip-chars-backward " \t") |
770 (cond ((= (preceding-char) ?,) | 813 (cond ((= (preceding-char) ?,) |
771 (forward-char -2))) ; -1 --> -2 sct@dcs.edinburgh.ac.uk | 814 (forward-char -2))) |
772 (cond ((= (preceding-char) (aref bibtex-field-right-delimiter 0)) | 815 (cond ((or |
773 (forward-char -1)))) ;MON - only go back if quote | 816 (= (preceding-char) ?}) |
817 (= (preceding-char) ?\")) | |
818 (forward-char -1)))) | |
774 | 819 |
775 (defun bibtex-enclosing-field () | 820 (defun bibtex-enclosing-field () |
776 ;; Search for BibTeX field enclosing point. Point moves to end of | 821 ;; Search for BibTeX field enclosing point. Point moves to end of |
777 ;; field; also, use match-beginning and match-end to parse the field. | 822 ;; field; also, use match-beginning and match-end to parse the field. |
778 ;; sct@dcs.edinburgh.ac.uk | 823 ;; sct@dcs.edinburgh.ac.uk |
782 (search-failed | 827 (search-failed |
783 (goto-char old-point) | 828 (goto-char old-point) |
784 (error "Can't find enclosing BibTeX field."))))) | 829 (error "Can't find enclosing BibTeX field."))))) |
785 | 830 |
786 (defun bibtex-enclosing-reference () | 831 (defun bibtex-enclosing-reference () |
787 ;; Search for BibTeX reference enclosing point. Point moves to begin | 832 ;; Search for BibTeX reference enclosing point. Point moves to |
788 ;; of reference. (match-end 0) denotes end of reference. | 833 ;; beginning of reference. Beginning/end of reference is given by |
789 ;; Hacked up for speed. Parsing isn't guaranteed any more. | 834 ;; (match-beginning/match-end 0). |
790 ;; schoef@informatik.uni-oldenburg.de | 835 (let ((old-point (point))) |
791 ;; sct@dcs.edinburgh.ac.uk | 836 (if (not |
837 (re-search-backward bibtex-reference-head (point-min) t)) | |
838 (progn | |
839 (error "Can't find enclosing BibTeX reference.") | |
840 (goto-char old-point))) | |
841 (goto-char (match-beginning bibtex-type-in-head)) | |
842 (let ((pnt (point))) | |
843 (if (not | |
844 (re-search-forward bibtex-reference (point-max) t)) | |
845 (progn | |
846 (error "Can't find enclosing BibTeX reference.") | |
847 (goto-char old-point)) | |
848 (goto-char pnt))))) | |
849 | |
850 (defun bibtex-enclosing-reference-maybe-empty-head () | |
851 ;; Search for BibTeX reference enclosing point. Point moves to | |
852 ;; beginning of reference. Beginning/end of reference is given by | |
853 ;; (match-beginning/match-end 0). | |
792 (let ((old-point (point))) | 854 (let ((old-point (point))) |
793 (if (not | 855 (if (not |
794 (re-search-backward | 856 (re-search-backward |
795 "^@[A-Za-z]+[ \t\n]*[{(][^, \t\n]*[ \t\n]*," | 857 bibtex-reference-maybe-empty-head (point-min) t)) |
796 (point-min) t)) | |
797 (progn | 858 (progn |
798 (error "Can't find enclosing BibTeX reference.") | 859 (error "Can't find enclosing BibTeX reference.") |
799 (goto-char old-point))) | 860 (goto-char old-point))) |
861 (goto-char (match-beginning bibtex-type-in-head)) | |
800 (let ((pnt (point))) | 862 (let ((pnt (point))) |
801 (if (not | 863 (if (not |
802 (re-search-forward "^[)}]$" (point-max) t)) | 864 (re-search-forward |
865 (concat | |
866 bibtex-reference-maybe-empty-head | |
867 "\\([ \t\n]*" bibtex-field "\\)*" | |
868 "[ \t\n]*,?[ \t\n]*[})]") | |
869 (point-max) t)) | |
803 (progn | 870 (progn |
804 (error "Can't find enclosing BibTeX reference.") | 871 (error "Can't find enclosing BibTeX reference.") |
805 (goto-char old-point)) | 872 (goto-char old-point)) |
806 (goto-char pnt))))) | 873 (goto-char pnt))))) |
807 | 874 |
937 (point))) | 1004 (point))) |
938 (namefield | 1005 (namefield |
939 (progn | 1006 (progn |
940 (goto-char min) | 1007 (goto-char min) |
941 (if (or | 1008 (if (or |
942 (search-forward-regexp "^[ \t]*author[ \t]*=" max t) | 1009 (re-search-forward "^[ \t]*author[ \t]*=" max t) |
943 (search-forward-regexp "^[ \t]*editor[ \t]*=" max t)) | 1010 (re-search-forward "^[ \t]*editor[ \t]*=" max t)) |
944 (let* (bibtex-help-message | 1011 (let* (bibtex-help-message |
945 (start (progn | 1012 (start (progn |
946 (bibtex-find-text t) | 1013 (bibtex-find-text t) |
947 (point))) | 1014 (point))) |
948 (end (progn | 1015 (end (progn |
993 namelist | 1060 namelist |
994 bibtex-autokey-name-separator)) | 1061 bibtex-autokey-name-separator)) |
995 (yearfield | 1062 (yearfield |
996 (progn | 1063 (progn |
997 (goto-char min) | 1064 (goto-char min) |
998 (if (search-forward-regexp | 1065 (if (re-search-forward |
999 "^[ \t]*year[ \t]*=[ \t]*\\([0-9]*\\)" max t) | 1066 "^[ \t]*year[ \t]*=[ \t]*\\([0-9]*\\)" max t) |
1000 (buffer-substring-no-properties | 1067 (buffer-substring-no-properties |
1001 (match-beginning 1) (match-end 1)) | 1068 (match-beginning 1) (match-end 1)) |
1002 ""))) | 1069 ""))) |
1003 (yearpart | 1070 (yearpart |
1009 (titlestring | 1076 (titlestring |
1010 (let ((case-fold-search t) | 1077 (let ((case-fold-search t) |
1011 (titlefield | 1078 (titlefield |
1012 (progn | 1079 (progn |
1013 (goto-char min) | 1080 (goto-char min) |
1014 (if (search-forward-regexp | 1081 (if (re-search-forward |
1015 "^[ \t]*title[ \t]*=" max t) | 1082 "^[ \t]*title[ \t]*=" max t) |
1016 (let* (bibtex-help-message | 1083 (let* (bibtex-help-message |
1017 (start (progn | 1084 (start (progn |
1018 (bibtex-find-text t) | 1085 (bibtex-find-text t) |
1019 (point))) | 1086 (point))) |
1110 bibtex-autokey-year-title-separator) | 1177 bibtex-autokey-year-title-separator) |
1111 titlepart))) | 1178 titlepart))) |
1112 (goto-char pnt) | 1179 (goto-char pnt) |
1113 autokey)) | 1180 autokey)) |
1114 | 1181 |
1182 (defun bibtex-parse-keys (add &optional abortable) | |
1183 ;; Sets bibtex-keys to the keys used in the whole (possibly | |
1184 ;; restricted) buffer (either as entry keys or as crossref entries). | |
1185 ;; If ADD is non-nil adds the new keys to bibtex-keys instead of | |
1186 ;; simply resetting it. If ABORTABLE is non-nil abort on user input. | |
1187 (if bibtex-maintain-sorted-entries | |
1188 (let ((labels (if add | |
1189 bibtex-keys)) | |
1190 label | |
1191 (case-fold-search t)) | |
1192 (save-excursion | |
1193 (goto-char (point-min)) | |
1194 (if (not add) | |
1195 (message "Parsing reference keys...")) | |
1196 | |
1197 (if (not | |
1198 (catch 'userkey | |
1199 (while | |
1200 (re-search-forward | |
1201 (concat | |
1202 "\\(" | |
1203 bibtex-reference-head | |
1204 "\\)\\|\\(" | |
1205 "^[ \t\n]*crossref[ \t\n]*=[ \t\n]*[{\"]\\([A-Za-z][]A-Za-z0-9.:;?!`'()/*@_+-]*\\)[}\"],?$" | |
1206 "\\)") | |
1207 nil t) | |
1208 (if (and | |
1209 abortable | |
1210 (input-pending-p)) | |
1211 (throw 'userkey t)) | |
1212 (if (match-beginning (1+ bibtex-key-in-head)) | |
1213 (setq | |
1214 label | |
1215 (buffer-substring-no-properties | |
1216 (match-beginning (1+ bibtex-key-in-head)) | |
1217 (match-end (1+ bibtex-key-in-head)))) | |
1218 (setq | |
1219 label | |
1220 (buffer-substring-no-properties | |
1221 (match-beginning (+ 3 bibtex-key-in-head)) | |
1222 (match-end (+ 3 bibtex-key-in-head))))) | |
1223 (if (not (assoc label labels)) | |
1224 (setq labels | |
1225 (cons (list label) labels)))))) | |
1226 (progn | |
1227 (setq | |
1228 bibtex-buffer-last-parsed-for-keys-tick | |
1229 (buffer-modified-tick)) | |
1230 (if (not add) | |
1231 (message "Parsing reference keys... done")) | |
1232 (setq bibtex-keys labels))))))) | |
1233 | |
1234 (defun bibtex-auto-fill-function () | |
1235 (let ((fill-prefix (make-string (+ bibtex-text-alignment 1) ? ))) | |
1236 (do-auto-fill))) | |
1237 | |
1115 | 1238 |
1116 | 1239 |
1117 ;; Interactive Functions: | 1240 ;; Interactive Functions: |
1118 | 1241 |
1119 ;;;###autoload | 1242 ;;;###autoload |
1224 (compl bibtex-completion-candidates)) | 1347 (compl bibtex-completion-candidates)) |
1225 (create-file-buffer bufname) | 1348 (create-file-buffer bufname) |
1226 (set-buffer bufname) | 1349 (set-buffer bufname) |
1227 (insert-file-contents fullfilename) | 1350 (insert-file-contents fullfilename) |
1228 (goto-char (point-min)) | 1351 (goto-char (point-min)) |
1229 (while (search-forward-regexp bibtex-string nil t) | 1352 (while (re-search-forward bibtex-string nil t) |
1230 (setq | 1353 (setq |
1231 compl | 1354 compl |
1232 (append | 1355 (append |
1233 compl | 1356 compl |
1234 (list | 1357 (list |
1235 (list (buffer-substring-no-properties | 1358 (list (buffer-substring-no-properties |
1236 (match-beginning bibtex-name-in-string) | 1359 (match-beginning bibtex-key-in-string) |
1237 (match-end bibtex-name-in-string))))))) | 1360 (match-end bibtex-key-in-string))))))) |
1238 (kill-buffer bufname) | 1361 (kill-buffer bufname) |
1239 (set-buffer curbuf) | 1362 (set-buffer curbuf) |
1240 (setq bibtex-completion-candidates compl)) | 1363 (setq bibtex-completion-candidates compl)) |
1241 (error "File %s not in $BIBINPUTS paths" filename))))) | 1364 (error "File %s not in $BIBINPUTS paths" filename))))) |
1242 bibtex-string-files) | 1365 bibtex-string-files) |
1366 (add-hook | |
1367 'auto-save-hook | |
1368 (function | |
1369 (lambda () | |
1370 (if (and | |
1371 bibtex-maintain-sorted-entries | |
1372 (eq major-mode 'bibtex-mode) | |
1373 (not | |
1374 (eq (buffer-modified-tick) | |
1375 bibtex-buffer-last-parsed-for-keys-tick))) | |
1376 (bibtex-parse-keys nil t))))) | |
1377 (bibtex-parse-keys nil) | |
1243 (make-local-variable 'paragraph-start) | 1378 (make-local-variable 'paragraph-start) |
1244 (setq paragraph-start "[ \f\n\t]*$") | 1379 (setq paragraph-start "[ \f\n\t]*$") |
1245 (make-local-variable 'comment-start) | 1380 (make-local-variable 'comment-start) |
1246 (setq comment-start "%") | 1381 (setq comment-start "%") |
1247 (auto-fill-mode 1) ; nice alignments | 1382 (auto-fill-mode 1) |
1248 (setq left-margin (+ bibtex-text-alignment 1)) | 1383 (setq auto-fill-function 'bibtex-auto-fill-function) |
1384 (set (make-local-variable 'font-lock-defaults) | |
1385 '(bibtex-font-lock-keywords nil t ((?$ . "\"")))) | |
1249 (run-hooks 'bibtex-mode-hook)) | 1386 (run-hooks 'bibtex-mode-hook)) |
1250 | 1387 |
1251 (defun bibtex-entry (entry-type &optional required optional) | 1388 (defun bibtex-entry (entry-type &optional required optional) |
1389 "Inserts a new BibTeX entry. | |
1390 Calls the value of bibtex-add-entry-hook if that value is non-nil." | |
1252 (interactive (let* ((completion-ignore-case t) | 1391 (interactive (let* ((completion-ignore-case t) |
1253 (e-t (completing-read | 1392 (e-t (completing-read |
1254 "Entry Type: " | 1393 "Entry Type: " |
1255 bibtex-entry-field-alist | 1394 bibtex-entry-field-alist |
1256 nil t))) | 1395 nil t))) |
1266 c-ref) | 1405 c-ref) |
1267 (setq required (elt c-ref 0) | 1406 (setq required (elt c-ref 0) |
1268 optional (elt c-ref 1)) | 1407 optional (elt c-ref 1)) |
1269 (setq required (elt r-n-o 0) | 1408 (setq required (elt r-n-o 0) |
1270 optional (elt r-n-o 1))))) | 1409 optional (elt r-n-o 1))))) |
1271 (let* | 1410 (let ((key |
1272 (labels | 1411 (if bibtex-maintain-sorted-entries |
1273 label | 1412 (completing-read |
1274 (case-fold-search t) | 1413 (format "%s key: " entry-type) |
1275 (key | 1414 bibtex-keys)))) |
1276 (if bibtex-maintain-sorted-entries | 1415 (if bibtex-maintain-sorted-entries |
1277 (progn | 1416 (bibtex-find-entry-location key) |
1278 (save-excursion | 1417 (bibtex-move-outside-of-entry)) |
1279 (goto-char (point-min)) | |
1280 (while | |
1281 (re-search-forward | |
1282 "\\(^@[a-z]+[ \t\n]*[{(][ \t\n]*\\([^ ,\t\n]+\\)[ \t\n]*,\\)\\|\\(^[ \t\n]*crossref[ \t\n]*=[ \t\n]*[{\"]\\([^ ,\t\n]*\\)[}\"],$\\)" | |
1283 nil t) | |
1284 (if (match-beginning 2) | |
1285 (setq label (buffer-substring-no-properties | |
1286 (match-beginning 2) (match-end 2))) | |
1287 (setq label (buffer-substring-no-properties | |
1288 (match-beginning 4) (match-end 4)))) | |
1289 (if (not (assoc label labels)) | |
1290 (setq labels | |
1291 (cons (list label) labels))))) | |
1292 (completing-read | |
1293 (format "%s key: " entry-type) | |
1294 labels))))) | |
1295 (if key | |
1296 (bibtex-find-entry-location key)) | |
1297 (bibtex-move-outside-of-entry) | |
1298 (insert "@" entry-type "{") | 1418 (insert "@" entry-type "{") |
1299 (if key | 1419 (if key |
1300 (insert key)) | 1420 (insert key)) |
1301 (save-excursion | 1421 (save-excursion |
1302 (mapcar 'bibtex-make-field required) | 1422 (mapcar 'bibtex-make-field required) |
1308 (mapcar 'bibtex-make-optional-field | 1428 (mapcar 'bibtex-make-optional-field |
1309 bibtex-mode-user-optional-fields) | 1429 bibtex-mode-user-optional-fields) |
1310 (if bibtex-include-OPTannote | 1430 (if bibtex-include-OPTannote |
1311 (bibtex-make-optional-field '("annote"))) | 1431 (bibtex-make-optional-field '("annote"))) |
1312 (insert "\n}\n\n")) | 1432 (insert "\n}\n\n")) |
1313 (if key | 1433 (bibtex-next-field t) |
1314 (bibtex-next-field t)) | |
1315 (run-hooks 'bibtex-add-entry-hook))) | 1434 (run-hooks 'bibtex-add-entry-hook))) |
1316 | 1435 |
1317 (defun bibtex-print-help-message () | 1436 (defun bibtex-print-help-message () |
1318 "Prints helpful information about current field in current BibTeX entry." | 1437 "Prints helpful information about current field in current BibTeX entry." |
1319 (interactive) | 1438 (interactive) |
1324 (condition-case errname | 1443 (condition-case errname |
1325 (bibtex-enclosing-regexp bibtex-field) | 1444 (bibtex-enclosing-regexp bibtex-field) |
1326 (search-failed | 1445 (search-failed |
1327 (goto-char pnt) | 1446 (goto-char pnt) |
1328 (error "Not on BibTeX field"))) | 1447 (error "Not on BibTeX field"))) |
1329 (re-search-backward | 1448 (let ((mb (match-beginning bibtex-name-in-field)) |
1330 "^[ \t]*\\([A-Za-z]+\\)[ \t\n]*=" nil t) | 1449 (me (match-end bibtex-name-in-field))) |
1331 (let ((mb (match-beginning 1)) | 1450 (goto-char mb) |
1332 (me (match-end 1))) | |
1333 (buffer-substring-no-properties | 1451 (buffer-substring-no-properties |
1334 (if (looking-at "^[ \t]*OPT") | 1452 (if (looking-at "OPT") |
1335 (+ 3 mb) | 1453 (+ 3 mb) |
1336 mb) | 1454 mb) |
1337 me)))) | 1455 me)))) |
1338 (reference-type | 1456 (reference-type |
1339 (progn | 1457 (progn |
1340 (re-search-backward | 1458 (re-search-backward |
1341 "^@\\([A-Za-z]+\\)[ \t\n]*[{(][^, \t\n]*[ \t\n]*," nil t) | 1459 bibtex-reference-maybe-empty-head nil t) |
1342 (buffer-substring-no-properties | 1460 (buffer-substring-no-properties |
1343 (match-beginning 1) (match-end 1)))) | 1461 (1+ (match-beginning bibtex-type-in-head)) |
1462 (match-end bibtex-type-in-head)))) | |
1344 (entry-list | 1463 (entry-list |
1345 (assoc-ignore-case reference-type | 1464 (assoc-ignore-case reference-type |
1346 bibtex-entry-field-alist)) | 1465 bibtex-entry-field-alist)) |
1347 (c-r-list (elt entry-list 2)) | 1466 (c-r-list (elt entry-list 2)) |
1348 (req-opt-list | 1467 (req-opt-list |
1371 (message (elt (assoc field-name list-of-entries) 1)) | 1490 (message (elt (assoc field-name list-of-entries) 1)) |
1372 (message "NO COMMENT AVAILABLE")))) | 1491 (message "NO COMMENT AVAILABLE")))) |
1373 | 1492 |
1374 (defun bibtex-make-field (e-t) | 1493 (defun bibtex-make-field (e-t) |
1375 "Makes a field named E-T in current BibTeX entry." | 1494 "Makes a field named E-T in current BibTeX entry." |
1376 (interactive "sBibTeX entry type: ") | 1495 (interactive "sBibTeX field name: ") |
1377 (let ((name (if (consp e-t) | 1496 (let ((name (if (consp e-t) |
1378 (elt e-t 0) | 1497 (elt e-t 0) |
1379 e-t))) | 1498 e-t))) |
1380 (bibtex-find-text nil) | 1499 (if (interactive-p) |
1381 (forward-char 1) | 1500 (progn |
1501 (bibtex-find-text nil) | |
1502 (if (looking-at "[}\"]") | |
1503 (forward-char 1)))) | |
1382 (insert ",\n") | 1504 (insert ",\n") |
1383 (indent-to-column bibtex-name-alignment) | 1505 (indent-to-column bibtex-name-alignment) |
1384 (insert name " = ") | 1506 (insert name " = ") |
1385 (indent-to-column bibtex-text-alignment) | 1507 (indent-to-column bibtex-text-alignment) |
1386 (insert bibtex-field-left-delimiter bibtex-field-right-delimiter))) | 1508 (insert bibtex-field-left-delimiter bibtex-field-right-delimiter) |
1509 (if (interactive-p) | |
1510 (forward-char -1)))) | |
1387 | 1511 |
1388 (defun bibtex-make-optional-field (e-t) | 1512 (defun bibtex-make-optional-field (e-t) |
1389 "Makes an optional field named E-T in current BibTeX entry." | 1513 "Makes an optional field named E-T in current BibTeX entry." |
1390 (interactive "sOptional BibTeX entry type: ") | |
1391 (if (consp e-t) | 1514 (if (consp e-t) |
1392 (setq e-t (cons (concat "OPT" (car e-t)) (cdr e-t))) | 1515 (setq e-t (cons (concat "OPT" (car e-t)) (cdr e-t))) |
1393 (setq e-t (concat "OPT" e-t))) | 1516 (setq e-t (concat "OPT" e-t))) |
1394 (bibtex-make-field e-t)) | 1517 (bibtex-make-field e-t)) |
1395 | 1518 |
1457 (setq selective-display (not arg)) | 1580 (setq selective-display (not arg)) |
1458 (set-buffer-modified-p modifiedp)))) | 1581 (set-buffer-modified-p modifiedp)))) |
1459 | 1582 |
1460 (defun bibtex-sort-entries () | 1583 (defun bibtex-sort-entries () |
1461 "Sort BibTeX entries alphabetically by key. | 1584 "Sort BibTeX entries alphabetically by key. |
1462 Text before the first BibTeX entry, and following the last is not affected. | 1585 Text outside of BibTeX entries is not affected. If |
1463 If bibtex-sort-ignore-string-entries is true, @string entries will be ignored. | 1586 bibtex-sort-ignore-string-entries is non-nil, @string entries will be |
1464 | 1587 ignored." |
1465 Bugs: | |
1466 1. Text between the closing brace ending one BibTeX entry, and the @ starting | |
1467 the next, is considered part of the PRECEDING entry. Perhaps it should be | |
1468 part of the following entry." | |
1469 (interactive) | 1588 (interactive) |
1470 (save-restriction | 1589 (save-restriction |
1471 (beginning-of-first-bibtex-entry) | 1590 (beginning-of-first-bibtex-entry) |
1472 (narrow-to-region | 1591 (narrow-to-region |
1473 (point) | 1592 (point) |
1474 (save-excursion | 1593 (save-excursion |
1475 (goto-char (point-max)) | 1594 (goto-char (point-max)) |
1476 (bibtex-end-of-entry) | 1595 (bibtex-end-of-entry) |
1477 (point))) | 1596 (point))) |
1597 (if bibtex-sort-ignore-string-entries | |
1598 (if (re-search-forward bibtex-reference nil 'move) | |
1599 (goto-char (match-beginning 0)))) | |
1478 (sort-subr | 1600 (sort-subr |
1479 nil | 1601 nil |
1480 ;; NEXTREC function | 1602 ;; NEXTREC function |
1481 'forward-line | |
1482 ;; ENDREC function | |
1483 (function | 1603 (function |
1484 (lambda () | 1604 (lambda () |
1485 (and | 1605 (if bibtex-sort-ignore-string-entries |
1486 (re-search-forward "}\\s-*\n[\n \t]*@" nil 'move) | 1606 (if (re-search-forward bibtex-reference nil 'move) |
1487 (forward-char -2)))) | 1607 (goto-char (match-beginning 0))) |
1608 (if (re-search-forward bibtex-reference-head nil 'move) | |
1609 (goto-char (match-beginning 0)))))) | |
1610 ;; ENDREC function | |
1611 'bibtex-end-of-entry | |
1488 ;; STARTKEY function | 1612 ;; STARTKEY function |
1489 (if bibtex-sort-ignore-string-entries | |
1490 (function | |
1491 (lambda () | |
1492 (while | |
1493 (and | |
1494 (re-search-forward "^\\s-*\\([@a-zA-Z]*\\)\\s-*{\\s-*") | |
1495 (string-equal | |
1496 "@string" | |
1497 (downcase | |
1498 (buffer-substring-no-properties | |
1499 (match-beginning 1) | |
1500 (match-end 1)))))) | |
1501 nil)) | |
1502 (function | |
1503 (lambda () | |
1504 (re-search-forward "{\\s-*")))) | |
1505 ;; ENDKEY function | |
1506 (function | 1613 (function |
1507 (lambda () | 1614 (lambda () |
1508 (search-forward ",")))))) | 1615 (if bibtex-sort-ignore-string-entries |
1616 (progn | |
1617 (re-search-forward bibtex-reference) | |
1618 (buffer-substring-no-properties | |
1619 (match-beginning bibtex-key-in-reference) | |
1620 (match-end bibtex-key-in-reference))) | |
1621 (re-search-forward bibtex-reference-head) | |
1622 (buffer-substring-no-properties | |
1623 (match-beginning bibtex-key-in-head) | |
1624 (match-end bibtex-key-in-head))))) | |
1625 ;; ENDKEY function | |
1626 nil))) | |
1509 | 1627 |
1510 (defun bibtex-find-entry-location (entry-name &optional ignore-errors) | 1628 (defun bibtex-find-entry-location (entry-name &optional ignore-dups) |
1511 "Looking for place to put the BibTeX entry named ENTRY-NAME. | 1629 "Looking for place to put the BibTeX entry named ENTRY-NAME. |
1512 Searches from beginning of buffer. Buffer is assumed to be in sorted | 1630 Performs a binary search (therefore, buffer is assumed to be in sorted |
1513 order, without duplicates (see \\[bibtex-sort-entries]), if it is not, | 1631 order, without duplicates (see \\[bibtex-validate-buffer]), if it is |
1514 an error will be signalled. However, if optional argument | 1632 not, bibtex-find-entry-location will fail). If entry-name is already |
1515 IGNORE-ERRORS is non-nil, no error messages about duplicate entries or | 1633 used as a reference key, an error is signalled. However, if optional |
1516 sort order violences are signalled, but the error handling is assumed | 1634 variable IGNORE-DUPS is non-nil, no error messages about duplicate |
1517 to be made in the calling function. Nil is returned, if any error | 1635 entries are signalled, but the error handling is assumed to be made in |
1518 occured during search for location of the new entry, and t in all | 1636 the calling function. Nil is returned, if an duplicate entry error |
1519 other cases. If an error occured, point is not moved." | 1637 occured, and t in all other cases." |
1520 (interactive "sBibtex entry key: ") | 1638 (let* ((left |
1521 (let ((noerr t) | 1639 (progn |
1522 (previous nil) | 1640 (beginning-of-first-bibtex-entry) |
1523 (pnt (point)) | 1641 (if bibtex-sort-ignore-string-entries |
1524 point) | 1642 (re-search-forward bibtex-reference nil `move) |
1525 (beginning-of-first-bibtex-entry) | 1643 (bibtex-end-of-entry)) |
1526 (or | 1644 (point))) |
1527 (catch 'done | 1645 (right |
1528 (map-bibtex-entries | 1646 (progn |
1529 (function | 1647 (goto-char (point-max)) |
1530 (lambda (current) | 1648 (if bibtex-sort-ignore-string-entries |
1531 (cond ((string-equal entry-name current) | 1649 (re-search-backward bibtex-reference nil `move) |
1532 (setq noerr nil) | 1650 (bibtex-beginning-of-entry)) |
1533 (bibtex-beginning-of-entry) | 1651 (point))) |
1534 (if ignore-errors | 1652 actual-point |
1535 (throw 'done t) | 1653 actual-key |
1536 (error "Entry duplicates existing!"))) | 1654 (done (>= left right)) |
1537 ((or (null previous) | 1655 new |
1538 (string< previous current)) | 1656 dup) |
1539 (setq previous current | 1657 (while (not done) |
1540 point (point)) | 1658 (setq actual-point (/ (+ left right) 2)) |
1541 (if (string< entry-name current) | 1659 (goto-char actual-point) |
1542 (progn | 1660 (bibtex-beginning-of-entry) |
1543 (bibtex-beginning-of-entry) | 1661 (setq actual-key |
1544 ;; Many schemes append strings to | 1662 (if bibtex-sort-ignore-string-entries |
1545 ;; existing entries to resolve them, | 1663 (progn |
1546 ;; so initial substring matches may | 1664 (re-search-forward bibtex-reference) |
1547 ;; indicate a duplicate entry. | 1665 (buffer-substring-no-properties |
1548 (let ((idx | 1666 (match-beginning bibtex-key-in-reference) |
1549 (string-match | 1667 (match-end bibtex-key-in-reference))) |
1550 (regexp-quote entry-name) current))) | 1668 (re-search-forward bibtex-reference-head) |
1551 (if (and | 1669 (buffer-substring-no-properties |
1552 (integerp idx) | 1670 (match-beginning bibtex-key-in-head) |
1553 (zerop idx) | 1671 (match-end bibtex-key-in-head)))) |
1554 ;; (not ignore-errors) | 1672 (cond |
1555 (not (equal entry-name ""))) | 1673 ((string-lessp entry-name actual-key) |
1556 (progn | 1674 (setq new (match-beginning 0)) |
1557 (message | 1675 (if (equal right new) |
1558 "Warning: Entry %s may be a duplicate of %s!" | 1676 (setq done t) |
1559 entry-name current) | 1677 (setq right new))) |
1560 (ding t)))) | 1678 ((string-lessp actual-key entry-name) |
1561 (throw 'done t)))) | 1679 (setq new (match-end 0)) |
1562 ((string-equal previous current) | 1680 (if (equal left new) |
1563 (setq noerr nil) | 1681 (setq done t) |
1564 (if ignore-errors | 1682 (setq left new))) |
1565 (throw 'done t) | 1683 ((string-equal actual-key entry-name) |
1566 (error "Duplicate here with previous!"))) | 1684 (setq dup t |
1567 (t | 1685 done t) |
1568 (setq noerr nil) | 1686 (if (not ignore-dups) |
1569 (if ignore-errors | 1687 (error "Entry with key `%s' already exists!" entry-name))))) |
1570 (throw 'done t) | 1688 (if dup |
1571 (error "Entries out of order here!")))))))) | 1689 nil |
1572 (goto-char (point-max))) | 1690 (goto-char right) |
1573 (if (not noerr) | 1691 (if (re-search-forward bibtex-reference nil t) |
1574 (goto-char pnt)) | 1692 (progn |
1575 noerr)) | 1693 (setq actual-key |
1694 (buffer-substring-no-properties | |
1695 (match-beginning bibtex-key-in-reference) | |
1696 (match-end bibtex-key-in-reference))) | |
1697 (if (string-lessp actual-key entry-name) | |
1698 ;; even greater than last entry --> we must append | |
1699 (progn | |
1700 (goto-char (match-end 0)) | |
1701 (newline (forward-line 2)) | |
1702 (beginning-of-line)) | |
1703 (goto-char right)))) | |
1704 t))) | |
1576 | 1705 |
1577 (defun bibtex-validate-buffer () | 1706 (defun bibtex-validate-buffer () |
1578 "Validate if the current BibTeX buffer is syntactically correct. | 1707 "Validate if the current BibTeX buffer is syntactically correct. |
1579 Any garbage (e.g. comments) before the first \"@\" is not tested (so | 1708 Any garbage (e.g. comments) before the first \"@\" is not tested (so |
1580 you can put comments here)." | 1709 you can put comments here)." |
1581 (interactive) | 1710 (interactive) |
1582 (let ((pnt (point)) | 1711 (let ((pnt (point)) |
1583 (max (point-max))) | 1712 (max (point-max))) |
1713 ;; looking if entries fit syntactical structure | |
1584 (goto-char (point-min)) | 1714 (goto-char (point-min)) |
1585 (while (< (re-search-forward "@\\|\\'") max) | 1715 (while (< (re-search-forward "@\\|\\'") max) |
1586 (forward-char -1) | 1716 (forward-char -1) |
1587 (let ((p (point))) | 1717 (let ((p (point))) |
1588 (if (looking-at "@string") | 1718 (if (or |
1719 (looking-at "@string") | |
1720 (looking-at "@preamble")) | |
1589 (forward-char) | 1721 (forward-char) |
1590 (if (not (and | 1722 (if (not (and |
1591 (re-search-forward bibtex-reference nil t) | 1723 (re-search-forward bibtex-reference nil t) |
1592 (equal p (match-beginning 0)))) | 1724 (equal p (match-beginning 0)))) |
1593 (progn | 1725 (progn |
1594 (goto-char p) | 1726 (goto-char p) |
1595 (error "Bad entry begins here")))))) | 1727 (error "Bad entry begins here")))))) |
1596 (bibtex-find-entry-location (make-string 10 255)) | 1728 ;; looking if entries are balanced (a single non-escaped quote |
1597 ;; find duplicates | 1729 ;; inside braces is not detected by the former check, but |
1730 ;; bibtex-sort-entries stumbles about it | |
1731 (goto-char (point-min)) | |
1732 (map-bibtex-entries | |
1733 (function | |
1734 (lambda (current) | |
1735 (bibtex-beginning-of-entry) | |
1736 (forward-sexp 2)))) | |
1737 ;; looking for correct sort order and duplicates | |
1738 (if bibtex-maintain-sorted-entries | |
1739 (let ((entry-name (make-string 10 255)) | |
1740 (previous nil) | |
1741 point) | |
1742 (beginning-of-first-bibtex-entry) | |
1743 (map-bibtex-entries | |
1744 (function | |
1745 (lambda (current) | |
1746 (cond ((or (null previous) | |
1747 (string< previous current)) | |
1748 (setq previous current | |
1749 point (point))) | |
1750 ((string-equal previous current) | |
1751 (error "Duplicate here with previous!")) | |
1752 (t | |
1753 (error "Entries out of order here!")))))))) | |
1598 (goto-char pnt) | 1754 (goto-char pnt) |
1599 (message "BibTeX buffer is syntactically correct"))) | 1755 (message "BibTeX buffer is syntactically correct"))) |
1600 | 1756 |
1601 (defun bibtex-next-field (arg) | 1757 (defun bibtex-next-field (arg) |
1602 "Finds end of text of next BibTeX field; with arg, to its beginning." | 1758 "Finds end of text of next BibTeX field; with arg, to its beginning." |
1718 (cond ((or (eq last-command 'bibtex-pop-previous) | 1874 (cond ((or (eq last-command 'bibtex-pop-previous) |
1719 (eq last-command 'bibtex-pop-next)) | 1875 (eq last-command 'bibtex-pop-next)) |
1720 t | 1876 t |
1721 ) | 1877 ) |
1722 (t | 1878 (t |
1723 (bibtex-enclosing-reference) | 1879 (bibtex-enclosing-reference-maybe-empty-head) |
1724 (setq bibtex-pop-previous-search-point (point)) | 1880 (setq bibtex-pop-previous-search-point (point)) |
1725 (setq bibtex-pop-next-search-point (match-end 0)))) | 1881 (setq bibtex-pop-next-search-point (match-end 0)))) |
1726 (goto-char bibtex-pop-previous-search-point) | 1882 (goto-char bibtex-pop-previous-search-point) |
1727 ; Now search for arg'th previous similar field | 1883 ; Now search for arg'th previous similar field |
1728 (cond | 1884 (cond |
1795 (cond ((or (eq last-command 'bibtex-pop-next) | 1951 (cond ((or (eq last-command 'bibtex-pop-next) |
1796 (eq last-command 'bibtex-pop-previous)) | 1952 (eq last-command 'bibtex-pop-previous)) |
1797 t | 1953 t |
1798 ) | 1954 ) |
1799 (t | 1955 (t |
1800 (bibtex-enclosing-reference) | 1956 (bibtex-enclosing-reference-maybe-empty-head) |
1801 (setq bibtex-pop-previous-search-point (point)) | 1957 (setq bibtex-pop-previous-search-point (point)) |
1802 (setq bibtex-pop-next-search-point (match-end 0)))) | 1958 (setq bibtex-pop-next-search-point (match-end 0)))) |
1803 (goto-char bibtex-pop-next-search-point) | 1959 (goto-char bibtex-pop-next-search-point) |
1804 | 1960 |
1805 ; Now search for arg'th next similar field | 1961 ; Now search for arg'th next similar field |
1869 (if (not (looking-at | 2025 (if (not (looking-at |
1870 (concat | 2026 (concat |
1871 bibtex-field-left-delimiter | 2027 bibtex-field-left-delimiter |
1872 bibtex-field-right-delimiter))) | 2028 bibtex-field-right-delimiter))) |
1873 (setq crossref-there t)))))) | 2029 (setq crossref-there t)))))) |
1874 (bibtex-enclosing-reference) | 2030 (bibtex-enclosing-reference-maybe-empty-head) |
1875 (re-search-forward bibtex-reference-type) | 2031 (re-search-forward bibtex-reference-type) |
1876 (let ((begin-type (1+ (match-beginning 0))) | 2032 (let ((begin-type (1+ (match-beginning 0))) |
1877 (end-type (match-end 0))) | 2033 (end-type (match-end 0))) |
1878 (goto-char start) | 2034 (goto-char start) |
1879 (while (re-search-forward bibtex-field (point-max) t 1) | 2035 (while (re-search-forward bibtex-field (point-max) t 1) |
1963 (buffer-substring-no-properties | 2119 (buffer-substring-no-properties |
1964 begin-name end-name)))) | 2120 begin-name end-name)))) |
1965 (t | 2121 (t |
1966 (goto-char end-field))))))))) | 2122 (goto-char end-field))))))))) |
1967 (goto-char start) | 2123 (goto-char start) |
1968 (bibtex-end-of-entry) | 2124 (bibtex-end-of-entry)) |
1969 ;; sct@dcs.edinburgh.ac.uk | |
1970 (save-excursion | |
1971 (forward-line -1) | |
1972 (end-of-line) | |
1973 (if (eq (preceding-char) ?,) | |
1974 (backward-delete-char 1)))) | |
1975 (let* ((eob (progn | 2125 (let* ((eob (progn |
1976 (bibtex-end-of-entry) | 2126 (bibtex-end-of-entry) |
1977 (point))) | 2127 (point))) |
1978 (key (progn | 2128 (key (progn |
1979 (bibtex-beginning-of-entry) | 2129 (bibtex-beginning-of-entry) |
1980 (if (search-forward-regexp | 2130 (if (re-search-forward |
1981 bibtex-reference-head eob t) | 2131 bibtex-reference-head eob t) |
1982 (buffer-substring-no-properties | 2132 (buffer-substring-no-properties |
1983 (match-beginning bibtex-key-in-head) | 2133 (match-beginning bibtex-key-in-head) |
1984 (match-end bibtex-key-in-head)))))) | 2134 (match-end bibtex-key-in-head)))))) |
1985 (if (or | 2135 (if (or |
1990 (if bibtex-autokey-edit-before-use | 2140 (if bibtex-autokey-edit-before-use |
1991 (read-from-minibuffer "Key to use: " | 2141 (read-from-minibuffer "Key to use: " |
1992 (bibtex-generate-autokey)) | 2142 (bibtex-generate-autokey)) |
1993 (bibtex-generate-autokey)))) | 2143 (bibtex-generate-autokey)))) |
1994 (bibtex-beginning-of-entry) | 2144 (bibtex-beginning-of-entry) |
1995 (search-forward-regexp "^@[A-Za-z]+[ \t]*[({]\\([^,]*\\)") | 2145 (re-search-forward bibtex-reference-maybe-empty-head) |
1996 (delete-region (match-beginning 1) | 2146 (if (match-beginning bibtex-key-in-head) |
1997 (match-end 1)) | 2147 (delete-region (match-beginning bibtex-key-in-head) |
2148 (match-end bibtex-key-in-head))) | |
1998 (insert autokey) | 2149 (insert autokey) |
1999 (let ((start (progn | 2150 (let ((start (progn |
2000 (bibtex-beginning-of-entry) | 2151 (bibtex-beginning-of-entry) |
2001 (point))) | 2152 (point))) |
2002 (end (progn | 2153 (end (progn |
2003 (bibtex-end-of-entry) | 2154 (bibtex-end-of-entry) |
2004 (search-forward-regexp "^@" nil 'move) | 2155 (re-search-forward "^@" nil 'move) |
2005 (beginning-of-line) | 2156 (beginning-of-line) |
2006 (point))) | 2157 (point))) |
2007 last-command) | 2158 last-command) |
2008 (kill-region start end) | 2159 (kill-region start end) |
2009 (let ((success (bibtex-find-entry-location autokey t))) | 2160 (let ((success |
2161 (or | |
2162 (not bibtex-maintain-sorted-entries) | |
2163 (bibtex-find-entry-location autokey t)))) | |
2010 (yank) | 2164 (yank) |
2011 (setq kill-ring (cdr kill-ring)) | 2165 (setq kill-ring (cdr kill-ring)) |
2012 (if success | 2166 (forward-char -1) |
2013 (bibtex-beginning-of-entry) | 2167 (bibtex-beginning-of-entry) |
2014 (goto-char start)) | 2168 (re-search-forward bibtex-reference-head) |
2015 (search-forward-regexp bibtex-reference-head) | |
2016 (if (not success) | 2169 (if (not success) |
2017 (error | 2170 (error |
2018 "BibTeX buffer was or has become invalid (call `bibtex-validate-buffer')"))))))))) | 2171 "New inserted reference may be a duplicate.")))))))) |
2172 (save-excursion | |
2173 (let ((start (progn (bibtex-beginning-of-entry) (point))) | |
2174 (end (progn (bibtex-end-of-entry) (point)))) | |
2175 (save-restriction | |
2176 (narrow-to-region start end) | |
2177 (bibtex-parse-keys t))))) | |
2019 | 2178 |
2020 (defun bibtex-complete-string () | 2179 (defun bibtex-complete-string () |
2021 "Complete word fragment before point to longest prefix of a defined string. | 2180 "Complete word fragment before point to longest prefix of a defined string. |
2022 If point is not after the part of a word, all strings are listed." | 2181 If point is not after the part of a word, all strings are listed." |
2023 (interactive "*") | 2182 (interactive "*") |
2030 (string-list (copy-sequence bibtex-completion-candidates)) | 2189 (string-list (copy-sequence bibtex-completion-candidates)) |
2031 (case-fold-search t) | 2190 (case-fold-search t) |
2032 (completion (save-excursion | 2191 (completion (save-excursion |
2033 (progn | 2192 (progn |
2034 (while (re-search-backward | 2193 (while (re-search-backward |
2035 "@string[ \t\n]*{" (point-min) t) | 2194 bibtex-string (point-min) t) |
2036 (goto-char (match-end 0)) | 2195 (setq string-list |
2037 (let ((pnt (point)) | 2196 (cons |
2038 (strt (match-beginning 0))) | 2197 (list |
2039 (re-search-forward "[ \t\n]*=" | 2198 (buffer-substring-no-properties |
2040 (point-max) t) | 2199 (match-beginning bibtex-key-in-string) |
2041 (goto-char (match-beginning 0)) | 2200 (match-end bibtex-key-in-string))) |
2042 (setq string-list | 2201 string-list))) |
2043 (cons | |
2044 (list | |
2045 (buffer-substring-no-properties | |
2046 pnt (point))) | |
2047 string-list)) | |
2048 (goto-char strt))) | |
2049 (setq string-list | 2202 (setq string-list |
2050 (sort string-list | 2203 (sort string-list |
2051 (lambda(x y) | 2204 (lambda(x y) |
2052 (string-lessp | 2205 (string-lessp |
2053 (car x) | 2206 (car x) |