Anonymous avatar Anonymous committed 833a7fe

Created

Comments (0)

Files changed (10)

+1998-01-12  SL Baur  <steve@altair.xemacs.org>
+
+	* Makefile (CATEGORY): Created.
+# Makefile for TPU/EDT lisp code
+
+# This file is part of XEmacs.
+
+# XEmacs is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2, or (at your option) any
+# later version.
+
+# XEmacs is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with XEmacs; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+VERSION = 1.0
+PACKAGE = textools
+PKG_TYPE = regular
+REQUIRES = xemacs-base
+CATEGORY = wp
+
+ELCS = bib-mode.elc bibtex.elc doctex.elc refbib.elc reftex.elc
+
+include ../../XEmacs.rules
+
+all:: $(ELCS) auto-autoloads.elc
+
+srckit: srckit-std
+
+binkit: binkit-sourceonly
+;;;###autoload
+(package-provide 'textools
+		 :version 1.0
+		 :type 'regular)
+;;; bib-mode.el --- bib-mode, major mode for editing bib files.
+
+;; Copyright (C) 1989 Free Software Foundation, Inc.
+
+;; Maintainer: FSF
+;; Keywords: bib
+
+;; This file is part of XEmacs.
+
+;; XEmacs is free software; you can redistribute it and/or modify it
+;; under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+
+;; XEmacs is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;; General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with XEmacs; see the file COPYING.  If not, write to the Free
+;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+;; 02111-1307, USA.
+
+;;; Synched up with: FSF 19.34.
+
+;;; Commentary:
+
+;;   GNU Emacs code to help maintain databases compatible with (troff)
+;;   refer and lookbib.  The file bib-file should be set to your 
+;;   bibliography file.  Keys are automagically inserted as you type,
+;;   and appropriate keys are presented for various kinds of entries.
+
+;;; Code:
+
+(defvar bib-file "~/my-bibliography.bib" 
+   "Default name of file used by `addbib'.")
+
+(defvar unread-bib-file "~/to-be-read.bib"
+   "Default name of file used by `unread-bib' in Bib mode.")
+
+(defvar bib-mode-map (copy-keymap text-mode-map))
+(define-key bib-mode-map "\C-M" 'return-key-bib)
+(define-key bib-mode-map "\C-c\C-u" 'unread-bib)
+(define-key bib-mode-map "\C-c\C-@" 'mark-bib)
+(define-key bib-mode-map "\e`" 'abbrev-mode)
+(defvar bib-mode-abbrev-table nil
+   "Abbrev table used in Bib mode")
+
+(defun addbib ()
+   "Set up editor to add to troff bibliography file specified 
+by global variable `bib-file'.  See description of `bib-mode'."
+   (interactive)
+   (find-file bib-file)
+   (goto-char (point-max))
+   (bib-mode)
+   )
+   
+(defun bib-mode ()
+   "Mode for editing `lookbib' style bibliographies.  
+Hit RETURN to get next % field key.
+If you want to ignore this field, just hit RETURN again.
+Use `text-mode' to turn this feature off.
+
+ journal papers:                    A* T D J V N P K W X
+ articles in books & proceedings:   A* T D B E* I C P K W X 
+ tech reports:                      A* T D R I C K W X
+ books:                             A* T D I C K W X
+
+Fields:
+
+A uthor		T itle		D ate  		J ournal
+V olume		N umber		P age		K eywords
+B in book or proceedings	E ditor		C ity & state
+I nstitution, school, or publisher
+R eport number or 'phd thesis' or 'masters thesis' or 'draft' or 
+     'unnumbered' or 'unpublished'
+W here can be found locally (login name, or ailib, etc.)
+X comments (not used in indexing)
+
+\\[unread-bib] appends current entry to a different file (for example,
+a file of papers to be read in the future), given by the value of the
+variable `unread-bib-file'.
+\\[mark-bib] marks current or previous entry.
+Abbreviations are saved in `bib-mode-abbrev-table'.
+Hook can be stored in `bib-mode-hook'.
+Field keys given by variable `bib-assoc'.
+
+Commands:
+\\{bib-mode-map}
+"
+   (interactive)
+   (text-mode)
+   (use-local-map bib-mode-map)
+   (setq mode-name "Bib")
+   (setq major-mode 'bib-mode)
+   (define-abbrev-table 'bib-mode-abbrev-table ())
+   (setq local-abbrev-table bib-mode-abbrev-table)
+   (abbrev-mode 1)
+   (run-hooks 'bib-mode-hook)
+   )
+
+(defconst bib-assoc '(
+		   (" *$" . "%A ")
+		   ("%A ." . "%A ")
+		   ("%A $" . "%T ")
+		   ("%T " . "%D ")
+		   ("%D " . "%J ")
+		   ("%J ." . "%V ")
+		   ("%V " . "%N ")
+		   ("%N " . "%P ")
+		   ("%P " . "%K ")
+		   ("%K " . "%W ")
+		   ("%W " . "%X ")
+		   ("%X " . "")
+		   ("%J $" . "%B ")
+		   ("%B ." . "%E ")
+		   ("%E ." . "%E ")
+		   ("%E $" . "%I ")
+		   ("%I " . "%C ")
+		   ("%C " . "%P ")
+		   ("%B $" . "%R ")
+		   ("%R " . "%I ")
+		   )
+		   
+"Describes bibliographic database format.  A line beginning with
+the car of an entry is followed by one beginning with the cdr.
+")
+
+(defun bib-find-key (slots)
+   (cond
+      ((null slots)
+	 (if (bobp)
+	    ""
+	    (progn (previous-line 1) (bib-find-key bib-assoc))))
+      ((looking-at (car (car slots)))
+	 (cdr (car slots)))
+      (t (bib-find-key (cdr slots)))
+      ))
+
+
+(defvar bib-auto-capitalize t 
+"*True to automatically capitalize appropriate fields in Bib mode.")
+
+(defconst bib-capitalized-fields "%[AETCBIJR]")
+
+(defun return-key-bib ()
+  "Magic when user hits return, used by `bib-mode'."
+  (interactive)
+  (if (eolp)
+    (let (empty new-key beg-current end-current)
+      (beginning-of-line)
+      (setq empty (looking-at "%. $"))
+      (if (not empty)
+	(progn
+	  (end-of-line)
+	  (newline)
+	  (forward-line -1)
+	  ))
+      (end-of-line)
+      (setq end-current (point))
+      (beginning-of-line)
+      (setq beg-current (point))
+      (setq new-key (bib-find-key bib-assoc))
+      (if (and (not empty) bib-auto-capitalize
+	    (looking-at bib-capitalized-fields))
+	(save-excursion
+	  (capitalize-title-region (+ (point) 3) end-current)))
+      (goto-char beg-current)
+      (if empty
+	(kill-line nil)
+	(forward-line 1)
+	)
+      (insert-string new-key))
+    (newline)))
+
+(defun mark-bib ()
+   "Set mark at beginning of current or previous bib entry, point at end."
+   (interactive)
+   (beginning-of-line nil)
+   (if (looking-at "^ *$") (re-search-backward "[^ \n]" nil 2))
+   (re-search-backward "^ *$" nil 2)
+   (re-search-forward "^%")
+   (beginning-of-line nil)
+   (push-mark (point))
+   (re-search-forward "^ *$" nil 2)
+   (next-line 1)
+   (beginning-of-line nil))
+
+(defun unread-bib ()
+   "Append current or previous entry to file of unread papers
+named by variable `unread-bib-file'."
+   (interactive)
+   (mark-bib)
+   (if (get-file-buffer unread-bib-file)
+      (append-to-buffer (get-file-buffer unread-bib-file) (mark) (point))
+      (append-to-file (mark) (point) unread-bib-file)))
+
+
+(defvar capitalize-title-stop-words
+   (concat
+      "the\\|and\\|of\\|is\\|a\\|an\\|of\\|for\\|in\\|to\\|in\\|on\\|at\\|"
+      "by\\|with\\|that\\|its")
+   "Words not to be capitalized in a title (unless they're the first word
+in the title).")
+
+(defvar capitalize-title-stop-regexp
+   (concat "\\(" capitalize-title-stop-words "\\)\\(\\b\\|'\\)"))
+
+(defun capitalize-title-region (begin end)
+   "Like `capitalize-region', but don't capitalize stop words, except the first."
+   (interactive "r")
+   (let ((case-fold-search nil) (orig-syntax-table (syntax-table)))
+      (unwind-protect
+	 (save-restriction
+	    (set-syntax-table text-mode-syntax-table)
+	    (narrow-to-region begin end)
+	    (goto-char (point-min))
+	    (if (looking-at "[A-Z][a-z]*[A-Z]")
+	       (forward-word 1)
+	       (capitalize-word 1))
+	    (while (re-search-forward "\\<" nil t)
+	       (if (looking-at "[A-Z][a-z]*[A-Z]")
+		  (forward-word 1)
+		  (if (let ((case-fold-search t))
+			 (looking-at capitalize-title-stop-regexp))
+		     (downcase-word 1)
+		     (capitalize-word 1)))
+	       ))
+	 (set-syntax-table orig-syntax-table))))
+
+
+(defun capitalize-title (s)
+   "Like `capitalize', but don't capitalize stop words, except the first."
+   (save-excursion
+      (set-buffer (get-buffer-create "$$$Scratch$$$"))
+      (erase-buffer)
+      (insert s)
+      (capitalize-title-region (point-min) (point-max))
+      (buffer-string)))
+
+(provide 'bib-mode)
+
+;;; bib-mode.el ends here
+;;; bibtex.el --- BibTeX mode for GNU Emacs
+
+;; Copyright (C) 1992, 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
+
+;; Author: Stefan Schoef <schoef@offis.uni-oldenburg.de>
+;;      Bengt Martensson <bengt@mathematik.uni-Bremen.de>
+;;	Mark Shapiro <shapiro@corto.inria.fr>
+;;	Mike Newton <newton@gumby.cs.caltech.edu>
+;;	Aaron Larson <alarson@src.honeywell.com>
+;; Maintainer: none right now
+;; Keywords: BibTeX, LaTeX, TeX
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
+
+;;; Commentary:
+
+;;  Major mode for editing and validating BibTeX files.
+
+;;  Usage:
+;;  See documentation for function bibtex-mode (or type "\M-x describe-mode"
+;;  when you are in BibTeX mode).
+
+;;  Todo:
+;;  Distribute texinfo file.
+
+;;; Code:
+
+(eval-when-compile
+  (require 'compile))
+
+;; User Options:
+
+(defgroup bibtex nil
+  "BibTeX mode."
+  :group 'tex
+  :prefix "bibtex-")
+
+(defgroup bibtex-autokey nil
+  "Generates automatically a key from the author/editor and the title field"
+  :group 'bibtex
+  :prefix 'bibtex-autokey)
+
+(defcustom bibtex-mode-hook nil
+  "List of functions to call on entry to BibTeX mode."
+  :group 'bibtex
+  :type '(repeat function))
+
+(defcustom bibtex-field-delimiters 'braces
+  "*Controls type of field delimiters used.
+Set this to `braces' or `double-quotes' according to your personal
+preferences.  This variable is buffer-local."
+  :group 'bibtex
+  :type '(choice (const braces)
+		 (const double-quotes)))
+(make-variable-buffer-local 'bibtex-field-delimiters)
+
+(defcustom bibtex-entry-delimiters 'braces
+  "*Controls type of entry delimiters used.
+Set this to `braces' or `parentheses' according to your personal
+preferences.  This variable is buffer-local."
+  :group 'bibtex
+  :type '(choice (const braces)
+		 (const parentheses)))
+(make-variable-buffer-local 'bibtex-entry-delimiters)
+
+(defcustom bibtex-include-OPTcrossref '("InProceedings" "InCollection")
+  "*All entries listed here will have an OPTcrossref field."
+  :group 'bibtex
+  :type '(repeat string))
+
+(defcustom bibtex-include-OPTkey t
+  "*If non-nil, all entries will have an OPTkey field.
+If this is a string, it will be used as the initial field text.
+If this is a function, it will be called to generate the initial field text."
+  :group 'bibtex
+  :type '(choice (const :tag "None" nil)
+		 (const :tag "Default" t)
+		 (string :tag "Initial text")
+		 (function :tag "Initialize Function")))
+
+(defcustom bibtex-user-optional-fields
+  '(("annote" "Personal annotation (ignored)"))
+  "*List of optional fields the user wants to have always present.
+Entries should be of the same form as the OPTIONAL and
+CROSSREF-OPTIONAL lists in `bibtex-entry-field-alist' (see documentation
+of this variable for details)."
+  :group 'bibtex
+  :type '(repeat
+	  (repeat string)))
+
+(defcustom bibtex-entry-format '(opts-or-alts numerical-fields)
+  "*Controls type of formatting performed by `bibtex-clean-entry'.
+It may be t, nil, or a list of symbols out of the following: 
+opts-or-alts        Delete empty optional and alternative fields and
+                      remove OPT and ALT prefixes from used fields.
+numerical-fields    Delete delimiters around numeral fields.
+page-dashes         Change double dashes in page field to single dash
+                      (for scribe compatibility).
+inherit-booktitle   If entry contains a crossref field and booktitle
+                      field is empty, it is set to the contents of the
+                      title field of the crossreferenced entry.
+                      Caution: this will work only if buffer is
+                       correctly sorted.
+realign             Realign entries, so that field texts and perhaps equal
+                      signs (depending on the value of
+                      bibtex-align-at-equal-sign) begin in the same column.
+last-comma          Add or delete comma on end of last field in entry,
+                      according to value of `bibtex-comma-after-last-field'.
+delimiters          Change delimiters according to variables
+                      `bibtex-field-delimiters' and `bibtex-entry-delimiters'.
+unify-case          Change case of entry and field names.
+
+The value t means do all of the above formatting actions.
+The value nil means do no formatting at all."
+  :group 'bibtex
+  :type '(choice (const :tag "None" nil)
+		 (const :tag "All" t)
+		 (repeat symbol)))
+
+(defcustom bibtex-clean-entry-hook nil
+  "*List of functions to call when entry has been cleaned.
+Functions are called with point inside the cleaned entry, and the buffer
+narrowed to just the entry."
+  :group 'bibtex
+  :type '(repeat function))
+
+(defcustom bibtex-sort-ignore-string-entries t
+  "*If non-nil, BibTeX @String entries are not sort-significant.
+That means they are ignored when determining ordering of the buffer
+(e.g. sorting, locating alphabetical position for new entries, etc.).
+This variable is buffer-local."
+  :group 'bibtex
+  :type 'boolean)
+(make-variable-buffer-local 'bibtex-sort-ignore-string-entries)
+
+(defcustom bibtex-maintain-sorted-entries nil
+  "*If non-nil, BibTeX mode maintains all BibTeX entries in sorted order.
+Setting this variable to nil will strip off some comfort (e.g. TAB
+completion for reference keys in minibuffer, automatic detection of
+duplicates) from BibTeX mode.  See also `bibtex-sort-ignore-string-entries'.
+This variable is buffer-local."
+  :group 'bibtex
+  :type 'boolean)
+(make-variable-buffer-local 'bibtex-maintain-sorted-entries)
+
+(defcustom bibtex-field-kill-ring-max 20
+  "*Max length of `bibtex-field-kill-ring' before discarding oldest elements."
+  :group 'bibtex
+  :type 'integer)
+
+(defcustom bibtex-entry-kill-ring-max 20
+  "*Max length of `bibtex-entry-kill-ring' before discarding oldest elements."
+  :group 'bibtex
+  :type 'integer)
+
+(defcustom bibtex-parse-keys-timeout 60
+  "*Specifies interval for parsing buffers.
+All BibTeX buffers in emacs are parsed if emacs has been idle
+`bibtex-parse-keys-timeout' seconds.  Only buffers which were modified
+after last parsing and which are maintained in sorted order are parsed."
+  :group 'bibtex
+  :type 'integer)
+
+(defvar bibtex-entry-field-alist
+  '(
+    ("Article" . (((("author" "Author1 [and Author2 ...] [and others]")
+                    ("title" "Title of the article (BibTeX converts it to lowercase)")
+                    ("journal" "Name of the journal (use string, remove braces)")
+                    ("year" "Year of publication"))
+		   (("volume" "Volume of the journal")
+                    ("number" "Number of the journal (only allowed if entry contains volume)")
+                    ("pages" "Pages in the journal")
+                    ("month" "Month of the publication as a string (remove braces)")
+                    ("note" "Remarks to be put at the end of the \\bibitem")))
+		  ((("author" "Author1 [and Author2 ...] [and others]")
+                    ("title" "Title of the article (BibTeX converts it to lowercase)"))
+		   (("pages" "Pages in the journal")
+                    ("journal" "Name of the journal (use string, remove braces)") 
+                    ("year" "Year of publication")
+                    ("volume" "Volume of the journal")
+                    ("number" "Number of the journal")
+		    ("month" "Month of the publication as a string (remove braces)")
+                    ("note" "Remarks to be put at the end of the \\bibitem")))))
+    ("Book" . (((("author" "Author1 [and Author2 ...] [and others]" "" t)
+                 ("editor" "Editor1 [and Editor2 ...] [and others]" "" t)
+                 ("title" "Title of the book")
+                 ("publisher" "Publishing company")
+                 ("year" "Year of publication"))
+		(("volume" "Volume of the book in the series")
+                 ("number" "Number of the book in a small series (overwritten by volume)")
+                 ("series" "Series in which the book appeared")
+                 ("address" "Address of the publisher")
+		 ("edition" "Edition of the book as a capitalized English word")
+                 ("month" "Month of the publication as a string (remove braces)")
+                 ("note" "Remarks to be put at the end of the \\bibitem")))
+               ((("author" "Author1 [and Author2 ...] [and others]" "" t)
+                 ("editor" "Editor1 [and Editor2 ...] [and others]" "" t)
+                 ("title" "Title of the book"))
+                (("publisher" "Publishing company")
+                 ("year" "Year of publication")
+                 ("volume" "Volume of the book in the series")
+                 ("number" "Number of the book in a small series (overwritten by volume)")
+                 ("series" "Series in which the book appeared")
+                 ("address" "Address of the publisher")
+		 ("edition" "Edition of the book as a capitalized English word")
+                 ("month" "Month of the publication as a string (remove braces)")
+                 ("note" "Remarks to be put at the end of the \\bibitem")))))
+    ("Booklet" . (((("title" "Title of the booklet (BibTeX converts it to lowercase)"))
+		   (("author" "Author1 [and Author2 ...] [and others]")
+                    ("howpublished" "The way in which the booklet was published")
+                    ("address" "Address of the publisher")
+                    ("month" "Month of the publication as a string (remove braces)")
+                    ("year" "Year of publication")
+                    ("note" "Remarks to be put at the end of the \\bibitem")))))
+    ("InBook" . (((("author" "Author1 [and Author2 ...] [and others]" "" t)
+                   ("editor" "Editor1 [and Editor2 ...] [and others]" "" t)
+                   ("title" "Title of the book")
+                   ("chapter" "Chapter in the book")
+                   ("publisher" "Publishing company")
+                   ("year" "Year of publication"))
+		  (("volume" "Volume of the book in the series")
+                   ("number" "Number of the book in a small series (overwritten by volume)")
+                   ("series" "Series in which the book appeared")
+                   ("type" "Word to use instead of \"chapter\"")
+                   ("address" "Address of the publisher")
+		   ("edition" "Edition of the book as a capitalized English word")
+                   ("month" "Month of the publication as a string (remove braces)")
+                   ("pages" "Pages in the book")
+                   ("note" "Remarks to be put at the end of the \\bibitem")))
+		 ((("author" "Author1 [and Author2 ...] [and others]" "" t)
+                   ("editor" "Editor1 [and Editor2 ...] [and others]" "" t)
+                   ("title" "Title of the book")
+                   ("chapter" "Chapter in the book"))
+		  (("pages" "Pages in the book")
+                   ("publisher" "Publishing company")
+                   ("year" "Year of publication")
+                   ("volume" "Volume of the book in the series")
+                   ("number" "Number of the book in a small series (overwritten by volume)")
+		   ("series" "Series in which the book appeared")
+                   ("type" "Word to use instead of \"chapter\"")
+                   ("address" "Address of the publisher")
+                   ("edition" "Edition of the book as a capitalized English word")
+                   ("month" "Month of the publication as a string (remove braces)")
+                   ("note" "Remarks to be put at the end of the \\bibitem")))))
+    ("InCollection" . (((("author" "Author1 [and Author2 ...] [and others]")
+                         ("title" "Title of the article in book (BibTeX converts it to lowercase)")
+			 ("booktitle" "Name of the book")
+                         ("publisher" "Publishing company")
+                         ("year" "Year of publication"))
+			(("editor" "Editor1 [and Editor2 ...] [and others]")
+                         ("volume" "Volume of the book in the series")
+                         ("number" "Number of the book in a small series (overwritten by volume)")
+                         ("series" "Series in which the book appeared")
+                         ("type" "Word to use instead of \"chapter\"")
+                         ("chapter" "Chapter in the book")
+			 ("pages" "Pages in the book")
+                         ("address" "Address of the publisher")
+                         ("edition" "Edition of the book as a capitalized English word")
+                         ("month" "Month of the publication as a string (remove braces)")
+                         ("note" "Remarks to be put at the end of the \\bibitem")))
+		       ((("author" "Author1 [and Author2 ...] [and others]")
+                         ("title" "Title of the article in book (BibTeX converts it to lowercase)")
+                         ("booktitle" "Name of the book"))
+			(("pages" "Pages in the book")
+                         ("publisher" "Publishing company")
+                         ("year" "Year of publication")
+			 ("editor" "Editor1 [and Editor2 ...] [and others]")
+                         ("volume" "Volume of the book in the series")
+                         ("number" "Number of the book in a small series (overwritten by volume)")
+                         ("series" "Series in which the book appeared")
+                         ("type" "Word to use instead of \"chapter\"")
+                         ("chapter" "Chapter in the book")
+                         ("address" "Address of the publisher")
+                         ("edition" "Edition of the book as a capitalized English word")
+                         ("month" "Month of the publication as a string (remove braces)")
+                         ("note" "Remarks to be put at the end of the \\bibitem")))))
+    ("InProceedings" . (((("author" "Author1 [and Author2 ...] [and others]")
+                          ("title" "Title of the article in proceedings (BibTeX converts it to lowercase)")
+                          ("booktitle" "Name of the conference proceedings")
+                          ("year" "Year of publication"))
+			 (("editor" "Editor1 [and Editor2 ...] [and others]")
+                          ("volume" "Volume of the conference proceedings in the series")
+                          ("number" "Number of the conference proceedings in a small series (overwritten by volume)")
+                          ("series" "Series in which the conference proceedings appeared")
+                          ("pages" "Pages in the conference proceedings")
+                          ("address" "Location of the Proceedings")
+                          ("month" "Month of the publication as a string (remove braces)")
+			  ("organization" "Sponsoring organization of the conference")
+                          ("publisher" "Publishing company, its location")
+                          ("note" "Remarks to be put at the end of the \\bibitem")))
+			((("author" "Author1 [and Author2 ...] [and others]")
+                          ("title" "Title of the article in proceedings (BibTeX converts it to lowercase)")
+			  ("booktitle" "Name of the conference proceedings"))
+			 (("pages" "Pages in the conference proceedings")
+                          ("year" "Year of publication")
+                          ("editor" "Editor1 [and Editor2 ...] [and others]")
+                          ("volume" "Volume of the conference proceedings in the series")
+                          ("number" "Number of the conference proceedings in a small series (overwritten by volume)")
+                          ("series" "Series in which the conference proceedings appeared")
+                          ("address" "Location of the Proceedings")
+                          ("month" "Month of the publication as a string (remove braces)")
+			  ("organization" "Sponsoring organization of the conference")
+                          ("publisher" "Publishing company, its location")
+                          ("note" "Remarks to be put at the end of the \\bibitem")))))
+    ("Manual" . (((("title" "Title of the manual"))
+		  (("author" "Author1 [and Author2 ...] [and others]")
+                   ("organization" "Publishing organization of the manual")
+                   ("address" "Address of the organization")
+                   ("edition" "Edition of the manual as a capitalized English word")
+		   ("month" "Month of the publication as a string (remove braces)")
+                   ("year" "Year of publication")
+                   ("note" "Remarks to be put at the end of the \\bibitem")))))
+    ("MastersThesis" . (((("author" "Author1 [and Author2 ...] [and others]")
+                          ("title" "Title of the master\'s thesis (BibTeX converts it to lowercase)")
+                          ("school" "School where the master\'s thesis was written")
+                          ("year" "Year of publication"))
+                         (("type" "Type of the master\'s thesis (if other than \"Master\'s thesis\")")
+			  ("address" "Address of the school (if not part of field \"school\") or country")
+                          ("month" "Month of the publication as a string (remove braces)")
+                          ("note" "Remarks to be put at the end of the \\bibitem")))))
+    ("Misc" . ((()
+		(("author" "Author1 [and Author2 ...] [and others]")
+                 ("title" "Title of the reference (BibTeX converts it to lowercase)")
+                 ("howpublished" "The way in which the reference was published")
+                 ("month" "Month of the publication as a string (remove braces)")
+                 ("year" "Year of publication")
+                 ("note" "Remarks to be put at the end of the \\bibitem")))))
+    ("PhdThesis" . (((("author" "Author1 [and Author2 ...] [and others]")
+                      ("title" "Title of the PhD. thesis")
+                      ("school" "School where the PhD. thesis was written")
+                      ("year" "Year of publication"))
+                     (("type" "Type of the PhD. thesis")
+                      ("address" "Address of the school (if not part of field \"school\") or country")
+                      ("month" "Month of the publication as a string (remove braces)")
+                      ("note" "Remarks to be put at the end of the \\bibitem")))))
+    ("Proceedings" . (((("title" "Title of the conference proceedings")
+                        ("year" "Year of publication"))
+		       (("editor" "Editor1 [and Editor2 ...] [and others]")
+                        ("volume" "Volume of the conference proceedings in the series")
+                        ("number" "Number of the conference proceedings in a small series (overwritten by volume)")
+                        ("series" "Series in which the conference proceedings appeared")
+                        ("address" "Location of the Proceedings")
+                        ("month" "Month of the publication as a string (remove braces)")
+			("organization" "Sponsoring organization of the conference")
+                        ("publisher" "Publishing company, its location")
+                        ("note" "Remarks to be put at the end of the \\bibitem")))))
+    ("TechReport" . (((("author" "Author1 [and Author2 ...] [and others]")
+                       ("title" "Title of the technical report (BibTeX converts it to lowercase)")
+                       ("institution" "Sponsoring institution of the report")
+                       ("year" "Year of publication"))
+		      (("type" "Type of the report (if other than \"technical report\")")
+                       ("number" "Number of the technical report")
+                       ("address" "Address of the institution (if not part of field \"institution\") or country")
+                       ("month" "Month of the publication as a string (remove braces)")
+                       ("note" "Remarks to be put at the end of the \\bibitem")))))
+    ("Unpublished" . (((("author" "Author1 [and Author2 ...] [and others]")
+                        ("title" "Title of the unpublished reference (BibTeX converts it to lowercase)")
+                        ("note" "Remarks to be put at the end of the \\bibitem"))
+		       (("month" "Month of the publication as a string (remove braces)")
+                        ("year" "Year of publication")))))
+    )
+
+  "Defines reference types and their associated fields.
+List of
+(ENTRY-NAME (REQUIRED OPTIONAL) (CROSSREF-REQUIRED CROSSREF-OPTIONAL))
+triples.
+If the third element is nil, the first pair is always used.
+If not, the second pair is used in the case of presence of a crossref
+field and the third in the case of absence.
+REQUIRED, OPTIONAL, CROSSREF-REQUIRED and CROSSREF-OPTIONAL are lists. 
+Each element of these lists is a list of the form
+(FIELD-NAME COMMENT-STRING INIT ALTERNATIVE-FLAG).
+COMMENT-STRING, INIT, and ALTERNATIVE-FLAG are optional.
+FIELD-NAME is the name of the field, COMMENT-STRING the comment to
+appear in the echo area, INIT is either the initial content of the
+field or a function, which is called to determine the initial content
+of the field, and ALTERNATIVE-FLAG (either nil or t) marks if the
+field is an alternative.  ALTERNATIVE-FLAG may be t only in the
+REQUIRED or CROSSREF-REQUIRED lists.")
+
+(defcustom bibtex-add-entry-hook nil
+  "List of functions to call when entry has been inserted."
+  :group 'bibtex
+  :type '(repeat function))
+
+(defcustom bibtex-predefined-month-strings
+  '(
+    ("jan") ("feb") ("mar") ("apr") ("may") ("jun")
+    ("jul") ("aug") ("sep") ("oct") ("nov") ("dec")
+    )
+  "Alist of month string definitions.
+Should contain all strings used for months in the BibTeX style files.
+Each element is a list with just one element: the string."
+  :group 'bibtex
+  :type '(repeat
+	  (list string)))
+
+(defcustom bibtex-predefined-strings
+  (append
+   bibtex-predefined-month-strings
+   '(
+     ("acmcs") ("acta") ("cacm") ("ibmjrd") ("ibmsj") ("ieeese")
+     ("ieeetc") ("ieeetcad") ("ipl") ("jacm") ("jcss") ("scp")
+     ("sicomp") ("tcs") ("tocs") ("tods") ("tog") ("toms") ("toois")
+     ("toplas")
+     ))
+  "Alist of string definitions.
+Should contain the strings defined in the BibTeX style files.  Each
+element is a list with just one element: the string."
+  :group 'bibtex
+  :type '(repeat
+	  (list string)))
+
+(defcustom bibtex-string-files nil
+  "*List of BibTeX files containing string definitions.
+Those files must be specified using pathnames relative to the
+directories specified in `bibtex-string-file-path'.  This variable is only
+evaluated when BibTeX mode is entered (i. e. when loading the BibTeX
+file)."
+  :group 'bibtex
+  :type '(repeat file))
+
+(defvar bibtex-string-file-path (getenv "BIBINPUTS")
+  "*Colon separated list of pathes to search for `bibtex-string-files'.")
+
+(defcustom bibtex-help-message t
+  "*If not nil print help messages in the echo area on entering a new field."
+  :group 'bibtex
+  :type 'boolean)
+
+(defcustom bibtex-autokey-prefix-string ""
+  "*String to use as a prefix for all generated keys.
+See the documentation of function `bibtex-generate-autokey' for more detail."
+  :group 'bibtex-autokey
+  :type 'string)
+
+(defcustom bibtex-autokey-names 1
+  "*Number of names to use for the automatically generated reference key.
+If this is set to anything but a number, all names are used.
+Possibly more names are used according to `bibtex-autokey-names-stretch'.
+See the documentation of function `bibtex-generate-autokey' for more detail."
+  :group 'bibtex-autokey
+  :type 'integer)
+
+(defcustom bibtex-autokey-names-stretch 0
+  "*Number of names that can additionally be used.
+These names are used only, if all names are used then.
+See the documentation of function `bibtex-generate-autokey' for details."
+  :group 'bibtex-autokey
+  :type 'integer)
+
+(defcustom bibtex-autokey-additional-names ""
+  "*String to prepend to the generated key if not all names could be used.
+See the documentation of function `bibtex-generate-autokey' for details."
+  :group 'bibtex-autokey
+  :type 'string)
+
+(defvar bibtex-autokey-transcriptions
+  '(
+    ;; language specific characters
+    ("\\\\aa" "a")
+    ("\\\\AA" "A")
+    ("\\\"a\\|\\\\\\\"a\\|\\\\ae" "ae")
+    ("\\\"A\\|\\\\\\\"A\\|\\\\AE" "Ae")
+    ("\\\\i" "i")
+    ("\\\\j" "j")
+    ("\\\\l" "l")
+    ("\\\\L" "L")
+    ("\\\"o\\|\\\\\\\"o\\|\\\\o\\|\\\\oe" "oe")
+    ("\\\"O\\|\\\\\\\"O\\|\\\\O\\|\\\\OE" "Oe")
+    ("\\\"s\\|\\\\\\\"s" "ss")
+    ("\\\"u\\|\\\\\\\"u" "ue")
+    ("\\\"U\\|\\\\\\\"U" "Ue")
+    ;; accents
+    ("\\\\`\\|\\\\'\\|\\\\\\^\\|\\\\~\\|\\\\=\\|\\\\\\.\\|\\\\u\\|\\\\v\\|\\\\H\\|\\\\t\\|\\\\c\\|\\\\d\\|\\\\b" "")
+    ;; braces
+    ("{" "") ("}" ""))
+  "Alist of (old-regexp new-string) pairs.
+Used by the default values of `bibtex-autokey-name-change-strings' and
+`bibtex-autokey-titleword-change-strings'.  Defaults to translating some
+language specific characters to their ASCII transcriptions, and
+removing any character accents.")
+
+(defcustom bibtex-autokey-name-change-strings
+  bibtex-autokey-transcriptions
+  "Alist of (OLD-REGEXP NEW-STRING) pairs.
+Any part of name matching a OLD-REGEXP is replaced by NEW-STRING.
+Case is significant in OLD-REGEXP.  All regexps are tried in the
+order in which they appear in the list, so be sure to avoid inifinite
+loops here.
+See the documentation of function `bibtex-generate-autokey' for details."
+  :group 'bibtex-autokey
+  :type '(repeat
+	  (list (regexp :tag "Old")
+		(string :tag "New"))))
+
+(defcustom bibtex-autokey-name-length 'infty
+  "*Number of characters from name to incorporate into key.
+If this is set to anything but a number, all characters are used.
+See the documentation of function `bibtex-generate-autokey' for details."
+  :group 'bibtex-autokey
+  :type '(choice (const :tag "All" infty)
+		 integer))
+
+(defcustom bibtex-autokey-name-separator ""
+  "*String that comes between any two names in the key.
+See the documentation of function `bibtex-generate-autokey' for details."
+  :group 'bibtex-autokey
+  :type 'string)
+
+(defcustom bibtex-autokey-year-length 2
+  "*Number of rightmost digits from the year field yo incorporate into key.
+See the documentation of function `bibtex-generate-autokey' for details."
+  :group 'bibtex-autokey
+  :type 'integer)
+
+(defcustom bibtex-autokey-year-use-crossref-entry t
+  "*If non-nil use year field from crossreferenced entry if necessary.
+If this variable is non-nil and the current entry has no year, but a
+valid crossref entry, the year field from the crossreferenced entry is
+used.
+See the documentation of function `bibtex-generate-autokey' for details."
+  :group 'bibtex-autokey
+  :type 'boolean)
+
+(defcustom bibtex-autokey-titlewords 5
+  "*Number of title words to use for the automatically generated reference key.
+If this is set to anything but a number, all title words are used.
+Possibly more words from the title are used according to
+`bibtex-autokey-titlewords-stretch'.
+See the documentation of function `bibtex-generate-autokey' for details."
+  :group 'bibtex-autokey
+  :type '(choice (const :tag "All" infty)
+		 integer))
+
+(defcustom bibtex-autokey-title-terminators
+  '("\\." "!"  "\\?" ":" ";" "--")
+  "*Regexp list defining the termination of the main part of the title.
+Case of the regexps is ignored.
+See the documentation of function `bibtex-generate-autokey' for details."
+  :group 'bibtex-autokey
+  :type '(repeat regexp))
+
+(defcustom bibtex-autokey-titlewords-stretch 2
+  "*Number of words that can additionally be used from the title.
+These words are used only, if a sentence from the title can be ended then.
+See the documentation of function `bibtex-generate-autokey' for details."
+  :group 'bibtex-autokey
+  :type 'integer)
+
+(defcustom bibtex-autokey-titleword-first-ignore
+  '("a" "an" "on" "the" "eine?" "der" "die" "das")
+  "*Determines words that may begin a title but are not to be used in the key.
+Each item of the list is a regexp.  If the first word of the title matchs a
+regexp from that list, it is not included in the title, even if it is
+capitalized. Case of regexps in this list doesn't matter.
+See the documentation of function `bibtex-generate-autokey' for details."
+  :group 'bibtex-autokey
+  :type '(repeat regexp))
+
+(defcustom bibtex-autokey-titleword-abbrevs nil
+  "*Determines exceptions to the usual abbreviation mechanism.
+An alist of (OLD-REGEXP NEW-STRING) pairs.  Case is ignored
+in matching against OLD-REGEXP, and the first matching pair is used.
+See the documentation of function `bibtex-generate-autokey' for details.")
+
+(defcustom bibtex-autokey-titleword-change-strings
+  bibtex-autokey-transcriptions
+  "Alist of (OLD-REGEXP NEW-STRING) pairs.
+Any part of title word matching a OLD-REGEXP is replaced by NEW-STRING.
+Case is significant in OLD-REGEXP.  All regexps are tried in the
+order in which they appear in the list, so be sure to avoid inifinite
+loops here.
+See the documentation of function `bibtex-generate-autokey' for details."
+  :group 'bibtex-autokey
+  :type '(repeat
+	  (list (regexp :tag "Old")
+		(string :tag "New"))))
+
+(defcustom bibtex-autokey-titleword-length 5
+  "*Number of characters from title words to incorporate into key.
+If this is set to anything but a number, all characters are used.
+See the documentation of function `bibtex-generate-autokey' for details."
+  :group 'bibtex-autokey
+  :type '(choice (const :tag "All" infty)
+		 integer))
+
+(defcustom bibtex-autokey-titleword-separator "_"
+  "*String to be put between the title words.
+See the documentation of function `bibtex-generate-autokey' for details."
+  :group 'bibtex-autokey
+  :type 'string)
+
+(defcustom bibtex-autokey-name-year-separator ""
+  "*String to be put between name part and year part of key.
+See the documentation of function `bibtex-generate-autokey' for details."
+  :group 'bibtex-autokey
+  :type 'string)
+
+(defcustom bibtex-autokey-year-title-separator ":_"
+  "*String to be put between name part and year part of key.
+See the documentation of function `bibtex-generate-autokey' for details."
+  :group 'bibtex-autokey
+  :type 'string)
+
+(defcustom bibtex-autokey-preserve-case nil
+  "*If non-nil, names and titlewords used aren't converted to lower case.
+See the documentation of function `bibtex-generate-autokey' for details."
+  :group 'bibtex-autokey
+  :type 'boolean)
+
+(defcustom bibtex-autokey-edit-before-use t
+  "*If non-nil, user is allowed to edit the generated key before it is used."
+  :group 'bibtex-autokey
+  :type 'boolean)
+
+(defcustom bibtex-autokey-before-presentation-hook nil
+  "Function to call before the generated key is presented.
+If non-nil this should be a single function, which is called before
+the generated key is presented (in entry or, if
+`bibtex-autokey-edit-before-use' is t, in minibuffer). This function
+must take one argument (the automatically generated key), and must
+return with a string (the key to use)."
+  :group 'bibtex-autokey
+  :type 'function)
+
+(defcustom bibtex-entry-offset 0
+  "*Offset for BibTeX entries.
+Added to the value of all other variables which determine colums."
+  :group 'bibtex
+  :type 'integer)
+
+(defcustom bibtex-field-indentation 2
+  "*Starting column for the name part in BibTeX fields."
+  :group 'bibtex
+  :type 'integer)
+
+(defcustom bibtex-text-indentation
+  (+
+   bibtex-field-indentation
+   (length "organization = "))
+  "*Starting column for the text part in BibTeX fields.
+Should be equal to the space needed for the longest name part."
+  :group 'bibtex
+  :type 'integer)
+
+(defcustom bibtex-contline-indentation
+  (+ bibtex-text-indentation 1)
+  "*Starting column for continuation lines of BibTeX fields."
+  :group 'bibtex
+  :type 'integer)
+
+(defcustom bibtex-align-at-equal-sign nil
+  "*If non-nil, align fields at equal sign instead of field text.
+If non-nil, the column for the equal sign is
+the value of `bibtex-text-indentation', minus 2."
+  :group 'bibtex
+  :type 'boolean)
+
+(defcustom bibtex-comma-after-last-field nil
+  "*If non-nil, a comma is put at end of last field in the entry template."
+  :group 'bibtex
+  :type 'boolean)
+
+;; bibtex-font-lock-keywords is a user option as well, but since the
+;; patterns used to define this variable are defined in a later
+;; section of this file, it is defined later.
+
+
+;; Syntax Table, Keybindings and BibTeX Entry List
+(defvar bibtex-mode-syntax-table
+  (let ((st (make-syntax-table)))
+    (modify-syntax-entry ?\" "\"" st)
+    (modify-syntax-entry ?$ "$$  " st)
+    (modify-syntax-entry ?% "<   " st)
+    (modify-syntax-entry ?' "w   " st)
+    (modify-syntax-entry ?@ "w   " st)
+    (modify-syntax-entry ?\\ "\\" st)
+    (modify-syntax-entry ?\f ">   " st)
+    (modify-syntax-entry ?\n ">   " st)
+    (modify-syntax-entry ?~ " " st)
+    st))
+
+(defvar bibtex-mode-map
+  (let ((km (make-sparse-keymap)))
+    (define-key km "\t" 'bibtex-find-text)
+    (define-key km "\n" 'bibtex-next-field)
+    (define-key km "\M-\t" 'bibtex-complete-string)
+    (define-key km [(control tab)] 'bibtex-complete-key)
+    (define-key km "\C-c\"" 'bibtex-remove-delimiters)
+    (define-key km "\C-c{" 'bibtex-remove-delimiters)
+    (define-key km "\C-c}" 'bibtex-remove-delimiters)
+    (define-key km "\C-c\C-c" 'bibtex-clean-entry)
+    (define-key km "\C-c\C-q" 'bibtex-fill-entry)
+    (define-key km "\C-c?" 'bibtex-print-help-message)
+    (define-key km "\C-c\C-p" 'bibtex-pop-previous)
+    (define-key km "\C-c\C-n" 'bibtex-pop-next)
+    (define-key km "\C-c\C-k" 'bibtex-kill-field)
+    (define-key km "\C-c\M-k" 'bibtex-copy-field-as-kill)
+    (define-key km "\C-c\C-w" 'bibtex-kill-entry)
+    (define-key km "\C-c\M-w" 'bibtex-copy-entry-as-kill)
+    (define-key km "\C-c\C-y" 'bibtex-yank)
+    (define-key km "\C-c\M-y" 'bibtex-yank-pop)
+    (define-key km "\C-c\C-d" 'bibtex-empty-field)
+    (define-key km "\C-c\C-f" 'bibtex-make-field)
+    (define-key km "\C-c$" 'bibtex-ispell-abstract)
+    (define-key km "\M-\C-a" 'bibtex-beginning-of-entry)
+    (define-key km "\M-\C-e" 'bibtex-end-of-entry)
+    (define-key km "\C-\M-l" 'bibtex-reposition-window)
+    (define-key km "\C-\M-h" 'bibtex-mark-entry)
+    (define-key km "\C-c\C-b" 'bibtex-entry)
+    (define-key km "\C-c\C-t" 'bibtex-hide-entry-bodies)
+    (define-key km "\C-c\C-rn" 'bibtex-narrow-to-entry)
+    (define-key km "\C-c\C-rw" 'widen)
+    (define-key km "\C-c\C-o" 'bibtex-remove-OPT-or-ALT)
+    (define-key km "\C-c\C-e\C-i" 'bibtex-InProceedings)
+    (define-key km "\C-c\C-ei" 'bibtex-InCollection)
+    (define-key km "\C-c\C-eI" 'bibtex-InBook)
+    (define-key km "\C-c\C-e\C-a" 'bibtex-Article)
+    (define-key km "\C-c\C-e\C-b" 'bibtex-InBook)
+    (define-key km "\C-c\C-eb" 'bibtex-Book)
+    (define-key km "\C-c\C-eB" 'bibtex-Booklet)
+    (define-key km "\C-c\C-e\C-c" 'bibtex-InCollection)
+    (define-key km "\C-c\C-e\C-m" 'bibtex-Manual)
+    (define-key km "\C-c\C-em" 'bibtex-MastersThesis)
+    (define-key km "\C-c\C-eM" 'bibtex-Misc)
+    (define-key km "\C-c\C-e\C-p" 'bibtex-InProceedings)
+    (define-key km "\C-c\C-ep" 'bibtex-Proceedings)
+    (define-key km "\C-c\C-eP" 'bibtex-PhdThesis)
+    (define-key km "\C-c\C-e\M-p" 'bibtex-Preamble)
+    (define-key km "\C-c\C-e\C-s" 'bibtex-String)
+    (define-key km "\C-c\C-e\C-t" 'bibtex-TechReport)
+    (define-key km "\C-c\C-e\C-u" 'bibtex-Unpublished)
+    km))
+
+(easy-menu-define
+ bibtex-edit-menu bibtex-mode-map "BibTeX-Edit Menu in BibTeX mode"
+ '("BibTeX-Edit"
+   ("Moving inside an Entry"
+    ["End of Field" bibtex-find-text t]
+    ["Next Field" bibtex-next-field t]
+    ["Beginning of Entry" bibtex-beginning-of-entry t]
+    ["End of Entry" bibtex-end-of-entry t])
+   ("Operating on Current Entry"
+    ["Fill Entry" bibtex-fill-entry t]
+    ["Clean Entry" bibtex-clean-entry t]
+    "--"
+    ["Kill Entry" bibtex-kill-entry t]
+    ["Copy Entry to Kill Ring" bibtex-copy-entry-as-kill t]
+    ["Paste Most Recently Killed Entry" bibtex-yank t]
+    ["Paste Previously Killed Entry" bibtex-yank-pop t]
+    "--"
+    ["Ispell Entry" bibtex-ispell-entry t]
+    ["Ispell Entry Abstract" bibtex-ispell-abstract t]
+    ["Narrow to Entry" bibtex-narrow-to-entry t])
+   ("Operating on Current Field"
+    ["Remove Delimiters" bibtex-remove-delimiters t]
+    ["Remove OPT or ALT Prefix" bibtex-remove-OPT-or-ALT t]
+    ["Clear Field" bibtex-empty-field t]
+    "--"
+    ["Kill Field" bibtex-kill-field t]
+    ["Copy Field to Kill Ring" bibtex-copy-field-as-kill t]
+    ["Paste Most Recently Killed Field" bibtex-yank t]
+    ["Paste Previously Killed Field" bibtex-yank-pop t]
+    "--"
+    ["Make New Field" bibtex-make-field t]
+    "--"
+    ["Snatch from Similar Following Field" bibtex-pop-next t]
+    ["Snatch from Similar Preceding Field" bibtex-pop-previous t]
+    "--"
+    ["String Complete" bibtex-complete-string t]
+    ["Key Complete" bibtex-complete-key t]
+    "--"
+    ["Help about Current Field" bibtex-print-help-message t])
+   ("Operating on Buffer or Region"
+    ["Validate Entries" bibtex-validate t]
+    ["Sort Entries" bibtex-sort-buffer t]
+    ["Reformat Entries" bibtex-reformat t]
+    ["Hide Entry Bodies" bibtex-hide-entry-bodies t]
+    ["Count Entries" bibtex-count-entries t])
+   ("Miscellaneous"
+    ["Convert Alien Buffer" bibtex-convert-alien t]
+    ["Submit Bug Report" bibtex-submit-bug-report t])))
+
+(easy-menu-define
+ bibtex-entry-menu bibtex-mode-map "Entry-Types Menu in BibTeX mode"
+ (list "Entry-Types"
+       ["Article in Journal" bibtex-Article t]
+       ["Article in Conference Proceedings" bibtex-InProceedings t]
+       ["Article in a Collection" bibtex-InCollection t]
+       ["Chapter or Pages in a Book" bibtex-InBook t]
+       ["Conference Proceedings" bibtex-Proceedings t]
+       ["Book" bibtex-Book t]
+       ["Booklet (Bound, but no Publisher/Institution)" bibtex-Booklet t]
+       ["PhD. Thesis" bibtex-PhdThesis t]
+       ["Master's Thesis" bibtex-MastersThesis t]
+       ["Technical Report" bibtex-TechReport t]
+       ["Technical Manual" bibtex-Manual t]
+       ["Unpublished" bibtex-Unpublished t]
+       ["Miscellaneous" bibtex-Misc t]
+       ["String" bibtex-String t]
+       ["Preamble" bibtex-Preamble t]))
+
+
+;; Bug Reporting
+
+(defconst
+  bibtex-maintainer-address "Stefan Schoef <schoef@offis.uni-oldenburg.de>")
+;; current maintainer
+
+
+;; Internal Variables
+
+(defvar bibtex-pop-previous-search-point nil)
+;; Next point where bibtex-pop-previous starts looking for a similar
+;; entry.
+
+(defvar bibtex-pop-next-search-point nil)
+;; Next point where bibtex-pop-next starts looking for a similar entry.
+
+(defvar bibtex-field-kill-ring nil)
+;; Ring of least recently killed fields. At most
+;; bibtex-field-kill-ring-max items are kept here.
+
+(defvar bibtex-field-kill-ring-yank-pointer nil)
+;; The tail of bibtex-field-kill-ring whose car is the last item yanked.
+
+(defvar bibtex-entry-kill-ring nil)
+;; Ring of least recently killed entries. At most
+;; bibtex-entry-kill-ring-max items are kept here.
+
+(defvar bibtex-entry-kill-ring-yank-pointer nil)
+;; The tail of bibtex-entry-kill-ring whose car is the last item yanked.
+
+(defvar bibtex-last-kill-command nil)
+;; Holds the type of the last kill command (either 'field or 'entry)
+
+(defvar bibtex-strings nil)
+;; Candidates for bibtex-complete-string. Initialized from
+;; bibtex-predefined-strings and bibtex-string-files. This variable is
+;; buffer-local.
+(make-variable-buffer-local 'bibtex-strings)
+
+(defvar bibtex-keys nil)
+;; Candidates for TAB completion when entering a reference key using
+;; the minibuffer. Also used for bibtex-complete-key. Initialized in
+;; bibtex-mode and updated for each new entry. This variable is
+;; buffer-local.
+(make-variable-buffer-local 'bibtex-keys)
+
+(defvar bibtex-buffer-last-parsed-tick nil)
+;; Remembers the value returned by buffer-modified-tick when buffer
+;; was parsed for keys the last time.
+(make-variable-buffer-local 'bibtex-buffer-last-parsed-tick)
+
+(defvar bibtex-parse-idle-timer nil)
+;; Stores if timer is already installed
+
+(defvar bibtex-progress-lastperc nil)
+;; Holds the last reported percentage for the progress message
+
+(defvar bibtex-progress-lastmes nil)
+;; Holds the last reported progress message
+
+(defvar bibtex-progress-interval nil)
+;; Holds the chosen interval
+
+(defvar bibtex-key-history nil)
+;; Used to store the history list for reading keys
+
+(defvar bibtex-entry-type-history nil)
+;; Used to store the history list for reading entry types
+
+(defvar bibtex-field-history nil)
+;; Used to store the history list for reading field names
+
+(defvar bibtex-reformat-previous-options nil)
+;; Used to store the last reformat options given
+
+(defvar bibtex-reformat-previous-labels nil)
+;; Used to store the last reformat label option given
+
+
+;; Functions to Parse the BibTeX Entries
+
+(defun bibtex-cfield (name text)
+  ;; Create a regexp for a BibTeX field of name NAME and text TEXT.
+  (concat ",[ \t\n]*\\("
+	  name
+	  "\\)[ \t\n]*=[ \t\n]*\\("
+	  text
+	  "\\)"))
+(defconst bibtex-name-in-cfield 1)
+;; The regexp subexpression number of the name part in bibtex-cfield.
+
+(defconst bibtex-text-in-cfield 2)
+;; The regexp subexpression number of the text part in bibtex-cfield.
+
+(defconst bibtex-reference-type "@[^\"#%'(),={} \t\n0-9][^\"#%'(),={} \t\n]*")
+;; Regexp defining the type part of a BibTeX reference entry (almost
+;; the same as bibtex-field-name)
+
+(defconst bibtex-reference-key "[][a-z0-9.:;?!`'/*@+=|()<>&_^$-]+")
+;; Regexp defining the label part of a BibTeX reference entry
+
+(defconst bibtex-field-name "[^\"#%'(),={} \t\n0-9][^\"#%'(),={} \t\n]*")
+;; Regexp defining the name part of a BibTeX field (almost the same as
+;; bibtex-reference-type)
+
+(defconst bibtex-field-const "[][a-z0-9.:;?!`'/*@+=|<>&_^$-]+")
+;; Regexp defining a bibtex field constant
+
+(defconst bibtex-field-string-part-not-braced
+  "[^{}]")
+;; Match field string part without braces
+
+(defconst bibtex-field-string-part-no-inner-braces
+  (concat
+   "{"
+   bibtex-field-string-part-not-braced "*"
+   "}"))
+;; Match field string part with no inner braces
+
+(defconst bibtex-field-string-part-1-inner-brace
+  (concat
+   "{"
+   "\\("
+     bibtex-field-string-part-not-braced 
+     "\\|"
+     "\\(" bibtex-field-string-part-no-inner-braces "\\)"
+   "\\)*"
+   "}"))
+;; Match field string part with at most 1 inner brace
+
+(defconst bibtex-field-string-part-2-inner-braces
+  (concat
+   "{"
+   "\\("
+     bibtex-field-string-part-not-braced
+     "\\|"
+     "\\(" bibtex-field-string-part-1-inner-brace "\\)"
+   "\\)*"
+   "}"))
+;; Match field string part with at most 2 inner braces
+
+(defconst bibtex-field-string-part-3-inner-braces
+  (concat
+   "{"
+   "\\("
+     bibtex-field-string-part-not-braced
+     "\\|"
+     "\\(" bibtex-field-string-part-2-inner-braces "\\)"
+   "\\)*"
+   "}"))
+;; Match field string part with at most 3 inner braces
+
+(defconst bibtex-field-string-braced
+  bibtex-field-string-part-3-inner-braces)
+;; Match braced field string with inner nesting level of braces at most 3
+
+(defconst bibtex-field-string-quoted
+  (concat
+   "\""
+   "\\("
+     "[^\"\\]"      ;; every character except quote or backslash
+     "\\|"
+;;     "\\(" "\"[a-z-]" "\\)"  ;; a quote followed by a letter or dash 
+;;     "\\|"
+;; last two lines commented out until lines like
+;;   author = "Stefan Sch"of"
+;; are supported by BibTeX
+     "\\(" "\\\\\\(.\\|\n\\)"  "\\)" ;; a backslash followed by any character
+   "\\)*"
+   "\""))
+;; Match quoted field string
+
+(defconst bibtex-field-string
+  (concat
+   "\\(" bibtex-field-string-braced "\\)"
+   "\\|"
+   "\\(" bibtex-field-string-quoted "\\)"))
+;; Match a braced or quoted string
+
+(defconst bibtex-field-string-or-const
+  (concat bibtex-field-const "\\|" bibtex-field-string))
+;; Match either bibtex-field-string or bibtex-field-const.
+
+(defconst bibtex-field-text
+  (concat
+    "\\(" bibtex-field-string-or-const "\\)"
+    "\\([ \t\n]+#[ \t\n]+\\(" bibtex-field-string-or-const "\\)\\)*"))
+;; Regexp defining the text part of a BibTeX field: either a string,
+;; or an empty string, or a constant followed by one or more # /
+;; constant pairs.
+
+(defconst bibtex-field
+  (bibtex-cfield bibtex-field-name bibtex-field-text))
+;; Regexp defining the format of a BibTeX field.
+
+(defconst bibtex-name-in-field bibtex-name-in-cfield)
+;; The regexp subexpression number of the name part in BibTeX-field.
+
+(defconst bibtex-text-in-field bibtex-text-in-cfield)
+;; The regexp subexpression number of the text part in BibTeX-field.
+
+(defconst bibtex-reference-head
+  (concat "^[ \t]*\\("
+	  bibtex-reference-type
+	  "\\)[ \t]*[({][ \t]*\\("
+	  bibtex-reference-key
+	  "\\)"))
+;; Regexp defining format of the header line of a BibTeX reference
+;; entry.
+
+(defconst bibtex-reference-maybe-empty-head
+  (concat bibtex-reference-head "?"))
+;; Regexp defining format of the header line of a maybe empty
+;; BibTeX reference entry (without reference key).
+
+(defconst bibtex-type-in-head 1)
+;; The regexp subexpression number of the type part in
+;; bibtex-reference-head.
+
+(defconst bibtex-key-in-head 2)
+;; The regexp subexpression number of the key part in
+;; bibtex-reference-head.
+
+(defconst bibtex-reference-infix (concat "[ \t\n]*" bibtex-field))
+;; Regexp defining the (repeatable) infix of a bibtex reference
+
+(defconst bibtex-reference-postfix "[ \t\n]*,?[ \t\n]*[})]")
+;; Regexp defining the postfix of a bibtex reference
+
+(defconst bibtex-key-in-reference bibtex-key-in-head)
+;; The regexp subexpression number of the key part in
+;; bibtex-reference.
+
+(defconst bibtex-string
+  (concat "^[ \t]*@string[ \t\n]*[({][ \t\n]*\\("
+	  bibtex-reference-key
+	  "\\)[ \t\n]*=[ \t\n]*\\("
+	  bibtex-field-text
+	  "\\)[ \t\n]*[})]"))
+;; Regexp defining the format of a BibTeX string entry.
+
+(defconst bibtex-key-in-string 1)
+;; The regexp subexpression of the name part in bibtex-string.
+
+(defconst bibtex-text-in-string 2)
+;; The regexp subexpression of the text part in bibtex-string.
+
+(defvar bibtex-font-lock-keywords
+  (list
+   (list bibtex-reference-maybe-empty-head
+         (list bibtex-type-in-head 'font-lock-function-name-face)
+         (list bibtex-key-in-head 'font-lock-reference-face nil t))
+   ;; reference type and reference label
+   (list
+    (concat "^[ \t]*\\(OPT" bibtex-field-name "\\)[ \t]*=")
+    1 'font-lock-comment-face)
+   ;; optional field names (treated as comments)
+   (list (concat "^[ \t]*\\(" bibtex-field-name "\\)[ \t]*=")
+         1 'font-lock-variable-name-face)
+   ;; field names
+   "*Default expressions to highlight in BibTeX mode."))
+;; now all needed patterns are defined
+
+
+;; Helper Functions
+
+(defun bibtex-delete-whitespace ()
+  ;; Delete all whitespace starting at point
+  (if (looking-at "[ \t\n]+")
+      (delete-region (point) (match-end 0))))
+
+(defun bibtex-current-line ()
+  ;; this computes line number of point regardless whether the buffer
+  ;; is narrowed
+  (+ (count-lines 1 (point))
+     (if (equal (current-column) 0) 1 0)))
+
+(defun bibtex-member-of-regexp (string list)
+  ;; Return non-nil if STRING is exactly matched by an element of
+  ;; LIST (case ignored). The value is actually the tail of LIST whose
+  ;; car matches STRING.
+  (let ((case-fold-search t))
+    (while
+        (and list (not (string-match (concat "^" (car list) "$") string)))
+      (setq list (cdr list)))
+    list))
+
+(defun bibtex-assoc-of-regexp (string alist)
+  ;; Return non-nil if STRING is exactly matched by the car of an
+  ;; element of LIST (case ignored). The value is actually the element
+  ;; of LIST whose car matches STRING.
+  (let ((case-fold-search t))
+    (while
+        (and alist
+             (not (string-match (concat "^" (car (car alist)) "$") string)))
+      (setq alist (cdr alist)))
+    (car alist)))
+
+(defun bibtex-skip-to-valid-entry (&optional backward)
+  ;; If not at beginning of valid BibTeX entry, move to beginning of
+  ;; the next valid one. With argument backward non-nil, move backward
+  ;; to beginning of previous valid one. A valid entry is a
+  ;; syntactical correct one with type contained in
+  ;; bibtex-entry-field-alist or, if bibtex-sort-ignore-string-entries
+  ;; is nil, a syntactical correct string entry.
+  (let ((case-fold-search t)
+        (valid-bibtex-entry
+         (concat
+          "@[ \t]*\\("
+          (mapconcat
+           (lambda (type)
+             (concat "\\(" (car type) "\\)"))
+           bibtex-entry-field-alist
+           "\\|")
+          "\\)"))
+        found)
+    (while (and (not found)
+                (not (if backward
+                         (bobp)
+                       (eobp))))
+      (let ((pnt (point)))
+        (cond
+         ((looking-at valid-bibtex-entry)
+          (if (and
+               (bibtex-search-reference nil nil t)
+               (equal (match-beginning 0) pnt))
+              (setq found t)))
+         ((and (not bibtex-sort-ignore-string-entries)
+               (looking-at bibtex-string))
+          (setq found t)))
+        (if found
+            (goto-char pnt)
+          (if backward
+              (progn
+                (goto-char (1- pnt))
+                (if (re-search-backward "^[ \t]*\\(@\\)" nil 'move)
+                    (goto-char (match-beginning 1))))
+            (goto-char (1+ pnt))
+            (if (re-search-forward "^[ \t]*@" nil 'move)
+                (forward-char -1))))))))
+
+(defun bibtex-map-entries (fun)
+  ;; Call FUN for each BibTeX entry starting with the current. Do this
+  ;; to the end of the file. FUN is called with one argument, the key
+  ;; of the entry, and with point inside the entry. If
+  ;; bibtex-sort-ignore-string-entries is non-nil, FUN will not be
+  ;; called for @String entries.
+  (let ((case-fold-search t))
+    (bibtex-beginning-of-entry)
+    (while (re-search-forward bibtex-reference-maybe-empty-head nil t)
+      (let ((pnt (point))
+            (reference-type
+             (downcase (buffer-substring-no-properties
+                        (1+ (match-beginning bibtex-type-in-head))
+                        (match-end bibtex-type-in-head))))
+            (reference-key
+             (if (match-beginning bibtex-key-in-head)
+                 (buffer-substring-no-properties
+                  (match-beginning bibtex-key-in-head)
+                  (match-end bibtex-key-in-head))
+               "")))
+        (if (or
+             (and
+              (not bibtex-sort-ignore-string-entries)
+              (string-equal "string" (downcase reference-type)))
+             (assoc-ignore-case reference-type bibtex-entry-field-alist))
+            (funcall fun reference-key))
+        (goto-char pnt)
+        (bibtex-end-of-entry)))))
+
+(defun bibtex-progress-message (&optional flag interval)
+  ;; echos a message about progress of current buffer
+  ;; if flag is a string, the message is initialized (in this case a
+  ;; value for INTERVAL may be given as well (if not this is set to 5))
+  ;; if flag is done, the message is deinitialized
+  ;; if flag is absent, a message is echoed if point was incremented
+  ;; at least INTERVAL percent since last message was echoed
+  (let* ((size (- (point-max) (point-min)))
+         (perc (if (= size 0)
+                   100
+                 (/ (* 100 (- (point) (point-min))) size))))
+    (if (or (and (not flag)
+                 (>= perc
+                     (+ bibtex-progress-interval bibtex-progress-lastperc)))
+            (stringp flag))
+        (progn
+          (if (stringp flag)
+              (progn
+                (setq bibtex-progress-lastmes flag)
+                (if interval
+                    (setq bibtex-progress-interval interval)
+                  (setq bibtex-progress-interval 5))))
+          (setq bibtex-progress-lastperc perc)
+          (message (concat bibtex-progress-lastmes " (%d%%)") perc))
+      (if (equal flag 'done)
+          (progn
+            (message (concat bibtex-progress-lastmes " (done)"))
+            (setq bibtex-progress-lastmes nil))))))
+
+
+(defun bibtex-field-left-delimiter ()
+  ;; returns a string dependent on bibtex-field-delimiters
+  (if (equal bibtex-field-delimiters 'braces)
+      "{"
+    "\""))
+
+(defun bibtex-field-right-delimiter ()
+  ;; returns a string dependent on bibtex-field-delimiters
+  (if (equal bibtex-field-delimiters 'braces)
+      "}"
+    "\""))
+
+(defun bibtex-entry-left-delimiter ()
+  ;; returns a string dependent on bibtex-field-delimiters
+  (if (equal bibtex-entry-delimiters 'braces)
+      "{"
+    "("))
+
+(defun bibtex-entry-right-delimiter ()
+  ;; returns a string dependent on bibtex-field-delimiters
+  (if (equal bibtex-entry-delimiters 'braces)
+      "}"
+    ")"))
+
+(defun bibtex-search-reference
+  (empty-head &optional bound noerror backward)
+  ;; A helper function necessary since the failure stack size limit for
+  ;; regexps was reduced in emacs 19.32.
+  ;; It searches for a BibTeX reference (maybe with an empty head if
+  ;; EMPTY-HEAD is t).
+  ;; BOUND and NOERROR are exactly as in re-search-forward. If
+  ;; BACKWARD is non-nil, search is done in reverse direction. After
+  ;; call to this function MATCH-BEGINNING and MATCH-END functions are
+  ;; defined, but only for the head part of the reference (especially
+  ;; (match-end 0) just gives the end of the head part).
+  (let ((pnt (point))
+        (prefix (if empty-head
+                    bibtex-reference-maybe-empty-head
+                  bibtex-reference-head))
+        (infix bibtex-reference-infix)
+        (postfix bibtex-reference-postfix))
+    (if backward
+        (let (found)
+          (while (and (not found)
+                      (re-search-backward prefix bound noerror))
+            (setq found (bibtex-search-reference empty-head pnt t)))
+          (if found
+              (goto-char (match-beginning 0))
+            (if (equal noerror nil)
+                ;; yell
+                (error "Search of BibTeX reference failed."))
+            (if (equal noerror t)
+                ;; don't move
+                (goto-char pnt))
+            nil))
+      (let ((limit (if bound bound (point-max)))
+            md
+            found)
+        (while (and (not found)
+                    (re-search-forward prefix bound noerror))
+          (setq md (match-data))
+          ;; save match-data of prefix regexp
+          (let ((entry-closer
+                 (if (save-excursion
+                       (goto-char (match-end bibtex-type-in-head))
+                       (looking-at "[ \t]*("))
+                     ;; entry opened with parenthesis
+                     ")"
+                   "}")))
+            (while (and
+                    (looking-at infix)
+                    (<= (match-end 0) limit))
+              (goto-char (match-end 0)))
+            ;; This matches the infix* part. The AND construction assures
+            ;; that BOUND is respected.
+            (if (and (looking-at postfix)
+                     (string-equal
+                      (buffer-substring-no-properties
+                       (1- (match-end 0)) (match-end 0))
+                      entry-closer)
+                     (<= (match-end 0) limit))
+                (progn
+                  (re-search-forward postfix)
+                  (setq found t)))))
+        (if found
+            (progn
+              (store-match-data md)
+              ;; to set match-beginning/end again
+              (point))
+          (if (equal noerror nil)
+              ;; yell
+              (error "Search of BibTeX reference failed."))
+          (if (equal noerror t)
+              ;; don't move
+              (goto-char pnt))
+          nil)))))
+
+(defun bibtex-flash-head ()
+  ;; Flash at BibTeX reference head before point, if exists.
+  (let ((case-fold-search t)
+        flash)
+    (cond ((re-search-backward bibtex-reference-head nil t)
+	   (goto-char (match-beginning bibtex-type-in-head))
+	   (setq flash (match-end bibtex-key-in-reference)))
+	  (t
+	   (end-of-line)
+	   (skip-chars-backward " \t")
+	   (setq flash (point))
+	   (beginning-of-line)
+	   (skip-chars-forward " \t")))
+    (if (pos-visible-in-window-p (point))
+	(sit-for 1)
+      (message "From: %s"
+	       (buffer-substring (point) flash)))))
+
+(defun bibtex-make-optional-field (e-t)
+  "Makes an optional field named E-T in current BibTeX entry."
+  (if (consp e-t)
+      (bibtex-make-field (cons (concat "OPT" (car e-t)) (cdr e-t)))
+    (bibtex-make-field (concat "OPT" e-t))))
+
+(defun bibtex-move-outside-of-entry ()
+  ;; Make sure we are outside of a BibTeX entry.
+  (bibtex-end-of-entry)
+  (skip-chars-forward " \t\n"))
+
+(defun bibtex-beginning-of-first-entry ()
+  ;; Go to the beginning of the first BibTeX entry in buffer. Return
+  ;; point.
+  (goto-char (point-min))
+  (if (re-search-forward "^[ \t]*@" nil 'move)
+      (beginning-of-line))
+  (point))
+
+(defun bibtex-beginning-of-last-entry ()
+  ;; Go to the beginning of the last BibTeX entry in buffer.
+  (goto-char (point-max))
+  (if (re-search-backward "^[ \t]*@" nil 'move)
+      (beginning-of-line))
+  (point))
+
+(defun bibtex-inside-field ()
+  ;; Try to avoid point being at end of a BibTeX field.
+  (end-of-line)
+  (skip-chars-backward " \t")
+  (cond ((= (preceding-char) ?,)
+	 (forward-char -2)))
+  (cond ((or
+          (= (preceding-char) ?})
+          (= (preceding-char) ?\"))
+         (forward-char -1))))
+
+(defun bibtex-enclosing-field (&optional noerr)
+  ;; Search for BibTeX field enclosing point. Point moves to end of
+  ;; field. Use match-beginning and match-end to parse the field. If
+  ;; NOERR is non-nil, no error is signalled. In this case, t is
+  ;; returned on success, nil otherwise.
+  (let ((case-fold-search t)
+        (old-point (point))
+        (boe (bibtex-beginning-of-entry))
+        (success t))
+    (goto-char old-point)
+    (if (not (re-search-backward
+              (bibtex-cfield bibtex-field-name "")
+              boe t))
+        ;; Search possible beginning of field
+        (progn
+          (goto-char old-point)
+          (if noerr
+              (setq success nil)
+            (error "Can't find enclosing BibTeX field.")))
+      (if (or (not (re-search-forward bibtex-field nil t))
+              (< (match-end 0) old-point)
+              (> (match-beginning 0) old-point))
+          (progn
+            (goto-char old-point)
+            (if noerr
+                (setq success nil)
+              (error "Can't find enclosing BibTeX field.")))))
+    success))
+
+(defun bibtex-enclosing-reference-maybe-empty-head ()
+  ;; Search for BibTeX reference enclosing point. Point moves to
+  ;; end of reference. Beginning (but not end) of reference is given
+  ;; by (match-beginning 0).
+  (let ((case-fold-search t)
+        (old-point (point)))
+    (if (not
+         (re-search-backward
+          bibtex-reference-maybe-empty-head nil t))
+        (progn
+          (error "Can't find enclosing BibTeX reference.")
+          (goto-char old-point)))
+    (goto-char (match-beginning bibtex-type-in-head))
+    (if (not
+         (bibtex-search-reference t nil t))
+        (progn
+          (error "Can't find enclosing BibTeX reference.")
+          (goto-char old-point)))))
+
+(defun bibtex-insert-current-kill (n)
+  (if (not bibtex-last-kill-command)
+      (error "BibTeX kill ring is empty.")
+    (let* ((kr (if (equal bibtex-last-kill-command 'field)
+                   'bibtex-field-kill-ring
+                 'bibtex-entry-kill-ring))
+           (kryp (if (equal bibtex-last-kill-command 'field)
+                     'bibtex-field-kill-ring-yank-pointer
+                   'bibtex-entry-kill-ring-yank-pointer))
+           (ARGth-kill-element
+            (nthcdr
+             (mod (- n (length (eval kryp))) (length (eval kr)))
+             (eval kr)))
+           (current (car (set kryp ARGth-kill-element))))
+      (cond
+       ((equal bibtex-last-kill-command 'field)
+        (let (bibtex-help-message)
+          (bibtex-find-text nil t)
+          (if (looking-at "[}\"]")
+              (forward-char)))
+        (set-mark (point))
+        (message "Mark set")
+        (bibtex-make-field (list (elt current 1) nil (elt current 2)) t))
+       ((equal bibtex-last-kill-command 'entry)
+        (if (not (eobp))
+            (bibtex-beginning-of-entry))
+        (set-mark (point))
+        (message "Mark set")
+        (insert (elt current 1)))
+       (t
+        (error
+         "Unknown tag field: %s. Please submit a bug report."
+         bibtex-last-kill-command))))))
+
+(defun bibtex-format-entry ()
+  ;; Helper function for bibtex-clean-entry. Formats current entry
+  ;; according to variable bibtex-entry-format.
+  (let ((case-fold-search t)
+        (beg (point))
+        (start (bibtex-beginning-of-entry))
+        crossref-there
+        alternatives-there
+        non-empty-alternative)
+    (let ((end (copy-marker (bibtex-end-of-entry))))
+      (if (equal start (marker-position end))
+          (error "Not on a known BibTeX entry.")
+        (goto-char start)
+        (while (re-search-forward bibtex-field end t)
+          ;; determine if reference has crossref entry and if at least
+          ;; one alternative is non-empty
+          (let ((begin-name (match-beginning bibtex-name-in-field))
+                (end-name (match-end bibtex-name-in-field))
+                (begin-text (match-beginning bibtex-text-in-field))
+                (end-text (match-end bibtex-text-in-field)))
+            (goto-char begin-name)
+            (if (looking-at "ALT")
+                (progn
+                  (setq alternatives-there t)
+                  (goto-char begin-text)
+                  (if (not (looking-at "\\(\"\"\\)\\|\\({}\\)"))
+                      (setq non-empty-alternative t))))
+            (if (string-match
+                 "\\(OPT\\)?crossref"
+                 (buffer-substring-no-properties begin-name end-name))
+                (progn
+                  (setq
+                   crossref-there
+                   (buffer-substring-no-properties
+                    (1+ begin-text) (1- end-text)))
+                  (if (equal crossref-there "")
+                      (setq crossref-there nil))))))
+        (if (and alternatives-there
+                 (not non-empty-alternative))
+            (progn
+              (goto-char beg)
+              (error "All alternatives are empty.")))
+        (goto-char start)
+        (re-search-forward bibtex-reference-type end)
+        (let* ((begin-type (1+ (match-beginning 0)))
+               (end-type (match-end 0))
+               (reference-type
+                (downcase
+                 (buffer-substring-no-properties begin-type end-type)))
+               (entry-list
+                (assoc-ignore-case reference-type bibtex-entry-field-alist))
+               (req (elt (elt entry-list 1) 0))
+               (creq (elt (elt entry-list 2) 0))
+               (format (if (equal bibtex-entry-format t)
+                           '(realign opts-or-alts numerical-fields
+                                     last-comma page-dashes delimiters
+                                     unify-case inherit-booktitle)
+                         bibtex-entry-format))
+               field-done)
+          (if (memq 'unify-case format)
+              (progn
+                (delete-region begin-type end-type)
+                (insert (car entry-list))))
+          (if (memq 'delimiters format)
+              (progn
+                (goto-char end-type)
+                (skip-chars-forward " \t\n")
+                (delete-char 1)
+                (insert (bibtex-entry-left-delimiter))))
+          (goto-char start)
+          (while (re-search-forward bibtex-field end t)
+            (let* ((begin-field
+                    (copy-marker (match-beginning 0)))
+                   (end-field
+                    (copy-marker (match-end 0)))
+                   (begin-name
+                    (copy-marker (match-beginning bibtex-name-in-field)))
+                   (end-name
+                    (copy-marker (match-end bibtex-name-in-field)))
+                   (begin-text
+                    (copy-marker (match-beginning bibtex-text-in-field)))
+                   (end-text
+                    (copy-marker (match-end bibtex-text-in-field)))
+                   (field-name
+                    (buffer-substring-no-properties
+                     (if (string-match
+                          "^OPT\\|ALT$"
+                          (buffer-substring-no-properties
+                           begin-name (+ begin-name 3)))
+                         (+ begin-name 3)
+                       begin-name)
+                     end-name)))
+              (cond
+               ((and
+                 (memq 'opts-or-alts format)
+                 (progn (goto-char begin-name)
+                        (looking-at "OPT\\|ALT")))
+                (goto-char begin-text)
+                (if (looking-at "\\(\"\"\\)\\|\\({}\\)")
+                    ;; empty: delete whole field if really optional
+                    ;; (missing crossref handled) or complain
+                    (if (and
+                         (progn
+                           (goto-char begin-name)
+                           (looking-at "OPT"))
+                         (not crossref-there)
+                         (assoc-ignore-case field-name req))
+                        ;; field is not really optional
+                        (progn
+                          (goto-char begin-name)
+                          (bibtex-remove-OPT-or-ALT)
+                          (error
+                           "Mandatory field ``%s'' is empty." field-name))
+                      ;; field is optional
+                      (delete-region begin-field end-field))
+                  ;; otherwise: not empty, delete "OPT"
+                  (goto-char begin-name)
+                  (bibtex-remove-OPT-or-ALT)))
+               ((and
+                 (memq 'numerical-fields format)
+                 (progn
+                   (goto-char begin-text)
+                   (looking-at "\\(\"[0-9]+\"\\)\\|\\({[0-9]+}\\)")))
+                (goto-char end-text)
+                (delete-char -1)
+                (goto-char begin-text)
+                (delete-char 1))
+               (t
+                (if (memq 'delimiters format)
+                    (progn
+                      (goto-char begin-text)
+                      (while (and
+                              (<= (point) end-text)
+                              (re-search-forward
+                               bibtex-field-string-or-const end-text t))
+                        (let ((end (point)))
+                          (goto-char (match-beginning 0))
+                          (if (or
+                               (and
+                                (equal bibtex-field-delimiters 'double-quotes)
+                                (looking-at bibtex-field-string-braced))
+                               (and
+                                (equal bibtex-field-delimiters 'braces)
+                                (looking-at bibtex-field-string-quoted)))
+                              (progn
+                                (goto-char (match-end 0))
+                                (delete-backward-char 1)
+                                (insert (bibtex-field-right-delimiter))
+                                (goto-char (match-beginning 0))
+                                (delete-char 1)
+                                (insert (bibtex-field-left-delimiter))))
+                          (goto-char end)))))
+                (if (and
+                     (memq 'page-dashes format)
+                     (string-match "^\\(OPT\\)?pages$" (downcase field-name))
+                     (progn
+                       (goto-char begin-text)
+                       (looking-at
+                        "\\([\"{][0-9]+\\)[ \t\n]*--?[ \t\n]*\\([0-9]+[\"}]\\)")))
+                    (replace-match "\\1-\\2"))
+                (if (and
+                     (memq 'inherit-booktitle format)
+                     (equal (downcase field-name) "booktitle")
+                     (progn
+                       (goto-char begin-text)
+                       (looking-at "\\(\"\"\\)\\|\\({}\\)"))
+                     crossref-there
+                     (not (bibtex-find-entry-location crossref-there t)))
+                    ;; booktitle field empty and crossref entry found
+                    ;; --> insert title field of crossreferenced entry if there
+                    (let ((end-of-crefd-entry (bibtex-end-of-entry)))
+                      (bibtex-beginning-of-entry)
+                      (if (re-search-forward
+                           (bibtex-cfield "title" bibtex-field-text)
+                           end-of-crefd-entry t)
+                          (progn
+                            (goto-char begin-text)
+                            (forward-char)
+                            (insert
+                             (buffer-substring-no-properties 
+                              (1+ (match-beginning bibtex-text-in-field))
+                              (1- (match-end bibtex-text-in-field))))))))
+                (if (progn
+                      (goto-char begin-text)
+                      (looking-at "\\(\"\"\\)\\|\\({}\\)"))
+                    ;; if empty field, complain
+                    (progn
+                      (forward-char)
+                      (if (or (and
+                               crossref-there
+                               (assoc-ignore-case
+                                field-name creq))
+                              (and
+                               (not crossref-there)
+                               (assoc-ignore-case
+                                field-name req)))
+                          (error
+                           "Mandatory field ``%s'' is empty." field-name))))
+                (if (memq 'unify-case format)
+                    (let* ((fl
+                            (car (cdr (assoc-ignore-case
+                                       reference-type
+                                       bibtex-entry-field-alist))))
+                           (field-list
+                            (append
+                             (elt fl 0)
+                             (elt fl 1)
+                             bibtex-user-optional-fields))
+                           (new-field-name
+                            (car
+                             (assoc-ignore-case field-name field-list))))
+                      (goto-char begin-name)
+                      (if new-field-name
+                          (progn
+                            (delete-region begin-name end-name)
+                            (insert new-field-name))
+                        (downcase-region begin-name end-name))))
+                (setq field-done t)))
+              (if (not field-done)
+                  (goto-char begin-field)
+                (setq field-done nil)
+                (goto-char end-field))))
+          (if (looking-at (bibtex-field-right-delimiter))
+              (forward-char))
+          (if (memq 'last-comma format)
+              (cond ((and
+                      bibtex-comma-after-last-field
+                      (not (looking-at ",")))
+                     (insert ","))
+                    ((and
+                      (not bibtex-comma-after-last-field)
+                      (looking-at ","))
+                     (delete-char 1))))
+          (if (looking-at ",")
+              (forward-char))
+          (if (memq 'delimiters format)
+              (progn
+                (skip-chars-forward " \t\n")
+                (delete-char 1)
+                (insert (bibtex-entry-right-delimiter))))
+          (if (memq 'realign format)
+              (bibtex-fill-entry)))))))
+
+(defun bibtex-autokey-change (string change-list)
+  ;; Returns a string where some regexps are changed according to
+  ;; change-list. Every item of change-list is an (old-regexp
+  ;; new-string) pair.
+  (let (case-fold-search
+        (return-string string)
+        (index 0)
+        (len (length change-list))
+        change-item)
+    (while (< index len)
+      (setq change-item (elt change-list index))
+      (while (string-match (car change-item) return-string)
+        (setq
+         return-string
+         (concat (substring return-string 0 (match-beginning 0))
+                 (elt change-item 1)
+                 (substring return-string (match-end 0)))))
+      (setq index (1+ index)))
+    return-string))
+
+(defun bibtex-autokey-abbrev (string len)
+  ;; Returns an abbreviation of string with at least len
+  ;; characters. String is aborted only after a consonant or at the
+  ;; word end. If len is not a number, string is returned unchanged.
+  (cond ((or
+          (not (numberp len))
+          (<= (length string) len))
+         string)
+        ((equal len 0)
+         "")
+        (t
+         (let* ((case-fold-search t)
+                (abort-char
+                 (string-match "[^aeiou]" string (1- len))))
+           (if abort-char
+               (substring string 0 (1+ abort-char))
+             string)))))
+
+(defun bibtex-autokey-get-namefield (min max)
+  ;; returns the contents of the name field of the current entry
+  ;; does some modifications based on
+  ;; `bibtex-autokey-name-change-strings'
+  (goto-char min)
+  (let ((case-fold-search t))
+    (if (re-search-forward
+         (bibtex-cfield "\\(author\\)\\|\\(editor\\)" bibtex-field-text)
+         max t)
+        (bibtex-autokey-change
+         (buffer-substring-no-properties
+          (1+ (match-beginning (+ bibtex-text-in-cfield 2)))
+          (1- (match-end (+ bibtex-text-in-cfield 2))))
+         bibtex-autokey-name-change-strings)
+      "")))
+
+(defun bibtex-autokey-get-names (namefield)
+  ;; gathers all names in namefield into a list
+  (let ((case-fold-search t)
+        names)
+    (while (not (equal namefield ""))
+      (let (name)
+        (if (string-match "[ \t\n]and[ \t\n]" namefield)
+            (setq name (substring namefield 0 (match-beginning 0))
+                  namefield (substring namefield (match-end 0)))
+          (setq name namefield
+                namefield ""))
+        (setq names (append names (list name)))))
+    names))
+
+(defun bibtex-autokey-demangle-name (fullname)
+  ;; gets the `last' part from a well-formed name
+  (let* (case-fold-search
+         (lastname
+          (if (string-match "," fullname)
+              ;; name is of the form "von Last, First" or
+              ;; "von Last, Jr, First"
+              ;; --> take only the part before the comma
+              (let ((von-last
+                     (substring fullname 0 (match-beginning 0))))
+                (if (string-match "^[a-z]" von-last)
+                    ;; von-last has a "von" part --> take the "last" part
+                    (if (string-match "[ \t][A-Z]" von-last)
+                        (substring von-last (1+ (match-beginning 0)))
+                      (error
+                       "Name %s is incorrectly formed" fullname))
+                  ;; von-last has no "von" part --> take all
+                  von-last))
+            ;; name is of the form "First von Last"
+            (if (string-match "[ \t]" fullname)
+                ;; more than one token
+                (if (string-match "[ \t][a-z]" fullname)
+                    ;; there is a "von" part
+                    ;; --> take everything after that
+                    (if (string-match
+                         "[ \t][A-Z]" fullname (match-end 0))
+                        (substring fullname (1+ (match-beginning 0)))
+                      (error
+                       "Name %s is incorrectly formed" fullname))
+                  ;; there is no "von" part --> take only the last token
+                  (if (string-match " [^ ]*$" fullname)
+                      (substring fullname (1+ (match-beginning 0)))
+                    (error "Name %s is incorrectly formed" fullname)))
+              ;; only one token --> take it
+              fullname)))
+         (usename
+          (if (string-match "[ \t]+" lastname)
+              ;; lastname consists of two or more tokens
+              ;; --> take only the first one
+              (substring lastname 0 (match-beginning 0))
+            lastname)))
+    (if bibtex-autokey-preserve-case
+        usename
+      (downcase usename))))
+
+(defun bibtex-autokey-get-namelist (namefield)
+  ;; gets namefield, performs abbreviations on the last parts, and
+  ;; return results as a list
+  (mapcar
+   (lambda (fullname)
+     (setq
+      fullname (substring fullname (string-match "[^ \t]" fullname)))
+     (bibtex-autokey-abbrev
+      (bibtex-autokey-demangle-name fullname)
+      bibtex-autokey-name-length))
+   (bibtex-autokey-get-names namefield)))
+
+(defun bibtex-autokey-get-yearfield (min max)
+  ;; get year field from current or maybe crossreferenced entry
+  (let ((case-fold-search t))
+    (goto-char min)
+    (if (re-search-forward
+         (bibtex-cfield "year" "[0-9]+") max t)
+        (buffer-substring-no-properties
+         (match-beginning bibtex-text-in-cfield)
+         (match-end bibtex-text-in-cfield))
+      (if bibtex-autokey-year-use-crossref-entry
+          (let ((crossref-field
+                 (progn
+                   (goto-char min)
+                   (if (re-search-forward
+                        (bibtex-cfield
+                         "\\(OPT\\)?crossref" bibtex-field-text)
+                        max t)
+                       (buffer-substring-no-properties
+                        (1+
+                         (match-beginning (+ bibtex-text-in-cfield 1)))
+                        (1-
+                         (match-end (+ bibtex-text-in-cfield 1))))))))
+            (if (not (bibtex-find-entry-location crossref-field t))
+                (let ((end-of-crefd-entry (bibtex-end-of-entry)))
+                  (bibtex-beginning-of-entry)
+                  (if (re-search-forward
+                       (bibtex-cfield "year" "[0-9]+")
+                       end-of-crefd-entry t)
+                      (buffer-substring-no-properties
+                       (match-beginning bibtex-text-in-cfield)
+                       (match-end bibtex-text-in-cfield))
+                    ""))
+              ""))
+        ""))))
+
+(defun bibtex-autokey-get-titlestring (min max)
+  ;; get title field contents up to a terminator
+  (let ((case-fold-search t))
+    (let ((titlefield
+           (progn
+             (goto-char min)
+             (if (re-search-forward
+                  (bibtex-cfield "title" bibtex-field-text) max t)
+                 (bibtex-autokey-change
+                  (buffer-substring-no-properties
+                   (match-beginning bibtex-text-in-cfield)
+                   (match-end bibtex-text-in-cfield))
+                  bibtex-autokey-titleword-change-strings)
+               "")))
+          (index 0)
+          (numberofitems
+           (length bibtex-autokey-title-terminators)))
+      (while (< index numberofitems)
+        (if (string-match
+             (elt bibtex-autokey-title-terminators index) titlefield)
+            (setq
+             titlefield (substring titlefield 0 (match-beginning 0))))
+        (setq index (1+ index)))
+      titlefield)))
+
+(defun bibtex-autokey-get-titles (titlestring)
+  ;; gathers capitalized words from titlestring into a list. Ignores
+  ;; specific words at the beginning and use only a specific amount of
+  ;; words
+  (let (case-fold-search
+        titlewords
+        titlewords-extra
+        (counter 0)
+        (first t))
+    (while (and
+            (not (equal titlestring ""))
+            (or
+             (not (numberp bibtex-autokey-titlewords))
+             (< counter
+                (+ bibtex-autokey-titlewords
+                   bibtex-autokey-titlewords-stretch))))
+      (if (string-match "\\b[A-Z][A-Za-z0-9]*" titlestring)
+          (let* ((end-match (match-end 0))
+                 (titleword
+                  (if bibtex-autokey-preserve-case
+                      (substring
+                       titlestring (match-beginning 0) end-match)
+                    (downcase
+                     (substring
+                      titlestring (match-beginning 0) end-match)))))
+            (if (or
+                 (not (numberp bibtex-autokey-titlewords))
+                 (< counter bibtex-autokey-titlewords))
+                (if (and
+                     first
+                     (bibtex-member-of-regexp
+                      titleword
+                      bibtex-autokey-titleword-first-ignore))
+                    (setq counter -1)
+                  (setq
+                   titlewords (append titlewords (list titleword))))
+              (setq
+               titlewords-extra
+               (append titlewords-extra (list titleword))))
+            (setq
+             titlestring (substring titlestring end-match)))
+        (setq titlestring ""))
+      (setq first nil
+            counter (1+ counter)))
+    (if (string-match "\\b[A-Z][^ ]*\\b" titlestring)
+        titlewords
+      (append titlewords titlewords-extra))))
+
+(defun bibtex-autokey-get-titlelist (titlestring)
+  ;; returns all capitalized words in titlestring as a list
+  ;; does some abbreviation on the found words
+  (mapcar
+   (lambda (titleword)
+     (let ((abbrev
+            (bibtex-assoc-of-regexp
+             titleword bibtex-autokey-titleword-abbrevs)))
+       (if abbrev
+           (elt abbrev 1)
+         (bibtex-autokey-abbrev
+          titleword
+          bibtex-autokey-titleword-length))))
+   (bibtex-autokey-get-titles titlestring)))
+
+(defun bibtex-generate-autokey ()
+  ;; Generates automatically a key from the author/editor and the
+  ;; title field. This will only work for entries where each field
+  ;; begins on a separate line.
+  ;; The generation algorithm works as follows:
+  ;;  1. Use the value of `bibtex-autokey-prefix-string' as a prefix.
+  ;;  2. If there is a non-empty author (preferred) or editor field,
+  ;;     use it as the name part of the key.
+  ;;  3. Change any substring found in
+  ;;     `bibtex-autokey-name-change-strings' to the corresponding new
+  ;;     one (see documentation of this variable for further detail).
+  ;;  4. For every of at least first `bibtex-autokey-names' names in
+  ;;     the name field, determine the last name. If there are maximal
+  ;;     `bibtex-autokey-names' + `bibtex-autokey-names-stretch'
+  ;;     names, all names are used.
+  ;;  5. From every last name, take at least
+  ;;     `bibtex-autokey-name-length' characters (abort only after a
+  ;;     consonant or at a word end).
+  ;;  6. Unless `bibtex-autokey-preserve-case' is non-nil, convert all
+  ;;     last names to lowercase letters.
+  ;;  7. Build the name part of the key by concatenating all
+  ;;     abbreviated last names with the string
+  ;;     `bibtex-autokey-name-separator' between any two. If there are
+  ;;     more names than are used in the name part, prepend the string
+  ;;     contained in `bibtex-autokey-additional-names'.
+  ;;  8. Build the year part of the key by truncating the contents of
+  ;;     the year field to the rightmost `bibtex-autokey-year-length'
+  ;;     digits (useful values are 2 and 4). If the year field is
+  ;;     absent, but the entry has a valid crossref field and the
+  ;;     variable `bibtex-autokey-year-use-crossref-entry' is non-nil,
+  ;;     use the year field of the crossreferenced entry instead.
+  ;;  9. For the title part of the key change the contents of the
+  ;;     title field of the reference according to
+  ;;     `bibtex-autokey-titleword-change-strings' to the
+  ;;     corresponding new one (see documentation of this variable for
+  ;;     further detail).
+  ;; 10. Abbreviate the result to the string up to (but not including)
+  ;;     the first occurrence of a regexp matched by the items of
+  ;;     `bibtex-autokey-title-terminators' and delete the first
+  ;;     word if it appears in
+  ;;     `bibtex-autokey-titleword-first-ignore'. Build the title part
+  ;;     of the key by using at least the first
+  ;;     `bibtex-autokey-titlewords' capitalized words from this
+  ;;     abbreviated title. If the abbreviated title ends after
+  ;;     maximal `bibtex-autokey-titlewords' +
+  ;;     `bibtex-autokey-titlewords-stretch' capitalized words, all
+  ;;     capitalized words from the abbreviated title are used.
+  ;; 11. Unless `bibtex-autokey-preserve-case' is non-nil, convert all
+  ;;     used titlewords to lowercase letters.
+  ;; 12. For every used title word that appears in
+  ;;     `bibtex-autokey-titleword-abbrevs' use the corresponding
+  ;;     abbreviation (see documentation of this variable for further
+  ;;     detail).
+  ;; 13. From every title word not generated by an abbreviation, take
+  ;;     at least `bibtex-autokey-titleword-length' characters (abort
+  ;;     only after a consonant or at a word end).
+  ;; 14. Build the title part of the key by concatenating all
+  ;;     abbreviated title words with the string
+  ;;     `bibtex-autokey-titleword-separator' between any two.
+  ;; 15. At least, to get the key, concatenate
+  ;;     `bibtex-autokey-prefix-string', the name part, the year part
+  ;;     and the title part with `bibtex-autokey-name-year-separator'
+  ;;     between the name part and the year part if both are non-empty
+  ;;     and `bibtex-autokey-year-title-separator' between the year
+  ;;     part and the title part if both are non-empty. If the year
+  ;;     part is empty, but not the other two parts,
+  ;;     `bibtex-autokey-year-title-separator' is used as well.
+  ;; 16. If the value of `bibtex-autokey-before-presentation-hook' is
+  ;;     non-nil, it must be a function taking one argument. This
+  ;;     function is then called with the generated key as the
+  ;;     argument. The return value of this function (a string) is
+  ;;     used as the key.
+  ;; 17. If the value of `bibtex-autokey-edit-before-use' is non-nil,
+  ;;     the key is then presented in the minibuffer to the user,
+  ;;     where it can be edited. The key given by the user is then
+  ;;     used.
+
+  (let* ((pnt (point))
+         (min (bibtex-beginning-of-entry))
+         (max (bibtex-end-of-entry))
+         (namefield (bibtex-autokey-get-namefield min max))
+         (name-etal "")
+         (namelist
+          (let ((nl (bibtex-autokey-get-namelist namefield)))
+            (if (or (not (numberp bibtex-autokey-names))
+                    (<= (length nl)
+                        (+ bibtex-autokey-names
+                           bibtex-autokey-names-stretch)))
+                nl
+              (setq name-etal bibtex-autokey-additional-names)
+              (let (nnl)
+                (while (< (length nnl) bibtex-autokey-names)
+                  (setq nnl (append nnl (list (car nl)))
+                        nl (cdr nl)))
+                nnl))))
+         (namepart
+          (concat
+           (mapconcat (lambda (name) name)
+                      namelist
+                      bibtex-autokey-name-separator)
+           name-etal))
+         (yearfield (bibtex-autokey-get-yearfield min max))
+         (yearpart
+          (if (equal yearfield "")
+              ""
+            (substring
+             yearfield
+             (- (length yearfield) bibtex-autokey-year-length))))
+         (titlestring (bibtex-autokey-get-titlestring min max))
+         (titlelist (bibtex-autokey-get-titlelist titlestring))
+         (titlepart
+          (mapconcat