1 ;;; bibtex.el --- BibTeX mode for GNU Emacs
3 ;; Copyright (C) 1992, 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
5 ;; Author: Stefan Schoef <schoef@offis.uni-oldenburg.de>
6 ;; Bengt Martensson <bengt@mathematik.uni-Bremen.de>
7 ;; Mark Shapiro <shapiro@corto.inria.fr>
8 ;; Mike Newton <newton@gumby.cs.caltech.edu>
9 ;; Aaron Larson <alarson@src.honeywell.com>
10 ;; Maintainer: Dirk Herrmann <D.Herrmann@tu-bs.de>
11 ;; Keywords: BibTeX, LaTeX, TeX
13 ;; This file is part of GNU Emacs.
15 ;; GNU Emacs is free software; you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation; either version 2, or (at your option)
20 ;; GNU Emacs is distributed in the hope that it will be useful,
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 ;; GNU General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs; see the file COPYING. If not, write to the
27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
28 ;; Boston, MA 02111-1307, USA.
32 ;; Major mode for editing and validating BibTeX files.
35 ;; See documentation for function bibtex-mode (or type "\M-x describe-mode"
36 ;; when you are in BibTeX mode).
39 ;; Distribute texinfo file.
53 (defgroup bibtex-autokey nil
54 "Generates automatically a key from the author/editor and the title field"
56 :prefix
"bibtex-autokey-")
58 (defcustom bibtex-mode-hook nil
59 "List of functions to call on entry to BibTeX mode."
63 (defcustom bibtex-field-delimiters
'braces
64 "*Controls type of field delimiters used.
65 Set this to `braces' or `double-quotes' according to your personal
66 preferences. This variable is buffer-local."
68 :type
'(choice (const braces
)
69 (const double-quotes
)))
70 (make-variable-buffer-local 'bibtex-field-delimiters
)
72 (defcustom bibtex-entry-delimiters
'braces
73 "*Controls type of entry delimiters used.
74 Set this to `braces' or `parentheses' according to your personal
75 preferences. This variable is buffer-local."
77 :type
'(choice (const braces
)
79 (make-variable-buffer-local 'bibtex-entry-delimiters
)
81 (defcustom bibtex-include-OPTcrossref
'("InProceedings" "InCollection")
82 "*All entries listed here will have an OPTcrossref field."
84 :type
'(repeat string
))
86 (defcustom bibtex-include-OPTkey t
87 "*If non-nil, all entries will have an OPTkey field.
88 If this is a string, it will be used as the initial field text.
89 If this is a function, it will be called to generate the initial field text."
91 :type
'(choice (const :tag
"None" nil
)
92 (string :tag
"Initial text")
93 (function :tag
"Initialize Function" :value fun
)
94 (other :tag
"Default" t
)))
96 (defcustom bibtex-user-optional-fields
97 '(("annote" "Personal annotation (ignored)"))
98 "*List of optional fields the user wants to have always present.
99 Entries should be of the same form as the OPTIONAL and
100 CROSSREF-OPTIONAL lists in `bibtex-entry-field-alist' (see documentation
101 of this variable for details)."
104 (group (string :tag
"Field")
105 (string :tag
"Comment")
106 (option (group :inline t
108 (choice :tag
"Init" :value
""
112 (defcustom bibtex-entry-format
'(opts-or-alts numerical-fields
)
113 "*Controls type of formatting performed by `bibtex-clean-entry'.
114 It may be t, nil, or a list of symbols out of the following:
115 opts-or-alts Delete empty optional and alternative fields and
116 remove OPT and ALT prefixes from used fields.
117 numerical-fields Delete delimiters around numeral fields.
118 page-dashes Change double dashes in page field to single dash
119 (for scribe compatibility).
120 inherit-booktitle If entry contains a crossref field and booktitle
121 field is empty, it is set to the contents of the
122 title field of the crossreferenced entry.
123 Caution: this will work only if buffer is
125 realign Realign entries, so that field texts and perhaps equal
126 signs (depending on the value of
127 `bibtex-align-at-equal-sign') begin in the same column.
128 last-comma Add or delete comma on end of last field in entry,
129 according to value of `bibtex-comma-after-last-field'.
130 delimiters Change delimiters according to variables
131 `bibtex-field-delimiters' and `bibtex-entry-delimiters'.
132 unify-case Change case of entry and field names.
134 The value t means do all of the above formatting actions.
135 The value nil means do no formatting at all."
137 :type
'(choice (const :tag
"None" nil
)
139 (set :menu-tag
"Some"
141 (const numerical-fields
)
143 (const inherit-booktitle
)
147 (const unify-case
))))
149 (defcustom bibtex-clean-entry-hook nil
150 "*List of functions to call when entry has been cleaned.
151 Functions are called with point inside the cleaned entry, and the buffer
152 narrowed to just the entry."
156 (defcustom bibtex-sort-ignore-string-entries t
157 "*If non-nil, BibTeX @String entries are not sort-significant.
158 That means they are ignored when determining ordering of the buffer
159 (e.g., sorting, locating alphabetical position for new entries, etc.).
160 This variable is buffer-local."
163 (make-variable-buffer-local 'bibtex-sort-ignore-string-entries
)
165 (defcustom bibtex-maintain-sorted-entries nil
166 "*If non-nil, BibTeX mode maintains all BibTeX entries in sorted order.
167 Setting this variable to nil will strip off some comfort (e.g., TAB
168 completion for reference keys in minibuffer, automatic detection of
169 duplicates) from BibTeX mode. See also `bibtex-sort-ignore-string-entries'.
170 This variable is buffer-local."
173 (make-variable-buffer-local 'bibtex-maintain-sorted-entries
)
175 (defcustom bibtex-field-kill-ring-max
20
176 "*Max length of `bibtex-field-kill-ring' before discarding oldest elements."
180 (defcustom bibtex-entry-kill-ring-max
20
181 "*Max length of `bibtex-entry-kill-ring' before discarding oldest elements."
185 (defcustom bibtex-parse-keys-timeout
60
186 "*Specifies interval for parsing buffers.
187 All BibTeX buffers in Emacs are parsed if Emacs has been idle
188 `bibtex-parse-keys-timeout' seconds. Only buffers which were modified
189 after last parsing and which are maintained in sorted order are parsed."
193 (defvar bibtex-entry-field-alist
195 ("Article" .
(((("author" "Author1 [and Author2 ...] [and others]")
196 ("title" "Title of the article (BibTeX converts it to lowercase)")
197 ("journal" "Name of the journal (use string, remove braces)")
198 ("year" "Year of publication"))
199 (("volume" "Volume of the journal")
200 ("number" "Number of the journal (only allowed if entry contains volume)")
201 ("pages" "Pages in the journal")
202 ("month" "Month of the publication as a string (remove braces)")
203 ("note" "Remarks to be put at the end of the \\bibitem")))
204 ((("author" "Author1 [and Author2 ...] [and others]")
205 ("title" "Title of the article (BibTeX converts it to lowercase)"))
206 (("pages" "Pages in the journal")
207 ("journal" "Name of the journal (use string, remove braces)")
208 ("year" "Year of publication")
209 ("volume" "Volume of the journal")
210 ("number" "Number of the journal")
211 ("month" "Month of the publication as a string (remove braces)")
212 ("note" "Remarks to be put at the end of the \\bibitem")))))
213 ("Book" .
(((("author" "Author1 [and Author2 ...] [and others]" "" t
)
214 ("editor" "Editor1 [and Editor2 ...] [and others]" "" t
)
215 ("title" "Title of the book")
216 ("publisher" "Publishing company")
217 ("year" "Year of publication"))
218 (("volume" "Volume of the book in the series")
219 ("number" "Number of the book in a small series (overwritten by volume)")
220 ("series" "Series in which the book appeared")
221 ("address" "Address of the publisher")
222 ("edition" "Edition of the book as a capitalized English word")
223 ("month" "Month of the publication as a string (remove braces)")
224 ("note" "Remarks to be put at the end of the \\bibitem")))
225 ((("author" "Author1 [and Author2 ...] [and others]" "" t
)
226 ("editor" "Editor1 [and Editor2 ...] [and others]" "" t
)
227 ("title" "Title of the book"))
228 (("publisher" "Publishing company")
229 ("year" "Year of publication")
230 ("volume" "Volume of the book in the series")
231 ("number" "Number of the book in a small series (overwritten by volume)")
232 ("series" "Series in which the book appeared")
233 ("address" "Address of the publisher")
234 ("edition" "Edition of the book as a capitalized English word")
235 ("month" "Month of the publication as a string (remove braces)")
236 ("note" "Remarks to be put at the end of the \\bibitem")))))
237 ("Booklet" .
(((("title" "Title of the booklet (BibTeX converts it to lowercase)"))
238 (("author" "Author1 [and Author2 ...] [and others]")
239 ("howpublished" "The way in which the booklet was published")
240 ("address" "Address of the publisher")
241 ("month" "Month of the publication as a string (remove braces)")
242 ("year" "Year of publication")
243 ("note" "Remarks to be put at the end of the \\bibitem")))))
244 ("InBook" .
(((("author" "Author1 [and Author2 ...] [and others]" "" t
)
245 ("editor" "Editor1 [and Editor2 ...] [and others]" "" t
)
246 ("title" "Title of the book")
247 ("chapter" "Chapter in the book")
248 ("publisher" "Publishing company")
249 ("year" "Year of publication"))
250 (("volume" "Volume of the book in the series")
251 ("number" "Number of the book in a small series (overwritten by volume)")
252 ("series" "Series in which the book appeared")
253 ("type" "Word to use instead of \"chapter\"")
254 ("address" "Address of the publisher")
255 ("edition" "Edition of the book as a capitalized English word")
256 ("month" "Month of the publication as a string (remove braces)")
257 ("pages" "Pages in the book")
258 ("note" "Remarks to be put at the end of the \\bibitem")))
259 ((("author" "Author1 [and Author2 ...] [and others]" "" t
)
260 ("editor" "Editor1 [and Editor2 ...] [and others]" "" t
)
261 ("title" "Title of the book")
262 ("chapter" "Chapter in the book"))
263 (("pages" "Pages in the book")
264 ("publisher" "Publishing company")
265 ("year" "Year of publication")
266 ("volume" "Volume of the book in the series")
267 ("number" "Number of the book in a small series (overwritten by volume)")
268 ("series" "Series in which the book appeared")
269 ("type" "Word to use instead of \"chapter\"")
270 ("address" "Address of the publisher")
271 ("edition" "Edition of the book as a capitalized English word")
272 ("month" "Month of the publication as a string (remove braces)")
273 ("note" "Remarks to be put at the end of the \\bibitem")))))
274 ("InCollection" .
(((("author" "Author1 [and Author2 ...] [and others]")
275 ("title" "Title of the article in book (BibTeX converts it to lowercase)")
276 ("booktitle" "Name of the book")
277 ("publisher" "Publishing company")
278 ("year" "Year of publication"))
279 (("editor" "Editor1 [and Editor2 ...] [and others]")
280 ("volume" "Volume of the book in the series")
281 ("number" "Number of the book in a small series (overwritten by volume)")
282 ("series" "Series in which the book appeared")
283 ("type" "Word to use instead of \"chapter\"")
284 ("chapter" "Chapter in the book")
285 ("pages" "Pages in the book")
286 ("address" "Address of the publisher")
287 ("edition" "Edition of the book as a capitalized English word")
288 ("month" "Month of the publication as a string (remove braces)")
289 ("note" "Remarks to be put at the end of the \\bibitem")))
290 ((("author" "Author1 [and Author2 ...] [and others]")
291 ("title" "Title of the article in book (BibTeX converts it to lowercase)")
292 ("booktitle" "Name of the book"))
293 (("pages" "Pages in the book")
294 ("publisher" "Publishing company")
295 ("year" "Year of publication")
296 ("editor" "Editor1 [and Editor2 ...] [and others]")
297 ("volume" "Volume of the book in the series")
298 ("number" "Number of the book in a small series (overwritten by volume)")
299 ("series" "Series in which the book appeared")
300 ("type" "Word to use instead of \"chapter\"")
301 ("chapter" "Chapter in the book")
302 ("address" "Address of the publisher")
303 ("edition" "Edition of the book as a capitalized English word")
304 ("month" "Month of the publication as a string (remove braces)")
305 ("note" "Remarks to be put at the end of the \\bibitem")))))
306 ("InProceedings" .
(((("author" "Author1 [and Author2 ...] [and others]")
307 ("title" "Title of the article in proceedings (BibTeX converts it to lowercase)")
308 ("booktitle" "Name of the conference proceedings")
309 ("year" "Year of publication"))
310 (("editor" "Editor1 [and Editor2 ...] [and others]")
311 ("volume" "Volume of the conference proceedings in the series")
312 ("number" "Number of the conference proceedings in a small series (overwritten by volume)")
313 ("series" "Series in which the conference proceedings appeared")
314 ("pages" "Pages in the conference proceedings")
315 ("address" "Location of the Proceedings")
316 ("month" "Month of the publication as a string (remove braces)")
317 ("organization" "Sponsoring organization of the conference")
318 ("publisher" "Publishing company, its location")
319 ("note" "Remarks to be put at the end of the \\bibitem")))
320 ((("author" "Author1 [and Author2 ...] [and others]")
321 ("title" "Title of the article in proceedings (BibTeX converts it to lowercase)")
322 ("booktitle" "Name of the conference proceedings"))
323 (("pages" "Pages in the conference proceedings")
324 ("year" "Year of publication")
325 ("editor" "Editor1 [and Editor2 ...] [and others]")
326 ("volume" "Volume of the conference proceedings in the series")
327 ("number" "Number of the conference proceedings in a small series (overwritten by volume)")
328 ("series" "Series in which the conference proceedings appeared")
329 ("address" "Location of the Proceedings")
330 ("month" "Month of the publication as a string (remove braces)")
331 ("organization" "Sponsoring organization of the conference")
332 ("publisher" "Publishing company, its location")
333 ("note" "Remarks to be put at the end of the \\bibitem")))))
334 ("Manual" .
(((("title" "Title of the manual"))
335 (("author" "Author1 [and Author2 ...] [and others]")
336 ("organization" "Publishing organization of the manual")
337 ("address" "Address of the organization")
338 ("edition" "Edition of the manual as a capitalized English word")
339 ("month" "Month of the publication as a string (remove braces)")
340 ("year" "Year of publication")
341 ("note" "Remarks to be put at the end of the \\bibitem")))))
342 ("MastersThesis" .
(((("author" "Author1 [and Author2 ...] [and others]")
343 ("title" "Title of the master\'s thesis (BibTeX converts it to lowercase)")
344 ("school" "School where the master\'s thesis was written")
345 ("year" "Year of publication"))
346 (("type" "Type of the master\'s thesis (if other than \"Master\'s thesis\")")
347 ("address" "Address of the school (if not part of field \"school\") or country")
348 ("month" "Month of the publication as a string (remove braces)")
349 ("note" "Remarks to be put at the end of the \\bibitem")))))
351 (("author" "Author1 [and Author2 ...] [and others]")
352 ("title" "Title of the reference (BibTeX converts it to lowercase)")
353 ("howpublished" "The way in which the reference was published")
354 ("month" "Month of the publication as a string (remove braces)")
355 ("year" "Year of publication")
356 ("note" "Remarks to be put at the end of the \\bibitem")))))
357 ("PhdThesis" .
(((("author" "Author1 [and Author2 ...] [and others]")
358 ("title" "Title of the PhD. thesis")
359 ("school" "School where the PhD. thesis was written")
360 ("year" "Year of publication"))
361 (("type" "Type of the PhD. thesis")
362 ("address" "Address of the school (if not part of field \"school\") or country")
363 ("month" "Month of the publication as a string (remove braces)")
364 ("note" "Remarks to be put at the end of the \\bibitem")))))
365 ("Proceedings" .
(((("title" "Title of the conference proceedings")
366 ("year" "Year of publication"))
367 (("editor" "Editor1 [and Editor2 ...] [and others]")
368 ("volume" "Volume of the conference proceedings in the series")
369 ("number" "Number of the conference proceedings in a small series (overwritten by volume)")
370 ("series" "Series in which the conference proceedings appeared")
371 ("address" "Location of the Proceedings")
372 ("month" "Month of the publication as a string (remove braces)")
373 ("organization" "Sponsoring organization of the conference")
374 ("publisher" "Publishing company, its location")
375 ("note" "Remarks to be put at the end of the \\bibitem")))))
376 ("TechReport" .
(((("author" "Author1 [and Author2 ...] [and others]")
377 ("title" "Title of the technical report (BibTeX converts it to lowercase)")
378 ("institution" "Sponsoring institution of the report")
379 ("year" "Year of publication"))
380 (("type" "Type of the report (if other than \"technical report\")")
381 ("number" "Number of the technical report")
382 ("address" "Address of the institution (if not part of field \"institution\") or country")
383 ("month" "Month of the publication as a string (remove braces)")
384 ("note" "Remarks to be put at the end of the \\bibitem")))))
385 ("Unpublished" .
(((("author" "Author1 [and Author2 ...] [and others]")
386 ("title" "Title of the unpublished reference (BibTeX converts it to lowercase)")
387 ("note" "Remarks to be put at the end of the \\bibitem"))
388 (("month" "Month of the publication as a string (remove braces)")
389 ("year" "Year of publication")))))
392 "Defines reference types and their associated fields.
394 (ENTRY-NAME (REQUIRED OPTIONAL) (CROSSREF-REQUIRED CROSSREF-OPTIONAL))
396 If the third element is nil, the first pair is always used.
397 If not, the second pair is used in the case of presence of a crossref
398 field and the third in the case of absence.
399 REQUIRED, OPTIONAL, CROSSREF-REQUIRED and CROSSREF-OPTIONAL are lists.
400 Each element of these lists is a list of the form
401 (FIELD-NAME COMMENT-STRING INIT ALTERNATIVE-FLAG).
402 COMMENT-STRING, INIT, and ALTERNATIVE-FLAG are optional.
403 FIELD-NAME is the name of the field, COMMENT-STRING the comment to
404 appear in the echo area, INIT is either the initial content of the
405 field or a function, which is called to determine the initial content
406 of the field, and ALTERNATIVE-FLAG (either nil or t) marks if the
407 field is an alternative. ALTERNATIVE-FLAG may be t only in the
408 REQUIRED or CROSSREF-REQUIRED lists.")
410 (defvar bibtex-comment-start
"@Comment ")
412 (defcustom bibtex-add-entry-hook nil
413 "List of functions to call when entry has been inserted."
417 (defcustom bibtex-predefined-month-strings
419 ("jan") ("feb") ("mar") ("apr") ("may") ("jun")
420 ("jul") ("aug") ("sep") ("oct") ("nov") ("dec")
422 "Alist of month string definitions.
423 Should contain all strings used for months in the BibTeX style files.
424 Each element is a list with just one element: the string."
429 (defcustom bibtex-predefined-strings
431 bibtex-predefined-month-strings
433 ("acmcs") ("acta") ("cacm") ("ibmjrd") ("ibmsj") ("ieeese")
434 ("ieeetc") ("ieeetcad") ("ipl") ("jacm") ("jcss") ("scp")
435 ("sicomp") ("tcs") ("tocs") ("tods") ("tog") ("toms") ("toois")
438 "Alist of string definitions.
439 Should contain the strings defined in the BibTeX style files. Each
440 element is a list with just one element: the string."
445 (defcustom bibtex-string-files nil
446 "*List of BibTeX files containing string definitions.
447 Those files must be specified using pathnames relative to the
448 directories specified in `bibtex-string-file-path'. This variable is only
449 evaluated when BibTeX mode is entered (i.e., when loading the BibTeX
452 :type
'(repeat file
))
454 (defvar bibtex-string-file-path
(getenv "BIBINPUTS")
455 "*Colon separated list of pathes to search for `bibtex-string-files'.")
457 (defcustom bibtex-help-message t
458 "*If not nil print help messages in the echo area on entering a new field."
462 (defcustom bibtex-autokey-prefix-string
""
463 "*String to use as a prefix for all generated keys.
464 See the documentation of function `bibtex-generate-autokey' for more detail."
465 :group
'bibtex-autokey
468 (defcustom bibtex-autokey-names
1
469 "*Number of names to use for the automatically generated reference key.
470 If this is variable is nil, all names are used.
471 Possibly more names are used according to `bibtex-autokey-names-stretch'.
472 See the documentation of function `bibtex-generate-autokey' for more detail."
473 :group
'bibtex-autokey
474 :type
'(choice (const :tag
"All" infty
)
477 (defcustom bibtex-autokey-names-stretch
0
478 "*Number of names that can additionally be used.
479 These names are used only, if all names are used then.
480 See the documentation of function `bibtex-generate-autokey' for details."
481 :group
'bibtex-autokey
484 (defcustom bibtex-autokey-additional-names
""
485 "*String to prepend to the generated key if not all names could be used.
486 See the documentation of function `bibtex-generate-autokey' for details."
487 :group
'bibtex-autokey
490 (defvar bibtex-autokey-transcriptions
492 ;; language specific characters
495 ("\\\"a\\|\\\\\\\"a\\|\\\\ae" "ae")
496 ("\\\"A\\|\\\\\\\"A\\|\\\\AE" "Ae")
501 ("\\\"o\\|\\\\\\\"o\\|\\\\o\\|\\\\oe" "oe")
502 ("\\\"O\\|\\\\\\\"O\\|\\\\O\\|\\\\OE" "Oe")
503 ("\\\"s\\|\\\\\\\"s" "ss")
504 ("\\\"u\\|\\\\\\\"u" "ue")
505 ("\\\"U\\|\\\\\\\"U" "Ue")
507 ("\\\\`\\|\\\\'\\|\\\\\\^\\|\\\\~\\|\\\\=\\|\\\\\\.\\|\\\\u\\|\\\\v\\|\\\\H\\|\\\\t\\|\\\\c\\|\\\\d\\|\\\\b" "")
510 "Alist of (old-regexp new-string) pairs.
511 Used by the default values of `bibtex-autokey-name-change-strings' and
512 `bibtex-autokey-titleword-change-strings'. Defaults to translating some
513 language specific characters to their ASCII transcriptions, and
514 removing any character accents.")
516 (defcustom bibtex-autokey-name-change-strings
517 bibtex-autokey-transcriptions
518 "Alist of (OLD-REGEXP NEW-STRING) pairs.
519 Any part of name matching a OLD-REGEXP is replaced by NEW-STRING.
520 Case is significant in OLD-REGEXP. All regexps are tried in the
521 order in which they appear in the list, so be sure to avoid inifinite
523 See the documentation of function `bibtex-generate-autokey' for details."
524 :group
'bibtex-autokey
526 (list (regexp :tag
"Old")
527 (string :tag
"New"))))
529 (defcustom bibtex-autokey-name-case-convert
'downcase
530 "*Function called for each name to perform case conversion.
531 See the documentation of function `bibtex-generate-autokey' for more detail."
532 :group
'bibtex-autokey
533 :type
'(choice (const :tag
"Preserve case" identity
)
534 (const :tag
"Downcase" downcase
)
535 (const :tag
"Capitalize" capitalize
)
536 (const :tag
"Upcase" upcase
)
537 (function :tag
"Conversion function")))
539 (defcustom bibtex-autokey-name-length
'infty
540 "*Number of characters from name to incorporate into key.
541 If this is set to anything but a number, all characters are used.
542 See the documentation of function `bibtex-generate-autokey' for details."
543 :group
'bibtex-autokey
544 :type
'(choice (const :tag
"All" infty
)
547 (defcustom bibtex-autokey-name-separator
""
548 "*String that comes between any two names in the key.
549 See the documentation of function `bibtex-generate-autokey' for details."
550 :group
'bibtex-autokey
553 (defcustom bibtex-autokey-year-length
2
554 "*Number of rightmost digits from the year field to incorporate into key.
555 See the documentation of function `bibtex-generate-autokey' for details."
556 :group
'bibtex-autokey
559 (defcustom bibtex-autokey-year-use-crossref-entry t
560 "*If non-nil use year field from crossreferenced entry if necessary.
561 If this variable is non-nil and the current entry has no year, but a
562 valid crossref entry, the year field from the crossreferenced entry is
564 See the documentation of function `bibtex-generate-autokey' for details."
565 :group
'bibtex-autokey
568 (defcustom bibtex-autokey-titlewords
5
569 "*Number of title words to use for the automatically generated reference key.
570 If this is set to anything but a number, all title words are used.
571 Possibly more words from the title are used according to
572 `bibtex-autokey-titlewords-stretch'.
573 See the documentation of function `bibtex-generate-autokey' for details."
574 :group
'bibtex-autokey
575 :type
'(choice (const :tag
"All" infty
)
578 (defcustom bibtex-autokey-title-terminators
579 '("\\." "!" "\\?" ":" ";" "--")
580 "*Regexp list defining the termination of the main part of the title.
581 Case of the regexps is ignored.
582 See the documentation of function `bibtex-generate-autokey' for details."
583 :group
'bibtex-autokey
584 :type
'(repeat regexp
))
586 (defcustom bibtex-autokey-titlewords-stretch
2
587 "*Number of words that can additionally be used from the title.
588 These words are used only, if a sentence from the title can be ended then.
589 See the documentation of function `bibtex-generate-autokey' for details."
590 :group
'bibtex-autokey
593 (defcustom bibtex-autokey-titleword-ignore
594 '("A" "An" "On" "The" "Eine?" "Der" "Die" "Das"
595 "[^A-Z].*" ".*[^a-zA-Z0-9].*")
596 "*Determines words from the title that are not to be used in the key.
597 Each item of the list is a regexp. If a word of the title matchs a
598 regexp from that list, it is not included in the title part of the key.
599 See the documentation of function `bibtex-generate-autokey' for details."
600 :group
'bibtex-autokey
601 :type
'(repeat regexp
))
603 (defcustom bibtex-autokey-titleword-case-convert
'downcase
604 "*Function called for each titleword to perform case conversion.
605 See the documentation of function `bibtex-generate-autokey' for more detail."
606 :group
'bibtex-autokey
607 :type
'(choice (const :tag
"Preserve case" identity
)
608 (const :tag
"Downcase" downcase
)
609 (const :tag
"Capitalize" capitalize
)
610 (const :tag
"Upcase" upcase
)
611 (function :tag
"Conversion function")))
613 (defcustom bibtex-autokey-titleword-abbrevs nil
614 "*Determines exceptions to the usual abbreviation mechanism.
615 An alist of (OLD-REGEXP NEW-STRING) pairs. Case is ignored
616 in matching against OLD-REGEXP, and the first matching pair is used.
617 See the documentation of function `bibtex-generate-autokey' for details.")
619 (defcustom bibtex-autokey-titleword-change-strings
620 bibtex-autokey-transcriptions
621 "Alist of (OLD-REGEXP NEW-STRING) pairs.
622 Any part of title word matching a OLD-REGEXP is replaced by NEW-STRING.
623 Case is significant in OLD-REGEXP. All regexps are tried in the
624 order in which they appear in the list, so be sure to avoid inifinite
626 See the documentation of function `bibtex-generate-autokey' for details."
627 :group
'bibtex-autokey
629 (list (regexp :tag
"Old")
630 (string :tag
"New"))))
632 (defcustom bibtex-autokey-titleword-length
5
633 "*Number of characters from title words to incorporate into key.
634 If this is set to anything but a number, all characters are used.
635 See the documentation of function `bibtex-generate-autokey' for details."
636 :group
'bibtex-autokey
637 :type
'(choice (const :tag
"All" infty
)
640 (defcustom bibtex-autokey-titleword-separator
"_"
641 "*String to be put between the title words.
642 See the documentation of function `bibtex-generate-autokey' for details."
643 :group
'bibtex-autokey
646 (defcustom bibtex-autokey-name-year-separator
""
647 "*String to be put between name part and year part of key.
648 See the documentation of function `bibtex-generate-autokey' for details."
649 :group
'bibtex-autokey
652 (defcustom bibtex-autokey-year-title-separator
":_"
653 "*String to be put between name part and year part of key.
654 See the documentation of function `bibtex-generate-autokey' for details."
655 :group
'bibtex-autokey
658 (defcustom bibtex-autokey-edit-before-use t
659 "*If non-nil, user is allowed to edit the generated key before it is used."
660 :group
'bibtex-autokey
663 (defcustom bibtex-autokey-before-presentation-function nil
664 "Function to call before the generated key is presented.
665 If non-nil this should be a single function, which is called before
666 the generated key is presented (in entry or, if
667 `bibtex-autokey-edit-before-use' is t, in minibuffer). This function
668 must take one argument (the automatically generated key), and must
669 return with a string (the key to use)."
670 :group
'bibtex-autokey
673 (defcustom bibtex-entry-offset
0
674 "*Offset for BibTeX entries.
675 Added to the value of all other variables which determine colums."
679 (defcustom bibtex-field-indentation
2
680 "*Starting column for the name part in BibTeX fields."
684 (defcustom bibtex-text-indentation
686 bibtex-field-indentation
687 (length "organization = "))
688 "*Starting column for the text part in BibTeX fields.
689 Should be equal to the space needed for the longest name part."
693 (defcustom bibtex-contline-indentation
694 (+ bibtex-text-indentation
1)
695 "*Starting column for continuation lines of BibTeX fields."
699 (defcustom bibtex-align-at-equal-sign nil
700 "*If non-nil, align fields at equal sign instead of field text.
701 If non-nil, the column for the equal sign is
702 the value of `bibtex-text-indentation', minus 2."
706 (defcustom bibtex-comma-after-last-field nil
707 "*If non-nil, a comma is put at end of last field in the entry template."
711 ;; bibtex-font-lock-keywords is a user option as well, but since the
712 ;; patterns used to define this variable are defined in a later
713 ;; section of this file, it is defined later.
715 ;; Special support taking care of variants
716 (if (boundp 'mark-active
)
717 (defun bibtex-mark-active ()
718 ;; In Emacs mark-active indicates if mark is active.
720 (defun bibtex-mark-active ()
721 ;; In XEmacs (mark) returns nil when not active.
722 (if zmacs-regions
(mark) (mark t
))))
724 (if (fboundp 'run-with-idle-timer
)
725 ;; timer.el is distributed with Emacs
726 (fset 'bibtex-run-with-idle-timer
'run-with-idle-timer
)
727 ;; timer.el is not distributed with XEmacs
728 ;; Notice that this does not (yet) pass the arguments, but they
729 ;; are not used (yet) in bibtex.el. Fix if needed.
730 (defun bibtex-run-with-idle-timer (secs repeat function
&rest args
)
731 (start-itimer "bibtex" function secs
(if repeat secs nil
) t
)))
734 ;; Syntax Table, Keybindings and BibTeX Entry List
735 (defvar bibtex-mode-syntax-table
736 (let ((st (make-syntax-table)))
737 (modify-syntax-entry ?
\" "\"" st
)
738 (modify-syntax-entry ?$
"$$ " st
)
739 (modify-syntax-entry ?%
"< " st
)
740 (modify-syntax-entry ?
' "w " st
)
741 (modify-syntax-entry ?
@ "w " st
)
742 (modify-syntax-entry ?
\\ "\\" st
)
743 (modify-syntax-entry ?
\f "> " st
)
744 (modify-syntax-entry ?
\n "> " st
)
745 (modify-syntax-entry ?~
" " st
)
748 (defvar bibtex-mode-map
749 (let ((km (make-sparse-keymap)))
750 (define-key km
"\t" 'bibtex-find-text
)
751 (define-key km
"\n" 'bibtex-next-field
)
752 (define-key km
"\M-\t" 'bibtex-complete-string
)
753 (define-key km
[(meta tab
)] 'bibtex-complete-key
)
754 (define-key km
"\C-c\"" 'bibtex-remove-delimiters
)
755 (define-key km
"\C-c{" 'bibtex-remove-delimiters
)
756 (define-key km
"\C-c}" 'bibtex-remove-delimiters
)
757 (define-key km
"\C-c\C-c" 'bibtex-clean-entry
)
758 (define-key km
"\C-c\C-q" 'bibtex-fill-entry
)
759 (define-key km
"\C-c?" 'bibtex-print-help-message
)
760 (define-key km
"\C-c\C-p" 'bibtex-pop-previous
)
761 (define-key km
"\C-c\C-n" 'bibtex-pop-next
)
762 (define-key km
"\C-c\C-k" 'bibtex-kill-field
)
763 (define-key km
"\C-c\M-k" 'bibtex-copy-field-as-kill
)
764 (define-key km
"\C-c\C-w" 'bibtex-kill-entry
)
765 (define-key km
"\C-c\M-w" 'bibtex-copy-entry-as-kill
)
766 (define-key km
"\C-c\C-y" 'bibtex-yank
)
767 (define-key km
"\C-c\M-y" 'bibtex-yank-pop
)
768 (define-key km
"\C-c\C-d" 'bibtex-empty-field
)
769 (define-key km
"\C-c\C-f" 'bibtex-make-field
)
770 (define-key km
"\C-c$" 'bibtex-ispell-abstract
)
771 (define-key km
"\M-\C-a" 'bibtex-beginning-of-entry
)
772 (define-key km
"\M-\C-e" 'bibtex-end-of-entry
)
773 (define-key km
"\C-\M-l" 'bibtex-reposition-window
)
774 (define-key km
"\C-\M-h" 'bibtex-mark-entry
)
775 (define-key km
"\C-c\C-b" 'bibtex-entry
)
776 (define-key km
"\C-c\C-t" 'bibtex-hide-entry-bodies
)
777 (define-key km
"\C-c\C-rn" 'bibtex-narrow-to-entry
)
778 (define-key km
"\C-c\C-rw" 'widen
)
779 (define-key km
"\C-c\C-o" 'bibtex-remove-OPT-or-ALT
)
780 (define-key km
"\C-c\C-e\C-i" 'bibtex-InProceedings
)
781 (define-key km
"\C-c\C-ei" 'bibtex-InCollection
)
782 (define-key km
"\C-c\C-eI" 'bibtex-InBook
)
783 (define-key km
"\C-c\C-e\C-a" 'bibtex-Article
)
784 (define-key km
"\C-c\C-e\C-b" 'bibtex-InBook
)
785 (define-key km
"\C-c\C-eb" 'bibtex-Book
)
786 (define-key km
"\C-c\C-eB" 'bibtex-Booklet
)
787 (define-key km
"\C-c\C-e\C-c" 'bibtex-InCollection
)
788 (define-key km
"\C-c\C-e\C-m" 'bibtex-Manual
)
789 (define-key km
"\C-c\C-em" 'bibtex-MastersThesis
)
790 (define-key km
"\C-c\C-eM" 'bibtex-Misc
)
791 (define-key km
"\C-c\C-e\C-p" 'bibtex-InProceedings
)
792 (define-key km
"\C-c\C-ep" 'bibtex-Proceedings
)
793 (define-key km
"\C-c\C-eP" 'bibtex-PhdThesis
)
794 (define-key km
"\C-c\C-e\M-p" 'bibtex-Preamble
)
795 (define-key km
"\C-c\C-e\C-s" 'bibtex-String
)
796 (define-key km
"\C-c\C-e\C-t" 'bibtex-TechReport
)
797 (define-key km
"\C-c\C-e\C-u" 'bibtex-Unpublished
)
801 bibtex-edit-menu bibtex-mode-map
"BibTeX-Edit Menu in BibTeX mode"
803 ("Moving inside an Entry"
804 ["End of Field" bibtex-find-text t
]
805 ["Next Field" bibtex-next-field t
]
806 ["Beginning of Entry" bibtex-beginning-of-entry t
]
807 ["End of Entry" bibtex-end-of-entry t
])
808 ("Operating on Current Entry"
809 ["Fill Entry" bibtex-fill-entry t
]
810 ["Clean Entry" bibtex-clean-entry t
]
812 ["Kill Entry" bibtex-kill-entry t
]
813 ["Copy Entry to Kill Ring" bibtex-copy-entry-as-kill t
]
814 ["Paste Most Recently Killed Entry" bibtex-yank t
]
815 ["Paste Previously Killed Entry" bibtex-yank-pop t
]
817 ["Ispell Entry" bibtex-ispell-entry t
]
818 ["Ispell Entry Abstract" bibtex-ispell-abstract t
]
819 ["Narrow to Entry" bibtex-narrow-to-entry t
])
820 ("Operating on Current Field"
821 ["Remove Delimiters" bibtex-remove-delimiters t
]
822 ["Remove OPT or ALT Prefix" bibtex-remove-OPT-or-ALT t
]
823 ["Clear Field" bibtex-empty-field t
]
825 ["Kill Field" bibtex-kill-field t
]
826 ["Copy Field to Kill Ring" bibtex-copy-field-as-kill t
]
827 ["Paste Most Recently Killed Field" bibtex-yank t
]
828 ["Paste Previously Killed Field" bibtex-yank-pop t
]
830 ["Make New Field" bibtex-make-field t
]
832 ["Snatch from Similar Following Field" bibtex-pop-next t
]
833 ["Snatch from Similar Preceding Field" bibtex-pop-previous t
]
835 ["String Complete" bibtex-complete-string t
]
836 ["Key Complete" bibtex-complete-key t
]
838 ["Help about Current Field" bibtex-print-help-message t
])
839 ("Operating on Buffer or Region"
840 ["Validate Entries" bibtex-validate t
]
841 ["Sort Entries" bibtex-sort-buffer t
]
842 ["Reformat Entries" bibtex-reformat t
]
843 ["Hide Entry Bodies" bibtex-hide-entry-bodies t
]
844 ["Count Entries" bibtex-count-entries t
])
846 ["Convert Alien Buffer" bibtex-convert-alien t
]
847 ["Submit Bug Report" bibtex-submit-bug-report t
])))
850 bibtex-entry-menu bibtex-mode-map
"Entry-Types Menu in BibTeX mode"
852 ["Article in Journal" bibtex-Article t
]
853 ["Article in Conference Proceedings" bibtex-InProceedings t
]
854 ["Article in a Collection" bibtex-InCollection t
]
855 ["Chapter or Pages in a Book" bibtex-InBook t
]
856 ["Conference Proceedings" bibtex-Proceedings t
]
857 ["Book" bibtex-Book t
]
858 ["Booklet (Bound, but no Publisher/Institution)" bibtex-Booklet t
]
859 ["PhD. Thesis" bibtex-PhdThesis t
]
860 ["Master's Thesis" bibtex-MastersThesis t
]
861 ["Technical Report" bibtex-TechReport t
]
862 ["Technical Manual" bibtex-Manual t
]
863 ["Unpublished" bibtex-Unpublished t
]
864 ["Miscellaneous" bibtex-Misc t
]
865 ["String" bibtex-String t
]
866 ["Preamble" bibtex-Preamble t
]))
872 bibtex-maintainer-address
"Dirk Herrmann <D.Herrmann@tu-bs.de>")
873 ;; current maintainer
876 ;; Internal Variables
878 (defvar bibtex-pop-previous-search-point nil
)
879 ;; Next point where bibtex-pop-previous starts looking for a similar
882 (defvar bibtex-pop-next-search-point nil
)
883 ;; Next point where bibtex-pop-next starts looking for a similar entry.
885 (defvar bibtex-field-kill-ring nil
)
886 ;; Ring of least recently killed fields. At most
887 ;; bibtex-field-kill-ring-max items are kept here.
889 (defvar bibtex-field-kill-ring-yank-pointer nil
)
890 ;; The tail of bibtex-field-kill-ring whose car is the last item yanked.
892 (defvar bibtex-entry-kill-ring nil
)
893 ;; Ring of least recently killed entries. At most
894 ;; bibtex-entry-kill-ring-max items are kept here.
896 (defvar bibtex-entry-kill-ring-yank-pointer nil
)
897 ;; The tail of bibtex-entry-kill-ring whose car is the last item yanked.
899 (defvar bibtex-last-kill-command nil
)
900 ;; Holds the type of the last kill command (either 'field or 'entry)
902 (defvar bibtex-strings nil
)
903 ;; Candidates for bibtex-complete-string. Initialized from
904 ;; bibtex-predefined-strings and bibtex-string-files. This variable is
906 (make-variable-buffer-local 'bibtex-strings
)
908 (defvar bibtex-keys nil
)
909 ;; Candidates for TAB completion when entering a reference key using
910 ;; the minibuffer. Also used for bibtex-complete-key. Initialized in
911 ;; bibtex-mode and updated for each new entry. This variable is
913 (make-variable-buffer-local 'bibtex-keys
)
915 (defvar bibtex-buffer-last-parsed-tick nil
)
916 ;; Remembers the value returned by buffer-modified-tick when buffer
917 ;; was parsed for keys the last time.
918 (make-variable-buffer-local 'bibtex-buffer-last-parsed-tick
)
920 (defvar bibtex-parse-idle-timer nil
)
921 ;; Stores if timer is already installed
923 (defvar bibtex-progress-lastperc nil
)
924 ;; Holds the last reported percentage for the progress message
926 (defvar bibtex-progress-lastmes nil
)
927 ;; Holds the last reported progress message
929 (defvar bibtex-progress-interval nil
)
930 ;; Holds the chosen interval
932 (defvar bibtex-key-history nil
)
933 ;; Used to store the history list for reading keys
935 (defvar bibtex-entry-type-history nil
)
936 ;; Used to store the history list for reading entry types
938 (defvar bibtex-field-history nil
)
939 ;; Used to store the history list for reading field names
941 (defvar bibtex-reformat-previous-options nil
)
942 ;; Used to store the last reformat options given
944 (defvar bibtex-reformat-previous-labels nil
)
945 ;; Used to store the last reformat label option given
948 ;; Functions to Parse the BibTeX Entries
950 (defun bibtex-cfield (name text
)
951 ;; Create a regexp for a BibTeX field of name NAME and text TEXT.
952 (concat ",[ \t\n]*\\("
954 "\\)[ \t\n]*=[ \t\n]*\\("
957 (defconst bibtex-name-in-cfield
1)
958 ;; The regexp subexpression number of the name part in bibtex-cfield.
960 (defconst bibtex-text-in-cfield
2)
961 ;; The regexp subexpression number of the text part in bibtex-cfield.
963 (defconst bibtex-reference-type
"@[^\"#%'(),={} \t\n0-9][^\"#%'(),={} \t\n]*")
964 ;; Regexp defining the type part of a BibTeX reference entry (almost
965 ;; the same as bibtex-field-name)
967 (defconst bibtex-reference-key
"[][a-z0-9.:;?!`'/*@+=|()<>&_^$-]+")
968 ;; Regexp defining the label part of a BibTeX reference entry
970 (defconst bibtex-field-name
"[^\"#%'(),={} \t\n0-9][^\"#%'(),={} \t\n]*")
971 ;; Regexp defining the name part of a BibTeX field (almost the same as
972 ;; bibtex-reference-type)
974 (defconst bibtex-field-const
"[][a-z0-9.:;?!`'/*@+=|<>&_^$-]+")
975 ;; Regexp defining a bibtex field constant
977 (defconst bibtex-field-string-part-not-braced
979 ;; Match field string part without braces
981 (defconst bibtex-field-string-part-no-inner-braces
984 bibtex-field-string-part-not-braced
"*"
986 ;; Match field string part with no inner braces
988 (defconst bibtex-field-string-part-1-inner-brace
992 bibtex-field-string-part-not-braced
994 "\\(" bibtex-field-string-part-no-inner-braces
"\\)"
997 ;; Match field string part with at most 1 inner brace
999 (defconst bibtex-field-string-part-2-inner-braces
1003 bibtex-field-string-part-not-braced
1005 "\\(" bibtex-field-string-part-1-inner-brace
"\\)"
1008 ;; Match field string part with at most 2 inner braces
1010 (defconst bibtex-field-string-part-3-inner-braces
1014 bibtex-field-string-part-not-braced
1016 "\\(" bibtex-field-string-part-2-inner-braces
"\\)"
1019 ;; Match field string part with at most 3 inner braces
1021 (defconst bibtex-field-string-braced
1022 bibtex-field-string-part-3-inner-braces
)
1023 ;; Match braced field string with inner nesting level of braces at most 3
1025 (defconst bibtex-field-string-quoted
1029 "[^\"\\]" ;; every character except quote or backslash
1031 ;; "\\(" "\"[a-z-]" "\\)" ;; a quote followed by a letter or dash
1033 ;; last two lines commented out until lines like
1034 ;; author = "Stefan Sch"of"
1035 ;; are supported by BibTeX
1036 "\\(" "\\\\\\(.\\|\n\\)" "\\)" ;; a backslash followed by any character
1039 ;; Match quoted field string
1041 (defconst bibtex-field-string
1043 "\\(" bibtex-field-string-braced
"\\)"
1045 "\\(" bibtex-field-string-quoted
"\\)"))
1046 ;; Match a braced or quoted string
1048 (defconst bibtex-field-string-or-const
1049 (concat bibtex-field-const
"\\|" bibtex-field-string
))
1050 ;; Match either bibtex-field-string or bibtex-field-const.
1052 (defconst bibtex-field-text
1054 "\\(" bibtex-field-string-or-const
"\\)"
1055 "\\([ \t\n]+#[ \t\n]+\\(" bibtex-field-string-or-const
"\\)\\)*"))
1056 ;; Regexp defining the text part of a BibTeX field: either a string,
1057 ;; or an empty string, or a constant followed by one or more # /
1060 (defconst bibtex-field
1061 (bibtex-cfield bibtex-field-name bibtex-field-text
))
1062 ;; Regexp defining the format of a BibTeX field.
1064 (defconst bibtex-name-in-field bibtex-name-in-cfield
)
1065 ;; The regexp subexpression number of the name part in BibTeX-field.
1067 (defconst bibtex-text-in-field bibtex-text-in-cfield
)
1068 ;; The regexp subexpression number of the text part in BibTeX-field.
1070 (defconst bibtex-reference-head
1071 (concat "^[ \t]*\\("
1072 bibtex-reference-type
1073 "\\)[ \t]*[({][ \t]*\\("
1074 bibtex-reference-key
1076 ;; Regexp defining format of the header line of a BibTeX reference
1079 (defconst bibtex-reference-maybe-empty-head
1080 (concat bibtex-reference-head
"?"))
1081 ;; Regexp defining format of the header line of a maybe empty
1082 ;; BibTeX reference entry (without reference key).
1084 (defconst bibtex-type-in-head
1)
1085 ;; The regexp subexpression number of the type part in
1086 ;; bibtex-reference-head.
1088 (defconst bibtex-key-in-head
2)
1089 ;; The regexp subexpression number of the key part in
1090 ;; bibtex-reference-head.
1092 (defconst bibtex-reference-infix
(concat "[ \t\n]*" bibtex-field
))
1093 ;; Regexp defining the (repeatable) infix of a bibtex reference
1095 (defconst bibtex-reference-postfix
"[ \t\n]*,?[ \t\n]*[})]")
1096 ;; Regexp defining the postfix of a bibtex reference
1098 (defconst bibtex-key-in-reference bibtex-key-in-head
)
1099 ;; The regexp subexpression number of the key part in
1100 ;; bibtex-reference.
1102 (defconst bibtex-string
1103 (concat "^[ \t]*@string[ \t\n]*[({][ \t\n]*\\("
1104 bibtex-reference-key
1105 "\\)[ \t\n]*=[ \t\n]*\\("
1108 ;; Regexp defining the format of a BibTeX string entry.
1110 (defconst bibtex-key-in-string
1)
1111 ;; The regexp subexpression of the name part in bibtex-string.
1113 (defconst bibtex-text-in-string
2)
1114 ;; The regexp subexpression of the text part in bibtex-string.
1116 (defvar bibtex-font-lock-keywords
1118 ;; reference type and reference label
1119 (list bibtex-reference-maybe-empty-head
1120 (list bibtex-type-in-head
'font-lock-function-name-face
)
1121 (list bibtex-key-in-head
'font-lock-constant-face nil t
))
1124 (concat "^\\([ \t]*" bibtex-comment-start
".*\\)$")
1125 1 'font-lock-comment-face
)
1126 ;; optional field names (treated as comments)
1128 (concat "^[ \t]*\\(OPT" bibtex-field-name
"\\)[ \t]*=")
1129 1 'font-lock-comment-face
)
1131 (list (concat "^[ \t]*\\(" bibtex-field-name
"\\)[ \t]*=")
1132 1 'font-lock-variable-name-face
)
1133 "*Default expressions to highlight in BibTeX mode."))
1134 ;; now all needed patterns are defined
1139 (defun bibtex-delete-whitespace ()
1140 ;; Delete all whitespace starting at point
1141 (if (looking-at "[ \t\n]+")
1142 (delete-region (point) (match-end 0))))
1144 (defun bibtex-current-line ()
1145 ;; this computes line number of point regardless whether the buffer
1147 (+ (count-lines 1 (point))
1148 (if (equal (current-column) 0) 1 0)))
1150 (defun bibtex-member-of-regexp (string list
)
1151 ;; Return non-nil if STRING is exactly matched by an element of
1152 ;; LIST. The value is actually the tail of LIST whose
1153 ;; car matches STRING.
1154 (let (case-fold-search)
1156 (and list
(not (string-match (concat "^" (car list
) "$") string
)))
1157 (setq list
(cdr list
)))
1160 (defun bibtex-assoc-of-regexp (string alist
)
1161 ;; Return non-nil if STRING is exactly matched by the car of an
1162 ;; element of LIST (case ignored). The value is actually the element
1163 ;; of LIST whose car matches STRING.
1164 (let ((case-fold-search t
))
1167 (not (string-match (concat "^" (car (car alist
)) "$") string
)))
1168 (setq alist
(cdr alist
)))
1171 (defun bibtex-skip-to-valid-entry (&optional backward
)
1172 ;; If not at beginning of valid BibTeX entry, move to beginning of
1173 ;; the next valid one. With argument backward non-nil, move backward
1174 ;; to beginning of previous valid one. A valid entry is a
1175 ;; syntactical correct one with type contained in
1176 ;; bibtex-entry-field-alist or, if bibtex-sort-ignore-string-entries
1177 ;; is nil, a syntactical correct string entry.
1178 (let ((case-fold-search t
)
1184 (concat "\\(" (car type
) "\\)"))
1185 bibtex-entry-field-alist
1189 (while (and (not found
)
1193 (let ((pnt (point)))
1195 ((looking-at valid-bibtex-entry
)
1197 (bibtex-search-reference nil nil t
)
1198 (equal (match-beginning 0) pnt
))
1200 ((and (not bibtex-sort-ignore-string-entries
)
1201 (looking-at bibtex-string
))
1207 (goto-char (1- pnt
))
1208 (if (re-search-backward "^[ \t]*\\(@\\)" nil
'move
)
1209 (goto-char (match-beginning 1))))
1210 (goto-char (1+ pnt
))
1211 (if (re-search-forward "^[ \t]*@" nil
'move
)
1212 (forward-char -
1))))))))
1214 (defun bibtex-map-entries (fun)
1215 ;; Call FUN for each BibTeX entry starting with the current. Do this
1216 ;; to the end of the file. FUN is called with one argument, the key
1217 ;; of the entry, and with point inside the entry. If
1218 ;; bibtex-sort-ignore-string-entries is non-nil, FUN will not be
1219 ;; called for @String entries.
1220 (let ((case-fold-search t
))
1221 (bibtex-beginning-of-entry)
1222 (while (re-search-forward bibtex-reference-maybe-empty-head nil t
)
1225 (downcase (buffer-substring-no-properties
1226 (1+ (match-beginning bibtex-type-in-head
))
1227 (match-end bibtex-type-in-head
))))
1229 (if (match-beginning bibtex-key-in-head
)
1230 (buffer-substring-no-properties
1231 (match-beginning bibtex-key-in-head
)
1232 (match-end bibtex-key-in-head
))
1236 (not bibtex-sort-ignore-string-entries
)
1237 (string-equal "string" (downcase reference-type
)))
1238 (assoc-ignore-case reference-type bibtex-entry-field-alist
))
1239 (funcall fun reference-key
))
1241 (bibtex-end-of-entry)))))
1243 (defun bibtex-progress-message (&optional flag interval
)
1244 ;; echos a message about progress of current buffer
1245 ;; if flag is a string, the message is initialized (in this case a
1246 ;; value for INTERVAL may be given as well (if not this is set to 5))
1247 ;; if flag is done, the message is deinitialized
1248 ;; if flag is absent, a message is echoed if point was incremented
1249 ;; at least INTERVAL percent since last message was echoed
1250 (let* ((size (- (point-max) (point-min)))
1251 (perc (if (= size
0)
1253 (/ (* 100 (- (point) (point-min))) size
))))
1254 (if (or (and (not flag
)
1256 (+ bibtex-progress-interval bibtex-progress-lastperc
)))
1261 (setq bibtex-progress-lastmes flag
)
1263 (setq bibtex-progress-interval interval
)
1264 (setq bibtex-progress-interval
5))))
1265 (setq bibtex-progress-lastperc perc
)
1266 (message (concat bibtex-progress-lastmes
" (%d%%)") perc
))
1267 (if (equal flag
'done
)
1269 (message (concat bibtex-progress-lastmes
" (done)"))
1270 (setq bibtex-progress-lastmes nil
))))))
1273 (defun bibtex-field-left-delimiter ()
1274 ;; returns a string dependent on bibtex-field-delimiters
1275 (if (equal bibtex-field-delimiters
'braces
)
1279 (defun bibtex-field-right-delimiter ()
1280 ;; returns a string dependent on bibtex-field-delimiters
1281 (if (equal bibtex-field-delimiters
'braces
)
1285 (defun bibtex-entry-left-delimiter ()
1286 ;; returns a string dependent on bibtex-field-delimiters
1287 (if (equal bibtex-entry-delimiters
'braces
)
1291 (defun bibtex-entry-right-delimiter ()
1292 ;; returns a string dependent on bibtex-field-delimiters
1293 (if (equal bibtex-entry-delimiters
'braces
)
1297 (defun bibtex-search-reference
1298 (empty-head &optional bound noerror backward
)
1299 ;; A helper function necessary since the failure stack size limit for
1300 ;; regexps was reduced in emacs 19.32.
1301 ;; It searches for a BibTeX reference (maybe with an empty head if
1302 ;; EMPTY-HEAD is t).
1303 ;; BOUND and NOERROR are exactly as in re-search-forward. If
1304 ;; BACKWARD is non-nil, search is done in reverse direction. After
1305 ;; call to this function MATCH-BEGINNING and MATCH-END functions are
1306 ;; defined, but only for the head part of the reference (especially
1307 ;; (match-end 0) just gives the end of the head part).
1309 (prefix (if empty-head
1310 bibtex-reference-maybe-empty-head
1311 bibtex-reference-head
))
1312 (infix bibtex-reference-infix
)
1313 (postfix bibtex-reference-postfix
))
1316 (while (and (not found
)
1317 (re-search-backward prefix bound noerror
))
1318 (setq found
(bibtex-search-reference empty-head pnt t
)))
1320 (goto-char (match-beginning 0))
1321 (if (equal noerror nil
)
1323 (error "Search of BibTeX reference failed"))
1324 (if (equal noerror t
)
1328 (let ((limit (if bound bound
(point-max)))
1331 (while (and (not found
)
1332 (re-search-forward prefix bound noerror
))
1333 (setq md
(match-data))
1334 ;; save match-data of prefix regexp
1337 (goto-char (match-end bibtex-type-in-head
))
1338 (looking-at "[ \t]*("))
1339 ;; entry opened with parenthesis
1344 (<= (match-end 0) limit
))
1345 (goto-char (match-end 0)))
1346 ;; This matches the infix* part. The AND construction assures
1347 ;; that BOUND is respected.
1348 (if (and (looking-at postfix
)
1350 (buffer-substring-no-properties
1351 (1- (match-end 0)) (match-end 0))
1353 (<= (match-end 0) limit
))
1355 (re-search-forward postfix
)
1360 ;; to set match-beginning/end again
1362 (if (equal noerror nil
)
1364 (error "Search of BibTeX reference failed"))
1365 (if (equal noerror t
)
1370 (defun bibtex-flash-head ()
1371 ;; Flash at BibTeX reference head before point, if exists.
1372 (let ((case-fold-search t
)
1374 (cond ((re-search-backward bibtex-reference-head nil t
)
1375 (goto-char (match-beginning bibtex-type-in-head
))
1376 (setq flash
(match-end bibtex-key-in-reference
)))
1379 (skip-chars-backward " \t")
1380 (setq flash
(point))
1382 (skip-chars-forward " \t")))
1383 (if (pos-visible-in-window-p (point))
1386 (buffer-substring (point) flash
)))))
1388 (defun bibtex-make-optional-field (e-t)
1389 "Makes an optional field named E-T in current BibTeX entry."
1391 (bibtex-make-field (cons (concat "OPT" (car e-t
)) (cdr e-t
)))
1392 (bibtex-make-field (concat "OPT" e-t
))))
1394 (defun bibtex-move-outside-of-entry ()
1395 ;; Make sure we are outside of a BibTeX entry.
1396 (let ((orig-point (point)))
1397 (bibtex-end-of-entry)
1398 (if (< (point) orig-point
)
1399 ;; We moved backward, so we weren't inside an entry to begin with.
1400 ;; Leave point at the beginning of a line, and preferably
1401 ;; at the beginning of a paragraph.
1403 (goto-char orig-point
)
1404 (beginning-of-line 1)
1405 (if (not (= ?
\n (char-before (1- (point)))))
1407 (re-search-forward "^[ \t]*[@\n]" nil
'move
)
1408 (backward-char 1)))))
1409 (skip-chars-forward " \t\n")))
1411 (defun bibtex-beginning-of-first-entry ()
1412 ;; Go to the beginning of the first BibTeX entry in buffer. Return
1414 (goto-char (point-min))
1415 (if (re-search-forward "^[ \t]*@" nil
'move
)
1416 (beginning-of-line))
1419 (defun bibtex-beginning-of-last-entry ()
1420 ;; Go to the beginning of the last BibTeX entry in buffer.
1421 (goto-char (point-max))
1422 (if (re-search-backward "^[ \t]*@" nil
'move
)
1423 (beginning-of-line))
1426 (defun bibtex-inside-field ()
1427 ;; Try to avoid point being at end of a BibTeX field.
1429 (skip-chars-backward " \t")
1430 (cond ((= (preceding-char) ?
,)
1433 (= (preceding-char) ?
})
1434 (= (preceding-char) ?
\"))
1435 (forward-char -
1))))
1437 (defun bibtex-enclosing-field (&optional noerr
)
1438 ;; Search for BibTeX field enclosing point. Point moves to end of
1439 ;; field. Use match-beginning and match-end to parse the field. If
1440 ;; NOERR is non-nil, no error is signalled. In this case, t is
1441 ;; returned on success, nil otherwise.
1442 (let ((case-fold-search t
)
1444 (boe (bibtex-beginning-of-entry))
1446 (goto-char old-point
)
1447 (if (not (re-search-backward
1448 (bibtex-cfield bibtex-field-name
"")
1450 ;; Search possible beginning of field
1452 (goto-char old-point
)
1455 (error "Can't find enclosing BibTeX field")))
1456 (if (or (not (re-search-forward bibtex-field nil t
))
1457 (< (match-end 0) old-point
)
1458 (> (match-beginning 0) old-point
))
1460 (goto-char old-point
)
1463 (error "Can't find enclosing BibTeX field")))))
1466 (defun bibtex-enclosing-reference-maybe-empty-head ()
1467 ;; Search for BibTeX reference enclosing point. Point moves to
1468 ;; end of reference. Beginning (but not end) of reference is given
1469 ;; by (match-beginning 0).
1470 (let ((case-fold-search t
)
1471 (old-point (point)))
1474 bibtex-reference-maybe-empty-head nil t
))
1476 (error "Can't find enclosing BibTeX reference")
1477 (goto-char old-point
)))
1478 (goto-char (match-beginning bibtex-type-in-head
))
1480 (bibtex-search-reference t nil t
))
1482 (error "Can't find enclosing BibTeX reference")
1483 (goto-char old-point
)))))
1485 (defun bibtex-insert-current-kill (n)
1486 (if (not bibtex-last-kill-command
)
1487 (error "BibTeX kill ring is empty")
1488 (let* ((kr (if (equal bibtex-last-kill-command
'field
)
1489 'bibtex-field-kill-ring
1490 'bibtex-entry-kill-ring
))
1491 (kryp (if (equal bibtex-last-kill-command
'field
)
1492 'bibtex-field-kill-ring-yank-pointer
1493 'bibtex-entry-kill-ring-yank-pointer
))
1496 (mod (- n
(length (eval kryp
))) (length (eval kr
)))
1498 (current (car (set kryp ARGth-kill-element
))))
1500 ((equal bibtex-last-kill-command
'field
)
1501 (let (bibtex-help-message)
1502 (bibtex-find-text nil t
)
1503 (if (looking-at "[}\"]")
1506 (message "Mark set")
1507 (bibtex-make-field (list (elt current
1) nil
(elt current
2)) t
))
1508 ((equal bibtex-last-kill-command
'entry
)
1510 (bibtex-beginning-of-entry))
1512 (message "Mark set")
1513 (insert (elt current
1)))
1516 "Unknown tag field: %s. Please submit a bug report"
1517 bibtex-last-kill-command
))))))
1519 (defun bibtex-format-entry ()
1520 ;; Helper function for bibtex-clean-entry. Formats current entry
1521 ;; according to variable bibtex-entry-format.
1522 (let ((case-fold-search t
)
1524 (start (bibtex-beginning-of-entry))
1527 non-empty-alternative
)
1528 (let ((end (copy-marker (bibtex-end-of-entry))))
1529 (if (equal start
(marker-position end
))
1530 (error "Not on a known BibTeX entry")
1532 (while (re-search-forward bibtex-field end t
)
1533 ;; determine if reference has crossref entry and if at least
1534 ;; one alternative is non-empty
1535 (let ((begin-name (match-beginning bibtex-name-in-field
))
1536 (end-name (match-end bibtex-name-in-field
))
1537 (begin-text (match-beginning bibtex-text-in-field
))
1538 (end-text (match-end bibtex-text-in-field
)))
1539 (goto-char begin-name
)
1540 (if (looking-at "ALT")
1542 (setq alternatives-there t
)
1543 (goto-char begin-text
)
1544 (if (not (looking-at "\\(\"\"\\)\\|\\({}\\)"))
1545 (setq non-empty-alternative t
))))
1547 "\\(OPT\\)?crossref"
1548 (buffer-substring-no-properties begin-name end-name
))
1552 (buffer-substring-no-properties
1553 (1+ begin-text
) (1- end-text
)))
1554 (if (equal crossref-there
"")
1555 (setq crossref-there nil
))))))
1556 (if (and alternatives-there
1557 (not non-empty-alternative
))
1560 (error "All alternatives are empty")))
1562 (re-search-forward bibtex-reference-type end
)
1563 (let* ((begin-type (1+ (match-beginning 0)))
1564 (end-type (match-end 0))
1567 (buffer-substring-no-properties begin-type end-type
)))
1569 (assoc-ignore-case reference-type bibtex-entry-field-alist
))
1570 (req (elt (elt entry-list
1) 0))
1571 (creq (elt (elt entry-list
2) 0))
1572 (format (if (equal bibtex-entry-format t
)
1573 '(realign opts-or-alts numerical-fields
1574 last-comma page-dashes delimiters
1575 unify-case inherit-booktitle
)
1576 bibtex-entry-format
))
1578 (if (memq 'unify-case format
)
1580 (delete-region begin-type end-type
)
1581 (insert (car entry-list
))))
1582 (if (memq 'delimiters format
)
1584 (goto-char end-type
)
1585 (skip-chars-forward " \t\n")
1587 (insert (bibtex-entry-left-delimiter))))
1589 (while (re-search-forward bibtex-field end t
)
1591 (copy-marker (match-beginning 0)))
1593 (copy-marker (match-end 0)))
1595 (copy-marker (match-beginning bibtex-name-in-field
)))
1597 (copy-marker (match-end bibtex-name-in-field
)))
1599 (copy-marker (match-beginning bibtex-text-in-field
)))
1601 (copy-marker (match-end bibtex-text-in-field
)))
1603 (buffer-substring-no-properties
1606 (buffer-substring-no-properties
1607 begin-name
(+ begin-name
3)))
1613 (memq 'opts-or-alts format
)
1614 (progn (goto-char begin-name
)
1615 (looking-at "OPT\\|ALT")))
1616 (goto-char begin-text
)
1617 (if (looking-at "\\(\"\"\\)\\|\\({}\\)")
1618 ;; empty: delete whole field if really optional
1619 ;; (missing crossref handled) or complain
1622 (goto-char begin-name
)
1624 (not crossref-there
)
1625 (assoc-ignore-case field-name req
))
1626 ;; field is not really optional
1628 (goto-char begin-name
)
1629 (bibtex-remove-OPT-or-ALT)
1631 "Mandatory field ``%s'' is empty" field-name
))
1632 ;; field is optional
1633 (delete-region begin-field end-field
))
1634 ;; otherwise: not empty, delete "OPT"
1635 (goto-char begin-name
)
1636 (bibtex-remove-OPT-or-ALT)))
1638 (memq 'numerical-fields format
)
1640 (goto-char begin-text
)
1641 (looking-at "\\(\"[0-9]+\"\\)\\|\\({[0-9]+}\\)")))
1642 (goto-char end-text
)
1644 (goto-char begin-text
)
1647 (if (memq 'delimiters format
)
1649 (goto-char begin-text
)
1651 (<= (point) end-text
)
1653 bibtex-field-string-or-const end-text t
))
1654 (let ((end (point)))
1655 (goto-char (match-beginning 0))
1658 (equal bibtex-field-delimiters
'double-quotes
)
1659 (looking-at bibtex-field-string-braced
))
1661 (equal bibtex-field-delimiters
'braces
)
1662 (looking-at bibtex-field-string-quoted
)))
1664 (goto-char (match-end 0))
1665 (delete-backward-char 1)
1666 (insert (bibtex-field-right-delimiter))
1667 (goto-char (match-beginning 0))
1669 (insert (bibtex-field-left-delimiter))))
1672 (memq 'page-dashes format
)
1673 (string-match "^\\(OPT\\)?pages$" (downcase field-name
))
1675 (goto-char begin-text
)
1677 "\\([\"{][0-9]+\\)[ \t\n]*--?[ \t\n]*\\([0-9]+[\"}]\\)")))
1678 (replace-match "\\1-\\2"))
1680 (memq 'inherit-booktitle format
)
1681 (equal (downcase field-name
) "booktitle")
1683 (goto-char begin-text
)
1684 (looking-at "\\(\"\"\\)\\|\\({}\\)"))
1686 (not (bibtex-find-entry-location crossref-there t
)))
1687 ;; booktitle field empty and crossref entry found
1688 ;; --> insert title field of crossreferenced entry if there
1689 (let ((end-of-crefd-entry (bibtex-end-of-entry)))
1690 (bibtex-beginning-of-entry)
1691 (if (re-search-forward
1692 (bibtex-cfield "title" bibtex-field-text
)
1693 end-of-crefd-entry t
)
1695 (goto-char begin-text
)
1698 (buffer-substring-no-properties
1699 (1+ (match-beginning bibtex-text-in-field
))
1700 (1- (match-end bibtex-text-in-field
))))))))
1702 (goto-char begin-text
)
1703 (looking-at "\\(\"\"\\)\\|\\({}\\)"))
1704 ;; if empty field, complain
1712 (not crossref-there
)
1716 "Mandatory field ``%s'' is empty" field-name
))))
1717 (if (memq 'unify-case format
)
1719 (car (cdr (assoc-ignore-case
1721 bibtex-entry-field-alist
))))
1726 bibtex-user-optional-fields
))
1729 (assoc-ignore-case field-name field-list
))))
1730 (goto-char begin-name
)
1733 (delete-region begin-name end-name
)
1734 (insert new-field-name
))
1735 (downcase-region begin-name end-name
))))
1736 (setq field-done t
)))
1737 (if (not field-done
)
1738 (goto-char begin-field
)
1739 (setq field-done nil
)
1740 (goto-char end-field
))))
1741 (if (looking-at (bibtex-field-right-delimiter))
1743 (if (memq 'last-comma format
)
1745 bibtex-comma-after-last-field
1746 (not (looking-at ",")))
1749 (not bibtex-comma-after-last-field
)
1752 (if (looking-at ",")
1754 (if (memq 'delimiters format
)
1756 (skip-chars-forward " \t\n")
1758 (insert (bibtex-entry-right-delimiter))))
1759 (if (memq 'realign format
)
1760 (bibtex-fill-entry)))))))
1762 (defun bibtex-autokey-change (string change-list
)
1763 ;; Returns a string where some regexps are changed according to
1764 ;; change-list. Every item of change-list is an (old-regexp
1765 ;; new-string) pair.
1766 (let (case-fold-search
1767 (return-string string
)
1769 (len (length change-list
))
1771 (while (< index len
)
1772 (setq change-item
(elt change-list index
))
1773 (while (string-match (car change-item
) return-string
)
1776 (concat (substring return-string
0 (match-beginning 0))
1778 (substring return-string
(match-end 0)))))
1779 (setq index
(1+ index
)))
1782 (defun bibtex-autokey-abbrev (string len
)
1783 ;; Returns an abbreviation of string with at least len
1784 ;; characters. String is aborted only after a consonant or at the
1785 ;; word end. If len is not a number, string is returned unchanged.
1788 (<= (length string
) len
))
1793 (let* ((case-fold-search t
)
1795 (string-match "[^aeiou]" string
(1- len
))))
1797 (substring string
0 (1+ abort-char
))
1800 (defun bibtex-autokey-get-namefield (min max
)
1801 ;; returns the contents of the name field of the current entry
1802 ;; does some modifications based on `bibtex-autokey-name-change-strings'
1803 ;; and removes newlines unconditionally
1805 (let ((case-fold-search t
))
1806 (if (re-search-forward
1807 (bibtex-cfield "\\(author\\)\\|\\(editor\\)" bibtex-field-text
)
1809 (bibtex-autokey-change
1810 (buffer-substring-no-properties
1811 (1+ (match-beginning (+ bibtex-text-in-cfield
2)))
1812 (1- (match-end (+ bibtex-text-in-cfield
2))))
1813 (append bibtex-autokey-name-change-strings
'(("\n" " "))))
1816 (defun bibtex-autokey-get-names (namefield)
1817 ;; gathers all names in namefield into a list
1818 (let ((case-fold-search t
)
1820 (while (not (equal namefield
""))
1822 (if (string-match "[ \t\n]and[ \t\n]" namefield
)
1823 (setq name
(substring namefield
0 (match-beginning 0))
1824 namefield
(substring namefield
(match-end 0)))
1825 (setq name namefield
1827 (setq names
(append names
(list name
)))))
1830 (defun bibtex-autokey-demangle-name (fullname)
1831 ;; gets the `last' part from a well-formed name
1832 (let* (case-fold-search
1834 (if (string-match "," fullname
)
1835 ;; name is of the form "von Last, First" or
1836 ;; "von Last, Jr, First"
1837 ;; --> take only the part before the comma
1839 (substring fullname
0 (match-beginning 0))))
1840 (if (string-match "^[a-z]" von-last
)
1841 ;; von-last has a "von" part --> take the "last" part
1842 (if (string-match "[ \t][A-Z]" von-last
)
1843 (substring von-last
(1+ (match-beginning 0)))
1845 "Name %s is incorrectly formed" fullname
))
1846 ;; von-last has no "von" part --> take all
1848 ;; name is of the form "First von Last"
1849 (if (string-match "[ \t]" fullname
)
1850 ;; more than one token
1851 (if (string-match "[ \t][a-z]" fullname
)
1852 ;; there is a "von" part
1853 ;; --> take everything after that
1855 "[ \t][A-Z]" fullname
(match-end 0))
1856 (substring fullname
(1+ (match-beginning 0)))
1858 "Name %s is incorrectly formed" fullname
))
1859 ;; there is no "von" part --> take only the last token
1860 (if (string-match " [^ ]*$" fullname
)
1861 (substring fullname
(1+ (match-beginning 0)))
1862 (error "Name %s is incorrectly formed" fullname
)))
1863 ;; only one token --> take it
1866 (if (string-match "[ \t]+" lastname
)
1867 ;; lastname consists of two or more tokens
1868 ;; --> take only the first one
1869 (substring lastname
0 (match-beginning 0))
1871 (funcall bibtex-autokey-name-case-convert usename
)))
1873 (defun bibtex-autokey-get-namelist (namefield)
1874 ;; gets namefield, performs abbreviations on the last parts, and
1875 ;; return results as a list
1879 fullname
(substring fullname
(string-match "[^ \t]" fullname
)))
1880 (bibtex-autokey-abbrev
1881 (bibtex-autokey-demangle-name fullname
)
1882 bibtex-autokey-name-length
))
1883 (bibtex-autokey-get-names namefield
)))
1885 (defun bibtex-autokey-get-yearfield (min max
)
1886 ;; get year field from current or maybe crossreferenced entry
1887 (let ((case-fold-search t
))
1889 (if (re-search-forward
1890 (bibtex-cfield "year" bibtex-field-text
) max t
)
1891 (let ((year (buffer-substring-no-properties
1892 (match-beginning bibtex-text-in-cfield
)
1893 (match-end bibtex-text-in-cfield
))))
1894 (string-match "[^0-9]*\\([0-9]+\\)" year
)
1895 (substring year
(match-beginning 1) (match-end 1)))
1896 (if bibtex-autokey-year-use-crossref-entry
1897 (let ((crossref-field
1900 (if (re-search-forward
1902 "\\(OPT\\)?crossref" bibtex-field-text
)
1904 (buffer-substring-no-properties
1906 (match-beginning (+ bibtex-text-in-cfield
1)))
1908 (match-end (+ bibtex-text-in-cfield
1))))))))
1909 (if (not (bibtex-find-entry-location crossref-field t
))
1910 (let ((end-of-crefd-entry (bibtex-end-of-entry)))
1911 (bibtex-beginning-of-entry)
1912 (if (re-search-forward
1913 (bibtex-cfield "year" "[0-9]+")
1914 end-of-crefd-entry t
)
1915 (buffer-substring-no-properties
1916 (match-beginning bibtex-text-in-cfield
)
1917 (match-end bibtex-text-in-cfield
))
1922 (defun bibtex-autokey-get-titlestring (min max
)
1923 ;; get title field contents up to a terminator
1924 (let ((case-fold-search t
))
1928 (if (re-search-forward
1929 (bibtex-cfield "title" bibtex-field-text
) max t
)
1930 (bibtex-autokey-change
1931 (buffer-substring-no-properties
1932 (1+ (match-beginning bibtex-text-in-cfield
))
1933 (1- (match-end bibtex-text-in-cfield
)))
1934 bibtex-autokey-titleword-change-strings
)
1938 (length bibtex-autokey-title-terminators
)))
1939 (while (< index numberofitems
)
1941 (elt bibtex-autokey-title-terminators index
) titlefield
)
1943 titlefield
(substring titlefield
0 (match-beginning 0))))
1944 (setq index
(1+ index
)))
1947 (defun bibtex-autokey-get-titles (titlestring)
1948 ;; gathers words from titlestring into a list. Ignores
1949 ;; specific words and uses only a specific amount of words.
1950 (let (case-fold-search
1955 (not (equal titlestring
""))
1957 (not (numberp bibtex-autokey-titlewords
))
1959 (+ bibtex-autokey-titlewords
1960 bibtex-autokey-titlewords-stretch
))))
1961 (if (string-match "\\b\\w+" titlestring
)
1962 (let* ((end-match (match-end 0))
1964 (substring titlestring
(match-beginning 0) end-match
)))
1965 (if (bibtex-member-of-regexp
1967 bibtex-autokey-titleword-ignore
)
1968 (setq counter
(1- counter
))
1971 (funcall bibtex-autokey-titleword-case-convert titleword
))
1972 (if (or (not (numberp bibtex-autokey-titlewords
))
1973 (< counter bibtex-autokey-titlewords
))
1974 (setq titlewords
(append titlewords
(list titleword
)))
1975 (setq titlewords-extra
1976 (append titlewords-extra
(list titleword
)))))
1978 titlestring
(substring titlestring end-match
)))
1979 (setq titlestring
""))
1980 (setq counter
(1+ counter
)))
1981 (if (string-match "\\b\\w+" titlestring
)
1983 (append titlewords titlewords-extra
))))
1985 (defun bibtex-autokey-get-titlelist (titlestring)
1986 ;; returns all words in titlestring as a list
1987 ;; does some abbreviation on the found words
1991 (bibtex-assoc-of-regexp
1992 titleword bibtex-autokey-titleword-abbrevs
)))
1995 (bibtex-autokey-abbrev
1997 bibtex-autokey-titleword-length
))))
1998 (bibtex-autokey-get-titles titlestring
)))
2000 (defun bibtex-generate-autokey ()
2001 "Generates automatically a key from the author/editor and the title field.
2002 This will only work for entries where each field begins on a separate line.
2003 The generation algorithm works as follows:
2004 1. Use the value of `bibtex-autokey-prefix-string' as a prefix.
2005 2. If there is a non-empty author (preferred) or editor field,
2006 use it as the name part of the key.
2007 3. Change any substring found in
2008 `bibtex-autokey-name-change-strings' to the corresponding new
2009 one (see documentation of this variable for further detail).
2010 4. For every of at least first `bibtex-autokey-names' names in
2011 the name field, determine the last name. If there are maximal
2012 `bibtex-autokey-names' + `bibtex-autokey-names-stretch'
2013 names, all names are used.
2014 5. From every last name, take at least
2015 `bibtex-autokey-name-length' characters (abort only after a
2016 consonant or at a word end).
2017 6. Convert all last names according to the conversion function
2018 `bibtex-autokey-name-case-convert'.
2019 7. Build the name part of the key by concatenating all
2020 abbreviated last names with the string
2021 `bibtex-autokey-name-separator' between any two. If there are
2022 more names than are used in the name part, prepend the string
2023 contained in `bibtex-autokey-additional-names'.
2024 8. Build the year part of the key by truncating the contents of
2025 the year field to the rightmost `bibtex-autokey-year-length'
2026 digits (useful values are 2 and 4). If the year field is
2027 absent, but the entry has a valid crossref field and the
2028 variable `bibtex-autokey-year-use-crossref-entry' is non-nil,
2029 use the year field of the crossreferenced entry instead.
2030 9. For the title part of the key change the contents of the
2031 title field of the reference according to
2032 `bibtex-autokey-titleword-change-strings' to the
2033 corresponding new one (see documentation of this variable for
2035 10. Abbreviate the result to the string up to (but not including)
2036 the first occurrence of a regexp matched by the items of
2037 `bibtex-autokey-title-terminators' and delete those words which
2038 appear in `bibtex-autokey-titleword-ignore'.
2039 Build the title part of the key by using at least the first
2040 `bibtex-autokey-titlewords' words from this
2041 abbreviated title. If the abbreviated title ends after
2042 maximal `bibtex-autokey-titlewords' +
2043 `bibtex-autokey-titlewords-stretch' words, all
2044 words from the abbreviated title are used.
2045 11. Convert all used titlewords according to the conversion function
2046 `bibtex-autokey-titleword-case-convert'.
2047 12. For every used title word that appears in
2048 `bibtex-autokey-titleword-abbrevs' use the corresponding
2049 abbreviation (see documentation of this variable for further
2051 13. From every title word not generated by an abbreviation, take
2052 at least `bibtex-autokey-titleword-length' characters (abort
2053 only after a consonant or at a word end).
2054 14. Build the title part of the key by concatenating all
2055 abbreviated title words with the string
2056 `bibtex-autokey-titleword-separator' between any two.
2057 15. At least, to get the key, concatenate
2058 `bibtex-autokey-prefix-string', the name part, the year part
2059 and the title part with `bibtex-autokey-name-year-separator'
2060 between the name part and the year part if both are non-empty
2061 and `bibtex-autokey-year-title-separator' between the year
2062 part and the title part if both are non-empty. If the year
2063 part is empty, but not the other two parts,
2064 `bibtex-autokey-year-title-separator' is used as well.
2065 16. If the value of `bibtex-autokey-before-presentation-function'
2066 is non-nil, it must be a function taking one argument. This
2067 function is then called with the generated key as the
2068 argument. The return value of this function (a string) is
2070 17. If the value of `bibtex-autokey-edit-before-use' is non-nil,
2071 the key is then presented in the minibuffer to the user,
2072 where it can be edited. The key given by the user is then
2074 (let* ((pnt (point))
2075 (min (bibtex-beginning-of-entry))
2076 (max (bibtex-end-of-entry))
2077 (namefield (bibtex-autokey-get-namefield min max
))
2080 (let ((nl (bibtex-autokey-get-namelist namefield
)))
2081 (if (or (not (numberp bibtex-autokey-names
))
2083 (+ bibtex-autokey-names
2084 bibtex-autokey-names-stretch
)))
2086 (setq name-etal bibtex-autokey-additional-names
)
2088 (while (< (length nnl
) bibtex-autokey-names
)
2089 (setq nnl
(append nnl
(list (car nl
)))
2094 (mapconcat (lambda (name) name
)
2096 bibtex-autokey-name-separator
)
2098 (yearfield (bibtex-autokey-get-yearfield min max
))
2100 (if (equal yearfield
"")
2104 (- (length yearfield
) bibtex-autokey-year-length
))))
2105 (titlestring (bibtex-autokey-get-titlestring min max
))
2106 (titlelist (bibtex-autokey-get-titlelist titlestring
))
2109 (lambda (name) name
)
2111 bibtex-autokey-titleword-separator
))
2114 bibtex-autokey-prefix-string
2119 (equal yearpart
"")))
2120 bibtex-autokey-name-year-separator
)
2126 (equal yearpart
""))
2127 (equal titlepart
"")))
2128 bibtex-autokey-year-title-separator
)
2130 (if bibtex-autokey-before-presentation-function
2133 (funcall bibtex-autokey-before-presentation-function autokey
)))
2137 (defun bibtex-parse-keys (add verbose
&optional abortable
)
2138 ;; Sets bibtex-keys to the keys used in the whole (possibly
2139 ;; restricted) buffer (either as entry keys or as crossref entries).
2140 ;; If ADD is non-nil adds the new keys to bibtex-keys instead of
2141 ;; simply resetting it. If VERBOSE is non-nil gives messages about
2142 ;; progress. If ABORTABLE is non-nil abort on user input.
2143 (if bibtex-maintain-sorted-entries
2144 (let ((case-fold-search t
)
2147 "crossref" (concat "[{\"]" bibtex-reference-key
"[}\"]")))
2151 (goto-char (point-min))
2153 (bibtex-progress-message
2154 (concat (buffer-name) ": parsing reference keys")))
2156 (bibtex-skip-to-valid-entry)
2163 (bibtex-progress-message))
2167 ((looking-at bibtex-reference-head
)
2170 (buffer-substring-no-properties
2171 (match-beginning bibtex-key-in-head
)
2172 (match-end bibtex-key-in-head
)))
2174 (m (bibtex-end-of-entry)))
2176 (if (re-search-forward crossref-field m t
)
2179 (buffer-substring-no-properties
2180 (1+ (match-beginning bibtex-text-in-cfield
))
2181 (1- (match-end bibtex-text-in-cfield
)))))
2183 ((looking-at bibtex-string
)
2186 (buffer-substring-no-properties
2187 (match-beginning bibtex-key-in-string
)
2188 (match-end bibtex-key-in-string
)))))
2190 (bibtex-skip-to-valid-entry)
2191 (if (not (assoc label labels
))
2193 (cons (list label
) labels
)))
2195 (not (assoc label2 labels
)))
2197 (cons (list label2
) labels
))))))
2198 ;; user has aborted by typing a key --> return nil
2200 ;; successful operation --> return t
2202 bibtex-buffer-last-parsed-tick
(buffer-modified-tick)
2205 (bibtex-progress-message 'done
))
2208 (defun bibtex-parse-buffers-stealthily ()
2209 ;; Called by bibtex-run-with-idle-timer. Whenever emacs has been idle
2210 ;; for bibtex-parse-keys-timeout seconds, all BibTeX buffers (starting
2211 ;; with the current) are parsed.
2212 (let ((buffers (buffer-list)))
2214 (while (and buffers
(not (input-pending-p)))
2215 (set-buffer (car buffers
))
2219 (eq major-mode
'bibtex-mode
)
2220 bibtex-maintain-sorted-entries
2222 (eq (buffer-modified-tick)
2223 bibtex-buffer-last-parsed-tick
)))
2224 (if (bibtex-parse-keys nil t t
)
2225 ;; successful operation --> remove buffer from list
2226 (setq buffers
(cdr buffers
)))
2227 ;; buffer is no BibTeX buffer or needs no parsing
2228 (setq buffers
(cdr buffers
))))))))
2230 (defun bibtex-complete (string-list &optional complete-strings
)
2231 ;; Complete word fragment before point to longest prefix of one
2232 ;; string defined in STRING-LIST. If point is not after the part of
2233 ;; a word, all strings are listed. If COMPLETE-STRINGS is non-nil,
2234 ;; add the strings defined in this buffer before cursor to
2235 ;; STRING-LIST and remove surrounding delimiters if complete string
2236 ;; could be expanded.
2237 (let* ((case-fold-search t
)
2239 (beg (save-excursion
2240 (re-search-backward "[ \t{\"]")
2243 (part-of-word (buffer-substring-no-properties beg end
))
2244 (completions (copy-sequence string-list
))
2245 (completion (save-excursion
2246 (if complete-strings
2247 (while (re-search-backward
2248 bibtex-string nil t
)
2252 (buffer-substring-no-properties
2253 (match-beginning bibtex-key-in-string
)
2254 (match-end bibtex-key-in-string
)))
2262 (try-completion part-of-word completions
))))
2263 (cond ((eq completion t
)
2264 (if complete-strings
2265 ;; remove double-quotes or braces if field is no concatenation
2267 (bibtex-inside-field)
2268 (bibtex-enclosing-field)
2269 (let ((end (match-end bibtex-text-in-field
)))
2270 (goto-char (match-beginning bibtex-text-in-field
))
2272 (looking-at bibtex-field-string
)
2273 (equal (match-end 0) end
))
2274 (bibtex-remove-delimiters))))))
2276 (error "Can't find completion for \"%s\"" part-of-word
))
2277 ((not (string= part-of-word completion
))
2278 (delete-region beg end
)
2280 (if (and (assoc completion completions
)
2282 ;; remove double-quotes or braces if field is no concatenation
2284 (bibtex-inside-field)
2285 (bibtex-enclosing-field)
2286 (let ((end (match-end bibtex-text-in-field
)))
2287 (goto-char (match-beginning bibtex-text-in-field
))
2289 (looking-at bibtex-field-string
)
2290 (equal (match-end 0) end
))
2291 (bibtex-remove-delimiters))))))
2293 (message "Making completion list...")
2294 (let ((list (all-completions part-of-word completions
)))
2295 (with-output-to-temp-buffer "*Completions*"
2296 (display-completion-list list
)))
2297 (message "Making completion list...done")))))
2299 (defun bibtex-do-auto-fill ()
2302 (+ bibtex-entry-offset bibtex-contline-indentation
) ?
)))
2305 (defun bibtex-pop (arg direction
)
2306 ;; generic function to be used by bibtex-pop-previous and bibtex-pop-next
2307 (let (bibtex-help-message)
2308 (bibtex-find-text nil
))
2310 ;; parse current field
2311 (bibtex-inside-field)
2312 (bibtex-enclosing-field)
2313 (let ((case-fold-search t
)
2314 (start-old-text (match-beginning bibtex-text-in-field
))
2315 (stop-old-text (match-end bibtex-text-in-field
))
2316 (start-name (match-beginning bibtex-name-in-field
))
2317 (stop-name (match-end bibtex-name-in-field
))
2319 (goto-char start-name
)
2320 ;; construct regexp for field with same name as this one,
2321 ;; ignoring possible OPT's or ALT's
2322 (let ((matching-entry
2324 (buffer-substring-no-properties
2325 (if (looking-at "OPT\\|ALT")
2326 (+ (point) (length "OPT"))
2329 bibtex-field-text
)))
2330 ;; if executed several times in a row, start each search where
2331 ;; the last one was finished
2332 (cond ((eq last-command
'bibtex-pop
)
2336 (bibtex-enclosing-reference-maybe-empty-head)
2338 bibtex-pop-previous-search-point
(match-beginning 0)
2339 bibtex-pop-next-search-point
(point))))
2340 (if (eq direction
'previous
)
2341 (goto-char bibtex-pop-previous-search-point
)
2342 (goto-char bibtex-pop-next-search-point
))
2343 ;; Now search for arg'th previous/next similar field
2345 ((if (eq direction
'previous
)
2346 (re-search-backward matching-entry nil t arg
)
2347 (re-search-forward matching-entry nil t arg
))
2348 ;; Found a matching field. Remember boundaries.
2349 (setq bibtex-pop-previous-search-point
(match-beginning 0))
2350 (setq bibtex-pop-next-search-point
(match-end 0))
2352 (buffer-substring-no-properties
2353 (match-beginning bibtex-text-in-field
)
2354 (match-end bibtex-text-in-field
)))
2355 ;; change delimiters, if any changes needed
2361 (if (equal bibtex-field-delimiters
'braces
)
2370 (while (string-match bibtex-field-string new-text start
)
2371 (let ((beg (match-beginning 0))
2372 (end (1- (match-end 0))))
2374 (eq (aref new-text beg
) old-open
)
2375 (eq (aref new-text end
) old-close
))
2377 (aset new-text beg new-open
)
2378 (aset new-text end new-close
))))
2379 (setq start
(match-end 0))))
2381 ;; Go back to where we started, delete old text, and pop new.
2382 (goto-char stop-old-text
)
2383 (delete-region start-old-text stop-old-text
)
2387 (error (concat "No "
2388 (if (eq direction
'previous
)
2391 " matching BibTeX field.")))))))
2392 (let (bibtex-help-message)
2393 (bibtex-find-text nil
))
2394 (setq this-command
'bibtex-pop
))
2397 ;; Interactive Functions:
2400 (defun bibtex-mode ()
2401 "Major mode for editing BibTeX files.
2403 To submit a problem report, enter \\[bibtex-submit-bug-report] from a
2404 BibTeX mode buffer. This automatically sets up a mail buffer with
2405 version information already added. You just need to add a description
2406 of the problem, including a reproducable test case and send the
2410 General information on working with BibTeX mode:
2412 You should use commands as \\[bibtex-Book] to get a template for a
2413 specific entry. You should then fill in all desired fields using
2414 \\[bibtex-next-field] to jump from field to field. After having filled
2415 in all desired fields in the entry, you should clean the new entry
2416 with command \\[bibtex-clean-entry].
2418 Some features of BibTeX mode are available only by setting variable
2419 bibtex-maintain-sorted-entries to t. However, then BibTeX mode will
2420 work with buffer containing only valid (syntactical correct) entries
2421 and with entries being sorted. This is usually the case, if you have
2422 created a buffer completely with BibTeX mode and finished every new
2423 entry with \\[bibtex-clean-entry].
2425 For third party BibTeX buffers, please call the function
2426 `bibtex-convert-alien' to fully take advantage of all features of
2430 Special information:
2432 A command such as \\[bibtex-Book] will outline the fields for a BibTeX book entry.
2434 The optional fields start with the string OPT, and are thus ignored by BibTeX.
2435 Alternatives from which only one is required start with the string ALT.
2436 The OPT or ALT string may be removed from a field with \\[bibtex-remove-OPT-or-ALT].
2437 \\[bibtex-make-field] inserts a new field after the current one.
2438 \\[bibtex-kill-field] kills the current field entirely.
2439 \\[bibtex-yank] will yank the last recently killed field after the
2441 \\[bibtex-remove-delimiters] removes the double-quotes or braces around the text of the current field.
2442 \\[bibtex-empty-field] replaces the text of the current field with the default \"\" or {}.
2444 The command \\[bibtex-clean-entry] cleans the current entry, i.e. it removes OPT/ALT
2445 from all non-empty optional or alternative fields, checks that no required
2446 fields are empty, and does some formatting dependent on the value of
2447 bibtex-entry-format.
2448 Note: some functions in BibTeX mode depend on entries being in a special
2449 format (all fields beginning on separate lines), so it is usually a bad
2450 idea to remove `realign' from bibtex-entry-format.
2452 Use \\[bibtex-find-text] to position the cursor at the end of the current field.
2453 Use \\[bibtex-next-field] to move to end of the next field.
2455 The following may be of interest as well:
2463 bibtex-complete-string
2465 bibtex-print-help-message
2466 bibtex-generate-autokey
2467 bibtex-beginning-of-entry
2469 bibtex-reposition-window
2471 bibtex-ispell-abstract
2473 bibtex-narrow-to-entry
2474 bibtex-hide-entry-bodies
2480 bibtex-convert-alien
2483 bibtex-field-delimiters
2484 bibtex-include-OPTcrossref
2485 bibtex-include-OPTkey
2486 bibtex-user-optional-fields
2488 bibtex-sort-ignore-string-entries
2489 bibtex-maintain-sorted-entries
2490 bibtex-entry-field-alist
2491 bibtex-predefined-strings
2494 ---------------------------------------------------------
2495 Entry to BibTeX mode calls the value of `bibtex-mode-hook' if that value is
2498 \\{bibtex-mode-map}"
2500 (kill-all-local-variables)
2501 (use-local-map bibtex-mode-map
)
2502 (setq major-mode
'bibtex-mode
)
2503 (setq mode-name
"BibTeX")
2504 (set-syntax-table bibtex-mode-syntax-table
)
2505 (setq bibtex-strings bibtex-predefined-strings
)
2508 ;; collect pathnames
2509 (let* ((path (if bibtex-string-file-path
2510 bibtex-string-file-path
2514 (lambda (dirname) ;; strips off trailing slashes
2515 (let ((len (length dirname
)))
2516 (if (equal (elt dirname
(1- len
)) "/")
2517 (substring dirname
0 (1- (1- len
)))
2520 (while (string-match ":" path
)
2523 (list (substring path
0 (1- (match-end 0)))))
2524 path
(substring path
(match-end 0))))
2525 (append actdirs
(list path
)))))
2526 (filename (if (string-match "\.bib$" filename
)
2528 (concat filename
".bib")))
2531 (size (length dirs
)))
2535 (not (file-readable-p
2537 (concat (elt dirs item
) "/" filename
)))))
2538 (setq item
(1+ item
)))
2541 (let ((case-fold-search t
)
2542 (curbuf (current-buffer))
2543 (bufname (make-temp-name ""))
2544 (compl bibtex-strings
))
2545 (create-file-buffer bufname
)
2546 (set-buffer bufname
)
2547 (insert-file-contents fullfilename
)
2548 (goto-char (point-min))
2549 (while (re-search-forward bibtex-string nil t
)
2553 (list (buffer-substring-no-properties
2554 (match-beginning bibtex-key-in-string
)
2555 (match-end bibtex-key-in-string
)))))))
2556 (kill-buffer bufname
)
2558 (setq bibtex-strings compl
))
2560 "File %s not in paths defined by bibtex-string-file-path variable"
2562 bibtex-string-files
)
2563 (if bibtex-maintain-sorted-entries
2564 (bibtex-run-with-idle-timer
2567 (bibtex-parse-keys nil t t
))))
2568 ;; to get buffer parsed once if everything else (including things
2569 ;; installed in bibtex-mode-hook) has done its work
2570 (if (not bibtex-parse-idle-timer
)
2571 (setq bibtex-parse-idle-timer
2572 (bibtex-run-with-idle-timer
2573 bibtex-parse-keys-timeout t
2574 'bibtex-parse-buffers-stealthily
)))
2575 ;; Install stealthy parse function if not already installed
2576 (set (make-local-variable 'paragraph-start
) "[ \f\n\t]*$")
2577 (set (make-local-variable 'comment-start
) bibtex-comment-start
)
2578 (set (make-local-variable 'comment-start-skip
) bibtex-comment-start
)
2579 (set (make-local-variable 'comment-column
) 0)
2580 (set (make-local-variable 'normal-auto-fill-function
)
2581 'bibtex-do-auto-fill
)
2582 (set (make-local-variable 'font-lock-defaults
)
2583 '(bibtex-font-lock-keywords
2585 ;; Mathematical expressions should be fontified as strings
2587 ;; Quotes are field delimiters and quote-delimited
2588 ;; entries should be fontified in the same way as
2589 ;; brace-delimited ones
2591 (setq font-lock-mark-block-function
2593 (set-mark (bibtex-end-of-entry))
2594 (bibtex-beginning-of-entry)))
2595 (setq imenu-generic-expression
2596 (list (list nil bibtex-reference-head bibtex-key-in-head
)))
2597 (setq imenu-case-fold-search t
)
2598 ;; XEmacs needs easy-menu-add, Emacs does not care
2599 (easy-menu-add bibtex-edit-menu
)
2600 (easy-menu-add bibtex-entry-menu
)
2601 (run-hooks 'bibtex-mode-hook
))
2603 (defun bibtex-submit-bug-report ()
2604 "Submit via mail a bug report on bibtex.el."
2606 (if (y-or-n-p "Do you want to submit a bug report on BibTeX mode? ")
2609 (let ((reporter-prompt-for-summary-p t
))
2610 (reporter-submit-bug-report
2611 bibtex-maintainer-address
2612 (concat "bibtex.el " "(emacs 19.35)")
2614 'system-configuration
2615 'system-configuration-options
2617 'bibtex-parse-keys-timeout
2618 ;; possible general errors
2619 'bibtex-sort-ignore-string-entries
2620 'bibtex-maintain-sorted-entries
2621 'bibtex-entry-delimiters
2622 'bibtex-field-delimiters
2623 'bibtex-comma-after-last-field
2624 'bibtex-entry-offset
2625 'bibtex-field-indentation
2626 'bibtex-text-indentation
2627 'bibtex-contline-indentation
2628 'bibtex-align-at-equal-sign
2629 ;; possible sorting and parsing bugs
2630 'bibtex-entry-format
2631 'bibtex-add-entry-hook
2632 'bibtex-clean-entry-hook
2633 ;; possible cleaning error
2634 'bibtex-user-optional-fields
2635 ;; possible format error
2636 'bibtex-predefined-month-strings
2637 'bibtex-predefined-strings
2638 'bibtex-string-files
2639 'bibtex-string-file-path
2640 ;; possible format error
2641 'bibtex-font-lock-keywords
2642 ;; possible bugs regarding fontlocking
2643 'bibtex-autokey-prefix-string
2644 'bibtex-autokey-names
2645 'bibtex-autokey-names-stretch
2646 'bibtex-autokey-additional-names
2647 'bibtex-autokey-transcriptions
2648 'bibtex-autokey-name-change-strings
2649 'bibtex-autokey-name-case-convert
2650 'bibtex-autokey-name-length
2651 'bibtex-autokey-name-separator
2652 'bibtex-autokey-year-length
2653 'bibtex-autokey-year-use-crossref-entry
2654 'bibtex-autokey-titlewords
2655 'bibtex-autokey-title-terminators
2656 'bibtex-autokey-titlewords-stretch
2657 'bibtex-autokey-titleword-ignore
2658 'bibtex-autokey-titleword-case-convert
2659 'bibtex-autokey-titleword-abbrevs
2660 'bibtex-autokey-titleword-change-strings
2661 'bibtex-autokey-titleword-length
2662 'bibtex-autokey-titleword-separator
2663 'bibtex-autokey-name-year-separator
2664 'bibtex-autokey-year-title-separator
2665 'bibtex-autokey-edit-before-use
2666 'bibtex-autokey-before-presentation-function
2667 ;; possible bugs regarding automatic labels
2668 'bibtex-entry-field-alist
2669 ;; possible format error
2670 'bibtex-help-message
2671 'bibtex-include-OPTcrossref
2672 'bibtex-include-OPTkey
2673 'bibtex-field-kill-ring-max
2674 'bibtex-entry-kill-ring-max
2675 ;; user variables which shouldn't cause any errors
2678 (concat "To the bibtex.el maintainer:
2680 I want to report a bug on Emacs BibTeX mode.
2681 I've read the `Bugs' section in the `Emacs' info page, so I know how
2682 to make a clear and unambiguous report. I have started a fresh Emacs
2683 via `"invocation-name
" --no-init-file --no-site-file', thereafter (in
2684 case I'm reporting on a version of `bibtex.el' which is not part of
2685 the standard emacs distribution) I loaded the questionable version
2686 of `bibtex.el' with `M-x load-file', and then, to produce the buggy
2687 behaviour, I did the following:")))
2690 (defun bibtex-entry (entry-type)
2691 "Insert a new BibTeX entry.
2692 After insertion it calls the functions in `bibtex-add-entry-hook'."
2693 (interactive (let* ((completion-ignore-case t
)
2694 (e-t (completing-read
2696 bibtex-entry-field-alist
2697 nil t nil
'bibtex-entry-type-history
)))
2699 (if (not bibtex-keys
)
2700 (bibtex-parse-keys nil t
))
2704 (if bibtex-maintain-sorted-entries
2706 (format "%s key: " entry-type
)
2707 bibtex-keys nil nil nil
'bibtex-key-history
)))
2708 (e (assoc-ignore-case entry-type bibtex-entry-field-alist
))
2712 (error "Bibtex entry type %s not defined" entry-type
))
2714 (member entry-type bibtex-include-OPTcrossref
)
2716 (setq required
(elt c-ref
0)
2717 optional
(elt c-ref
1))
2718 (setq required
(elt r-n-o
0)
2719 optional
(elt r-n-o
1)))
2720 (if bibtex-maintain-sorted-entries
2721 (bibtex-find-entry-location key
)
2722 (bibtex-move-outside-of-entry))
2723 (indent-to-column bibtex-entry-offset
)
2724 (insert "@" entry-type
(bibtex-entry-left-delimiter))
2728 (mapcar 'bibtex-make-field required
)
2729 (if (member entry-type bibtex-include-OPTcrossref
)
2730 (bibtex-make-optional-field '("crossref")))
2731 (if bibtex-include-OPTkey
2733 (stringp bibtex-include-OPTkey
)
2734 (fboundp bibtex-include-OPTkey
))
2735 (bibtex-make-optional-field
2736 (list "key" nil bibtex-include-OPTkey
))
2737 (bibtex-make-optional-field '("key"))))
2738 (mapcar 'bibtex-make-optional-field optional
)
2739 (mapcar 'bibtex-make-optional-field bibtex-user-optional-fields
)
2740 (if bibtex-comma-after-last-field
2743 (indent-to-column bibtex-entry-offset
)
2744 (insert (bibtex-entry-right-delimiter) "\n\n"))
2745 (bibtex-next-field t
)
2746 (run-hooks 'bibtex-add-entry-hook
)))
2748 (defun bibtex-print-help-message ()
2749 "Prints helpful information about current field in current BibTeX entry."
2751 (let* ((case-fold-search t
)
2755 (condition-case errname
2756 (bibtex-enclosing-field)
2759 (error "Not on BibTeX field")))
2760 (let ((mb (match-beginning bibtex-name-in-field
))
2761 (me (match-end bibtex-name-in-field
)))
2763 (buffer-substring-no-properties
2764 (if (looking-at "OPT\\|ALT")
2771 bibtex-reference-maybe-empty-head nil t
)
2772 (buffer-substring-no-properties
2773 (1+ (match-beginning bibtex-type-in-head
))
2774 (match-end bibtex-type-in-head
))))
2776 (assoc-ignore-case reference-type
2777 bibtex-entry-field-alist
))
2778 (c-r-list (elt entry-list
2))
2781 (member reference-type bibtex-include-OPTcrossref
)
2784 (elt entry-list
1)))
2785 (list-of-entries (append
2786 (elt req-opt-list
0)
2787 (elt req-opt-list
1)
2788 bibtex-user-optional-fields
2791 bibtex-include-OPTcrossref
)
2793 "Label of the crossreferenced entry")))
2794 (if bibtex-include-OPTkey
2796 "Key used for label creation if author and editor fields are missing"))))))
2798 (let ((comment (assoc-ignore-case field-name list-of-entries
)))
2800 (message (elt comment
1))
2801 (message "NO COMMENT AVAILABLE")))))
2803 (defun bibtex-make-field (e-t &optional called-by-yank
)
2804 "Makes a field named E-T in current BibTeX entry.
2805 This function is for interactive and non-interactive purposes. To call
2806 it interactively, just give it no arguments and enter the field name
2807 using the minibuffer."
2812 (let* ((reference-type
2814 (bibtex-enclosing-reference-maybe-empty-head)
2815 (buffer-substring-no-properties
2816 (1+ (match-beginning bibtex-type-in-head
))
2817 (match-end bibtex-type-in-head
))))
2819 (car (cdr (assoc-ignore-case
2820 reference-type bibtex-entry-field-alist
))))
2823 (elt fl
0) (elt fl
1) bibtex-user-optional-fields
2824 (if bibtex-include-OPTcrossref
'(("crossref" nil
)))
2825 (if bibtex-include-OPTkey
'(("key" nil
)))))
2826 (completion-ignore-case t
))
2828 "BibTeX field name: " field-list
2829 nil nil nil bibtex-field-history
))))
2830 (if (not (consp e-t
))
2831 (setq e-t
(list e-t
)))
2832 (if (equal (length e-t
) 1)
2833 (setq e-t
(append e-t
(list ""))))
2834 (if (equal (length e-t
) 2)
2835 (setq e-t
(append e-t
(list ""))))
2836 (let ((name (if (elt e-t
3)
2837 (concat "ALT" (car e-t
))
2839 (if (or (interactive-p) called-by-yank
)
2840 (let (bibtex-help-message)
2841 (bibtex-find-text nil t
)
2842 (if (looking-at "[}\"]")
2846 (+ bibtex-entry-offset bibtex-field-indentation
))
2848 (if bibtex-align-at-equal-sign
2850 (+ bibtex-entry-offset
(- bibtex-text-indentation
2))))
2852 (if (not bibtex-align-at-equal-sign
)
2854 (+ bibtex-entry-offset bibtex-text-indentation
)))
2855 (insert (if called-by-yank
2857 (bibtex-field-left-delimiter))
2858 (let ((init (elt e-t
2)))
2865 (error "%s is neither a string nor a function" init
))))
2868 (bibtex-field-right-delimiter)))
2870 (forward-char -
1))))
2872 (defun bibtex-beginning-of-entry ()
2873 "Move to beginning of BibTeX entry.
2874 If inside an entry, move to the beginning of it, otherwise move to the
2875 beginning of the previous entry.
2876 If called from a program, this function returns the new location of point."
2878 (skip-chars-forward " \t")
2879 (if (looking-at "@")
2881 (re-search-backward "^[ \t]*@" nil
'move
))
2883 (defun bibtex-end-of-entry ()
2884 "Move to end of BibTeX entry.
2885 If inside an entry, move to the end of it, otherwise move to the end
2886 of the previous entry.
2887 If called from a program, this function returns the new location of point."
2889 (let ((case-fold-search t
)
2891 (concat "[ \t]*@[ \t]*\\("
2894 (concat "\\(" (car type
) "\\)"))
2895 bibtex-entry-field-alist
2899 (pnt (bibtex-beginning-of-entry))
2902 ((looking-at "[ \t]*@[ \t]*string[ \t\n]*[({]")
2904 (re-search-forward bibtex-string nil t
)
2905 (equal (match-beginning 0) pnt
)))
2907 ((looking-at "[ \t]*@[ \t]*preamble[ \t\n]*")
2908 (goto-char (match-end 0))
2911 (if (not (re-search-forward ")[ \t]*\n\n" nil
'move
))
2914 (if (not (re-search-forward "}[ \t]*\n\n" nil
'move
))
2920 (goto-char (match-beginning 0))
2922 ((looking-at valid-entry-head
)
2923 (bibtex-search-reference t nil t
)
2924 (if (not (equal (match-beginning 0) pnt
))
2928 (message "Not on a known BibTeX entry."))
2933 (error "Syntactical incorrect entry starts here"))))
2936 (defun bibtex-reposition-window (arg)
2937 "Make the current BibTeX entry visible."
2941 (/ (+ (bibtex-beginning-of-entry) (bibtex-end-of-entry)) 2))
2944 (defun bibtex-mark-entry ()
2945 "Put mark at beginning, point at end of current BibTeX entry."
2947 (set-mark (bibtex-beginning-of-entry))
2948 (bibtex-end-of-entry))
2950 (defun bibtex-count-entries (&optional count-string-entries
)
2951 "Count number of entries in current buffer or region.
2952 With prefix argument COUNT-STRING-ENTRIES it counts all entries,
2953 otherwise it counts all except Strings.
2954 If mark is active it counts entries in region, if not in whole buffer."
2958 (if (bibtex-mark-active)
2960 (bibtex-beginning-of-first-entry)))
2962 (if (bibtex-mark-active)
2966 (bibtex-sort-ignore-string-entries
2967 (not count-string-entries
)))
2969 (narrow-to-region start-point end-point
)
2970 (goto-char start-point
)
2973 (setq number
(1+ number
)))))
2974 (message (concat (if (bibtex-mark-active) "Region" "Buffer")
2975 " contains %d entries.") number
)
2978 (defun bibtex-ispell-entry ()
2979 "Spell whole BibTeX entry."
2981 (ispell-region (bibtex-beginning-of-entry) (bibtex-end-of-entry)))
2983 (defun bibtex-ispell-abstract ()
2984 "Spell abstract of BibTeX entry."
2986 (let ((case-fold-search t
)
2987 (pnt (bibtex-end-of-entry)))
2988 (bibtex-beginning-of-entry)
2991 (bibtex-cfield "abstract" bibtex-field-text
) pnt t
))
2992 (error "No abstract in entry")))
2993 (ispell-region (match-beginning bibtex-text-in-cfield
)
2994 (match-end bibtex-text-in-cfield
)))
2996 (defun bibtex-narrow-to-entry ()
2997 "Narrow buffer to current BibTeX entry."
3001 (bibtex-beginning-of-entry) (bibtex-end-of-entry))))
3003 (defun bibtex-hide-entry-bodies (&optional arg
)
3004 "Hide all lines between first and last BibTeX entries not beginning with @.
3005 With prefix argument ARG, show all text."
3008 (let ((buffer-read-only nil
))
3010 (subst-char-in-region (point-min) (point-max) ?
\r ?
\n t
)
3011 (let ((pos (point-max)))
3012 (goto-char (point-max))
3013 (while (re-search-backward "^@" nil t
)
3014 (subst-char-in-region (point) pos ?
\n ?
\r t
)
3015 (if (not (bobp)) (forward-char -
1))
3016 (setq pos
(point)))))
3017 (setq selective-display
(not arg
)))))
3019 (defun bibtex-sort-buffer ()
3020 "Sort BibTeX buffer alphabetically by key.
3021 Text outside of BibTeX entries is not affected. If
3022 `bibtex-sort-ignore-string-entries' is non-nil, @String entries will be
3027 (bibtex-beginning-of-first-entry)
3029 (goto-char (point-max))
3030 (bibtex-end-of-entry)))
3031 (bibtex-skip-to-valid-entry)
3035 'bibtex-skip-to-valid-entry
3037 'bibtex-end-of-entry
3038 ;; STARTKEY function
3040 (let ((case-fold-search t
))
3041 (re-search-forward bibtex-reference-head
)
3042 (buffer-substring-no-properties
3043 (match-beginning bibtex-key-in-head
)
3044 (match-end bibtex-key-in-head
)))))))
3046 (defun bibtex-find-entry-location (entry-name &optional ignore-dups
)
3047 "Looking for place to put the BibTeX entry named ENTRY-NAME.
3048 Performs a binary search (therefore, buffer is assumed to be in sorted
3049 order, without duplicates (see \\[bibtex-validate]), if it is
3050 not, `bibtex-find-entry-location' will fail). If entry-name is already
3051 used as a reference key, an error is signaled. However, if optional
3052 variable IGNORE-DUPS is non-nil, no error messages about duplicate
3053 entries are signaled, but the error handling is assumed to be made in
3054 the calling function.
3055 The value is nil if an duplicate entry error occurred,
3056 and t in all other cases."
3057 (let* ((case-fold-search t
)
3060 (bibtex-beginning-of-first-entry)
3061 (bibtex-skip-to-valid-entry)
3062 (bibtex-end-of-entry)))
3065 (bibtex-beginning-of-last-entry)
3066 (bibtex-skip-to-valid-entry t
)
3070 (done (>= left right
))
3074 (setq actual-point
(/ (+ left right
) 2))
3075 (goto-char actual-point
)
3076 (bibtex-skip-to-valid-entry t
)
3079 (re-search-forward bibtex-reference-head
)
3080 (buffer-substring-no-properties
3081 (match-beginning bibtex-key-in-head
)
3082 (match-end bibtex-key-in-head
))))
3084 ((string-lessp entry-name actual-key
)
3085 (setq new
(bibtex-beginning-of-entry))
3086 (if (equal right new
)
3089 ((string-lessp actual-key entry-name
)
3090 (setq new
(bibtex-end-of-entry))
3091 (if (equal left new
)
3094 ((string-equal actual-key entry-name
)
3097 (if (not ignore-dups
)
3099 (bibtex-beginning-of-entry)
3100 (error "Entry with key `%s' already exists" entry-name
))))))
3103 (bibtex-beginning-of-entry)
3107 (if (looking-at bibtex-reference-head
)
3108 (buffer-substring-no-properties
3109 (match-beginning bibtex-key-in-reference
)
3110 (match-end bibtex-key-in-reference
))))
3113 (string-lessp actual-key entry-name
))
3114 ;; buffer contains no valid entries or
3115 ;; greater than last entry --> append
3117 (bibtex-end-of-entry)
3119 (newline (forward-line 2)))
3120 (beginning-of-line))
3124 (defun bibtex-validate (&optional test-thoroughly
)
3125 "Validate if buffer or region is syntactically correct.
3126 Only known reference types are checked, so you can put comments
3128 With optional argument TEST-THOROUGHLY non-nil it checks for absence of
3129 required fields and questionable month fields as well.
3130 If mark is active, it validates current region, if not whole buffer.
3131 Returns t if test was successful, nil otherwise."
3135 (case-fold-search t
)
3138 "@[ \t]*\\(\\(string\\)\\|"
3141 (concat "\\(" (car type
) "\\)"))
3142 bibtex-entry-field-alist
3147 (if (bibtex-mark-active)
3149 (bibtex-beginning-of-first-entry)))
3151 (if (bibtex-mark-active)
3155 (narrow-to-region start-point end-point
)
3156 ;; looking if entries fit syntactical structure
3157 (goto-char start-point
)
3158 (bibtex-progress-message "Checking syntactical structure")
3159 (while (re-search-forward "^[ \t]*@" nil t
)
3160 (bibtex-progress-message)
3164 (looking-at valid-bibtex-entry
)))
3165 (if (not must-match
)
3167 (let (bibtex-sort-ignore-string-entries)
3168 (bibtex-skip-to-valid-entry))
3169 (if (equal (point) p
)
3175 (bibtex-current-line)
3176 "Syntax error (check esp. commas, braces, and quotes)")
3179 (bibtex-progress-message 'done
)
3181 (setq syntax-error t
)
3182 ;; looking for correct sort order and duplicates (only if
3183 ;; there were no syntax errors)
3184 (if bibtex-maintain-sorted-entries
3186 (goto-char start-point
)
3187 (bibtex-progress-message "Checking correct sort order")
3190 (bibtex-progress-message)
3191 (cond ((or (not previous
)
3192 (string< previous current
))
3193 (setq previous current
))
3194 ((string-equal previous current
)
3197 (cons (list (bibtex-current-line)
3198 "Duplicate key with previous")
3201 (setq previous current
3203 (cons (list (bibtex-current-line)
3204 "Entries out of order")
3206 (bibtex-progress-message 'done
)))
3209 (goto-char start-point
)
3210 (bibtex-progress-message
3211 "Checking required fields and month fields")
3212 (let ((bibtex-sort-ignore-string-entries t
)
3218 (concat "\\(" (car mon
) "\\)"))
3219 bibtex-predefined-month-strings
3224 (bibtex-progress-message)
3225 (let* ((beg (bibtex-beginning-of-entry))
3226 (end (bibtex-end-of-entry))
3230 (bibtex-search-reference nil end
)
3232 (buffer-substring-no-properties
3233 (1+ (match-beginning bibtex-type-in-head
))
3234 (match-end bibtex-type-in-head
))
3235 bibtex-entry-field-alist
)))
3236 (req (copy-sequence (elt (elt entry-list
1) 0)))
3237 (creq (copy-sequence (elt (elt entry-list
2) 0)))
3240 (while (re-search-forward bibtex-field end t
)
3242 (buffer-substring-no-properties
3243 (match-beginning bibtex-name-in-field
)
3244 (match-end bibtex-name-in-field
))))
3245 (if (and (equal (downcase field-name
) "month")
3248 (buffer-substring-no-properties
3249 (match-beginning bibtex-text-in-field
)
3250 (match-end bibtex-text-in-field
))))
3255 (bibtex-current-line)
3256 "Questionable month field (delimited string)")
3260 (delete (assoc-ignore-case field-name req
) req
)
3262 (delete (assoc-ignore-case field-name creq
) creq
))
3263 (if (equal (downcase field-name
) "crossref")
3264 (setq crossref-there t
))))
3267 (if (or (> (length req
) 1)
3268 (and (= (length req
) 1)
3269 (not (elt (car req
) 3))))
3270 ;; two (or more) fields missed or one field
3271 ;; missed and this isn't flagged alternative
3272 ;; (notice that this fails if there are more
3273 ;; than two alternatives in a BibTeX entry,
3274 ;; which isn't the case momentarily)
3278 (list (save-excursion
3279 (bibtex-beginning-of-entry)
3280 (bibtex-current-line))
3286 (bibtex-progress-message 'done
)))))
3289 (let ((bufnam (buffer-name))
3290 (dir default-directory
))
3294 (< (car a
) (car b
)))))
3295 (let ((pop-up-windows t
))
3296 (pop-to-buffer nil t
))
3298 (get-buffer-create "*BibTeX validation errors*") t
)
3299 ;; don't use switch-to-buffer-other-window, since this
3300 ;; doesn't allow the second parameter NORECORD
3301 (setq default-directory dir
)
3302 (toggle-read-only -
1)
3304 (delete-region (point-min) (point-max))
3305 (goto-char (point-min))
3307 "BibTeX mode command `bibtex-validate'\n"
3309 "Maybe undetected errors due to syntax errors. Correct and validate again."
3314 bufnam
":" (number-to-string (elt (car error-list
) 0))
3315 ": " (elt (car error-list
) 1) "\n")
3316 (setq error-list
(cdr error-list
)))
3317 (compilation-parse-errors nil nil
)
3318 (setq compilation-old-error-list compilation-error-list
)
3319 ;; this is necessary to avoid reparsing of buffer if you
3320 ;; switch to compilation buffer and enter
3321 ;; `compile-goto-error'
3322 (set-buffer-modified-p nil
)
3323 (toggle-read-only 1)
3324 (goto-char (point-min))
3328 (if (bibtex-mark-active)
3329 (message "Region is syntactically correct")
3330 (message "Buffer is syntactically correct"))
3333 (defun bibtex-next-field (arg)
3334 "Finds end of text of next BibTeX field; with ARG, to its beginning."
3336 (bibtex-inside-field)
3337 (let ((start (point)))
3340 (bibtex-enclosing-field)
3341 (goto-char (match-end 0))
3347 (bibtex-find-text arg t
))
3349 (defun bibtex-find-text (arg &optional as-if-interactive silent
)
3350 "Go to end of text of current field; with ARG, go to beginning."
3352 (bibtex-inside-field)
3353 (if (bibtex-enclosing-field (or (interactive-p) as-if-interactive
))
3357 (goto-char (match-beginning bibtex-text-in-field
))
3358 (if (looking-at "[{\"]")
3360 (goto-char (match-end bibtex-text-in-field
))
3362 (= (preceding-char) ?
})
3363 (= (preceding-char) ?
\"))
3365 (if bibtex-help-message
3366 (bibtex-print-help-message)))
3369 ((looking-at bibtex-string
)
3372 (match-beginning bibtex-text-in-string
)
3373 (match-end bibtex-text-in-string
))))
3374 ((looking-at bibtex-reference-maybe-empty-head
)
3377 (match-beginning bibtex-key-in-head
)
3381 (error "Not on BibTeX field"))))))
3383 (defun bibtex-remove-OPT-or-ALT ()
3384 "Removes the string starting optional/alternative fields.
3385 Aligns text and goes thereafter to end of text."
3387 (let ((case-fold-search t
))
3388 (bibtex-inside-field)
3389 (bibtex-enclosing-field)
3391 (goto-char (match-beginning bibtex-name-in-field
))
3392 (if (looking-at "OPT\\|ALT")
3394 (delete-char (length "OPT"))
3395 ;; make field non-OPT
3396 (search-forward "=")
3398 (delete-horizontal-space)
3399 (if bibtex-align-at-equal-sign
3400 (indent-to-column (- bibtex-text-indentation
2))
3402 (search-forward "=")
3403 (delete-horizontal-space)
3404 (if bibtex-align-at-equal-sign
3406 (indent-to-column bibtex-text-indentation
)))))
3407 (bibtex-inside-field)))
3409 (defun bibtex-remove-delimiters ()
3410 "Removes \"\" or {} around string."
3412 (let ((case-fold-search t
))
3414 (bibtex-inside-field)
3415 (bibtex-enclosing-field)
3416 (let ((start (match-beginning bibtex-text-in-field
))
3417 (stop (match-end bibtex-text-in-field
)))
3419 (while (re-search-forward bibtex-field-string stop t
)
3420 (let ((beg (copy-marker (match-beginning 0)))
3421 (end (copy-marker (match-end 0))))
3423 (if (looking-at "[{\"]")
3427 (if (looking-at "[}\"]")
3428 (delete-char 1))))))))
3430 (defun bibtex-kill-field (&optional copy-only
)
3431 "Kills the entire enclosing BibTeX field.
3432 With prefix arg COPY-ONLY, copy the current field to `bibtex-field-kill-ring,'
3433 but do not actually kill it."
3436 (case-fold-search t
))
3437 (bibtex-inside-field)
3438 (bibtex-enclosing-field)
3439 (let ((the-end (match-end 0))
3440 (the-beginning (match-beginning 0)))
3442 (skip-chars-forward " \t\n,")
3444 bibtex-field-kill-ring
3448 (buffer-substring-no-properties
3449 (match-beginning bibtex-name-in-field
)
3450 (match-end bibtex-name-in-field
))
3451 (buffer-substring-no-properties
3452 (match-beginning bibtex-text-in-field
)
3453 (match-end bibtex-text-in-field
)))
3454 bibtex-field-kill-ring
))
3455 (if (> (length bibtex-field-kill-ring
) bibtex-field-kill-ring-max
)
3457 (nthcdr (1- bibtex-field-kill-ring-max
) bibtex-field-kill-ring
)
3459 (setq bibtex-field-kill-ring-yank-pointer bibtex-field-kill-ring
)
3462 (delete-region the-beginning the-end
)
3463 (let (bibtex-help-message)
3464 (bibtex-find-text nil t t
)))))
3465 (setq bibtex-last-kill-command
'field
))
3467 (defun bibtex-copy-field-as-kill ()
3469 (bibtex-kill-field t
))
3471 (defun bibtex-kill-entry (&optional copy-only
)
3472 "Kill the entire enclosing BibTeX reference entry.
3473 With prefix arg COPY-ONLY the current reference entry to
3474 `bibtex-entry-kill-ring', but do not actually kill it."
3477 (case-fold-search t
)
3478 (beg (bibtex-beginning-of-entry))
3481 (bibtex-end-of-entry)
3482 (if (re-search-forward
3483 bibtex-reference-maybe-empty-head nil
'move
)
3484 (goto-char (match-beginning 0)))
3487 bibtex-entry-kill-ring
3489 (list 'entry
(buffer-substring-no-properties beg end
))
3490 bibtex-entry-kill-ring
))
3491 (if (> (length bibtex-entry-kill-ring
) bibtex-entry-kill-ring-max
)
3493 (nthcdr (1- bibtex-entry-kill-ring-max
) bibtex-entry-kill-ring
)
3495 (setq bibtex-entry-kill-ring-yank-pointer bibtex-entry-kill-ring
)
3498 (delete-region beg end
)))
3499 (setq bibtex-last-kill-command
'entry
))
3501 (defun bibtex-copy-entry-as-kill ()
3503 (bibtex-kill-entry t
))
3505 (defun bibtex-yank (&optional n
)
3506 "Reinsert the last BibTeX item.
3507 More precisely, reinsert the field or entry killed or yanked most recently.
3508 With argument N, reinsert the Nth most recently killed BibTeX item.
3509 See also the command \\[bibtex-yank-pop]]."
3511 (bibtex-insert-current-kill (1- n
))
3512 (setq this-command
'bibtex-yank
))
3514 (defun bibtex-yank-pop (n)
3515 "Replace just-yanked killed BibTeX item with a different.
3516 This command is allowed only immediately after a `bibtex-yank' or a
3518 At such a time, the region contains a reinserted previously killed
3519 BibTeX item. `bibtex-yank-pop' deletes that item and inserts in its
3520 place a different killed BibTeX item.
3522 With no argument, the previous kill is inserted.
3523 With argument N, insert the Nth previous kill.
3524 If N is negative, this is a more recent kill.
3526 The sequence of kills wraps around, so that after the oldest one
3527 comes the newest one."
3529 (if (not (eq last-command
'bibtex-yank
))
3530 (error "Previous command was not a BibTeX yank"))
3531 (setq this-command
'bibtex-yank
)
3532 (let ((inhibit-read-only t
))
3533 (delete-region (point) (mark t
))
3534 (bibtex-insert-current-kill n
)))
3536 (defun bibtex-empty-field ()
3537 "Delete the text part of the current field, replace with empty text."
3539 (bibtex-inside-field)
3540 (bibtex-enclosing-field)
3541 (goto-char (match-beginning bibtex-text-in-field
))
3542 (delete-region (point) (match-end bibtex-text-in-field
))
3543 (insert (concat (bibtex-field-left-delimiter)
3544 (bibtex-field-right-delimiter)) )
3545 (bibtex-find-text t
))
3547 (defun bibtex-pop-previous (arg)
3548 "Replace text of current field with the similar field in previous entry.
3549 With arg, goes up ARG entries. Repeated, goes up so many times. May be
3550 intermixed with \\[bibtex-pop-next] (bibtex-pop-next)."
3552 (bibtex-pop arg
'previous
))
3554 (defun bibtex-pop-next (arg)
3555 "Replace text of current field with the text of similar field in next entry.
3556 With arg, goes down ARG entries. Repeated, goes down so many times. May be
3557 intermixed with \\[bibtex-pop-previous] (bibtex-pop-previous)."
3559 (bibtex-pop arg
'next
))
3561 (defun bibtex-clean-entry (&optional new-label called-by-reformat
)
3562 "Finish editing the current BibTeX entry and clean it up.
3563 Checks that no required fields are empty and formats entry dependent
3564 on the value of bibtex-entry-format.
3565 If label of entry is empty or a prefix argument is given, calculate a
3566 new entry label (note: this only will work if fields in entry begin on
3567 separate lines prior to calling bibtex-clean-entry or if 'realign is
3568 contained in bibtex-entry-format).
3569 Don't call this on `string' or `preamble' entries.
3570 At end of the cleaning process, the functions in
3571 bibtex-clean-entry-hook are called with region narrowed to entry."
3573 (bibtex-format-entry)
3574 (let* ((case-fold-search t
)
3575 (eob (bibtex-end-of-entry))
3577 (bibtex-beginning-of-entry)
3578 (if (re-search-forward
3579 bibtex-reference-head eob t
)
3580 (buffer-substring-no-properties
3581 (match-beginning bibtex-key-in-head
)
3582 (match-end bibtex-key-in-head
))))))
3588 (if bibtex-autokey-edit-before-use
3589 (read-from-minibuffer
3590 "Key to use: " (bibtex-generate-autokey) nil nil
3591 'bibtex-key-history
)
3592 (bibtex-generate-autokey))))
3593 (bibtex-beginning-of-entry)
3594 (re-search-forward bibtex-reference-maybe-empty-head
)
3595 (if (match-beginning bibtex-key-in-head
)
3596 (delete-region (match-beginning bibtex-key-in-head
)
3597 (match-end bibtex-key-in-head
)))
3599 (let* ((start (bibtex-beginning-of-entry))
3601 (bibtex-end-of-entry)
3602 (if (re-search-forward
3603 bibtex-reference-maybe-empty-head nil
'move
)
3604 (goto-char (match-beginning 0)))
3606 (entry (buffer-substring start end
)))
3607 (delete-region start end
)
3611 (not bibtex-maintain-sorted-entries
)
3612 (bibtex-find-entry-location autokey t
))))
3615 (bibtex-beginning-of-entry)
3616 (re-search-forward bibtex-reference-head
)
3619 "New inserted reference yields duplicate key"))))))))
3620 (if (not called-by-reformat
)
3624 (bibtex-beginning-of-entry) (bibtex-end-of-entry))
3625 (bibtex-parse-keys t nil
)
3626 (run-hooks 'bibtex-clean-entry-hook
)))))
3628 (defun bibtex-fill-entry ()
3629 "Fill current entry.
3630 Realigns entry, so that every field starts on a separate line. Field
3631 names appear in column `bibtex-field-indentation', field text starts in
3632 column `bibtex-text-indentation' and continuation lines start here, too.
3633 If `bibtex-align-at-equal-sign' is non-nil, align equal signs also."
3635 (let ((pnt (copy-marker (point)))
3636 (end (copy-marker (bibtex-end-of-entry))))
3637 (bibtex-beginning-of-entry)
3638 (bibtex-delete-whitespace)
3639 (indent-to-column bibtex-entry-offset
)
3640 (while (re-search-forward bibtex-field end t
)
3642 (copy-marker (match-beginning 0)))
3644 (copy-marker (match-end 0)))
3646 (copy-marker (match-beginning bibtex-name-in-field
)))
3648 (copy-marker (match-end bibtex-name-in-field
))))
3649 (goto-char begin-field
)
3651 (bibtex-delete-whitespace)
3655 (+ bibtex-entry-offset bibtex-field-indentation
))
3656 (re-search-forward "[ \t\n]*=" end
)
3659 (if bibtex-align-at-equal-sign
3661 (+ bibtex-entry-offset
(- bibtex-text-indentation
2)))
3664 (bibtex-delete-whitespace)
3665 (if bibtex-align-at-equal-sign
3667 (indent-to-column bibtex-text-indentation
))
3668 (while (re-search-forward "[ \t\n]+" end-field
'move
)
3669 (replace-match " "))
3670 (bibtex-do-auto-fill)))
3671 (if (looking-at ",")
3673 (bibtex-delete-whitespace)
3676 (indent-to-column bibtex-entry-offset
)
3679 (defun bibtex-reformat (&optional additional-options called-by-convert-alien
)
3680 "Reformat all BibTeX entries in buffer or region.
3681 With prefix argument, read options for reformatting from minibuffer.
3682 With \\[universal-argument] \\[universal-argument] prefix argument, reuse previous answers (if any) again.
3683 If mark is active it reformats entries in region, if not in whole buffer."
3685 (let* ((pnt (point))
3686 (use-previous-options
3687 (and (equal (prefix-numeric-value additional-options
) 16)
3688 (or bibtex-reformat-previous-options
3689 bibtex-reformat-previous-labels
)))
3690 (bibtex-entry-format
3691 (if additional-options
3692 (if use-previous-options
3693 bibtex-reformat-previous-options
3695 bibtex-reformat-previous-options
3700 called-by-convert-alien
3702 "Realign entries (recommended for files not created by BibTeX mode)? "))
3705 "Remove empty optional and alternative fields? ")
3708 "Remove delimiters around pure numerical fields? ")
3710 (if (y-or-n-p (concat
3711 (if bibtex-comma-after-last-field
3714 " comma at end of entry? "))
3717 "Replace double page dashes by single ones? ")
3720 "Force delimiters? ")
3723 "Unify case of entry types and field names? ")
3727 (if additional-options
3728 (if use-previous-options
3729 bibtex-reformat-previous-labels
3731 bibtex-reformat-previous-labels
3732 (y-or-n-p "Generate automatically new reference labels? ")))))
3733 bibtex-autokey-edit-before-use
3734 (bibtex-sort-ignore-string-entries t
)
3736 (if (bibtex-mark-active)
3739 (bibtex-beginning-of-first-entry)
3740 (bibtex-skip-to-valid-entry)
3743 (if (bibtex-mark-active)
3748 "[ \t\n]+\\(@[ \t]*\\("
3751 (concat "\\(" (car type
) "\\)"))
3752 bibtex-entry-field-alist
3756 (narrow-to-region start-point end-point
)
3757 (if (memq 'realign bibtex-entry-format
)
3759 (goto-char (point-min))
3760 (while (re-search-forward valid-bibtex-entry nil t
)
3761 (replace-match "\n\\1"))))
3762 (goto-char start-point
)
3763 (bibtex-progress-message "Formatting" 1)
3766 (bibtex-progress-message)
3767 (bibtex-clean-entry labels labels
)
3768 (if (memq 'realign bibtex-entry-format
)
3770 (bibtex-end-of-entry)
3771 (bibtex-delete-whitespace)
3773 (bibtex-progress-message 'done
))
3776 bibtex-maintain-sorted-entries
3777 (not called-by-convert-alien
))
3779 (bibtex-sort-buffer)
3780 (setq bibtex-keys nil
)
3781 (bibtex-parse-keys nil t t
)))
3784 (defun bibtex-convert-alien (&optional do-additional-reformatting
)
3785 "Converts an alien BibTeX buffer to be fully usable by BibTeX mode.
3786 If a file doesn't confirm with some standards used by BibTeX mode,
3787 some of the high-level features of BibTeX mode won't be available.
3788 This function tries to convert current buffer to confirm with these standards.
3789 With prefix argument DO-ADDITIONAL-REFORMATTING
3790 non-nil, read options for reformatting entries from minibuffer."
3792 (message "Starting to validate buffer...")
3794 (goto-char (point-min))
3795 (while (re-search-forward "[ \t\n]+@" nil t
)
3796 (replace-match "\n@"))
3798 "If errors occur, correct them and call `bibtex-convert-alien' again")
3800 (if (let ((bibtex-mark-active)
3801 bibtex-maintain-sorted-entries
)
3804 (message "Starting to reformat entries...")
3806 (bibtex-reformat do-additional-reformatting t
)
3807 (if bibtex-maintain-sorted-entries
3809 (message "Starting to sort buffer...")
3810 (bibtex-sort-buffer)))
3811 (goto-char (point-max))
3812 (message "Buffer is now parsable. Please save it."))))
3814 (defun bibtex-complete-string ()
3815 "Complete word fragment before point to longest prefix of a defined string.
3816 If point is not after the part of a word, all strings are listed.
3817 Remove surrounding delimiters if complete string could be expanded."
3819 (bibtex-complete bibtex-strings t
))
3821 (defun bibtex-complete-key ()
3822 "Complete word fragment before point to longest prefix of a defined key.
3823 If point is not after the part of a word, all keys are listed. This
3824 function is most useful in completing crossref entries."
3826 (if (not bibtex-keys
)
3827 (bibtex-parse-keys nil t
))
3828 (bibtex-complete bibtex-keys
))
3830 (defun bibtex-Article ()
3831 "Insert a new BibTeX @Article entry; see also `bibtex-entry'."
3833 (bibtex-entry "Article"))
3835 (defun bibtex-Book ()
3836 "Insert a new BibTeX @Book entry; see also `bibtex-entry'."
3838 (bibtex-entry "Book"))
3840 (defun bibtex-Booklet ()
3841 "Insert a new BibTeX @Booklet entry; see also `bibtex-entry'."
3843 (bibtex-entry "Booklet"))
3845 (defun bibtex-InBook ()
3846 "Insert a new BibTeX @InBook entry; see also `bibtex-entry'."
3848 (bibtex-entry "InBook"))
3850 (defun bibtex-InCollection ()
3851 "Insert a new BibTeX @InCollection entry; see also `bibtex-entry'."
3853 (bibtex-entry "InCollection"))
3855 (defun bibtex-InProceedings ()
3856 "Insert a new BibTeX @InProceedings entry; see also `bibtex-entry'."
3858 (bibtex-entry "InProceedings"))
3860 (defun bibtex-Manual ()
3861 "Insert a new BibTeX @Manual entry; see also `bibtex-entry'."
3863 (bibtex-entry "Manual"))
3865 (defun bibtex-MastersThesis ()
3866 "Insert a new BibTeX @MastersThesis entry; see also `bibtex-entry'."
3868 (bibtex-entry "MastersThesis"))
3870 (defun bibtex-Misc ()
3871 "Insert a new BibTeX @Misc entry; see also `bibtex-entry'."
3873 (bibtex-entry "Misc"))
3875 (defun bibtex-PhdThesis ()
3876 "Insert a new BibTeX @PhdThesis entry; see also `bibtex-entry'."
3878 (bibtex-entry "PhdThesis"))
3880 (defun bibtex-Proceedings ()
3881 "Insert a new BibTeX @Proceedings entry; see also `bibtex-entry'."
3883 (bibtex-entry "Proceedings"))
3885 (defun bibtex-TechReport ()
3886 "Insert a new BibTeX @TechReport entry; see also `bibtex-entry'."
3888 (bibtex-entry "TechReport"))
3890 (defun bibtex-Unpublished ()
3891 "Insert a new BibTeX @Unpublished entry; see also `bibtex-entry'."
3893 (bibtex-entry "Unpublished"))
3895 (defun bibtex-String ()
3896 "Insert a new BibTeX @String entry."
3898 (if (not bibtex-keys
)
3899 (bibtex-parse-keys nil t
))
3902 bibtex-maintain-sorted-entries
3903 (not bibtex-sort-ignore-string-entries
))
3905 "String key: " bibtex-keys nil nil nil
'bibtex-key-history
))))
3907 bibtex-maintain-sorted-entries
3908 (not bibtex-sort-ignore-string-entries
))
3909 (bibtex-find-entry-location key
)
3910 (bibtex-move-outside-of-entry))
3911 (indent-to-column bibtex-entry-offset
)
3915 (bibtex-entry-left-delimiter)
3917 bibtex-maintain-sorted-entries
3918 (not bibtex-sort-ignore-string-entries
))
3921 (bibtex-field-left-delimiter)
3922 (bibtex-field-right-delimiter)
3923 (bibtex-entry-right-delimiter)
3928 bibtex-maintain-sorted-entries
3929 (not bibtex-sort-ignore-string-entries
))
3930 (+ (length "@String{") (length key
) (length " = {"))
3931 (length "@String{")))))
3933 (defun bibtex-Preamble ()
3934 "Insert a new BibTeX @Preamble entry."
3936 (bibtex-move-outside-of-entry)
3937 (indent-to-column bibtex-entry-offset
)
3940 (bibtex-entry-left-delimiter)
3941 (bibtex-entry-right-delimiter)
3947 ;; Make BibTeX a Feature
3951 ;;; bibtex.el ends here