/[emacs]/emacs/lisp/textmodes/bibtex.el
ViewVC logotype

Diff of /emacs/lisp/textmodes/bibtex.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.76 by monnier, Mon Jun 2 22:41:50 2003 UTC revision 1.77 by kai, Sat Jul 5 12:41:24 2003 UTC
# Line 150  narrowed to just the entry." Line 150  narrowed to just the entry."
150    
151  (defcustom bibtex-maintain-sorted-entries nil  (defcustom bibtex-maintain-sorted-entries nil
152    "*If non-nil, BibTeX mode maintains all BibTeX entries in sorted order.    "*If non-nil, BibTeX mode maintains all BibTeX entries in sorted order.
153  If it is nil this will strip off some comfort (e.g., TAB  Allowed non-nil values are:
 completion for reference keys in minibuffer, automatic detection of  
 duplicates) from BibTeX mode. Allowed non-nil values are:  
154  plain        All entries are sorted alphabetically.  plain        All entries are sorted alphabetically.
155  crossref     All entries are sorted alphabetically unless an entry has a  crossref     All entries are sorted alphabetically unless an entry has a
156               crossref field. These crossrefed entries are placed in               crossref field. These crossrefed entries are placed in
# Line 169  See also `bibtex-sort-ignore-string-entr Line 167  See also `bibtex-sort-ignore-string-entr
167    
168  (defvar bibtex-sort-entry-class  (defvar bibtex-sort-entry-class
169    '(("String")    '(("String")
170      ("Article" "InBook" "InCollection" "InProceedings")      (catch-all)
171      ("Book" "Proceedings")      ("Book" "Proceedings"))
     ("Booklet" "Manual" "MastersThesis" "PhdThesis" "TechReport" )  
     ("Misc" "Unpublished"))  
172    "*List of classes of BibTeX entry names, used for sorting entries.    "*List of classes of BibTeX entry names, used for sorting entries.
173  Each class contains a list of entry names. If value of  If value of `bibtex-maintain-sorted-entries' is `entry-class'
174  `bibtex-maintain-sorted-entries' is `entry-class' entries are ordered  entries are ordered according to the classes they belong to. Each
175  according to the classes they belong to.")  class contains a list of entry names. An entry `catch-all' applies
176    to all entries not explicitely mentioned.")
177    
178  (defcustom bibtex-sort-ignore-string-entries  (defcustom bibtex-sort-ignore-string-entries t
   (not (equal bibtex-maintain-sorted-entries 'entry-class))  
179    "*If non-nil, BibTeX @String entries are not sort-significant.    "*If non-nil, BibTeX @String entries are not sort-significant.
180  That means they are ignored when determining ordering of the buffer  That means they are ignored when determining ordering of the buffer
181  \(e.g., sorting, locating alphabetical position for new entries, etc.)."  \(e.g., sorting, locating alphabetical position for new entries, etc.)."
# Line 191  That means they are ignored when determi Line 187  That means they are ignored when determi
187    :group 'bibtex    :group 'bibtex
188    :type 'integer)    :type 'integer)
189    
190    (defcustom bibtex-entry-kill-ring-max 20
191      "*Max length of `bibtex-entry-kill-ring' before discarding oldest elements."
192      :group 'bibtex
193      :type 'integer)
194    
195  (defcustom bibtex-parse-keys-timeout 60  (defcustom bibtex-parse-keys-timeout 60
196    "*Specify interval for parsing BibTeX buffers.    "*Specify interval for parsing BibTeX buffers.
197  All BibTeX buffers in Emacs are parsed if Emacs has been idle  All BibTeX buffers in Emacs are parsed if Emacs has been idle
# Line 199  after last parsing and which are maintai Line 200  after last parsing and which are maintai
200    :group 'bibtex    :group 'bibtex
201    :type 'integer)    :type 'integer)
202    
203    (defcustom bibtex-parse-keys-fast t
204      "*If non-nil, use fast but simplified algorithm for parsing BibTeX keys.
205    If parsing fails, try to set this variable to nil."
206      :group 'bibtex
207      :type 'boolean)
208    
209  (defvar bibtex-entry-field-alist  (defvar bibtex-entry-field-alist
210    '(    '(
211      ("Article"      ("Article"
212       ((("author" "Author1 [and Author2 ...] [and others]")       ((("author" "Author1 [and Author2 ...] [and others]")
213          ("title" "Title of the article (BibTeX converts it to lowercase)")         ("title" "Title of the article (BibTeX converts it to lowercase)")
214          ("journal" "Name of the journal (use string, remove braces)")         ("journal" "Name of the journal (use string, remove braces)")
215          ("year" "Year of publication"))         ("year" "Year of publication"))
216         (("volume" "Volume of the journal")        (("volume" "Volume of the journal")
217          ("number" "Number of the journal (only allowed if entry contains volume)")         ("number" "Number of the journal (only allowed if entry contains volume)")
218          ("pages" "Pages in the journal")         ("pages" "Pages in the journal")
219          ("month" "Month of the publication as a string (remove braces)")         ("month" "Month of the publication as a string (remove braces)")
220          ("note" "Remarks to be put at the end of the \\bibitem")))         ("note" "Remarks to be put at the end of the \\bibitem")))
221        ((("author" "Author1 [and Author2 ...] [and others]")       ((("author" "Author1 [and Author2 ...] [and others]")
222          ("title" "Title of the article (BibTeX converts it to lowercase)"))         ("title" "Title of the article (BibTeX converts it to lowercase)"))
223         (("pages" "Pages in the journal")        (("pages" "Pages in the journal")
224          ("journal" "Name of the journal (use string, remove braces)")         ("journal" "Name of the journal (use string, remove braces)")
225          ("year" "Year of publication")         ("year" "Year of publication")
226          ("volume" "Volume of the journal")         ("volume" "Volume of the journal")
227          ("number" "Number of the journal")         ("number" "Number of the journal")
228          ("month" "Month of the publication as a string (remove braces)")         ("month" "Month of the publication as a string (remove braces)")
229          ("note" "Remarks to be put at the end of the \\bibitem"))))         ("note" "Remarks to be put at the end of the \\bibitem"))))
230      ("Book"      ("Book"
231       ((("author" "Author1 [and Author2 ...] [and others]" "" t)       ((("author" "Author1 [and Author2 ...] [and others]" "" t)
232          ("editor" "Editor1 [and Editor2 ...] [and others]" "" t)         ("editor" "Editor1 [and Editor2 ...] [and others]" "" t)
233          ("title" "Title of the book")         ("title" "Title of the book")
234          ("publisher" "Publishing company")         ("publisher" "Publishing company")
235          ("year" "Year of publication"))         ("year" "Year of publication"))
236         (("volume" "Volume of the book in the series")        (("volume" "Volume of the book in the series")
237          ("number" "Number of the book in a small series (overwritten by volume)")         ("number" "Number of the book in a small series (overwritten by volume)")
238          ("series" "Series in which the book appeared")         ("series" "Series in which the book appeared")
239          ("address" "Address of the publisher")         ("address" "Address of the publisher")
240          ("edition" "Edition of the book as a capitalized English word")         ("edition" "Edition of the book as a capitalized English word")
241          ("month" "Month of the publication as a string (remove braces)")         ("month" "Month of the publication as a string (remove braces)")
242          ("note" "Remarks to be put at the end of the \\bibitem")))         ("note" "Remarks to be put at the end of the \\bibitem")))
243        ((("author" "Author1 [and Author2 ...] [and others]" "" t)       ((("author" "Author1 [and Author2 ...] [and others]" "" t)
244          ("editor" "Editor1 [and Editor2 ...] [and others]" "" t)         ("editor" "Editor1 [and Editor2 ...] [and others]" "" t)
245          ("title" "Title of the book"))         ("title" "Title of the book"))
246         (("publisher" "Publishing company")        (("publisher" "Publishing company")
247          ("year" "Year of publication")         ("year" "Year of publication")
248          ("volume" "Volume of the book in the series")         ("volume" "Volume of the book in the series")
249          ("number" "Number of the book in a small series (overwritten by volume)")         ("number" "Number of the book in a small series (overwritten by volume)")
250          ("series" "Series in which the book appeared")         ("series" "Series in which the book appeared")
251          ("address" "Address of the publisher")         ("address" "Address of the publisher")
252          ("edition" "Edition of the book as a capitalized English word")         ("edition" "Edition of the book as a capitalized English word")
253          ("month" "Month of the publication as a string (remove braces)")         ("month" "Month of the publication as a string (remove braces)")
254          ("note" "Remarks to be put at the end of the \\bibitem"))))         ("note" "Remarks to be put at the end of the \\bibitem"))))
255      ("Booklet"      ("Booklet"
256       ((("title" "Title of the booklet (BibTeX converts it to lowercase)"))       ((("title" "Title of the booklet (BibTeX converts it to lowercase)"))
257         (("author" "Author1 [and Author2 ...] [and others]")        (("author" "Author1 [and Author2 ...] [and others]")
258          ("howpublished" "The way in which the booklet was published")         ("howpublished" "The way in which the booklet was published")
259          ("address" "Address of the publisher")         ("address" "Address of the publisher")
260          ("month" "Month of the publication as a string (remove braces)")         ("month" "Month of the publication as a string (remove braces)")
261          ("year" "Year of publication")         ("year" "Year of publication")
262          ("note" "Remarks to be put at the end of the \\bibitem"))))         ("note" "Remarks to be put at the end of the \\bibitem"))))
263      ("InBook"      ("InBook"
264       ((("author" "Author1 [and Author2 ...] [and others]" "" t)       ((("author" "Author1 [and Author2 ...] [and others]" "" t)
265          ("editor" "Editor1 [and Editor2 ...] [and others]" "" t)         ("editor" "Editor1 [and Editor2 ...] [and others]" "" t)
266          ("title" "Title of the book")         ("title" "Title of the book")
267          ("chapter" "Chapter in the book")         ("chapter" "Chapter in the book")
268          ("publisher" "Publishing company")         ("publisher" "Publishing company")
269          ("year" "Year of publication"))         ("year" "Year of publication"))
270         (("volume" "Volume of the book in the series")        (("volume" "Volume of the book in the series")
271          ("number" "Number of the book in a small series (overwritten by volume)")         ("number" "Number of the book in a small series (overwritten by volume)")
272          ("series" "Series in which the book appeared")         ("series" "Series in which the book appeared")
273          ("type" "Word to use instead of \"chapter\"")         ("type" "Word to use instead of \"chapter\"")
274          ("address" "Address of the publisher")         ("address" "Address of the publisher")
275          ("edition" "Edition of the book as a capitalized English word")         ("edition" "Edition of the book as a capitalized English word")
276          ("month" "Month of the publication as a string (remove braces)")         ("month" "Month of the publication as a string (remove braces)")
277          ("pages" "Pages in the book")         ("pages" "Pages in the book")
278          ("note" "Remarks to be put at the end of the \\bibitem")))         ("note" "Remarks to be put at the end of the \\bibitem")))
279        ((("author" "Author1 [and Author2 ...] [and others]" "" t)       ((("author" "Author1 [and Author2 ...] [and others]" "" t)
280          ("editor" "Editor1 [and Editor2 ...] [and others]" "" t)         ("editor" "Editor1 [and Editor2 ...] [and others]" "" t)
281          ("title" "Title of the book")         ("title" "Title of the book")
282          ("chapter" "Chapter in the book"))         ("chapter" "Chapter in the book"))
283         (("pages" "Pages in the book")        (("pages" "Pages in the book")
284          ("publisher" "Publishing company")         ("publisher" "Publishing company")
285          ("year" "Year of publication")         ("year" "Year of publication")
286          ("volume" "Volume of the book in the series")         ("volume" "Volume of the book in the series")
287          ("number" "Number of the book in a small series (overwritten by volume)")         ("number" "Number of the book in a small series (overwritten by volume)")
288          ("series" "Series in which the book appeared")         ("series" "Series in which the book appeared")
289          ("type" "Word to use instead of \"chapter\"")         ("type" "Word to use instead of \"chapter\"")
290          ("address" "Address of the publisher")         ("address" "Address of the publisher")
291          ("edition" "Edition of the book as a capitalized English word")         ("edition" "Edition of the book as a capitalized English word")
292          ("month" "Month of the publication as a string (remove braces)")         ("month" "Month of the publication as a string (remove braces)")
293          ("note" "Remarks to be put at the end of the \\bibitem"))))         ("note" "Remarks to be put at the end of the \\bibitem"))))
294      ("InCollection"      ("InCollection"
295       ((("author" "Author1 [and Author2 ...] [and others]")       ((("author" "Author1 [and Author2 ...] [and others]")
296          ("title" "Title of the article in book (BibTeX converts it to lowercase)")         ("title" "Title of the article in book (BibTeX converts it to lowercase)")
297          ("booktitle" "Name of the book")         ("booktitle" "Name of the book")
298          ("publisher" "Publishing company")         ("publisher" "Publishing company")
299          ("year" "Year of publication"))         ("year" "Year of publication"))
300         (("editor" "Editor1 [and Editor2 ...] [and others]")        (("editor" "Editor1 [and Editor2 ...] [and others]")
301          ("volume" "Volume of the book in the series")         ("volume" "Volume of the book in the series")
302          ("number" "Number of the book in a small series (overwritten by volume)")         ("number" "Number of the book in a small series (overwritten by volume)")
303          ("series" "Series in which the book appeared")         ("series" "Series in which the book appeared")
304          ("type" "Word to use instead of \"chapter\"")         ("type" "Word to use instead of \"chapter\"")
305          ("chapter" "Chapter in the book")         ("chapter" "Chapter in the book")
306          ("pages" "Pages in the book")         ("pages" "Pages in the book")
307          ("address" "Address of the publisher")         ("address" "Address of the publisher")
308          ("edition" "Edition of the book as a capitalized English word")         ("edition" "Edition of the book as a capitalized English word")
309          ("month" "Month of the publication as a string (remove braces)")         ("month" "Month of the publication as a string (remove braces)")
310          ("note" "Remarks to be put at the end of the \\bibitem")))         ("note" "Remarks to be put at the end of the \\bibitem")))
311        ((("author" "Author1 [and Author2 ...] [and others]")       ((("author" "Author1 [and Author2 ...] [and others]")
312          ("title" "Title of the article in book (BibTeX converts it to lowercase)")         ("title" "Title of the article in book (BibTeX converts it to lowercase)")
313          ("booktitle" "Name of the book"))         ("booktitle" "Name of the book"))
314         (("pages" "Pages in the book")        (("pages" "Pages in the book")
315          ("publisher" "Publishing company")         ("publisher" "Publishing company")
316          ("year" "Year of publication")         ("year" "Year of publication")
317          ("editor" "Editor1 [and Editor2 ...] [and others]")         ("editor" "Editor1 [and Editor2 ...] [and others]")
318          ("volume" "Volume of the book in the series")         ("volume" "Volume of the book in the series")
319          ("number" "Number of the book in a small series (overwritten by volume)")         ("number" "Number of the book in a small series (overwritten by volume)")
320          ("series" "Series in which the book appeared")         ("series" "Series in which the book appeared")
321          ("type" "Word to use instead of \"chapter\"")         ("type" "Word to use instead of \"chapter\"")
322          ("chapter" "Chapter in the book")         ("chapter" "Chapter in the book")
323          ("address" "Address of the publisher")         ("address" "Address of the publisher")
324          ("edition" "Edition of the book as a capitalized English word")         ("edition" "Edition of the book as a capitalized English word")
325          ("month" "Month of the publication as a string (remove braces)")         ("month" "Month of the publication as a string (remove braces)")
326          ("note" "Remarks to be put at the end of the \\bibitem"))))         ("note" "Remarks to be put at the end of the \\bibitem"))))
327      ("InProceedings"      ("InProceedings"
328       ((("author" "Author1 [and Author2 ...] [and others]")       ((("author" "Author1 [and Author2 ...] [and others]")
329          ("title" "Title of the article in proceedings (BibTeX converts it to lowercase)")         ("title" "Title of the article in proceedings (BibTeX converts it to lowercase)")
330          ("booktitle" "Name of the conference proceedings")         ("booktitle" "Name of the conference proceedings")
331          ("year" "Year of publication"))         ("year" "Year of publication"))
332         (("editor" "Editor1 [and Editor2 ...] [and others]")        (("editor" "Editor1 [and Editor2 ...] [and others]")
333          ("volume" "Volume of the conference proceedings in the series")         ("volume" "Volume of the conference proceedings in the series")
334          ("number" "Number of the conference proceedings in a small series (overwritten by volume)")         ("number" "Number of the conference proceedings in a small series (overwritten by volume)")
335          ("series" "Series in which the conference proceedings appeared")         ("series" "Series in which the conference proceedings appeared")
336          ("pages" "Pages in the conference proceedings")         ("pages" "Pages in the conference proceedings")
337          ("address" "Location of the Proceedings")         ("address" "Location of the Proceedings")
338          ("month" "Month of the publication as a string (remove braces)")         ("month" "Month of the publication as a string (remove braces)")
339          ("organization" "Sponsoring organization of the conference")         ("organization" "Sponsoring organization of the conference")
340          ("publisher" "Publishing company, its location")         ("publisher" "Publishing company, its location")
341          ("note" "Remarks to be put at the end of the \\bibitem")))         ("note" "Remarks to be put at the end of the \\bibitem")))
342        ((("author" "Author1 [and Author2 ...] [and others]")       ((("author" "Author1 [and Author2 ...] [and others]")
343          ("title" "Title of the article in proceedings (BibTeX converts it to lowercase)"))         ("title" "Title of the article in proceedings (BibTeX converts it to lowercase)"))
344         (("booktitle" "Name of the conference proceedings")        (("booktitle" "Name of the conference proceedings")
345          ("pages" "Pages in the conference proceedings")         ("pages" "Pages in the conference proceedings")
346          ("year" "Year of publication")         ("year" "Year of publication")
347          ("editor" "Editor1 [and Editor2 ...] [and others]")         ("editor" "Editor1 [and Editor2 ...] [and others]")
348          ("volume" "Volume of the conference proceedings in the series")         ("volume" "Volume of the conference proceedings in the series")
349          ("number" "Number of the conference proceedings in a small series (overwritten by volume)")         ("number" "Number of the conference proceedings in a small series (overwritten by volume)")
350          ("series" "Series in which the conference proceedings appeared")         ("series" "Series in which the conference proceedings appeared")
351          ("address" "Location of the Proceedings")         ("address" "Location of the Proceedings")
352          ("month" "Month of the publication as a string (remove braces)")         ("month" "Month of the publication as a string (remove braces)")
353          ("organization" "Sponsoring organization of the conference")         ("organization" "Sponsoring organization of the conference")
354          ("publisher" "Publishing company, its location")         ("publisher" "Publishing company, its location")
355          ("note" "Remarks to be put at the end of the \\bibitem"))))         ("note" "Remarks to be put at the end of the \\bibitem"))))
356      ("Manual"      ("Manual"
357       ((("title" "Title of the manual"))       ((("title" "Title of the manual"))
358         (("author" "Author1 [and Author2 ...] [and others]")        (("author" "Author1 [and Author2 ...] [and others]")
359          ("organization" "Publishing organization of the manual")         ("organization" "Publishing organization of the manual")
360          ("address" "Address of the organization")         ("address" "Address of the organization")
361          ("edition" "Edition of the manual as a capitalized English word")         ("edition" "Edition of the manual as a capitalized English word")
362          ("month" "Month of the publication as a string (remove braces)")         ("month" "Month of the publication as a string (remove braces)")
363          ("year" "Year of publication")         ("year" "Year of publication")
364          ("note" "Remarks to be put at the end of the \\bibitem"))))         ("note" "Remarks to be put at the end of the \\bibitem"))))
365      ("MastersThesis"      ("MastersThesis"
366       ((("author" "Author1 [and Author2 ...] [and others]")       ((("author" "Author1 [and Author2 ...] [and others]")
367          ("title" "Title of the master\'s thesis (BibTeX converts it to lowercase)")         ("title" "Title of the master\'s thesis (BibTeX converts it to lowercase)")
368          ("school" "School where the master\'s thesis was written")         ("school" "School where the master\'s thesis was written")
369          ("year" "Year of publication"))         ("year" "Year of publication"))
370         (("type" "Type of the master\'s thesis (if other than \"Master\'s thesis\")")        (("type" "Type of the master\'s thesis (if other than \"Master\'s thesis\")")
371          ("address" "Address of the school (if not part of field \"school\") or country")         ("address" "Address of the school (if not part of field \"school\") or country")
372          ("month" "Month of the publication as a string (remove braces)")         ("month" "Month of the publication as a string (remove braces)")
373          ("note" "Remarks to be put at the end of the \\bibitem"))))         ("note" "Remarks to be put at the end of the \\bibitem"))))
374      ("Misc"      ("Misc"
375       (()       (()
376         (("author" "Author1 [and Author2 ...] [and others]")        (("author" "Author1 [and Author2 ...] [and others]")
377          ("title" "Title of the work (BibTeX converts it to lowercase)")         ("title" "Title of the work (BibTeX converts it to lowercase)")
378          ("howpublished" "The way in which the work was published")         ("howpublished" "The way in which the work was published")
379          ("month" "Month of the publication as a string (remove braces)")         ("month" "Month of the publication as a string (remove braces)")
380          ("year" "Year of publication")         ("year" "Year of publication")
381          ("note" "Remarks to be put at the end of the \\bibitem"))))         ("note" "Remarks to be put at the end of the \\bibitem"))))
382      ("PhdThesis"      ("PhdThesis"
383       ((("author" "Author1 [and Author2 ...] [and others]")       ((("author" "Author1 [and Author2 ...] [and others]")
384          ("title" "Title of the PhD. thesis")         ("title" "Title of the PhD. thesis")
385          ("school" "School where the PhD. thesis was written")         ("school" "School where the PhD. thesis was written")
386          ("year" "Year of publication"))         ("year" "Year of publication"))
387         (("type" "Type of the PhD. thesis")        (("type" "Type of the PhD. thesis")
388          ("address" "Address of the school (if not part of field \"school\") or country")         ("address" "Address of the school (if not part of field \"school\") or country")
389          ("month" "Month of the publication as a string (remove braces)")         ("month" "Month of the publication as a string (remove braces)")
390          ("note" "Remarks to be put at the end of the \\bibitem"))))         ("note" "Remarks to be put at the end of the \\bibitem"))))
391      ("Proceedings"      ("Proceedings"
392       ((("title" "Title of the conference proceedings")       ((("title" "Title of the conference proceedings")
393          ("year" "Year of publication"))         ("year" "Year of publication"))
394         (("booktitle" "Title of the proceedings for cross references")        (("booktitle" "Title of the proceedings for cross references")
395          ("editor" "Editor1 [and Editor2 ...] [and others]")         ("editor" "Editor1 [and Editor2 ...] [and others]")
396          ("volume" "Volume of the conference proceedings in the series")         ("volume" "Volume of the conference proceedings in the series")
397          ("number" "Number of the conference proceedings in a small series (overwritten by volume)")         ("number" "Number of the conference proceedings in a small series (overwritten by volume)")
398          ("series" "Series in which the conference proceedings appeared")         ("series" "Series in which the conference proceedings appeared")
399          ("address" "Location of the Proceedings")         ("address" "Location of the Proceedings")
400          ("month" "Month of the publication as a string (remove braces)")         ("month" "Month of the publication as a string (remove braces)")
401          ("organization" "Sponsoring organization of the conference")         ("organization" "Sponsoring organization of the conference")
402          ("publisher" "Publishing company, its location")         ("publisher" "Publishing company, its location")
403          ("note" "Remarks to be put at the end of the \\bibitem"))))         ("note" "Remarks to be put at the end of the \\bibitem"))))
404      ("TechReport"      ("TechReport"
405       ((("author" "Author1 [and Author2 ...] [and others]")       ((("author" "Author1 [and Author2 ...] [and others]")
406          ("title" "Title of the technical report (BibTeX converts it to lowercase)")         ("title" "Title of the technical report (BibTeX converts it to lowercase)")
407          ("institution" "Sponsoring institution of the report")         ("institution" "Sponsoring institution of the report")
408          ("year" "Year of publication"))         ("year" "Year of publication"))
409         (("type" "Type of the report (if other than \"technical report\")")        (("type" "Type of the report (if other than \"technical report\")")
410          ("number" "Number of the technical report")         ("number" "Number of the technical report")
411          ("address" "Address of the institution (if not part of field \"institution\") or country")         ("address" "Address of the institution (if not part of field \"institution\") or country")
412          ("month" "Month of the publication as a string (remove braces)")         ("month" "Month of the publication as a string (remove braces)")
413          ("note" "Remarks to be put at the end of the \\bibitem"))))         ("note" "Remarks to be put at the end of the \\bibitem"))))
414      ("Unpublished"      ("Unpublished"
415       ((("author" "Author1 [and Author2 ...] [and others]")       ((("author" "Author1 [and Author2 ...] [and others]")
416          ("title" "Title of the unpublished work (BibTeX converts it to lowercase)")         ("title" "Title of the unpublished work (BibTeX converts it to lowercase)")
417          ("note" "Remarks to be put at the end of the \\bibitem"))         ("note" "Remarks to be put at the end of the \\bibitem"))
418         (("month" "Month of the publication as a string (remove braces)")        (("month" "Month of the publication as a string (remove braces)")
419          ("year" "Year of publication"))))         ("year" "Year of publication"))))
420      )      )
421    
422    "Defines entry types and their associated fields.    "Defines entry types and their associated fields.
# Line 452  REQUIRED or CROSSREF-REQUIRED lists.") Line 459  REQUIRED or CROSSREF-REQUIRED lists.")
459      ("nov" . "November")      ("nov" . "November")
460      ("dec" . "December"))      ("dec" . "December"))
461    "Alist of month string definitions used in the BibTeX style files.    "Alist of month string definitions used in the BibTeX style files.
462  Each element is a pair of strings (ABBREVIATION EXPANSION)."  Each element is a pair of strings (ABBREVIATION . EXPANSION)."
463    :group 'bibtex    :group 'bibtex
464    :type '(repeat (cons (string :tag "Month abbreviation")    :type '(repeat (cons (string :tag "Month abbreviation")
465                         (string :tag "Month expansion"))))                         (string :tag "Month expansion"))))
# Line 481  Each element is a pair of strings (ABBRE Line 488  Each element is a pair of strings (ABBRE
488       ("toois"    . "ACM Transactions on Office Information Systems")       ("toois"    . "ACM Transactions on Office Information Systems")
489       ("toplas"   . "ACM Transactions on Programming Languages and Systems")))       ("toplas"   . "ACM Transactions on Programming Languages and Systems")))
490    "Alist of string definitions used in the BibTeX style files.    "Alist of string definitions used in the BibTeX style files.
491  Each element is a pair of strings (ABBREVIATION EXPANSION)."  Each element is a pair of strings (ABBREVIATION . EXPANSION)."
492    :group 'bibtex    :group 'bibtex
493    :type '(repeat (cons (string :tag "String")    :type '(repeat (cons (string :tag "String")
494                         (string :tag "String expansion"))))                         (string :tag "String expansion"))))
# Line 489  Each element is a pair of strings (ABBRE Line 496  Each element is a pair of strings (ABBRE
496  (defcustom bibtex-string-files nil  (defcustom bibtex-string-files nil
497    "*List of BibTeX files containing string definitions.    "*List of BibTeX files containing string definitions.
498  Those files must be specified using pathnames relative to the  Those files must be specified using pathnames relative to the
499  directories specified in `bibtex-string-file-path'.  This variable is only  directories specified in `bibtex-string-file-path'."
 evaluated when BibTeX mode is entered (i.e., when loading the BibTeX  
 file)."  
500    :group 'bibtex    :group 'bibtex
501    :type '(repeat file))    :type '(repeat file))
502    
# Line 499  file)." Line 504  file)."
504    "*Colon separated list of paths to search for `bibtex-string-files'.")    "*Colon separated list of paths to search for `bibtex-string-files'.")
505    
506  (defcustom bibtex-help-message t  (defcustom bibtex-help-message t
507    "*If not nil print help messages in the echo area on entering a new field."    "*If non-nil print help messages in the echo area on entering a new field."
508    :group 'bibtex    :group 'bibtex
509    :type 'boolean)    :type 'boolean)
510    
511  (defcustom bibtex-autokey-prefix-string ""  (defcustom bibtex-autokey-prefix-string ""
512    "*String to use as a prefix for all generated keys.    "*String to use as a prefix for all generated keys.
513  See the documentation of function `bibtex-generate-autokey' for more detail."  See `bibtex-generate-autokey' for details."
514    :group 'bibtex-autokey    :group 'bibtex-autokey
515    :type 'string)    :type 'string)
516    
517  (defcustom bibtex-autokey-names 1  (defcustom bibtex-autokey-names 1
518    "*Number of names to use for the automatically generated reference key.    "*Number of names to use for the automatically generated reference key.
 If this variable is nil, all names are used.  
519  Possibly more names are used according to `bibtex-autokey-names-stretch'.  Possibly more names are used according to `bibtex-autokey-names-stretch'.
520  See the documentation of function `bibtex-generate-autokey' for more detail."  If this variable is nil, all names are used.
521    See `bibtex-generate-autokey' for details."
522    :group 'bibtex-autokey    :group 'bibtex-autokey
523    :type '(choice (const :tag "All" infty)    :type '(choice (const :tag "All" infty)
524                   integer))                   integer))
# Line 521  See the documentation of function `bibte Line 526  See the documentation of function `bibte
526  (defcustom bibtex-autokey-names-stretch 0  (defcustom bibtex-autokey-names-stretch 0
527    "*Number of names that can additionally be used.    "*Number of names that can additionally be used.
528  These names are used only, if all names are used then.  These names are used only, if all names are used then.
529  See the documentation of function `bibtex-generate-autokey' for details."  See `bibtex-generate-autokey' for details."
530    :group 'bibtex-autokey    :group 'bibtex-autokey
531    :type 'integer)    :type 'integer)
532    
533  (defcustom bibtex-autokey-additional-names ""  (defcustom bibtex-autokey-additional-names ""
534    "*String to prepend to the generated key if not all names could be used.    "*String to prepend to the generated key if not all names could be used.
535  See the documentation of function `bibtex-generate-autokey' for details."  See `bibtex-generate-autokey' for details."
536    :group 'bibtex-autokey    :group 'bibtex-autokey
537    :type 'string)    :type 'string)
538    
# Line 548  See the documentation of function `bibte Line 553  See the documentation of function `bibte
553      ("\\\"U\\|\\\\\\\"U" . "Ue")          ; "U,\"U        -> Ue      ("\\\"U\\|\\\\\\\"U" . "Ue")          ; "U,\"U        -> Ue
554      ;; accents      ;; accents
555      ("\\\\`\\|\\\\'\\|\\\\\\^\\|\\\\~\\|\\\\=\\|\\\\\\.\\|\\\\u\\|\\\\v\\|\\\\H\\|\\\\t\\|\\\\c\\|\\\\d\\|\\\\b" . "")      ("\\\\`\\|\\\\'\\|\\\\\\^\\|\\\\~\\|\\\\=\\|\\\\\\.\\|\\\\u\\|\\\\v\\|\\\\H\\|\\\\t\\|\\\\c\\|\\\\d\\|\\\\b" . "")
556      ("`\\|'\\|\\\"" . "")      ;; braces, quotes, concatenation.
557      ;; braces      ("[`'\"{}#]" . "")
     ("{" . "") ("}" . "")  
558      ;; spaces      ;; spaces
559      ("[ \t\n]+" . " "))      ("[ \t\n]+" . " "))
560    "Alist of (OLD-REGEXP NEW-STRING) pairs.    "Alist of (OLD-REGEXP . NEW-STRING) pairs.
561  Used by the default values of `bibtex-autokey-name-change-strings' and  Used by the default values of `bibtex-autokey-name-change-strings' and
562  `bibtex-autokey-titleword-change-strings'.  Defaults to translating some  `bibtex-autokey-titleword-change-strings'.  Defaults to translating some
563  language specific characters to their ASCII transcriptions, and  language specific characters to their ASCII transcriptions, and
# Line 561  removing any character accents.") Line 565  removing any character accents.")
565    
566  (defcustom bibtex-autokey-name-change-strings  (defcustom bibtex-autokey-name-change-strings
567    bibtex-autokey-transcriptions    bibtex-autokey-transcriptions
568    "Alist of (OLD-REGEXP NEW-STRING) pairs.    "Alist of (OLD-REGEXP . NEW-STRING) pairs.
569  Any part of name matching a OLD-REGEXP is replaced by NEW-STRING.  Any part of name matching a OLD-REGEXP is replaced by NEW-STRING.
570  Case is significant in OLD-REGEXP.  All regexps are tried in the  Case is significant in OLD-REGEXP.  All regexps are tried in the
571  order in which they appear in the list.  order in which they appear in the list.
572  See the documentation of function `bibtex-generate-autokey' for details."  See `bibtex-generate-autokey' for details."
573    :group 'bibtex-autokey    :group 'bibtex-autokey
574    :type '(repeat (cons (regexp :tag "Old")    :type '(repeat (cons (regexp :tag "Old")
575                         (string :tag "New"))))                         (string :tag "New"))))
576    
577  (defcustom bibtex-autokey-name-case-convert 'downcase  (defcustom bibtex-autokey-name-case-convert 'downcase
578    "*Function called for each name to perform case conversion.    "*Function called for each name to perform case conversion.
579  See the documentation of function `bibtex-generate-autokey' for details."  See `bibtex-generate-autokey' for details."
580    :group 'bibtex-autokey    :group 'bibtex-autokey
581    :type '(choice (const :tag "Preserve case" identity)    :type '(choice (const :tag "Preserve case" identity)
582                   (const :tag "Downcase" downcase)                   (const :tag "Downcase" downcase)
# Line 583  See the documentation of function `bibte Line 587  See the documentation of function `bibte
587  (defcustom bibtex-autokey-name-length 'infty  (defcustom bibtex-autokey-name-length 'infty
588    "*Number of characters from name to incorporate into key.    "*Number of characters from name to incorporate into key.
589  If this is set to anything but a number, all characters are used.  If this is set to anything but a number, all characters are used.
590  See the documentation of function `bibtex-generate-autokey' for details."  See `bibtex-generate-autokey' for details."
591    :group 'bibtex-autokey    :group 'bibtex-autokey
592    :type '(choice (const :tag "All" infty)    :type '(choice (const :tag "All" infty)
593                   integer))                   integer))
594    
595  (defcustom bibtex-autokey-name-separator ""  (defcustom bibtex-autokey-name-separator ""
596    "*String that comes between any two names in the key.    "*String that comes between any two names in the key.
597  See the documentation of function `bibtex-generate-autokey' for details."  See `bibtex-generate-autokey' for details."
598    :group 'bibtex-autokey    :group 'bibtex-autokey
599    :type 'string)    :type 'string)
600    
601  (defcustom bibtex-autokey-year-length 2  (defcustom bibtex-autokey-year-length 2
602    "*Number of rightmost digits from the year field to incorporate into key.    "*Number of rightmost digits from the year field to incorporate into key.
603  See the documentation of function `bibtex-generate-autokey' for details."  See `bibtex-generate-autokey' for details."
604    :group 'bibtex-autokey    :group 'bibtex-autokey
605    :type 'integer)    :type 'integer)
606    
# Line 604  See the documentation of function `bibte Line 608  See the documentation of function `bibte
608    "*If non-nil use fields from crossreferenced entry if necessary.    "*If non-nil use fields from crossreferenced entry if necessary.
609  If this variable is non-nil and some field has no entry, but a  If this variable is non-nil and some field has no entry, but a
610  valid crossref entry, the field from the crossreferenced entry is used.  valid crossref entry, the field from the crossreferenced entry is used.
611  See the documentation of function `bibtex-generate-autokey' for details."  See `bibtex-generate-autokey' for details."
612    :group 'bibtex-autokey    :group 'bibtex-autokey
613    :type 'boolean)    :type 'boolean)
614    
# Line 613  See the documentation of function `bibte Line 617  See the documentation of function `bibte
617  If this is set to anything but a number, all title words are used.  If this is set to anything but a number, all title words are used.
618  Possibly more words from the title are used according to  Possibly more words from the title are used according to
619  `bibtex-autokey-titlewords-stretch'.  `bibtex-autokey-titlewords-stretch'.
620  See the documentation of function `bibtex-generate-autokey' for details."  See `bibtex-generate-autokey' for details."
621    :group 'bibtex-autokey    :group 'bibtex-autokey
622    :type '(choice (const :tag "All" infty)    :type '(choice (const :tag "All" infty)
623                   integer))                   integer))
# Line 622  See the documentation of function `bibte Line 626  See the documentation of function `bibte
626    '("\\." "!"  "\\?" ":" ";" "--")    '("\\." "!"  "\\?" ":" ";" "--")
627    "*Regexp list defining the termination of the main part of the title.    "*Regexp list defining the termination of the main part of the title.
628  Case of the regexps is ignored.  Case of the regexps is ignored.
629  See the documentation of function `bibtex-generate-autokey' for details."  See `bibtex-generate-autokey' for details."
630    :group 'bibtex-autokey    :group 'bibtex-autokey
631    :type '(repeat regexp))    :type '(repeat regexp))
632    
633  (defcustom bibtex-autokey-titlewords-stretch 2  (defcustom bibtex-autokey-titlewords-stretch 2
634    "*Number of words that can additionally be used from the title.    "*Number of words that can additionally be used from the title.
635  These words are used only, if a sentence from the title can be ended then.  These words are used only, if a sentence from the title can be ended then.
636  See the documentation of function `bibtex-generate-autokey' for details."  See `bibtex-generate-autokey' for details."
637    :group 'bibtex-autokey    :group 'bibtex-autokey
638    :type 'integer)    :type 'integer)
639    
# Line 639  See the documentation of function `bibte Line 643  See the documentation of function `bibte
643    "*Determines words from the title that are not to be used in the key.    "*Determines words from the title that are not to be used in the key.
644  Each item of the list is a regexp.  If a word of the title matchs a  Each item of the list is a regexp.  If a word of the title matchs a
645  regexp from that list, it is not included in the title part of the key.  regexp from that list, it is not included in the title part of the key.
646  See the documentation of function `bibtex-generate-autokey' for details."  See `bibtex-generate-autokey' for details."
647    :group 'bibtex-autokey    :group 'bibtex-autokey
648    :type '(repeat regexp))    :type '(repeat regexp))
649    
650  (defcustom bibtex-autokey-titleword-case-convert 'downcase  (defcustom bibtex-autokey-titleword-case-convert 'downcase
651    "*Function called for each titleword to perform case conversion.    "*Function called for each titleword to perform case conversion.
652  See the documentation of function `bibtex-generate-autokey' for details."  See `bibtex-generate-autokey' for details."
653    :group 'bibtex-autokey    :group 'bibtex-autokey
654    :type '(choice (const :tag "Preserve case" identity)    :type '(choice (const :tag "Preserve case" identity)
655                   (const :tag "Downcase" downcase)                   (const :tag "Downcase" downcase)
# Line 655  See the documentation of function `bibte Line 659  See the documentation of function `bibte
659    
660  (defcustom bibtex-autokey-titleword-abbrevs nil  (defcustom bibtex-autokey-titleword-abbrevs nil
661    "*Determines exceptions to the usual abbreviation mechanism.    "*Determines exceptions to the usual abbreviation mechanism.
662  An alist of (OLD-REGEXP NEW-STRING) pairs.  Case is ignored  An alist of (OLD-REGEXP . NEW-STRING) pairs.  Case is ignored
663  in matching against OLD-REGEXP, and the first matching pair is used.  in matching against OLD-REGEXP, and the first matching pair is used.
664  See the documentation of function `bibtex-generate-autokey' for details."  See `bibtex-generate-autokey' for details."
665    :group 'bibtex-autokey    :group 'bibtex-autokey
666    :type '(repeat (cons (regexp :tag "Old")    :type '(repeat (cons (regexp :tag "Old")
667                         (string :tag "New"))))                         (string :tag "New"))))
668    
669  (defcustom bibtex-autokey-titleword-change-strings  (defcustom bibtex-autokey-titleword-change-strings
670    bibtex-autokey-transcriptions    bibtex-autokey-transcriptions
671    "Alist of (OLD-REGEXP NEW-STRING) pairs.    "Alist of (OLD-REGEXP . NEW-STRING) pairs.
672  Any part of title word matching a OLD-REGEXP is replaced by NEW-STRING.  Any part of title word matching a OLD-REGEXP is replaced by NEW-STRING.
673  Case is significant in OLD-REGEXP.  All regexps are tried in the  Case is significant in OLD-REGEXP.  All regexps are tried in the
674  order in which they appear in the list.  order in which they appear in the list.
675  See the documentation of function `bibtex-generate-autokey' for details."  See `bibtex-generate-autokey' for details."
676    :group 'bibtex-autokey    :group 'bibtex-autokey
677    :type '(repeat (cons (regexp :tag "Old")    :type '(repeat (cons (regexp :tag "Old")
678                         (string :tag "New"))))                         (string :tag "New"))))
# Line 676  See the documentation of function `bibte Line 680  See the documentation of function `bibte
680  (defcustom bibtex-autokey-titleword-length 5  (defcustom bibtex-autokey-titleword-length 5
681    "*Number of characters from title words to incorporate into key.    "*Number of characters from title words to incorporate into key.
682  If this is set to anything but a number, all characters are used.  If this is set to anything but a number, all characters are used.
683  See the documentation of function `bibtex-generate-autokey' for details."  See `bibtex-generate-autokey' for details."
684    :group 'bibtex-autokey    :group 'bibtex-autokey
685    :type '(choice (const :tag "All" infty)    :type '(choice (const :tag "All" infty)
686                   integer))                   integer))
687    
688  (defcustom bibtex-autokey-titleword-separator "_"  (defcustom bibtex-autokey-titleword-separator "_"
689    "*String to be put between the title words.    "*String to be put between the title words.
690  See the documentation of function `bibtex-generate-autokey' for details."  See `bibtex-generate-autokey' for details."
691    :group 'bibtex-autokey    :group 'bibtex-autokey
692    :type 'string)    :type 'string)
693    
694  (defcustom bibtex-autokey-name-year-separator ""  (defcustom bibtex-autokey-name-year-separator ""
695    "*String to be put between name part and year part of key.    "*String to be put between name part and year part of key.
696  See the documentation of function `bibtex-generate-autokey' for details."  See `bibtex-generate-autokey' for details."
697    :group 'bibtex-autokey    :group 'bibtex-autokey
698    :type 'string)    :type 'string)
699    
700  (defcustom bibtex-autokey-year-title-separator ":_"  (defcustom bibtex-autokey-year-title-separator ":_"
701    "*String to be put between name part and year part of key.    "*String to be put between name part and year part of key.
702  See the documentation of function `bibtex-generate-autokey' for details."  See `bibtex-generate-autokey' for details."
703    :group 'bibtex-autokey    :group 'bibtex-autokey
704    :type 'string)    :type 'string)
705    
# Line 706  See the documentation of function `bibte Line 710  See the documentation of function `bibte
710    
711  (defcustom bibtex-autokey-before-presentation-function nil  (defcustom bibtex-autokey-before-presentation-function nil
712    "*Function to call before the generated key is presented.    "*Function to call before the generated key is presented.
713  If non-nil this should be a single function, which is called before  If non-nil this should be a function which is called before the generated key
714  the generated key is presented (in entry or, if  is presented.  The function must take one argument (the automatically
715  `bibtex-autokey-edit-before-use' is t, in minibuffer).  This function  generated key), and must return a string (the key to use)."
 must take one argument (the automatically generated key), and must  
 return with a string (the key to use)."  
716    :group 'bibtex-autokey    :group 'bibtex-autokey
717    :type '(choice (const nil) function))    :type '(choice (const nil) function))
718    
# Line 751  If non-nil, the column for the equal sig Line 753  If non-nil, the column for the equal sig
753    :group 'bibtex    :group 'bibtex
754    :type 'boolean)    :type 'boolean)
755    
756    (defcustom bibtex-autoadd-commas t
757      "If non-nil automatically add missing commas at end of BibTeX fields."
758      :type 'boolean)
759    
760    (defcustom bibtex-autofill-types '("Proceedings")
761      "Automatically fill fields if possible for those BibTeX entry types."
762      :type '(repeat string))
763    
764  (defcustom bibtex-complete-key-cleanup nil  (defcustom bibtex-complete-key-cleanup nil
765    "*Function called by `bibtex-complete' after insertion of a key fragment."    "*Function called by `bibtex-complete' after insertion of a key fragment."
766    :group 'bibtex-autokey    :group 'bibtex-autokey
# Line 839  If non-nil, the column for the equal sig Line 849  If non-nil, the column for the equal sig
849       ["Next Field" bibtex-next-field t]       ["Next Field" bibtex-next-field t]
850       ["Beginning of Entry" bibtex-beginning-of-entry t]       ["Beginning of Entry" bibtex-beginning-of-entry t]
851       ["End of Entry" bibtex-end-of-entry t])       ["End of Entry" bibtex-end-of-entry t])
852        ("Moving in BibTeX Buffer"
853         ["Find Entry" bibtex-find-entry t]
854         ["Find Crossref Entry" bibtex-find-crossref t])
855      ("Operating on Current Entry"      ("Operating on Current Entry"
856       ["Fill Entry" bibtex-fill-entry t]       ["Fill Entry" bibtex-fill-entry t]
857       ["Clean Entry" bibtex-clean-entry t]       ["Clean Entry" bibtex-clean-entry t]
# Line 855  If non-nil, the column for the equal sig Line 868  If non-nil, the column for the equal sig
868       ["View Cite Locations (RefTeX)" reftex-view-crossref-from-bibtex       ["View Cite Locations (RefTeX)" reftex-view-crossref-from-bibtex
869        (fboundp 'reftex-view-crossref-from-bibtex)])        (fboundp 'reftex-view-crossref-from-bibtex)])
870      ("Operating on Current Field"      ("Operating on Current Field"
871         ["Fill Field" fill-paragraph t]
872       ["Remove Delimiters" bibtex-remove-delimiters t]       ["Remove Delimiters" bibtex-remove-delimiters t]
873       ["Remove OPT or ALT Prefix" bibtex-remove-OPT-or-ALT t]       ["Remove OPT or ALT Prefix" bibtex-remove-OPT-or-ALT t]
874       ["Clear Field" bibtex-empty-field t]       ["Clear Field" bibtex-empty-field t]
# Line 925  At most `bibtex-entry-kill-ring-max' ite Line 939  At most `bibtex-entry-kill-ring-max' ite
939  (defvar bibtex-last-kill-command nil  (defvar bibtex-last-kill-command nil
940    "Type of the last kill command (either 'field or 'entry).")    "Type of the last kill command (either 'field or 'entry).")
941    
942  (defvar bibtex-strings nil  (defvar bibtex-strings
943    "Candidates for `bibtex-complete' (string completion).    (lazy-completion-table bibtex-strings
944                             bibtex-parse-strings (bibtex-string-files-init))
945      "Completion table for BibTeX string keys.
946  Initialized from `bibtex-predefined-strings' and `bibtex-string-files'.")  Initialized from `bibtex-predefined-strings' and `bibtex-string-files'.")
947    (make-variable-buffer-local 'bibtex-strings)
948    
949  (defvar bibtex-reference-keys nil  (defvar bibtex-reference-keys
950    "Candidates for TAB completion when entering a reference key using    (lazy-completion-table bibtex-reference-keys bibtex-parse-keys nil nil t)
951  the minibuffer. Also used for `bibtex-complete' (key completion).    "Completion table for BibTeX reference keys.")
952  Initialized in `bibtex-mode' and updated for each new entry.")  (make-variable-buffer-local 'bibtex-reference-keys)
953    
954  (defvar bibtex-buffer-last-parsed-tick nil  (defvar bibtex-buffer-last-parsed-tick nil
955    "Last value returned by `buffer-modified-tick' when buffer    "Last value returned by `buffer-modified-tick' when buffer
# Line 954  was parsed for keys the last time.") Line 971  was parsed for keys the last time.")
971    "History list for reading keys.")    "History list for reading keys.")
972    
973  (defvar bibtex-entry-type-history nil  (defvar bibtex-entry-type-history nil
974    "Used to store the history list for reading entry types.")    "History list for reading entry types.")
975    
976  (defvar bibtex-field-history nil  (defvar bibtex-field-history nil
977    "History list for reading field names.")    "History list for reading field names.")
# Line 987  was parsed for keys the last time.") Line 1004  was parsed for keys the last time.")
1004    
1005  (defconst bibtex-entry-maybe-empty-head  (defconst bibtex-entry-maybe-empty-head
1006    (concat bibtex-entry-head "?")    (concat bibtex-entry-head "?")
1007    "Regexp matching the header line of a maybe empty BibTeX entry    "Regexp matching the header line of a BibTeX entry (possibly without key).")
 \(possibly without reference key).")  
1008    
1009  (defconst bibtex-type-in-head 1  (defconst bibtex-type-in-head 1
1010    "Regexp subexpression number of the type part in `bibtex-entry-head'.")    "Regexp subexpression number of the type part in `bibtex-entry-head'.")
# Line 1063  function `bibtex-parse-field-name'.") Line 1079  function `bibtex-parse-field-name'.")
1079      (dolist (class bibtex-sort-entry-class alist)      (dolist (class bibtex-sort-entry-class alist)
1080        (setq i (1+ i))        (setq i (1+ i))
1081        (dolist (entry class)        (dolist (entry class)
1082          (push (cons entry i) alist))))          ;; all entry names should be downcase (for ease of comparison)
1083            (push (cons (if (stringp entry) (downcase entry) entry) i) alist))))
1084    "Alist for the classes of the entry types if the value of    "Alist for the classes of the entry types if the value of
1085  `bibtex-maintain-sorted-entries' is `entry-class'.")  `bibtex-maintain-sorted-entries' is `entry-class'.")
1086    
# Line 1105  function `bibtex-parse-field-name'.") Line 1122  function `bibtex-parse-field-name'.")
1122   '(bibtex-mode "@\\S(*\\s(" "\\s)" nil bibtex-hs-forward-sexp nil))   '(bibtex-mode "@\\S(*\\s(" "\\s)" nil bibtex-hs-forward-sexp nil))
1123    
1124    
1125  ;; Functions to Parse the BibTeX Entries  (defconst bibtex-braced-string-syntax-table
1126      (let ((st (make-syntax-table)))
1127        (modify-syntax-entry ?\{ "(}" st)
1128        (modify-syntax-entry ?\} "){" st)
1129        (modify-syntax-entry ?\[ "." st)
1130        (modify-syntax-entry ?\] "." st)
1131        (modify-syntax-entry ?\( "." st)
1132        (modify-syntax-entry ?\) "." st)
1133        (modify-syntax-entry ?\\ "." st)
1134        (modify-syntax-entry ?\" "." st)
1135        st)
1136      "Syntax-table to parse matched braces.")
1137    
1138  (defun bibtex-parse-nested-braces (nesting-level)  (defconst bibtex-quoted-string-syntax-table
1139    "Starting on an opening brace, find the corresponding closing brace.    (let ((st (make-syntax-table)))
1140  When the function is called, NESTING-LEVEL has to be set to `0'."      (modify-syntax-entry ?\\ "\\" st)
1141    (cond ((looking-at "{")      (modify-syntax-entry ?\" "\"" st)
1142           (search-forward-regexp "{[^{}]*")      st)
1143           (bibtex-parse-nested-braces (+ nesting-level 1)))    "Syntax-table to parse matched quotes.")
         ((looking-at "}")  
          (forward-char 1)  
          (if (= nesting-level 1)  
              (point)  
            (search-forward-regexp "[^{}]*")  
            (bibtex-parse-nested-braces (- nesting-level 1))))  
         (t nil)))  
1144    
1145  (defun bibtex-parse-field-string ()  (defun bibtex-parse-field-string ()
1146    "Parse a field string enclosed by braces or quotes.    "Parse a field string enclosed by braces or quotes.
1147  If a syntactically correct string is found, a pair containing the start and  If a syntactically correct string is found, a pair containing the start and
1148  end position of the field string is returned, nil otherwise."  end position of the field string is returned, nil otherwise."
1149    (save-match-data    (let ((end-point
1150      (let ((end-point (or (and (looking-at bibtex-quoted-string-re)           (or (and (eq (following-char) ?\")
1151                                (match-end 0))                    (save-excursion
1152                           (and (looking-at "{")                      (with-syntax-table bibtex-quoted-string-syntax-table
1153                                (save-excursion (bibtex-parse-nested-braces 0))))))                        (forward-sexp 1))
1154        (if end-point                      (point)))
1155            (cons (point) end-point)))))               (and (eq (following-char) ?\{)
1156                      (save-excursion
1157                        (with-syntax-table bibtex-braced-string-syntax-table
1158                          (forward-sexp 1))
1159                        (point))))))
1160        (if end-point
1161            (cons (point) end-point))))
1162    
1163  (defun bibtex-parse-association (parse-lhs parse-rhs)  (defun bibtex-parse-association (parse-lhs parse-rhs)
1164    "Parse a string of the format <left-hand-side = right-hand-side>.    "Parse a string of the format <left-hand-side = right-hand-side>.
# Line 1141  successfull.  If both functions return n Line 1168  successfull.  If both functions return n
1168  values of the functions PARSE-LHS and PARSE-RHS is returned."  values of the functions PARSE-LHS and PARSE-RHS is returned."
1169    (save-match-data    (save-match-data
1170      (save-excursion      (save-excursion
1171        (let (left right)        (let ((left (funcall parse-lhs))
1172          (if (and (setq left (funcall parse-lhs))              right)
1173            (if (and left
1174                   (looking-at "[ \t\n]*=[ \t\n]*")                   (looking-at "[ \t\n]*=[ \t\n]*")
1175                   (goto-char (match-end 0))                   (goto-char (match-end 0))
1176                   (setq right (funcall parse-rhs)))                   (setq right (funcall parse-rhs)))
# Line 1152  values of the functions PARSE-LHS and PA Line 1180  values of the functions PARSE-LHS and PA
1180    "Parse the field name stored in `bibtex-field-name-for-parsing'.    "Parse the field name stored in `bibtex-field-name-for-parsing'.
1181  If the field name is found, return a triple consisting of the position of the  If the field name is found, return a triple consisting of the position of the
1182  very first character of the match, the actual starting position of the name  very first character of the match, the actual starting position of the name
1183  part and end position of the match. Move point to end of field name."  part and end position of the match. Move point to end of field name.
1184    (if (looking-at ",[ \t\n]*")  If `bibtex-autoadd-commas' is non-nil add missing comma at end of preceeding
1185        (let ((start (point)))  BibTeX field as necessary."
1186          (goto-char (match-end 0))    (cond ((looking-at ",[ \t\n]*")
1187          (when (looking-at bibtex-field-name-for-parsing)           (let ((start (point)))
1188            (goto-char (match-end 0))             (goto-char (match-end 0))
1189            (list start (match-beginning 0) (match-end 0))))))             (when (looking-at bibtex-field-name-for-parsing)
1190                 (goto-char (match-end 0))
1191                 (list start (match-beginning 0) (match-end 0)))))
1192            ;; Maybe add a missing comma.
1193            ((and bibtex-autoadd-commas
1194                  (looking-at (concat "[ \t\n]*\\(?:" bibtex-field-name-for-parsing
1195                                      "\\)[ \t\n]*=")))
1196             (skip-chars-backward " \t\n")
1197             (insert ",")
1198             (forward-char -1)
1199             ;; Now try again.
1200             (bibtex-parse-field-name))))
1201    
1202  (defun bibtex-parse-field-text ()  (defun bibtex-parse-field-text ()
1203    "Parse the text part of a BibTeX field.    "Parse the text part of a BibTeX field.
# Line 1168  is found, a pair containing the start an Line 1207  is found, a pair containing the start an
1207  returned, nil otherwise. Move point to end of field text."  returned, nil otherwise. Move point to end of field text."
1208    (let ((starting-point (point))    (let ((starting-point (point))
1209          end-point failure boundaries)          end-point failure boundaries)
1210      (while (and (not end-point)      (while (not (or end-point failure))
                 (not failure))  
1211        (cond ((looking-at bibtex-field-const)        (cond ((looking-at bibtex-field-const)
1212               (goto-char (match-end 0)))               (goto-char (match-end 0)))
1213              ((setq boundaries (bibtex-parse-field-string))              ((setq boundaries (bibtex-parse-field-string))
# Line 1194  the name and text parts of the field is Line 1232  the name and text parts of the field is
1232    "Search forward to find a field of name NAME.    "Search forward to find a field of name NAME.
1233  If a syntactically correct field is found, a pair containing the boundaries of  If a syntactically correct field is found, a pair containing the boundaries of
1234  the name and text parts of the field is returned.  The search is limited by  the name and text parts of the field is returned.  The search is limited by
1235  optional arg BOUND. Do not move point."  optional arg BOUND. If BOUND is t the search is limited by the end of the current
1236    entry. Do not move point."
1237    (save-match-data    (save-match-data
1238      (save-excursion      (save-excursion
1239        (unless bound (setq bound (point-max)))        (unless (integer-or-marker-p bound)
1240            (setq bound (if bound
1241                            (save-excursion (bibtex-end-of-entry))
1242                          (point-max))))
1243        (let ((case-fold-search t)        (let ((case-fold-search t)
1244              (bibtex-field-name-for-parsing name)              (bibtex-field-name-for-parsing name)
1245              boundaries temp-boundaries)              boundaries temp-boundaries)
# Line 1217  optional arg BOUND. Do not move point." Line 1259  optional arg BOUND. Do not move point."
1259    "Search backward to find a field of name NAME.    "Search backward to find a field of name NAME.
1260  If a syntactically correct field is found, a pair containing the boundaries of  If a syntactically correct field is found, a pair containing the boundaries of
1261  the name and text parts of the field is returned.  The search is limited by  the name and text parts of the field is returned.  The search is limited by
1262  optional arg BOUND. Do not move point."  optional arg BOUND. If BOUND is t the search is limited by the beginning of the
1263    current entry. Do not move point."
1264    (save-match-data    (save-match-data
1265      (save-excursion      (save-excursion
1266        (unless bound (setq bound (point-min)))        (unless (integer-or-marker-p bound)
1267            (setq bound (if bound
1268                            (save-excursion (bibtex-beginning-of-entry))
1269                          (point-min))))
1270        (let ((case-fold-search t)        (let ((case-fold-search t)
1271              (bibtex-field-name-for-parsing name)              (bibtex-field-name-for-parsing name)
1272              boundaries temp-boundaries)              boundaries temp-boundaries)
# Line 1233  optional arg BOUND. Do not move point." Line 1279  optional arg BOUND. Do not move point."
1279                (setq boundaries temp-boundaries)))                (setq boundaries temp-boundaries)))
1280          boundaries))))          boundaries))))
1281    
1282  (defun bibtex-start-of-field (bounds)  (defsubst bibtex-start-of-field (bounds)
1283    (nth 0 (car bounds)))    (nth 0 (car bounds)))
1284  (defun bibtex-start-of-name-in-field (bounds)  (defsubst bibtex-start-of-name-in-field (bounds)
1285    (nth 1 (car bounds)))    (nth 1 (car bounds)))
1286  (defun bibtex-end-of-name-in-field (bounds)  (defsubst bibtex-end-of-name-in-field (bounds)
1287    (nth 2 (car bounds)))    (nth 2 (car bounds)))
1288  (defun bibtex-end-of-field (bounds)  (defsubst bibtex-end-of-field (bounds)
1289    (cddr bounds))    (cddr bounds))
1290  (defun bibtex-start-of-text-in-field (bounds)  (defsubst bibtex-start-of-text-in-field (bounds)
1291    (cadr bounds))    (cadr bounds))
1292  (defun bibtex-end-of-text-in-field (bounds)  (defsubst bibtex-end-of-text-in-field (bounds)
1293    (cddr bounds))    (cddr bounds))
1294    
1295  (defun bibtex-name-in-field (bounds)  (defun bibtex-name-in-field (bounds)
# Line 1267  if present." Line 1313  if present."
1313  If optional arg FOLLOW-CROSSREF is non-nil, follow crossref."  If optional arg FOLLOW-CROSSREF is non-nil, follow crossref."
1314    (save-excursion    (save-excursion
1315      (save-restriction      (save-restriction
1316          ;; We want to jump back and forth while searching FIELD
1317        (bibtex-narrow-to-entry)        (bibtex-narrow-to-entry)
1318        (goto-char (point-min))        (goto-char (point-min))
1319        (let ((bounds (bibtex-search-forward-field field))        (let ((bounds (bibtex-search-forward-field field))
# Line 1304  If the string postfix is found, return a Line 1351  If the string postfix is found, return a
1351  the actual starting and ending position of the text and the very last  the actual starting and ending position of the text and the very last
1352  character of the string entry. Move point past BibTeX string entry."  character of the string entry. Move point past BibTeX string entry."
1353    (let* ((case-fold-search t)    (let* ((case-fold-search t)
1354           (text-boundaries (bibtex-parse-field-text)))           (bounds (bibtex-parse-field-text)))
1355      (when text-boundaries      (when bounds
1356        (goto-char (cdr text-boundaries))        (goto-char (cdr bounds))
1357        (when (looking-at "[ \t\n]*[})]")        (when (looking-at "[ \t\n]*[})]")
1358          (goto-char (match-end 0))          (goto-char (match-end 0))
1359          (list (car text-boundaries)          (list (car bounds)
1360                (cdr text-boundaries)                (cdr bounds)
1361                (match-end 0))))))                (match-end 0))))))
1362    
1363  (defun bibtex-parse-string ()  (defun bibtex-parse-string ()
# Line 1367  delimiters if present." Line 1414  delimiters if present."
1414          (substring content (match-beginning 1) (match-end 1))          (substring content (match-beginning 1) (match-end 1))
1415        content)))        content)))
1416    
1417  (defun bibtex-start-of-text-in-string (bounds)  (defsubst bibtex-start-of-text-in-string (bounds)
1418    (nth 0 (cdr bounds)))    (nth 0 (cdr bounds)))
1419  (defun bibtex-end-of-text-in-string (bounds)  (defsubst bibtex-end-of-text-in-string (bounds)
1420    (nth 1 (cdr bounds)))    (nth 1 (cdr bounds)))
1421  (defun bibtex-end-of-string (bounds)  (defsubst bibtex-end-of-string (bounds)
1422    (nth 2 (cdr bounds)))    (nth 2 (cdr bounds)))
1423    
1424  (defun bibtex-type-in-head ()  (defsubst bibtex-type-in-head ()
1425    "Extract BibTeX type in head."    "Extract BibTeX type in head."
1426    ;;                              ignore @    ;;                              ignore @
1427    (buffer-substring-no-properties (1+ (match-beginning bibtex-type-in-head))    (buffer-substring-no-properties (1+ (match-beginning bibtex-type-in-head))
# Line 1424  next valid one. With optional argument B Line 1471  next valid one. With optional argument B
1471  beginning of previous valid one. A valid entry is a syntactical correct one  beginning of previous valid one. A valid entry is a syntactical correct one
1472  with type contained in `bibtex-entry-field-alist' or, if  with type contained in `bibtex-entry-field-alist' or, if
1473  `bibtex-sort-ignore-string-entries' is nil, a syntactical correct string  `bibtex-sort-ignore-string-entries' is nil, a syntactical correct string
1474  entry. Return buffer position if a valid entry is found, nil otherwise."  entry. Return buffer position of beginning and ending of entry if a valid
1475    entry is found, nil otherwise."
1476      (interactive "P")
1477    (let ((case-fold-search t)    (let ((case-fold-search t)
1478          found)          found)
1479      (while (and (not found)      (while (not (or found (if backward (bobp) (eobp))))
1480                  (not (if backward (bobp) (eobp))))        (let ((pnt (point))
1481        (let ((pnt (point)))              bounds)
1482          (cond ((or (and (looking-at bibtex-valid-entry-re)          (cond ((or (and (looking-at bibtex-valid-entry-re)
1483                          (bibtex-search-entry nil nil t)                          (setq found (bibtex-search-entry nil nil t))
1484                          (equal (match-beginning 0) pnt))                          (equal (match-beginning 0) pnt))
1485                     (and (not bibtex-sort-ignore-string-entries)                     (and (not bibtex-sort-ignore-string-entries)
1486                          (bibtex-parse-string)))                          (setq bounds (bibtex-parse-string))
1487                 (setq found pnt)                          (setq found (cons (bibtex-start-of-field bounds)
1488                                              (bibtex-end-of-string bounds)))))
1489                 (goto-char pnt))                 (goto-char pnt))
1490                (backward                (backward
                (goto-char (1- pnt))  
1491                 (if (re-search-backward "^[ \t]*\\(@\\)" nil 'move)                 (if (re-search-backward "^[ \t]*\\(@\\)" nil 'move)
1492                     (goto-char (match-beginning 1))))                     (goto-char (match-beginning 1))))
1493                (t (goto-char (1+ pnt))                (t (if (re-search-forward "\n[ \t]*@" nil 'move)
                  (if (re-search-forward "^[ \t]*@" nil 'move)  
1494                       (forward-char -1))))))                       (forward-char -1))))))
1495      found))      found))
1496    
1497  (defun bibtex-map-entries (fun)  (defun bibtex-map-entries (fun)
1498    "Call FUN for each BibTeX entry starting with the current.    "Call FUN for each BibTeX entry starting with the current.
1499  Do this to the end of the file.  FUN is called with one argument, the key  Do this to the end of the file. FUN is called with three arguments, the key of
1500  of the entry, and with point inside the entry.  the entry and the buffer positions (marker) of beginning and end of entry.
1501  If `bibtex-sort-ignore-string-entries' is non-nil, FUN will not be  Point is inside the entry. If `bibtex-sort-ignore-string-entries' is non-nil,
1502  called for @String entries."  FUN will not be called for @String entries."
1503    (let ((case-fold-search t))    (let ((case-fold-search t))
1504      (bibtex-beginning-of-entry)      (bibtex-beginning-of-entry)
1505      (while (re-search-forward bibtex-entry-maybe-empty-head nil t)      (while (re-search-forward bibtex-entry-head nil t)
1506        (save-excursion        (let ((entry-type (bibtex-type-in-head))
1507          (let ((entry-type (downcase (bibtex-type-in-head)))              (key (bibtex-key-in-head ""))
1508                (key (bibtex-key-in-head "")))              (beg (copy-marker (match-beginning 0)))
1509                (end (copy-marker (save-excursion (bibtex-end-of-entry)))))
1510            (save-excursion
1511            (if (or (and (not bibtex-sort-ignore-string-entries)            (if (or (and (not bibtex-sort-ignore-string-entries)
1512                         (string-equal "string" entry-type))                         (string-equal "string" (downcase entry-type)))
1513                    (assoc-ignore-case entry-type bibtex-entry-field-alist))                    (assoc-ignore-case entry-type bibtex-entry-field-alist))
1514                (funcall fun key))))                (funcall fun key beg end)))
1515        (bibtex-end-of-entry))))          (goto-char end)))))
1516    
1517  (defun bibtex-progress-message (&optional flag interval)  (defun bibtex-progress-message (&optional flag interval)
1518    "Echo a message about progress of current buffer.    "Echo a message about progress of current buffer.
# Line 1513  at least INTERVAL percent since last mes Line 1563  at least INTERVAL percent since last mes
1563      ")"))      ")"))
1564    
1565  (defun bibtex-search-entry (empty-head &optional bound noerror backward)  (defun bibtex-search-entry (empty-head &optional bound noerror backward)
1566    "A helper function necessary since the failure stack size limit for    "Search for a BibTeX entry (maybe without reference key if EMPTY-HEAD is t).
1567  regexps was reduced in emacs 19.32.  BOUND and NOERROR are exactly as in `re-search-forward'. If BACKWARD
1568  It searches for a BibTeX entry (maybe without a reference key if  is non-nil, search is done in reverse direction. Point is moved past the
1569  EMPTY-HEAD is t).  closing delimiter (at the beginning of entry if BACKWARD is non-nil).
1570  BOUND and NOERROR are exactly as in `re-search-forward'. If  Return a cons pair with buffer positions of beginning and end of entry.
1571  BACKWARD is non-nil, search is done in reverse direction. After  After call to this function MATCH-BEGINNING and MATCH-END functions
1572  call to this function MATCH-BEGINNING and MATCH-END functions are  are defined, but only for the head part of the entry
1573  defined, but only for the head part of the entry (especially  \(especially (match-end 0) just gives the end of the head part)."
 \(match-end 0) just gives the end of the head part)."  
1574    (let ((pnt (point))    (let ((pnt (point))
1575          (prefix (if empty-head          (entry-head-re (if empty-head
1576                      bibtex-entry-maybe-empty-head                             bibtex-entry-maybe-empty-head
1577                    bibtex-entry-head)))                           bibtex-entry-head)))
1578      (if backward      (if backward
1579          (let (found)          (let (found)
1580            (while (and (not found)            (while (and (not found)
1581                        (re-search-backward prefix bound noerror))                        (re-search-backward entry-head-re bound noerror))
1582              (setq found (bibtex-search-entry empty-head pnt t)))              (setq found (bibtex-search-entry empty-head pnt t)))
1583            (if found            (if found
1584                (goto-char (match-beginning 0))                (progn (goto-char (match-beginning 0))
1585                         found)
1586              (cond ((equal noerror nil)              (cond ((equal noerror nil)
1587                     ;; yell                     ;; yell
1588                     (error "Search of BibTeX entry failed"))                     (error "Backward search of BibTeX entry failed"))
1589                    ((equal noerror t)                    ((equal noerror t)
1590                     ;; don't move                     ;; don't move
1591                     (goto-char pnt)))                     (goto-char pnt)))
# Line 1543  defined, but only for the head part of t Line 1593  defined, but only for the head part of t
1593        (let ((limit (or bound (point-max)))        (let ((limit (or bound (point-max)))
1594              found)              found)
1595          (while (and (not found)          (while (and (not found)
1596                      (re-search-forward prefix bound noerror))                      (re-search-forward entry-head-re bound noerror))
1597            (save-match-data            (save-match-data
1598              (let ((entry-closer              (let ((entry-closer
1599                     (if (save-excursion                     (if (save-excursion
# Line 1569  defined, but only for the head part of t Line 1619  defined, but only for the head part of t
1619                  (goto-char (match-end 0))                  (goto-char (match-end 0))
1620                  (setq found t)))))                  (setq found t)))))
1621          (if found          (if found
1622              (point)              (cons (match-beginning 0) (point))
1623            (cond ((not noerror)            (cond ((not noerror)
1624                   ;; yell                   ;; yell
1625                   (error "Search of BibTeX entry failed"))                   (error "Search of BibTeX entry failed"))
# Line 1596  defined, but only for the head part of t Line 1646  defined, but only for the head part of t
1646        (message "From: %s"        (message "From: %s"
1647                 (buffer-substring (point) flash)))))                 (buffer-substring (point) flash)))))
1648    
1649  (defun bibtex-make-optional-field (e-t)  (defun bibtex-make-optional-field (field)
1650    "Make an optional field named E-T in current BibTeX entry."    "Make an optional field named FIELD in current BibTeX entry."
1651    (if (consp e-t)    (if (consp field)
1652        (bibtex-make-field (cons (concat "OPT" (car e-t)) (cdr e-t)))        (bibtex-make-field (cons (concat "OPT" (car field)) (cdr field)))
1653      (bibtex-make-field (concat "OPT" e-t))))      (bibtex-make-field (concat "OPT" field))))
1654    
1655  (defun bibtex-move-outside-of-entry ()  (defun bibtex-move-outside-of-entry ()
1656    "Make sure point is outside of a BibTeX entry."    "Make sure point is outside of a BibTeX entry."
# Line 1647  defined, but only for the head part of t Line 1697  defined, but only for the head part of t
1697  Use `match-beginning' and `match-end' to parse the field. If NOERR is non-nil,  Use `match-beginning' and `match-end' to parse the field. If NOERR is non-nil,
1698  no error is signalled. In this case, bounds are returned on success,  no error is signalled. In this case, bounds are returned on success,
1699  nil otherwise."  nil otherwise."
1700    (let* ((case-fold-search t)    (let ((bounds (bibtex-search-backward-field bibtex-field-name t)))
          (old-point (point))  
          (boe (save-excursion (bibtex-beginning-of-entry)))  
          (bounds (bibtex-search-backward-field bibtex-field-name boe)))  
1701      (if (and bounds      (if (and bounds
1702               (<= (bibtex-start-of-field bounds) old-point)               (<= (bibtex-start-of-field bounds) (point))
1703               (>= (bibtex-end-of-field bounds) old-point))               (>= (bibtex-end-of-field bounds) (point)))
1704          bounds          bounds
1705        (unless noerr        (unless noerr
1706          (error "Can't find enclosing BibTeX field")))))          (error "Can't find enclosing BibTeX field")))))
1707    
1708  (defun bibtex-enclosing-entry-maybe-empty-head ()  (defun bibtex-enclosing-entry-maybe-empty-head ()
1709    "Search for BibTeX entry enclosing point. Point moves to end of entry.    "Search for BibTeX entry enclosing point. Move point to end of entry.
1710  Beginning (but not end) of entry is given by (`match-beginning' 0)."  Beginning (but not end) of entry is given by (`match-beginning' 0)."
1711    (let ((case-fold-search t)    (let ((case-fold-search t)
1712          (old-point (point)))          (old-point (point)))
1713      (unless (re-search-backward bibtex-entry-maybe-empty-head nil t)      (unless (re-search-backward bibtex-entry-maybe-empty-head nil t)
1714        (error "Can't find enclosing BibTeX entry")        (goto-char old-point)
1715        (goto-char old-point))        (error "Can't find beginning of enclosing BibTeX entry"))
1716      (goto-char (match-beginning bibtex-type-in-head))      (goto-char (match-beginning bibtex-type-in-head))
1717      (unless (bibtex-search-entry t nil t)      (unless (bibtex-search-entry t nil t)
1718        (error "Can't find enclosing BibTeX entry")        (goto-char old-point)
1719        (goto-char old-point))))        (error "Can't find end of enclosing BibTeX entry"))))
1720    
1721  (defun bibtex-insert-current-kill (n)  (defun bibtex-insert-current-kill (n)
1722    (if (not bibtex-last-kill-command)    (if (not bibtex-last-kill-command)
# Line 1830  Formats current entry according to varia Line 1877  Formats current entry according to varia
1877                                 "\\([\"{][0-9]+\\)[ \t\n]*--?[ \t\n]*\\([0-9]+[\"}]\\)")))                                 "\\([\"{][0-9]+\\)[ \t\n]*--?[ \t\n]*\\([0-9]+[\"}]\\)")))
1878                    (replace-match "\\1-\\2"))                    (replace-match "\\1-\\2"))
1879    
1880                ;; use book title of crossrefed entry                ;; use book title of crossref'd entry
1881                (if (and (memq 'inherit-booktitle format)                (if (and (memq 'inherit-booktitle format)
                        (equal (downcase field-name) "booktitle")  
1882                         empty-field                         empty-field
1883                           (equal (downcase field-name) "booktitle")
1884                         crossref-key)                         crossref-key)
1885                    (let ((title (save-restriction                    (let ((title (save-restriction
1886                                   (widen)                                   (widen)
# Line 1844  Formats current entry according to varia Line 1891  Formats current entry according to varia
1891                        (goto-char (1+ beg-text))                        (goto-char (1+ beg-text))
1892                        (insert title))))                        (insert title))))
1893    
1894                  ;; Use booktitle to set a missing title.
1895                  (if (and empty-field
1896                           (equal (downcase field-name) "title"))
1897                      (let ((booktitle (bibtex-text-in-field "booktitle")))
1898                        (when booktitle
1899                          (setq empty-field nil)
1900                          (goto-char (1+ beg-text))
1901                          (insert booktitle))))
1902    
1903                ;; if empty field, complain                ;; if empty field, complain
1904                (if (and empty-field                (if (and empty-field
# Line 1954  and return results as a list." Line 2009  and return results as a list."
2009    (let ((case-fold-search t))    (let ((case-fold-search t))
2010      (mapcar 'bibtex-autokey-demangle-name      (mapcar 'bibtex-autokey-demangle-name
2011              (split-string (bibtex-autokey-get-field              (split-string (bibtex-autokey-get-field
2012                             "\\(author\\)\\|\\(editor\\)"                             "author\\|editor"
2013                             bibtex-autokey-name-change-strings)                             bibtex-autokey-name-change-strings)
2014                            "[ ]+and[ ]+"))))                            "[ \t\n]+and[ \t\n]+"))))
2015    
2016  (defun bibtex-autokey-demangle-name (fullname)  (defun bibtex-autokey-demangle-name (fullname)
2017    "Get the last part from a well-formed name and perform abbreviations."    "Get the last part from a well-formed name and perform abbreviations."
# Line 2120  The generation algorithm works as follow Line 2175  The generation algorithm works as follow
2175                  (setq nnl (append nnl (list (car nl)))                  (setq nnl (append nnl (list (car nl)))
2176                        nl (cdr nl)))                        nl (cdr nl)))
2177                nnl)))                nnl)))
2178           (namepart (concat (mapconcat (lambda (name) name)           (namepart (concat (mapconcat 'identity
2179                                        namelist                                        namelist
2180                                        bibtex-autokey-name-separator)                                        bibtex-autokey-name-separator)
2181                             name-etal))                             name-etal))
# Line 2130  The generation algorithm works as follow Line 2185  The generation algorithm works as follow
2185                       (substring yearfield                       (substring yearfield
2186                                  (- (length yearfield)                                  (- (length yearfield)
2187                                     bibtex-autokey-year-length))))                                     bibtex-autokey-year-length))))
2188           (titlepart (mapconcat (lambda (name) name)           (titlepart (mapconcat 'identity
2189                                 (bibtex-autokey-get-title)                                 (bibtex-autokey-get-title)
2190                                 bibtex-autokey-titleword-separator))                                 bibtex-autokey-titleword-separator))
2191           (autokey (concat bibtex-autokey-prefix-string           (autokey (concat bibtex-autokey-prefix-string
# Line 2149  The generation algorithm works as follow Line 2204  The generation algorithm works as follow
2204        autokey)))        autokey)))
2205    
2206    
2207  (defun bibtex-parse-keys (add verbose &optional abortable)  (defun bibtex-parse-keys (&optional add abortable verbose)
2208    "Set `bibtex-reference-keys' to the keys used in the whole buffer.    "Set `bibtex-reference-keys' to the keys used in the whole buffer.
2209  The buffer might possibly be restricted.  The buffer might possibly be restricted.
2210  Find both entry keys and crossref entries.  Find both entry keys and crossref entries.
2211  If ADD is non-nil adds the new keys to `bibtex-reference-keys' instead of  If ADD is non-nil add the new keys to `bibtex-reference-keys' instead of
2212  simply resetting it. If VERBOSE is non-nil gives messages about  simply resetting it. If ADD is an alist of keys, also add ADD to
2213  progress. If ABORTABLE is non-nil abort on user input.  `bibtex-reference-keys'. If ABORTABLE is non-nil abort on user
2214  Return t if parsing was completed, nil if aborted."  input. If VERBOSE is non-nil gives messages about progress.
2215    (let ((reference-keys (if add bibtex-reference-keys)))  Return alist of keys if parsing was completed, `aborted' otherwise."
2216      (let ((reference-keys (if (and add
2217                                     (listp bibtex-reference-keys))
2218                                bibtex-reference-keys)))
2219        (if (listp add)
2220            (dolist (key add)
2221              (unless (assoc (car key) reference-keys)
2222                          (push key reference-keys))))
2223      (save-excursion      (save-excursion
2224        (save-match-data        (save-match-data
         (goto-char (point-min))  
2225          (if verbose          (if verbose
2226              (bibtex-progress-message              (bibtex-progress-message
2227               (concat (buffer-name) ": parsing reference keys")))               (concat (buffer-name) ": parsing reference keys")))
2228          (if (catch 'userkey          (catch 'userkey
2229                (while (bibtex-skip-to-valid-entry)            (goto-char (point-min))
2230                  (if (and abortable            (if bibtex-parse-keys-fast
2231                           (input-pending-p))                (let ((case-fold-search t)
2232                      (throw 'userkey t))                      (re (concat bibtex-entry-head "\\|"
2233                  (if verbose                                  ",[ \t\n]*crossref[ \t\n]*=[ \t\n]*"
2234                      (bibtex-progress-message))                                  "\\(\"[^\"]*\"\\|{[^}]*}\\)[ \t\n]*[,})]")))
2235                  (let ((case-fold-search t)                  (while (re-search-forward re nil t)
2236                        key crossref-key bounds)                    (if (and abortable (input-pending-p))
2237                    (cond ((looking-at bibtex-entry-head)                        ;; user has aborted by typing a key --> return `aborted'
2238                           (setq key (bibtex-key-in-head))                        (throw 'userkey 'aborted))
2239                           (let ((p (point))                    (let ((key (cond ((match-end 3)
2240                                 (m (bibtex-end-of-entry)))                                      ;; This is a crossref.
2241                             (goto-char p)                                      (buffer-substring-no-properties
2242                             (if (setq bounds (bibtex-search-forward-field "crossref" m))                                       (1+ (match-beginning 3)) (1- (match-end 3))))
2243                                 (setq crossref-key (bibtex-text-in-field-bounds bounds t)))))                                     ((assoc-ignore-case (bibtex-type-in-head)
2244                          ((setq bounds (bibtex-parse-string))                                                         bibtex-entry-field-alist)
2245                           (setq key (bibtex-reference-key-in-string bounds))))                                      ;; This is an entry.
2246                    (forward-char)                                      (match-string-no-properties bibtex-key-in-head)))))
2247                    (unless (assoc key reference-keys)                      (if (and (stringp key)
2248                      (push (list key) reference-keys))                               (not (assoc key reference-keys)))
2249                    (if (and crossref-key                        (push (list key) reference-keys)))))
2250                             (not (assoc crossref-key reference-keys)))  
2251                        (push (list crossref-key) reference-keys)))))              (let (;; ignore @String entries because they are handled
2252              ;; user has aborted by typing a key --> return nil                    ;; separately by bibtex-parse-strings
2253              nil                    (bibtex-sort-ignore-string-entries t)
2254            ;; successful operation --> return t                    crossref-key bounds)
2255            (setq bibtex-reference-keys reference-keys)                (bibtex-map-entries
2256                   (lambda (key beg end)
2257                     (if (and abortable
2258                              (input-pending-p))
2259                         ;; user has aborted by typing a key --> return `aborted'
2260                         (throw 'userkey 'aborted))
2261                     (if verbose (bibtex-progress-message))
2262                     (unless (assoc key reference-keys)
2263                       (push (list key) reference-keys))
2264                     (if (and (setq bounds (bibtex-search-forward-field "crossref" end))
2265                              (setq crossref-key (bibtex-text-in-field-bounds bounds t))
2266                              (not (assoc crossref-key reference-keys)))
2267                         (push (list crossref-key) reference-keys))))))
2268    
2269            (if verbose            (if verbose
2270                (bibtex-progress-message 'done))                (bibtex-progress-message 'done))
2271            t)))))            ;; successful operation --> return `bibtex-reference-keys'
2272              (setq bibtex-reference-keys reference-keys))))))
2273    
2274  (defun bibtex-parse-strings (&optional init abortable)  (defun bibtex-parse-strings (&optional add abortable)
2275    "Set `bibtex-strings' to the string definitions in the whole buffer.    "Set `bibtex-strings' to the string definitions in the whole buffer.
2276  The buffer might possibly be restricted.  The buffer might possibly be restricted.
2277  Optional arg INIT is used to initialize `bibtex-strings'.  If ADD is non-nil add the new strings to `bibtex-strings' instead of
2278  If ABORTABLE is non-nil abort on user input.  simply resetting it. If ADD is an alist of strings, also add ADD to
2279  Return t if parsing was completed, nil if aborted."  `bibtex-strings'. If ABORTABLE is non-nil abort on user input.
2280    Return alist of strings if parsing was completed, `aborted' otherwise."
2281    (save-excursion    (save-excursion
2282      (save-match-data      (save-match-data
2283        (goto-char (point-min))        (goto-char (point-min))
2284        (let ((strings init)        (let ((strings (if (and add
2285                                  (listp bibtex-strings))
2286                             bibtex-strings))
2287              bounds key)              bounds key)
2288          (if (catch 'userkey          (if (listp add)
2289                (while (setq bounds (bibtex-search-forward-string))              (dolist (string add)
2290                  (if (and abortable                (unless (assoc (car string) strings)
2291                           (input-pending-p))                  (push string strings))))
2292                      (throw 'userkey t))          (catch 'userkey
2293                  (setq key (bibtex-reference-key-in-string bounds))            (while (setq bounds (bibtex-search-forward-string))
2294                  (if (not (assoc-ignore-case key strings))              (if (and abortable
2295                      (push (cons key (bibtex-text-in-string bounds t))                       (input-pending-p))
2296                            strings))                  ;; user has aborted by typing a key --> return `aborted'
2297                  (goto-char (bibtex-end-of-text-in-string bounds))))                  (throw 'userkey 'aborted))
2298              ;; user has aborted by typing a key --> return nil              (setq key (bibtex-reference-key-in-string bounds))
2299              nil              (if (not (assoc-ignore-case key strings))
2300            ;; successful operation --> return t                  (push (cons key (bibtex-text-in-string bounds t))
2301            (setq bibtex-strings strings)                        strings))
2302            t)))))              (goto-char (bibtex-end-of-text-in-string bounds)))
2303              ;; successful operation --> return `bibtex-strings'
2304              (setq bibtex-strings strings))))))
2305    
2306  (defun bibtex-string-files-init ()  (defun bibtex-string-files-init ()
2307    "Return initialization for `bibtex-strings'.    "Return initialization for `bibtex-strings'.
# Line 2251  Use `bibtex-predefined-strings' and bib Line 2331  Use `bibtex-predefined-strings' and bib
2331                    (goto-char (bibtex-end-of-string bounds))))                    (goto-char (bibtex-end-of-string bounds))))
2332                (setq found t)))                (setq found t)))
2333            (unless found            (unless found
2334              (error "File %s not in paths defined by bibtex-string-file-path variable"              (error "File %s not in paths defined via bibtex-string-file-path"
2335                     filename))))                     filename))))
2336        (append bibtex-predefined-strings (nreverse compl)))))        (append bibtex-predefined-strings (nreverse compl)))))
2337    
# Line 2271  with the current) are parsed." Line 2351  with the current) are parsed."
2351                (widen)                (widen)
2352                ;; Output no progress messages in bibtex-parse-keys                ;; Output no progress messages in bibtex-parse-keys
2353                ;; because when in y-or-n-p that can hide the question.                ;; because when in y-or-n-p that can hide the question.
2354                (if (and (if bibtex-maintain-sorted-entries                (if (and (listp (bibtex-parse-keys nil t))
                            (bibtex-parse-keys nil nil t)  
                          t)  
2355                         ;; update bibtex-strings                         ;; update bibtex-strings
2356                         (bibtex-parse-strings strings-init t))                         (listp (bibtex-parse-strings strings-init t)))
2357    
2358                    ;; remember that parsing was successful                    ;; remember that parsing was successful
2359                    (setq bibtex-buffer-last-parsed-tick (buffer-modified-tick)))))                    (setq bibtex-buffer-last-parsed-tick (buffer-modified-tick)))))
# Line 2310  of a word, all strings are listed. Retur Line 2388  of a word, all strings are listed. Retur
2388             nil))))             nil))))
2389    
2390  (defun bibtex-complete-string-cleanup (str)  (defun bibtex-complete-string-cleanup (str)
2391    "Remove enclosing field delimiters."    "Cleanup after inserting string STR.
2392    Remove enclosing field delimiters for string STR. Display message with
2393    expansion of STR."
2394    (let ((pair (assoc str bibtex-strings)))    (let ((pair (assoc str bibtex-strings)))
2395      (when pair      (when pair
2396        (if (cdr pair)        (if (cdr pair)
# Line 2348  of a word, all strings are listed. Retur Line 2428  of a word, all strings are listed. Retur
2428      (set-window-point window (point))))      (set-window-point window (point))))
2429    
2430  (defun bibtex-pop (arg direction)  (defun bibtex-pop (arg direction)
2431    "Generic function to be used by `bibtex-pop-previous' and `bibtex-pop-next'."    "Generic function used by `bibtex-pop-previous' and `bibtex-pop-next'."
2432    (let (bibtex-help-message)    (let (bibtex-help-message)
2433      (bibtex-find-text nil))      (bibtex-find-text nil))
2434    (save-excursion    (save-excursion
# Line 2407  of a word, all strings are listed. Retur Line 2487  of a word, all strings are listed. Retur
2487      (bibtex-find-text nil))      (bibtex-find-text nil))
2488    (setq this-command 'bibtex-pop))    (setq this-command 'bibtex-pop))
2489    
2490    (defsubst bibtex-read-key (prompt &optional key)
2491      "Read BibTeX key from minibuffer using PROMPT and default KEY."
2492      (completing-read prompt bibtex-reference-keys
2493                       nil nil key 'bibtex-key-history))
2494    
2495  ;; Interactive Functions:  ;; Interactive Functions:
2496    
# Line 2416  of a word, all strings are listed. Retur Line 2500  of a word, all strings are listed. Retur
2500    
2501  General information on working with BibTeX mode:  General information on working with BibTeX mode:
2502    
2503  You should use commands as \\[bibtex-Book] to get a template for a  You should use commands such as \\[bibtex-Book] to get a template for a
2504  specific entry. You should then fill in all desired fields using  specific entry. You should then fill in all desired fields using
2505  \\[bibtex-next-field] to jump from field to field. After having filled  \\[bibtex-next-field] to jump from field to field. After having filled
2506  in all desired fields in the entry, you should clean the new entry  in all desired fields in the entry, you should clean the new entry
2507  with command \\[bibtex-clean-entry].  with the command \\[bibtex-clean-entry].
2508    
2509  Some features of BibTeX mode are available only by setting variable  Some features of BibTeX mode are available only by setting the variable
2510  `bibtex-maintain-sorted-entries' to t. However, then BibTeX mode will  `bibtex-maintain-sorted-entries' to non-nil. However, then BibTeX mode will
2511  work with buffer containing only valid (syntactical correct) entries  work only with buffers containing valid (syntactical correct) entries
2512  and with entries being sorted. This is usually the case, if you have  and with entries being sorted. This is usually the case, if you have
2513  created a buffer completely with BibTeX mode and finished every new  created a buffer completely with BibTeX mode and finished every new
2514  entry with \\[bibtex-clean-entry].  entry with \\[bibtex-clean-entry].
2515    
2516  For third party BibTeX buffers, please call the function  For third party BibTeX files, call the function `bibtex-convert-alien'
2517  `bibtex-convert-alien' to fully take advantage of all features of  to fully take advantage of all features of BibTeX mode.
 BibTeX mode.  
2518    
2519    
2520  Special information:  Special information:
# Line 2443  Alternatives from which only one is requ Line 2526  Alternatives from which only one is requ
2526  The OPT or ALT string may be removed from a field with \\[bibtex-remove-OPT-or-ALT].  The OPT or ALT string may be removed from a field with \\[bibtex-remove-OPT-or-ALT].
2527  \\[bibtex-make-field] inserts a new field after the current one.  \\[bibtex-make-field] inserts a new field after the current one.
2528  \\[bibtex-kill-field] kills the current field entirely.  \\[bibtex-kill-field] kills the current field entirely.
2529  \\[bibtex-yank] will yank the last recently killed field after the  \\[bibtex-yank] yanks the last recently killed field after the current field.
 current field.  
2530  \\[bibtex-remove-delimiters] removes the double-quotes or braces around the text of the current field.  \\[bibtex-remove-delimiters] removes the double-quotes or braces around the text of the current field.
2531   \\[bibtex-empty-field] replaces the text of the current field with the default \"\" or {}.   \\[bibtex-empty-field] replaces the text of the current field with the default \"\" or {}.
2532    
# Line 2507  non-nil. Line 2589  non-nil.
2589    (setq major-mode 'bibtex-mode)    (setq major-mode 'bibtex-mode)
2590    (setq mode-name "BibTeX")    (setq mode-name "BibTeX")
2591    (set-syntax-table bibtex-mode-syntax-table)    (set-syntax-table bibtex-mode-syntax-table)
   (make-local-variable 'bibtex-strings)  
   (make-local-variable 'bibtex-reference-keys)  
2592    (make-local-variable 'bibtex-buffer-last-parsed-tick)    (make-local-variable 'bibtex-buffer-last-parsed-tick)
   (bibtex-parse-strings (bibtex-string-files-init))  
   (if bibtex-maintain-sorted-entries  
       (bibtex-parse-keys nil nil t))  
2593    ;; Install stealthy parse function if not already installed    ;; Install stealthy parse function if not already installed
2594    (unless bibtex-parse-idle-timer    (unless bibtex-parse-idle-timer
2595      (setq bibtex-parse-idle-timer (bibtex-run-with-idle-timer      (setq bibtex-parse-idle-timer (bibtex-run-with-idle-timer
# Line 2525  non-nil. Line 2602  non-nil.
2602    (set (make-local-variable 'comment-column) 0)    (set (make-local-variable 'comment-column) 0)
2603    (set (make-local-variable 'defun-prompt-regexp) "^[ \t]*@[a-zA-Z0-9]+[ \t]*")    (set (make-local-variable 'defun-prompt-regexp) "^[ \t]*@[a-zA-Z0-9]+[ \t]*")
2604    (set (make-local-variable 'outline-regexp) "[ \t]*@")    (set (make-local-variable 'outline-regexp) "[ \t]*@")
2605      (set (make-local-variable 'fill-paragraph-function) 'bibtex-fill-field)
2606    (set (make-local-variable 'fill-prefix) (make-string (+ bibtex-entry-offset    (set (make-local-variable 'fill-prefix) (make-string (+ bibtex-entry-offset
2607                                                           bibtex-contline-indentation)                                                           bibtex-contline-indentation)
2608                                                        ? ))                                                        ? ))
# Line 2538  non-nil. Line 2616  non-nil.
2616                  ;; brace-delimited ones                  ;; brace-delimited ones
2617                  )                  )
2618           nil           nil
2619           (font-lock-syntactic-keywords . bibtex-font-lock-syntactic-keywords)))           (font-lock-syntactic-keywords . bibtex-font-lock-syntactic-keywords)
2620    (set (make-local-variable 'font-lock-mark-block-function)           (font-lock-mark-block-function
2621         (lambda ()            . (lambda ()
2622           (set-mark (bibtex-end-of-entry))           (set-mark (bibtex-end-of-entry))
2623           (bibtex-beginning-of-entry)))                (bibtex-beginning-of-entry)))))
2624    (setq imenu-generic-expression    (setq imenu-generic-expression
2625          (list (list nil bibtex-entry-head bibtex-key-in-head)))          (list (list nil bibtex-entry-head bibtex-key-in-head)))
2626    (make-local-variable 'choose-completion-string-functions)    (make-local-variable 'choose-completion-string-functions)
# Line 2561  After insertion it calls the functions i Line 2639  After insertion it calls the functions i
2639                              bibtex-entry-field-alist                              bibtex-entry-field-alist
2640                              nil t nil 'bibtex-entry-type-history)))                              nil t nil 'bibtex-entry-type-history)))
2641                   (list e-t)))                   (list e-t)))
2642    (unless (consp bibtex-reference-keys) (bibtex-parse-keys nil t))    (let* (required optional
   (let* (required  
          optional  
2643           (key (if bibtex-maintain-sorted-entries           (key (if bibtex-maintain-sorted-entries
2644                    (completing-read (format "%s key: " entry-type)                    (bibtex-read-key (format "%s key: " entry-type))))
                                    bibtex-reference-keys  
                                    nil nil nil 'bibtex-key-history)))  
2645           (e (assoc-ignore-case entry-type bibtex-entry-field-alist))           (e (assoc-ignore-case entry-type bibtex-entry-field-alist))
2646           (r-n-o (elt e 1))           (r-n-o (elt e 1))
2647           (c-ref (elt e 2)))           (c-ref (elt e 2)))
# Line 2603  After insertion it calls the functions i Line 2677  After insertion it calls the functions i
2677        (indent-to-column bibtex-entry-offset)        (indent-to-column bibtex-entry-offset)
2678        (insert (bibtex-entry-right-delimiter) "\n\n"))        (insert (bibtex-entry-right-delimiter) "\n\n"))
2679      (bibtex-next-field t)      (bibtex-next-field t)
2680        (if (member-ignore-case entry-type bibtex-autofill-types)
2681            (bibtex-autofill-entry))
2682      (run-hooks 'bibtex-add-entry-hook)))      (run-hooks 'bibtex-add-entry-hook)))
2683    
2684    (defun bibtex-parse-entry ()
2685      "Parse entry at point, return an alist.
2686    The alist elements have the form (FIELD . TEXT), where FIELD can also be
2687    the special strings \"=type=\" and \"=key=\"."
2688      (let (alist bounds)
2689        (when (looking-at bibtex-entry-head)
2690          (push (cons "=type=" (match-string bibtex-type-in-head)) alist)
2691          (push (cons "=key=" (match-string bibtex-key-in-head)) alist)
2692          (goto-char (match-end bibtex-key-in-head))
2693          (while (setq bounds (bibtex-parse-field bibtex-field-name))
2694            (push (cons (bibtex-name-in-field bounds)
2695                        (bibtex-text-in-field-bounds bounds))
2696                  alist)
2697            (goto-char (bibtex-end-of-field bounds))))
2698        alist))
2699    
2700    (defun bibtex-autofill-entry ()
2701      "Try to fill fields based on surrounding entries."
2702      (interactive)
2703      (undo-boundary)       ;So you can easily undo it, if it didn't work right.
2704      (bibtex-beginning-of-entry)
2705      (when (looking-at bibtex-entry-head)
2706        (let ((type (match-string bibtex-type-in-head))
2707              (key (match-string bibtex-key-in-head))
2708              (key-end (match-end bibtex-key-in-head))
2709              (case-fold-search t)
2710              tmp other-key other bounds)
2711          ;; The fields we want to change start right after the key.
2712          (goto-char key-end)
2713          ;; First see whether to use the previous or the next entry
2714          ;; for "inspiration".
2715          (save-excursion
2716            (goto-char (1- (match-beginning 0)))
2717            (bibtex-beginning-of-entry)
2718            (when (and
2719                   (looking-at bibtex-entry-head)
2720                   (equal type (match-string bibtex-type-in-head))
2721                   ;; In case we found ourselves :-(
2722                   (not (equal key (setq tmp (match-string bibtex-key-in-head)))))
2723              (setq other-key tmp)
2724              (setq other (point))))
2725          (save-excursion
2726            (bibtex-end-of-entry)
2727            (bibtex-skip-to-valid-entry)
2728            (when (and
2729                   (looking-at bibtex-entry-head)
2730                   (equal type (match-string bibtex-type-in-head))
2731                   ;; In case we found ourselves :-(
2732                   (not (equal key (setq tmp (match-string bibtex-key-in-head))))
2733                   (or (not other-key)
2734                       ;; Check which is the best match.
2735                       (< (length (try-completion "" (list key other-key)))
2736                          (length (try-completion "" (list key tmp))))))
2737              (setq other-key tmp)
2738              (setq other (point))))
2739          ;; Then fill the new entry's fields with the chosen other entry.
2740          (when other
2741            (setq other (save-excursion (goto-char other) (bibtex-parse-entry)))
2742            (setq key-end (point))      ;In case parse-entry changed the buffer.
2743            (while (setq bounds (bibtex-parse-field bibtex-field-name))
2744              (goto-char (bibtex-start-of-name-in-field bounds))
2745              (let* ((name (buffer-substring
2746                            (if (looking-at "ALT\\|OPT") (match-end 0) (point))
2747                            (bibtex-end-of-name-in-field bounds)))
2748                     (text (assoc-ignore-case name other)))
2749                (goto-char (bibtex-start-of-text-in-field bounds))
2750                (if (not (and (looking-at bibtex-empty-field-re) text))
2751                    (goto-char (bibtex-end-of-field bounds))
2752                  (delete-region (point) (bibtex-end-of-text-in-field bounds))
2753                  (insert (cdr text)))))
2754            ;; Finally try to update the text based on the difference between
2755            ;; the two keys.
2756            (let* ((prefix (try-completion "" (list key other-key)))
2757                   ;; If the keys are foo91 and foo92, don't replace 1 for 2
2758                   ;; but 91 for 92 instead.
2759                   (_ (if (string-match "[0-9]+\\'" prefix)
2760                          (setq prefix (substring prefix 0 (match-beginning 0)))))
2761                   (suffix (substring key (length prefix)))
2762                   (other-suffix (substring other-key (length prefix))))
2763              (while (re-search-backward (regexp-quote other-suffix) key-end 'move)
2764                (replace-match suffix)))))))
2765    
2766  (defun bibtex-print-help-message ()  (defun bibtex-print-help-message ()
2767    "Print helpful information about current field in current BibTeX entry."    "Print helpful information about current field in current BibTeX entry."
2768    (interactive)    (interactive)
# Line 2615  After insertion it calls the functions i Line 2773  After insertion it calls the functions i
2773             (field-name (buffer-substring-no-properties             (field-name (buffer-substring-no-properties
2774                          (if (progn (goto-char mb)                          (if (progn (goto-char mb)
2775                                     (looking-at "OPT\\|ALT"))                                     (looking-at "OPT\\|ALT"))
2776                              (+ 3 mb) mb)                              (match-end 0) mb)
2777                          (bibtex-end-of-name-in-field bounds)))                          (bibtex-end-of-name-in-field bounds)))
2778             (entry-type (progn (re-search-backward             (entry-type (progn (re-search-backward
2779                                 bibtex-entry-maybe-empty-head nil t)                                 bibtex-entry-maybe-empty-head nil t)
# Line 2641  After insertion it calls the functions i Line 2799  After insertion it calls the functions i
2799            (message (elt comment 1))            (message (elt comment 1))
2800          (message "No comment available")))))          (message "No comment available")))))
2801    
2802  (defun bibtex-make-field (e-t &optional called-by-yank)  (defun bibtex-make-field (field &optional called-by-yank)
2803    "Make a field named E-T in current BibTeX entry."    "Make a field named FIELD in current BibTeX entry.
2804    FIELD is either a string or a list of the form
2805    \(FIELD-NAME COMMENT-STRING INIT ALTERNATIVE-FLAG) as in
2806    `bibtex-entry-field-alist'."
2807    (interactive    (interactive
2808     (list (let* ((entry-type     (list (let* ((entry-type
2809                   (save-excursion                   (save-excursion
2810                     (bibtex-enclosing-entry-maybe-empty-head)                     (bibtex-enclosing-entry-maybe-empty-head)
2811                     (bibtex-type-in-head)))                     (bibtex-type-in-head)))
2812                  (fl (cadr (assoc-ignore-case                  ;; "preliminary" completion list
2813                             entry-type bibtex-entry-field-alist)))                  (fl (nth 1 (assoc-ignore-case
2814                  (field-list (append (elt fl 0)                              entry-type bibtex-entry-field-alist)))
2815                                      (elt fl 1)                  ;; "full" completion list
2816                    (field-list (append (nth 0 fl)
2817                                        (nth 1 fl)
2818                                      bibtex-user-optional-fields                                      bibtex-user-optional-fields
2819                                      (if bibtex-include-OPTcrossref                                      (if (member entry-type
2820                                          '(("crossref" nil)))                                                  bibtex-include-OPTcrossref)
2821                                            '(("crossref")))
2822                                      (if bibtex-include-OPTkey                                      (if bibtex-include-OPTkey
2823                                          '(("key" nil)))))                                          '(("key")))))
2824                  (completion-ignore-case t))                  (completion-ignore-case t))
2825             (completing-read "BibTeX field name: " field-list             (completing-read "BibTeX field name: " field-list
2826                              nil nil nil bibtex-field-history))))                              nil nil nil bibtex-field-history))))
2827    (unless (consp e-t)    (unless (consp field)
2828      (setq e-t (list e-t)))      (setq field (list field)))
2829    (let ((name (if (elt e-t 3)    (if (or (interactive-p) called-by-yank)
2830                    (concat "ALT" (car e-t))        (let (bibtex-help-message)
2831                  (car e-t))))          (bibtex-find-text nil t t)
2832      (if (or (interactive-p) called-by-yank)          (if (looking-at "[}\"]")
2833          (let (bibtex-help-message)              (forward-char))))
2834            (bibtex-find-text nil t t)    (insert ",\n")
2835            (if (looking-at "[}\"]")    (indent-to-column (+ bibtex-entry-offset bibtex-field-indentation))
2836                (forward-char))))    (if (nth 3 field) (insert "ALT"))
2837      (insert ",\n")    (insert (car field) " ")
2838      (indent-to-column (+ bibtex-entry-offset bibtex-field-indentation))    (if bibtex-align-at-equal-sign
2839      (insert name " ")        (indent-to-column (+ bibtex-entry-offset
2840      (if bibtex-align-at-equal-sign                             (- bibtex-text-indentation 2))))
2841          (indent-to-column (+ bibtex-entry-offset    (insert "= ")
2842                               (- bibtex-text-indentation 2))))    (if (not bibtex-align-at-equal-sign)
2843      (insert "= ")        (indent-to-column (+ bibtex-entry-offset
2844      (if (not bibtex-align-at-equal-sign)                             bibtex-text-indentation)))
2845          (indent-to-column (+ bibtex-entry-offset    (if (not called-by-yank) (insert (bibtex-field-left-delimiter)))
2846                               bibtex-text-indentation)))    (let ((init (nth 2 field)))
2847      (insert (if called-by-yank      (cond ((stringp init)
2848                  ""             (insert init))
2849                (bibtex-field-left-delimiter))            ((fboundp init)
2850              (let ((init (elt e-t 2)))             (insert (funcall init)))))
2851                (cond ((stringp init)    (if (not called-by-yank) (insert (bibtex-field-right-delimiter)))
2852                       init)    (if (interactive-p)
2853                      ((fboundp init)        (forward-char -1)))
                      (funcall init))  
                     (t "")))  
             (if called-by-yank  
                 ""  
               (bibtex-field-right-delimiter)))  
     (if (interactive-p)  
         (forward-char -1))))  
2854    
2855  (defun bibtex-beginning-of-entry ()  (defun bibtex-beginning-of-entry ()
2856    "Move to beginning of BibTeX entry (beginning of line).    "Move to beginning of BibTeX entry (beginning of line).
2857  If inside an entry, move to the beginning of it, otherwise move to the  If inside an entry, move to the beginning of it, otherwise move to the
2858  beginning of the previous entry.  beginning of the previous entry. If point is ahead of all BibTeX entries
2859  If called from a program, this function returns the new location of point."  move point to the beginning of buffer. Return the new location of point."
2860    (interactive)    (interactive)
2861    (skip-chars-forward " \t")    (skip-chars-forward " \t")
2862    (if (looking-at "@")    (if (looking-at "@")
2863        (forward-char))        (forward-char))
2864    (re-search-backward "^[ \t]*@" nil 'move))    (re-search-backward "^[ \t]*@" nil 'move)
2865      (point))
2866    
2867  (defun bibtex-end-of-entry ()  (defun bibtex-end-of-entry ()
2868    "Move to end of BibTeX entry (past the closing brace).    "Move to end of BibTeX entry (past the closing brace).
2869  If inside an entry, move to the end of it, otherwise move to the end  If inside an entry, move to the end of it, otherwise move to the end
2870  of the previous entry. Do not move if ahead of first entry.  of the previous entry. Do not move if ahead of first entry.
2871  If called from a program, this function returns the new location of point."  Return the new location of point."
2872    (interactive)    (interactive)
2873    (let ((case-fold-search t)    (let ((case-fold-search t)
2874          (org (point))          (org (point))
2875          (pnt (bibtex-beginning-of-entry))          (pnt (bibtex-beginning-of-entry))
2876          err bounds)          err bounds)
2877      (cond ((setq bounds (bibtex-parse-string))      (cond ((looking-at bibtex-valid-entry-whitespace-re)
2878               (bibtex-search-entry t nil t)
2879               (unless (equal (match-beginning 0) pnt)
2880                 (setq err t)))
2881              ((setq bounds (bibtex-parse-string))
2882             (goto-char (bibtex-end-of-string bounds)))             (goto-char (bibtex-end-of-string bounds)))
2883            ((looking-at "[ \t]*@[ \t]*preamble[ \t\n]*")            ((looking-at "[ \t]*@[ \t]*preamble[ \t\n]*")
2884             (goto-char (match-end 0))             (goto-char (match-end 0))
# Line 2731  If called from a program, this function Line 2893  If called from a program, this function
2893             (unless err             (unless err
2894               (goto-char (match-beginning 0))               (goto-char (match-beginning 0))
2895               (forward-char)))               (forward-char)))
           ((looking-at bibtex-valid-entry-whitespace-re)  
            (bibtex-search-entry t nil t)  
            (unless (equal (match-beginning 0) pnt)  
              (setq err t)))  
2896            (t            (t
2897             (if (interactive-p)             (if (interactive-p)
2898                 (message "Not on a known BibTeX entry."))                 (message "Not on a known BibTeX entry."))
# Line 2777  If mark is active it counts entries in r Line 2935  If mark is active it counts entries in r
2935                                (region-end)                                (region-end)
2936                              (point-max)))                              (point-max)))
2937          (goto-char (point-min))          (goto-char (point-min))
2938          (bibtex-map-entries (lambda (current)          (bibtex-map-entries (lambda (key beg end)
2939                                (setq number (1+ number))))))                                (setq number (1+ number))))))
2940      (message "%s contains %d entries."      (message "%s contains %d entries."
2941               (if (bibtex-mark-active) "Region" "Buffer")               (if (bibtex-mark-active) "Region" "Buffer")
2942                 number)))               number)))
2943    
2944  (defun bibtex-ispell-entry ()  (defun bibtex-ispell-entry ()
2945    "Spell whole BibTeX entry."    "Spell whole BibTeX entry."
2946    (interactive)    (interactive)
2947    (ispell-region (bibtex-beginning-of-entry)    (ispell-region (save-excursion (bibtex-beginning-of-entry))
2948                   (bibtex-end-of-entry)))                   (save-excursion (bibtex-end-of-entry))))
2949    
2950  (defun bibtex-ispell-abstract ()  (defun bibtex-ispell-abstract ()
2951    "Spell abstract of BibTeX entry."    "Spell abstract of BibTeX entry."
2952    (interactive)    (interactive)
2953    (bibtex-beginning-of-entry)    (let ((bounds (save-excursion
2954    (let ((bounds (bibtex-search-forward-field "abstract"                    (bibtex-beginning-of-entry)
2955                                               (bibtex-end-of-entry))))                    (bibtex-search-forward-field "abstract" t))))
2956      (if bounds      (if bounds
2957          (ispell-region (bibtex-start-of-text-in-field bounds)          (ispell-region (bibtex-start-of-text-in-field bounds)
2958                         (bibtex-end-of-text-in-field bounds))                         (bibtex-end-of-text-in-field bounds))
# Line 2815  the entries of the BibTeX buffer. Return Line 2973  the entries of the BibTeX buffer. Return
2973    (let ((case-fold-search t))    (let ((case-fold-search t))
2974      (if (re-search-forward bibtex-entry-maybe-empty-head nil t)      (if (re-search-forward bibtex-entry-maybe-empty-head nil t)
2975          (let ((key (bibtex-key-in-head))          (let ((key (bibtex-key-in-head))
2976                (entry-name (bibtex-type-in-head)))                ;; all entry names should be downcase (for ease of comparison)
2977                  (entry-name (downcase (bibtex-type-in-head))))
2978            ;; Don't search CROSSREF-KEY if we don't need it.            ;; Don't search CROSSREF-KEY if we don't need it.
2979            (if (equal bibtex-maintain-sorted-entries 'crossref)            (if (equal bibtex-maintain-sorted-entries 'crossref)
2980                (save-excursion                (save-excursion
2981                  (save-restriction                  (bibtex-beginning-of-entry)
2982                    (bibtex-narrow-to-entry)                  (let ((bounds (bibtex-search-forward-field
2983                    (goto-char (point-min))                                 "\\(OPT\\)?crossref" t)))
2984                    (let ((bounds (bibtex-search-forward-field                    (list key
2985                                   "\\(OPT\\)?crossref")))                          (if bounds (bibtex-text-in-field-bounds bounds t))
2986                      (list key                          entry-name))))
2987                            (if bounds (bibtex-text-in-field-bounds bounds t))            (list key nil entry-name)))))
                           entry-name))))  
             (list key nil entry-name))))))  
2988    
2989  (defun bibtex-lessp (index1 index2)  (defun bibtex-lessp (index1 index2)
2990    "Predicate for sorting BibTeX entries with indices INDEX1 and INDEX2.    "Predicate for sorting BibTeX entries with indices INDEX1 and INDEX2.
# Line 2846  The predicate depends on the variable `b Line 3003  The predicate depends on the variable `b
3003                 (string-lessp (nth 0 index1) (nth 1 index2))                 (string-lessp (nth 0 index1) (nth 1 index2))
3004               (string-lessp (nth 0 index1) (nth 0 index2)))))               (string-lessp (nth 0 index1) (nth 0 index2)))))
3005          ((equal bibtex-maintain-sorted-entries 'entry-class)          ((equal bibtex-maintain-sorted-entries 'entry-class)
3006           (let ((n1 (cdr (assoc-ignore-case (nth 2 index1)           (let ((n1 (cdr (or (assoc (nth 2 index1) bibtex-sort-entry-class-alist)
3007                                             bibtex-sort-entry-class-alist)))                              (assoc 'catch-all bibtex-sort-entry-class-alist)
3008                 (n2 (cdr (assoc-ignore-case (nth 2 index2)                              '(nil . 1000))))  ; if there is nothing else
3009                                             bibtex-sort-entry-class-alist))))                 (n2 (cdr (or (assoc (nth 2 index2) bibtex-sort-entry-class-alist)
3010                                (assoc 'catch-all bibtex-sort-entry-class-alist)
3011                                '(nil . 1000))))) ; if there is nothing else
3012             (or (< n1 n2)             (or (< n1 n2)
3013                 (and (= n1 n2)                 (and (= n1 n2)
3014                      (string-lessp (car index1) (car index2))))))                      (string-lessp (car index1) (car index2))))))
# Line 2880  ignored." Line 3039  ignored."
3039  (defun bibtex-find-crossref (crossref-key)  (defun bibtex-find-crossref (crossref-key)
3040    "Move point to the beginning of BibTeX entry CROSSREF-KEY.    "Move point to the beginning of BibTeX entry CROSSREF-KEY.
3041  Return position of entry if CROSSREF-KEY is found and nil otherwise.  Return position of entry if CROSSREF-KEY is found and nil otherwise.
3042  If position of current entry is after CROSSREF-KEY an error is signaled."  If position of current entry is after CROSSREF-KEY an error is signaled.
3043    If called interactively, CROSSREF-KEY defaults to crossref key of current
3044    entry."
3045      (interactive
3046       (let ((crossref-key
3047              (save-excursion
3048                (bibtex-beginning-of-entry)
3049                (let ((bounds (bibtex-search-forward-field "crossref" t)))
3050                  (if bounds
3051                      (bibtex-text-in-field-bounds bounds t))))))
3052         (list (bibtex-read-key "Find crossref key: " crossref-key))))
3053    (let ((pos (save-excursion (bibtex-find-entry crossref-key))))    (let ((pos (save-excursion (bibtex-find-entry crossref-key))))
3054      (if (and pos (> (point) pos))      (if (and pos (> (point) pos))
3055          (error "This entry must not follow the crossrefed entry!"))          (error "This entry must not follow the crossrefed entry!"))
# Line 2889  If position of current entry is after CR Line 3058  If position of current entry is after CR
3058  (defun bibtex-find-entry (key)  (defun bibtex-find-entry (key)
3059    "Move point to the beginning of BibTeX entry named KEY.    "Move point to the beginning of BibTeX entry named KEY.
3060  Return position of entry if KEY is found or nil if not found."  Return position of entry if KEY is found or nil if not found."
3061    (interactive    (interactive (list (bibtex-read-key "Find key: ")))
    (list (if bibtex-maintain-sorted-entries  
              (completing-read "Find key: "  
                               bibtex-reference-keys  
                               nil nil nil 'bibtex-key-history)  
            (read-from-minibuffer "Find key: " nil nil nil  
                                  'bibtex-key-history))))  
3062    (let* (case-fold-search    (let* (case-fold-search
3063           (pnt (save-excursion           (pnt (save-excursion
3064                  (goto-char (point-min))                  (goto-char (point-min))
3065                  (when (re-search-forward (concat "^[ \t]*\\("                  (if (re-search-forward (concat "^[ \t]*\\("
3066                                                   bibtex-entry-type                                                 bibtex-entry-type
3067                                                   "\\)[ \t]*[({][ \t\n]*\\("                                                 "\\)[ \t]*[({][ \t\n]*\\("
3068                                                   (regexp-quote key) "\\)")                                                 (regexp-quote key)
3069                                           nil t)                                                 "\\)[ \t\n]*[,=]")
3070                    (match-beginning 2)))))                                         nil t)
3071                        (match-beginning 0)))))
3072      (cond (pnt      (cond (pnt
3073             (goto-char pnt)             (goto-char pnt))
            (bibtex-beginning-of-entry))  
3074            ((interactive-p)            ((interactive-p)
3075             (message "Key `%s' not found" key)))))             (message "Key `%s' not found" key)))))
3076    
# Line 3019  Returns t if test was successful, nil ot Line 3182  Returns t if test was successful, nil ot
3182                  (goto-char (point-min))                  (goto-char (point-min))
3183                  (bibtex-progress-message "Checking correct sort order")                  (bibtex-progress-message "Checking correct sort order")
3184                  (bibtex-map-entries                  (bibtex-map-entries
3185                   (lambda (dummy)                   (lambda (key beg end)
3186                     (bibtex-progress-message)                     (bibtex-progress-message)
3187                     (bibtex-beginning-of-entry)                     (goto-char beg)
3188                     (setq current (bibtex-entry-index))                     (setq current (bibtex-entry-index))
3189                     (cond ((or (not previous)                     (cond ((or (not previous)
3190                                (bibtex-lessp previous current))                                (bibtex-lessp previous current))
# Line 3045  Returns t if test was successful, nil ot Line 3208  Returns t if test was successful, nil ot
3208                    (questionable-month                    (questionable-month
3209                     (regexp-opt (mapcar 'car bibtex-predefined-month-strings))))                     (regexp-opt (mapcar 'car bibtex-predefined-month-strings))))
3210                (bibtex-map-entries                (bibtex-map-entries
3211                 (lambda (current)                 (lambda (key beg end)
3212                   (bibtex-progress-message)                   (bibtex-progress-message)
3213                   (let* ((beg (bibtex-beginning-of-entry))                   (let* ((entry-list (progn
                         (end (bibtex-end-of-entry))  
                         (entry-list (progn  
3214                                        (goto-char beg)                                        (goto-char beg)
3215                                        (bibtex-search-entry nil end)                                        (bibtex-search-entry nil end)
3216                                        (assoc-ignore-case (bibtex-type-in-head)                                        (assoc-ignore-case (bibtex-type-in-head)
# Line 3185  Align text and go thereafter to end of t Line 3346  Align text and go thereafter to end of t
3346      (save-excursion      (save-excursion
3347        (goto-char (bibtex-start-of-name-in-field bounds))        (goto-char (bibtex-start-of-name-in-field bounds))
3348        (when (looking-at "OPT\\|ALT")        (when (looking-at "OPT\\|ALT")
3349          (delete-char (length "OPT"))          (delete-region (match-beginning 0) (match-end 0))
3350          ;; make field non-OPT          ;; make field non-OPT
3351          (search-forward "=")          (search-forward "=")
3352          (forward-char -1)          (forward-char -1)
# Line 3326  intermixed with \\[bibtex-pop-previous] Line 3487  intermixed with \\[bibtex-pop-previous]
3487    
3488  (defun bibtex-clean-entry (&optional new-key called-by-reformat)  (defun bibtex-clean-entry (&optional new-key called-by-reformat)
3489    "Finish editing the current BibTeX entry and clean it up.    "Finish editing the current BibTeX entry and clean it up.
3490  Checks that no required fields are empty and formats entry dependent  Check that no required fields are empty and formats entry dependent
3491  on the value of `bibtex-entry-format'.  on the value of `bibtex-entry-format'.
3492  If the reference key of the entry is empty or a prefix argument is given,  If the reference key of the entry is empty or a prefix argument is given,
3493  calculate a new reference key. (Note: this only will work if fields in entry  calculate a new reference key. (Note: this will only work if fields in entry
3494  begin on separate lines prior to calling `bibtex-clean-entry' or if  begin on separate lines prior to calling `bibtex-clean-entry' or if
3495  'realign is contained in `bibtex-entry-format'.)  'realign is contained in `bibtex-entry-format'.)
3496  Don't call this on @String or @Preamble entries.  Don't call `bibtex-clean-entry' on @Preamble entries.
3497  At end of the cleaning process, the functions in  At end of the cleaning process, the functions in
3498  `bibtex-clean-entry-hook' are called with region narrowed to entry."  `bibtex-clean-entry-hook' are called with region narrowed to entry."
3499    ;; Opt. arg called-by-reformat is t if bibtex-clean-entry    ;; Opt. arg called-by-reformat is t if bibtex-clean-entry
3500    ;; is called by bibtex-reformat    ;; is called by bibtex-reformat
3501    (interactive "P")    (interactive "P")
   (bibtex-format-entry)  
3502    (let ((case-fold-search t)    (let ((case-fold-search t)
3503          key)          entry-type key)
3504      (bibtex-beginning-of-entry)      (bibtex-beginning-of-entry)
3505      (setq key (save-excursion      (save-excursion
3506                  (if (re-search-forward bibtex-entry-maybe-empty-head nil t)        (when (re-search-forward bibtex-entry-maybe-empty-head nil t)
3507                      (bibtex-key-in-head))))          (setq entry-type (downcase (bibtex-type-in-head)))
3508            (setq key (bibtex-key-in-head))))
3509        ;; formatting
3510        (cond ((equal entry-type "preamble")
3511               ;; (bibtex-format-preamble)
3512               (error "No clean up of @Preamble entries"))
3513              ((equal entry-type "string"))
3514               ;; (bibtex-format-string)
3515              (t (bibtex-format-entry)))
3516        ;; set key
3517      (when (or new-key (not key))      (when (or new-key (not key))
3518        (setq key (if bibtex-autokey-edit-before-use        (setq key (bibtex-generate-autokey))
3519                      (read-from-minibuffer        (if bibtex-autokey-edit-before-use
3520                       "Key to use: " (bibtex-generate-autokey) nil nil            (setq key (bibtex-read-key "Key to use: " key)))
                      'bibtex-key-history)  
                   (bibtex-generate-autokey)))  
       (bibtex-beginning-of-entry)  
3521        (re-search-forward bibtex-entry-maybe-empty-head)        (re-search-forward bibtex-entry-maybe-empty-head)
3522        (if (match-beginning bibtex-key-in-head)        (if (match-beginning bibtex-key-in-head)
3523            (delete-region (match-beginning bibtex-key-in-head)            (delete-region (match-beginning bibtex-key-in-head)
3524                           (match-end bibtex-key-in-head)))                           (match-end bibtex-key-in-head)))
3525        (insert key))        (insert key))
3526        ;; sorting
3527      (let* ((start (bibtex-beginning-of-entry))      (let* ((start (bibtex-beginning-of-entry))
3528             (end (progn (bibtex-end-of-entry)             (end (progn (bibtex-end-of-entry)
3529                         (if (re-search-forward                         (if (re-search-forward
# Line 3368  At end of the cleaning process, the func Line 3535  At end of the cleaning process, the func
3535                           (bibtex-entry-index))))                           (bibtex-entry-index))))
3536        (delete-region start end)        (delete-region start end)
3537        (unless (prog1 (or called-by-reformat        (unless (prog1 (or called-by-reformat
3538                           (if bibtex-maintain-sorted-entries                           (if (and bibtex-maintain-sorted-entries
3539                                      (not (and bibtex-sort-ignore-string-entries
3540                                                (equal entry-type "string"))))
3541                               (bibtex-prepare-new-entry index)                               (bibtex-prepare-new-entry index)
3542                             (not (bibtex-find-entry (car index)))))                             (not (bibtex-find-entry (car index)))))
3543                  (insert entry)                  (insert entry)
# Line 3376  At end of the cleaning process, the func Line 3545  At end of the cleaning process, the func
3545                  (bibtex-beginning-of-entry) ; moves backward                  (bibtex-beginning-of-entry) ; moves backward
3546                  (re-search-forward bibtex-entry-head))                  (re-search-forward bibtex-entry-head))
3547          (error "New inserted entry yields duplicate key")))          (error "New inserted entry yields duplicate key")))
3548        ;; final clean up
3549      (unless called-by-reformat      (unless called-by-reformat
3550        (save-excursion        (save-excursion
3551          (save-restriction          (save-restriction
3552            (bibtex-narrow-to-entry)            (bibtex-narrow-to-entry)
3553            ;; Only update the list of keys if it's been built already.            ;; Only update the list of keys if it has been built already.
3554            (if (consp bibtex-reference-keys) (bibtex-parse-keys t nil))            (cond ((equal entry-type "string")
3555                     (if (listp bibtex-strings) (bibtex-parse-strings t)))
3556                    ((listp bibtex-reference-keys) (bibtex-parse-keys t)))
3557            (run-hooks 'bibtex-clean-entry-hook))))))            (run-hooks 'bibtex-clean-entry-hook))))))
3558    
3559    (defun bibtex-fill-field-bounds (bounds justify &optional move)
3560      "Fill BibTeX field delimited by BOUNDS.
3561    If JUSTIFY is non-nil justify as well.
3562    If optional arg MOVE is non-nil move point to end of field."
3563      (let ((end-field (copy-marker (bibtex-end-of-field bounds))))
3564        (goto-char (bibtex-start-of-field bounds))
3565        (if justify
3566            (progn
3567              (forward-char)
3568              (bibtex-delete-whitespace)
3569              (open-line 1)
3570              (forward-char)
3571              (indent-to-column (+ bibtex-entry-offset
3572                                   bibtex-field-indentation))
3573              (re-search-forward "[ \t\n]*=" end-field)
3574              (replace-match "=")
3575              (forward-char -1)
3576              (if bibtex-align-at-equal-sign
3577                  (indent-to-column
3578                   (+ bibtex-entry-offset (- bibtex-text-indentation 2)))
3579                (insert " "))
3580              (forward-char)
3581              (bibtex-delete-whitespace)
3582              (if bibtex-align-at-equal-sign
3583                  (insert " ")
3584                (indent-to-column bibtex-text-indentation)))
3585          (re-search-forward "[ \t\n]*=[ \t\n]*" end-field))
3586        (while (re-search-forward "[ \t\n]+" end-field 'move)
3587          (replace-match " "))
3588        (do-auto-fill)
3589        (if move (goto-char end-field))))
3590    
3591    (defun bibtex-fill-field (&optional justify)
3592      "Like \\[fill-paragraph], but fill current BibTeX field.
3593    Optional prefix arg JUSTIFY non-nil means justify as well.
3594    In BibTeX mode this function is bound to `fill-paragraph-function'."
3595      (interactive "*P")
3596      (let ((pnt (copy-marker (point)))
3597            (bounds (bibtex-enclosing-field)))
3598        (when bounds
3599          (bibtex-fill-field-bounds bounds justify)
3600          (goto-char pnt))))
3601    
3602  (defun bibtex-fill-entry ()  (defun bibtex-fill-entry ()
3603    "Fill current BibTeX entry.    "Fill current BibTeX entry.
3604  Realign entry, so that every field starts on a separate line.  Field  Realign entry, so that every field starts on a separate line.  Field
3605  names appear in column `bibtex-field-indentation', field text starts in  names appear in column `bibtex-field-indentation', field text starts in
3606  column `bibtex-text-indentation' and continuation lines start here, too.  column `bibtex-text-indentation' and continuation lines start here, too.
3607  If `bibtex-align-at-equal-sign' is non-nil, align equal signs also."  If `bibtex-align-at-equal-sign' is non-nil, align equal signs, too."
3608    (interactive "*")    (interactive "*")
3609    (let ((pnt (copy-marker (point)))    (let ((pnt (copy-marker (point)))
3610          (end (copy-marker (bibtex-end-of-entry)))          (end (copy-marker (bibtex-end-of-entry)))
# Line 3398  If `bibtex-align-at-equal-sign' is non-n Line 3613  If `bibtex-align-at-equal-sign' is non-n
3613      (bibtex-delete-whitespace)      (bibtex-delete-whitespace)
3614      (indent-to-column bibtex-entry-offset)      (indent-to-column bibtex-entry-offset)
3615      (while (setq bounds (bibtex-search-forward-field bibtex-field-name end))      (while (setq bounds (bibtex-search-forward-field bibtex-field-name end))
3616        (let* ((begin-field (copy-marker (bibtex-start-of-field bounds)))        (bibtex-fill-field-bounds bounds t t))
              (end-field (copy-marker (bibtex-end-of-field bounds))))  
         (goto-char begin-field)  
         (forward-char)  
         (bibtex-delete-whitespace)  
         (open-line 1)  
         (forward-char)  
         (indent-to-column (+ bibtex-entry-offset  
                              bibtex-field-indentation))  
         (re-search-forward "[ \t\n]*=" end)  
         (replace-match "=")  
         (forward-char -1)  
         (if bibtex-align-at-equal-sign  
             (indent-to-column  
              (+ bibtex-entry-offset (- bibtex-text-indentation 2)))  
           (insert " "))  
         (forward-char)  
         (bibtex-delete-whitespace)  
         (if bibtex-align-at-equal-sign  
             (insert " ")  
           (indent-to-column bibtex-text-indentation))  
         (while (re-search-forward "[ \t\n]+" end-field 'move)  
           (replace-match " "))  
         (do-auto-fill)  
         (goto-char end-field)))  
3617      (if (looking-at ",")      (if (looking-at ",")
3618          (forward-char))          (forward-char))
3619      (bibtex-delete-whitespace)      (bibtex-delete-whitespace)
# Line 3488  If mark is active it reformats entries i Line 3679  If mark is active it reformats entries i
3679            (replace-match "\n\\1")))            (replace-match "\n\\1")))
3680        (goto-char start-point)        (goto-char start-point)
3681        (bibtex-progress-message "Formatting" 1)        (bibtex-progress-message "Formatting" 1)
3682        (bibtex-map-entries (lambda (current)        (bibtex-map-entries (lambda (key beg end)
3683                              (bibtex-progress-message)                              (bibtex-progress-message)
3684                              (bibtex-clean-entry reformat-reference-keys t)                              (bibtex-clean-entry reformat-reference-keys t)
3685                              (when (memq 'realign bibtex-entry-format)                              (when (memq 'realign bibtex-entry-format)
3686                                (bibtex-end-of-entry)                                (goto-char end)
3687                                (bibtex-delete-whitespace)                                (bibtex-delete-whitespace)
3688                                (open-line 2))))                                (open-line 2))))
3689        (bibtex-progress-message 'done))        (bibtex-progress-message 'done))
# Line 3500  If mark is active it reformats entries i Line 3691  If mark is active it reformats entries i
3691                 bibtex-maintain-sorted-entries                 bibtex-maintain-sorted-entries
3692                 (not called-by-convert-alien))                 (not called-by-convert-alien))
3693        (bibtex-sort-buffer)        (bibtex-sort-buffer)
3694        (setq bibtex-reference-keys nil)        (kill-local-variable 'bibtex-reference-keys))
       (bibtex-parse-keys nil t t))  
3695      (goto-char pnt)))      (goto-char pnt)))
3696    
3697  (defun bibtex-convert-alien (&optional do-additional-reformatting)  (defun bibtex-convert-alien (&optional do-additional-reformatting)
# Line 3534  non-nil, read options for reformatting e Line 3724  non-nil, read options for reformatting e
3724    
3725  (defun bibtex-complete ()  (defun bibtex-complete ()
3726    "Complete word fragment before point according to context.    "Complete word fragment before point according to context.
3727  If inside key or crossref field complete key based on  If point is inside key or crossref field perform key completion based on
3728  `bibtex-reference-keys'. Inside any other field perform string  `bibtex-reference-keys'. Inside any other field perform string
3729  completion based on `bibtex-strings'. An error is signaled if point  completion based on `bibtex-strings'. An error is signaled if point
3730  is outside key or BibTeX field."  is outside key or BibTeX field."
# Line 3570  is outside key or BibTeX field." Line 3760  is outside key or BibTeX field."
3760    
3761      (cond ((equal compl 'key)      (cond ((equal compl 'key)
3762             ;; key completion             ;; key completion
            (unless (consp bibtex-reference-keys) (bibtex-parse-keys nil t))  
3763             (setq choose-completion-string-functions             (setq choose-completion-string-functions
3764                   (lambda (choice buffer mini-p base-size)                   (lambda (choice buffer mini-p base-size)
3765                     (bibtex-choose-completion-string choice buffer mini-p base-size)                     (bibtex-choose-completion-string choice buffer mini-p base-size)
# Line 3661  is outside key or BibTeX field." Line 3850  is outside key or BibTeX field."
3850    
3851  (defun bibtex-String (&optional key)  (defun bibtex-String (&optional key)
3852    "Insert a new BibTeX @String entry with key KEY."    "Insert a new BibTeX @String entry with key KEY."
3853    (interactive    (interactive (list (completing-read "String key: " bibtex-strings
3854     (progn (unless (consp bibtex-reference-keys) (bibtex-parse-keys nil t))                                        nil nil nil 'bibtex-key-history)))
           (list (completing-read "String key: " bibtex-reference-keys  
                                    nil nil nil 'bibtex-key-history))))  
   ;; If we want to sort String entries only the sorting scheme  
   ;; entry-class is meaningful  
3855    (let ((bibtex-maintain-sorted-entries    (let ((bibtex-maintain-sorted-entries
3856           (if (and (not bibtex-sort-ignore-string-entries)           (if (not bibtex-sort-ignore-string-entries)
3857                    bibtex-maintain-sorted-entries)               bibtex-maintain-sorted-entries))
              'entry-class))  
3858          endpos)          endpos)
3859      (unless (bibtex-prepare-new-entry (list key nil "String"))      (unless (bibtex-prepare-new-entry (list key nil "String"))
3860        (error "Entry with key `%s' already exists" key))        (error "Entry with key `%s' already exists" key))
# Line 3696  is outside key or BibTeX field." Line 3880  is outside key or BibTeX field."
3880    (bibtex-move-outside-of-entry)    (bibtex-move-outside-of-entry)
3881    (indent-to-column bibtex-entry-offset)    (indent-to-column bibtex-entry-offset)
3882    (insert "@Preamble"    (insert "@Preamble"
3883            (bibtex-entry-left-delimiter)            (bibtex-entry-left-delimiter))
3884            (bibtex-entry-right-delimiter)    (let ((endpos (point)))
3885            "\n")      (insert (bibtex-entry-right-delimiter)
3886    (forward-line -1)              "\n")
3887    (forward-char 10))      (goto-char endpos)))
3888    
3889    
3890  ;; Make BibTeX a Feature  ;; Make BibTeX a Feature

Legend:
Removed from v.1.76  
changed lines
  Added in v.1.77

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26