Commits

Anonymous committed 8d278a6

Reftex.el-3.34

Comments (0)

Files changed (5)

+1998-08-11  SL Baur  <steve@altair.xemacs.org>
+
+	* reftex.el-3.34.
+
 1998-03-21  SL Baur  <steve@altair.xemacs.org>
 
-	* reftex.el-3.22
+	* reftex.el-3.22.
 
 1998-02-25  SL Baur  <steve@altair.xemacs.org>
 
 # the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 # Boston, MA 02111-1307, USA.
 
-VERSION = 1.04
-AUTHOR_VERSION = 3.22
+VERSION = 1.05
+AUTHOR_VERSION = 3.34
 MAINTAINER = Carsten Dominik <dominik@strw.LeidenUniv.nl>
 PACKAGE = reftex
 PKG_TYPE = regular
 
 all:: $(ELCS) auto-autoloads.elc $(PACKAGE).info
 
-reftex.info: reftex.texinfo
-	$(MAKEINFO) $(MAKEINFO_FLAGS) -o $@ $<
-
 srckit: srckit-std
 
 binkit: binkit-sourceinfo
-;; reftex.el --- Minor mode for doing \label, \ref and \cite in LaTeX
+;;; reftex.el --- Minor mode for doing \label, \ref and \cite in LaTeX
 ;; Copyright (c) 1997, 1998 Free Software Foundation, Inc.
 
-;; Version:    3.22 
+;; Version:    3.34 
 ;; Author:     Carsten Dominik <dominik@strw.LeidenUniv.nl>
 ;; Keywords:   tex
 
 ;; access to any part of a document.
 ;;
 ;;
-;; To turn RefTeX Minor Mode on and off in a particular buffer, use
+;; To turn RefTeX Mode on and off in a particular buffer, use
 ;; `M-x reftex-mode'.
 ;;
-;; To turn on RefTeX Minor Mode for all LaTeX files, add one of the
-;; following lines to your .emacs file:
+;; To turn on RefTeX Mode for all LaTeX files, add one of the following
+;; lines to your .emacs file:
 ;;
 ;;   (add-hook 'LaTeX-mode-hook 'turn-on-reftex)   ; with AUCTeX LaTeX mode
 ;;   (add-hook 'latex-mode-hook 'turn-on-reftex)   ; with Emacs latex mode
 ;; RefTeX in a Nutshell
 ;; ====================
 ;; 
-;;   1. Labels and References
-;;      RefTeX distinguishes labels for different environments.  It always
-;;      knows if a certain label references a figure, table etc..  You can
-;;      configure RefTeX to recognize any additional labeled environments
-;;      you have defined yourself (variable REFTEX-LABEL-ALIST).
-;;         - Creating Labels
-;;           Type `C-c (' (`reftex-label') to insert a label at point.
-;;           RefTeX will either
-;;              - derive a label from context (default for section labels)
-;; 
-;;              - insert a simple label consisting of a prefix and a number
-;;                (default for equations, enumerate items, and footnotes)
-;;                or
-;; 
-;;              - prompt for a label string (figures and tables).
-;; 
-;;           Which labels are created how is configurable (variable
-;;           REFTEX-INSERT-LABEL-FLAGS).
-;; 
-;;         - Referencing Labels
-;;           Referencing labels is a snap and I promise you'll love it.
-;;           In order to make a reference, type `C-c )'
-;;           (`reftex-reference').  This shows an outline of the document
-;;           with all labels of a certain type (figure, equation,...) and
-;;           context of the label definition.  Selecting one of the labels
-;;           inserts a `\ref' macro into the original buffer.  Online help
-;;           during the selection is available with `?'.
-;; 
-;;   2. Citations
-;;      After typing `C-c [' (`reftex-citation'), RefTeX will let you
-;;      specify a regular expression to search in current BibTeX database
-;;      files (as specified in the `\bibliography' command) and pull out a
-;;      formatted list of matches for you to choose from.  The list is
-;;      *formatted* and sorted, thus much easier to read than the raw
-;;      database entries.  The text inserted into the buffer is by default
-;;      just `\cite{KEY}', but can also contain author names and the year
-;;      in a configurable way (variable REFTEX-CITE-FORMAT).
-;; 
-;;   3. Viewing Cross References
-;;      With point on or anywhere before a `\ref' or `\cite' macro, press
-;;      `C-c &' (`reftex-view-crossref').  This will display the
-;;      corresponding label definition or BibTeX database entry in another
-;;      window.
-;; 
-;;   4. Table of Contents
-;;      Typing `C-c =' (`reftex-toc') will show a table of contents of the
-;;      document.  From that buffer, you can jump quickly to every part of
-;;      your document.
-;; 
-;;   5. Multifile Documents
-;;      Multifile Domuments are fully supported. RefTeX will provide cross
-;;      referencing information from all files which are part of the
-;;      document. You may also use it to reference labels in external
-;;      documents (in cooperation with the LaTeX package `xr').
-;; 
-;;   6. Document Parsing
-;;      RefTeX needs to parse the document in order to find labels and
-;;      other information.  It will do it automatically once, when you
-;;      start working with a document.  Re-parsing should not be necessary
-;;      too often since RefTeX updates its lists internally when you make
-;;      a new label with `reftex-label'.  To enforce reparsing, call any
-;;      of the commands described above with a raw `C-u' prefix, or press
-;;      the `r' key in the label selection buffer or the table of contents
-;;      buffer.
+;;  1. Labels and References
+;;     RefTeX distinguishes labels for different environments.  It knows
+;;     about all standard environments (and many others), and can be
+;;     configured to recognize any additional labeled environments you
+;;     have defined yourself (variable REFTEX-LABEL-ALIST().
+;;
+;;        * Creating Labels
+;;          Type `C-c (' (`reftex-label') to insert a label at point.
+;;          RefTeX will either
+;;             - derive a label from context (default for section labels)
+;;             - prompt for a label string (default for figures and
+;;               tables) or
+;;             - insert a simple label made of a prefix and a number (all
+;;               other environments).
+;;          Which labels are created how is configurable (variable
+;;          REFTEX-INSERT-LABEL-FLAGS).
+;;
+;;        * Referencing Labels
+;;          In order to make a reference, type `C-c )'
+;;          (`reftex-reference').  This shows an outline of the document
+;;          with all labels of a certain type (figure, equation,...) and
+;;          context of the label definition.  Selecting a label inserts a
+;;          `\ref{LABEL}' macro into the original buffer.
+;;
+;;  2. Citations
+;;     After typing `C-c [' (`reftex-citation'), RefTeX will let you
+;;     specify a regular expression to search in current BibTeX database
+;;     files (as specified in the `\bibliography' command) and pull out a
+;;     list of matches for you to choose from.  The list is *formatted*
+;;     and sorted.  The selected article is referenced as `\cite{KEY}'
+;;     (customizable with variable REFTEX-CITE-FORMAT).
+;;
+;;  3. Viewing Cross References
+;;     When no other message occupies the echo area and point is idle on
+;;     the argument of a `\ref' or `\cite' macro, the echo area will
+;;     display information about the citation/cross reference.
+;;     With point on or anywhere before such a macro, press `C-c &'
+;;     (`reftex-view-crossref'), or click with `S-mouse-2' on the macro
+;;     argument.  This will display the corresponding label definition or
+;;     BibTeX database entry in another window.
+;;
+;;  4. Table of Contents
+;;     Typing `C-c =' (`reftex-toc') will show a table of contents of the
+;;     document.  From that buffer, you can jump quickly to every part of
+;;     your document.
+;;
+;;  5. Multifile Documents
+;;     Multifile Documents are fully supported. RefTeX will provide cross
+;;     referencing information from all files which are part of the
+;;     document, and even across document borders (`xr.sty').
+;;
+;;  6. Document Parsing
+;;     RefTeX needs to parse the document in order to find labels and
+;;     other information.  It does it automatically once, when you start
+;;     working with a document.  RefTeX updates its lists internally when
+;;     you make a new label with `reftex-label'.  To enforce reparsing,
+;;     call any of the commands described above with a raw `C-u' prefix,
+;;     or press the `r' key in the label selection buffer or the table of
+;;     contents buffer.
+;;
+;;  7. Speed Issues
+;;     Useful settings to make RefTeX faster for large (multifile)
+;;     documents include:
+;;          (setq reftex-enable-partial-scans t)
+;;          (setq reftex-save-parse-info t)
+;;          (setq reftex-use-multiple-selection-buffers t)
 ;;
 ;;---------------------------------------------------------------------------
 ;;
 ;;    http://www.strw.leidenuniv.nl/~dominik/Tools/
 ;;    ftp://strw.leidenuniv.nl/pub/dominik/
 ;;
-;; The version at this site is compatible with Emacs 19 - the version
-;; distributed with Emacs 20 is not.
+;; At that site you can also get version 3.22 of RefTeX which is still
+;; compatible with Emacs 19.  The file you are reading now as well as the
+;; ones distributed with Emacs 20 are not.
 ;;
 ;; THANKS TO:
 ;; ---------
 ;;    Robin Socha, Richard Stanton, Allan Strand, Jan Vroonhof,
 ;;    Christoph Wedler.
 ;;
-;; The view crossref feature was inspired by the similar function in
-;; Peter Galbraith's bib-cite.el.
-;;
 ;; Finally thanks to Uwe Bolick who first got me (some years ago) into
 ;; supporting LaTeX labels and references with an Editor (which was
 ;; MicroEmacs at the time).
 ;; Version 1.07
 ;;    - RefTeX gets its own menu.
 ;; Version 1.09
-;;    - Support for tex-main-file, an analogue for TeX-master.
+;;    - Support for `tex-main-file', an analogue for `TeX-master'.
 ;;    - MS-DOS support.
 ;; Version 2.00
 ;;    - Labels can be derived from context (default for sections).
 ;;    - A few (minor) Mule-related changes.
 ;;    - Fixed bug which could cause HUGE .rel files.
 ;;    - Search for input and .bib files with recursive path definitions.
-;; Version 3.04
-;;    - Fixed BUG in the `xr' support.
-;; Version 3.05
-;;    - Compatibility code now first checks for XEmacs feature.
-;; Version 3.07
-;;    - `Ref' menu improved.
-;; Version 3.10
-;;    - Fixed a bug which made reftex 3.07 fail on [X]Emacs version 19.
-;;    - Removed unimportant code which caused OS/2 Emacs to crash.
-;;    - All customization variables now accessible from menu.
-;; Version 3.11
-;;    - Fixed bug which led to naked label in (e.g.) footnotes.
-;;    - Added scroll-other-window functions to RefTeX-Select.
 ;; Version 3.12
 ;;    - There are 3 new keymaps for customization: `reftex-toc-map',
 ;;      `reftex-select-label-map', `reftex-select-bib-map'.
 ;;    - New hooks `reftex-format-label-function', `reftex-format-ref-function',
 ;;      `reftex-format-cite-function'.
 ;;    - TeXInfo documentation completed.
-;;    - Some restrictions in Label inserting and referencing removed.
 ;;    - New variable `reftex-default-bibliography'.
 ;; Version 3.17
 ;;    - Additional bindings in selection and *toc* buffers.  `g' redefined. 
 ;;    - Fixed some problems regarding the interaction with VIPER mode.
 ;;    - Follow-mode is now only used after point motion.
 ;;    - RefTeX now finally does not fontify temporary files anymore!
-;; Version 3.19
-;;    - Fixed bug with AUCTeX TeX-master.
 ;; Version 3.21
-;;    - New options for all faces used by RefTeX. They're in the
+;;    - New options for all faces used by RefTeX.  They're in the
 ;;      customization group `reftex-fontification-configurations'.
 ;; Version 3.22
-;;    - Fixed bug with empty context strings.
 ;;    - `reftex-mouse-view-crossref' is now bound by default at `S-mouse-2'
+;;    - THIS VERSION IS RECOMMENDED FOR X/EMACS 19.
+;; Version 3.23
+;;    - Parse files MASTER.rel made compatible between Emacs and XEmacs.
+;;    - `kill-emacs-hook' and `kill-buffer-hook' now write the parse file.
+;;    - The cursor inside a \ref or \cite macro now triggers automatic
+;;      display of crossref information in the echo area.  See variable
+;;      `reftex-auto-view-crossref'.
+;;    - AUCTeX interface updates:
+;;      - AUCTeX 9.9c and later notifies RefTeX about new sections.
+;;      - RefTeX notifies ACUTeX about new labels.
+;;      - TeX-arg-ref no longer used (introduction was unnecessaary).
+;;      - `reftex-arg-label' and `reftex-arg-cite' fixed up.
+;;      - Settings added to RefTeX via style files remain local.
+;; Version 3.24
+;;    - New option `reftex-revisit-to-echo'.
+;;    - Interface with X-Symbol (>=2.6) is now complete and stable.
+;;    - Adapted to new outline, which uses overlays.
+;; Version 3.25
+;;    - Echoing of citation info caches the info for displayed entries.
+;;      New option `reftex-cache-cite-echo'.
+;;    - `M-x reftex-reset-mode' now also removes the file with parsing info.
+;;    - Default of `reftex-revisit-to-follow' changed to nil.
+;; Version 3.26
+;;    - [X]Emacs 19 support dropped.  Use 3.22 for them.
+;;    - New hooks `reftex-translate-to-ascii-function',
+;;      `reftex-string-to-label-function'.
+;; Version 3.27
+;;    - Macros can define "neutral" labels, just like \label{} itself.
+;;    - New option `reftex-allow-detached-macro-args', default nil!
+;; Version 3.28
+;;    - Auto view crossref for XEmacs uses post-command-hook to restart the
+;;      timer, since itimer restart is not reliable.
+;;    - Option `reftex-bibfile-ignore-list' renamed to `-regexps'.
+;;    - Expansion of recursive tex and bib path rewritten.
+;; Version 3.30
+;;    - In `reftex-citation', the regexp can be completed on known cite keys.
+;;    - New keys `a' and `A' in bib selecton process to cite all entries.
+;;    - New command `reftex-renumber-simple-labels' to renumber `eq:13' etc.
+;; Version 3.33
+;;    - Multiple Selection Buffers are now hidded (names start with a space).
+;;    - Fixed bug with file search when TEXINPUTS was empty.
+;; Version 3.34
+;;    - Additional flag in `reftex-derive-label-parameters' to make only
+;;      lowercase labels (default t).
+;;    - All .rel files have a final newline to avoid queries.
+;;    - Single byte representations of accented European letters (ISO-8859-1)
+;;      are legal in labels.  However, general Mule characters are not.
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;
 ;;;;;;
 (eval-when-compile (require 'cl))
 
 ;; Stuff that needs to be there when we use defcustom
-;; --------------------------------------------------
 (require 'custom)
 
 (defvar reftex-tables-dirty t
     (setq reftex-tables-dirty t)
     (set symbol value)))
 
-(eval-and-compile
-  (defmacro reftex-fp (n)
-    (if (fboundp 'forward-point) 
-	(list 'forward-point n)
-      (list '+ '(point) n))))
-
-;;; Begin of Configuration Section ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;; ======================================================================
+;;;
+;;; Configuration Section
 
 ;; Define the two constants which are needed during compilation
 
     ;; The LaTeX core stuff
     (LaTeX       "LaTeX default environments"
      (("section"   ?s "sec:" "~\\ref{%s}" (nil . t)
-       (regexp "Parts?" "Chapters?" "Chap\\." "Sections?" "Sect?\\."
-	       "Paragraphs?" "Par\\."
+       (regexp "parts?" "chapters?" "chap\\." "sections?" "sect?\\."
+	       "paragraphs?" "par\\."
 	       "\\\\S" "\247" "Teile?" "Kapitel" "Kap\\." "Abschnitte?"
-	       "Appendi\\(x\\|ces\\)" "App\\."  "Anh\"?ange?" "Anh\\."))
+	       "appendi\\(x\\|ces\\)" "App\\."  "Anh\"?ange?" "Anh\\."))
 
       ("enumerate" ?i "item:" "~\\ref{%s}" item
-       (regexp "Items?" "Punkte?"))
+       (regexp "items?" "Punkte?"))
       
       ("equation"  ?e "eq:" "~(\\ref{%s})" t
-       (regexp "Equations?" "Eqs?\\." "Eqn\\." "Gleichung\\(en\\)?"  "Gl\\."))
+       (regexp "equations?" "eqs?\\." "eqn\\." "Gleichung\\(en\\)?"  "Gl\\."))
       ("eqnarray"  ?e "eq:" nil eqnarray-like)
       
       ("figure"    ?f "fig:" "~\\ref{%s}" caption
-       (regexp "Figure[sn]?" "Figs?\\." "Abbildung\\(en\\)?" "Abb\\."))
+       (regexp "figure?[sn]?" "figs?\\." "Abbildung\\(en\\)?" "Abb\\."))
       ("figure*"   ?f nil nil caption)
       
       ("table"     ?t "tab:" "~\\ref{%s}" caption
-       (regexp "Tables?" "Tab\\." "Tabellen?"))
+       (regexp "tables?" "tab\\." "Tabellen?"))
       ("table*"    ?t nil nil caption)
       
       ("\\footnote[]{}" ?n "note:" "~\\ref{%s}" 2
-       (regexp "Footnotes?" "Notes?"))
+       (regexp "footnotes?" "notes?" "Anmerkung\\(en\\)?" "Anm\\."))
       
-      ("any"       ?\  " "   "~\\ref{%s}" nil)))
+      ("any"       ?\  " "   "~\\ref{%s}" nil)
+
+      ;; The label macro is hard coded, but it *could* be defined like this:
+      ;;("\\label{*}" nil nil nil nil)
+      ))
 
     )
   "The default label environment descriptions.
       (?p    . "\\citep{%l}")
       (?P    . "\\citep*{%l}")
       (?e    . "\\citep[e.g.][]{%l}")
+      (?s    . "\\citep[see][]{%l}")
       (?a    . "\\citeauthor{%l}")
+      (?A    . "\\citeauthor*{%l}")
       (?y    . "\\citeyear{%l}")))
     (harvard "The Harvard package"
      ((?\C-m . "\\cite{%l}")
       (?p    . "(%2a %y\\nocite{%l})")))
     (locally     "Full info in parenthesis"
      "(%2a %y, %j %v, %P, %e: %b, %u, %s %<)")
-    ;; undocumented feature: `%<' kills white space and punctuation locally.
     )
-  "Builtin versions of for the citation format.
+  "Builtin versions of the citation format.
 The following conventions are valid for all alist entries:
 `?\C-m' should always point to a straight \\cite{%l} macro.
 `?t'    should point to a textual citation (citation as a noun).
   :prefix "reftex-"
   :group 'tex)
 
-(defun reftex-customize ()
-  "Call the customize function with reftex as argument."
-  (interactive)
-  ;; Depending on the customize version we can call different functions.
-  (cond
-   ((fboundp 'customize-browse)
-    (customize-browse 'reftex))
-   ((fboundp 'customize-group)
-    (customize-group 'reftex))
-   ((fboundp 'customize)
-    (customize 'reftex))
-   (t (error "Custom.el not available"))))
-
-(defun reftex-create-customize-menu ()
-  "Create a full customization menu for RefTeX."
-  (interactive)
-  (if (fboundp 'customize-menu-create)
-      (progn
-	(easy-menu-change 
-	 '("Ref") "Customize"
-	 `(["Browse RefTeX group" reftex-customize t]
-	   "---"
-	   ,(customize-menu-create 'reftex)
-	   ["Set" Custom-set t]
-	   ["Save" Custom-save t]
-	   ["Reset to Current" Custom-reset-current t]
-	   ["Reset to Saved" Custom-reset-saved t]
-	   ["Reset to Standard Settings" Custom-reset-standard t]))
-	(message "\"Ref\"-menu now contains full customization menu"))
-    (error "Cannot expand menu (outdated version of cus-edit.el)")))
-
-(defun reftex-show-commentary ()
-  "Use the finder to view the file documentation from `reftex.el'."
-  (interactive)
-  (require 'finder)
-  (finder-commentary "reftex.el"))
-
-(defun reftex-info ()
-  "Read documentation for RefTeX in the info system."
-  (interactive)
-  (require 'info)
-  (Info-goto-node "(reftex)"))
-
-;; Support for \label and \ref --------------------------------------
-
 (defgroup reftex-label-support nil
   "Support for creation, insertion and referencing of labels in LaTeX."
   :group 'reftex)
   "Definition of environments and macros to do with label."
   :group 'reftex-label-support)
 
-;; Make a constant for the customization stuff
-(eval-and-compile
-  (defconst reftex-tmp
-    '((const  :tag "Default position" t)
-      (const  :tag "After label"      nil)
-      (number :tag "Macro arg nr" 1)
-      (regexp :tag "Regexp" "")
-      (const  :tag "Caption in float" caption)
-      (const  :tag "Item in list" item)
-      (const  :tag "Eqnarray-like" eqnarray-like)
-      (const  :tag "Alignat-like" alignat-like)
-      (symbol :tag "Function" my-func))))
-
 (defcustom reftex-default-label-alist-entries
   '(amsmath endnotes fancybox floatfig longtable picinpar
 	    rotating sidecap subfigure supertab wrapfig LaTeX)
     type.  The same character may occur several times in this list, to cover
     cases in which different environments carry the same label type (like
     `equation' and `eqnarray').
+    If the type indicator is nil and the macro has a label argument {*},
+    the macro defines neutral labels just like \label.  In this case
+    the reminder of this entry is ignored.
 
 2.  Label prefix string, like \"tab:\".
     The prefix is a short string used as the start of a label.  It may be the
   :set 'reftex-set-dirty
   :type
   `(repeat
-    (choice
+    (choice :tag "Package or Detailed   "
      :value ("" ?a nil nil nil nil)
-     (list :tag "Detailed label alist entry"
+     (list :tag "Detailed Entry"
            :value ("" ?a nil nil nil nil)
            (choice    :tag "Environment or \\macro "
                       (const  :tag "Ignore, just use typekey" nil)
                       (string ""))
-           (character :tag "Typekey character     " ?a)
+	   (choice    :tag "Type specification    "
+		      (const :tag "unspecified, like in \\label" nil)
+		      (character :tag "Char  " ?a))
            (choice    :tag "Label prefix string   "
                       (const  :tag "Default" nil)
                       (string :tag "String" "lab:"))
            (choice    :tag "Label reference format"
                       (const  :tag "Default" nil)
                       (string :tag "String" "~\\ref{%s}"))
-           (choice :tag "Context"
-                   (choice
-                    :tag "1 method"
-                    ,@reftex-tmp)
-                   (cons :tag "Split methods"
-                         (choice
-                          :tag "  Display context     "
-                          ,@reftex-tmp)
-                         (choice
-                          :tag "  Derive label context"
-                          ,@reftex-tmp)))
-	   (repeat :tag "List of Magic Words" (string)))
+           (choice    :tag "Context method        "
+		      (const  :tag "Default position" t)
+		      (const  :tag "After label"      nil)
+		      (number :tag "Macro arg nr" 1)
+		      (regexp :tag "Regexp" "")
+		      (const  :tag "Caption in float" caption)
+		      (const  :tag "Item in list" item)
+		      (const  :tag "Eqnarray-like" eqnarray-like)
+		      (const  :tag "Alignat-like" alignat-like)
+		      (symbol :tag "Function" my-func))
+	   (repeat :tag "Magic words" :extra-offset 2 (string)))
      (choice
       :tag "Package"
       :value AMSTeX
                         (const  :tag "never" nil)
                         (string :tag "selected label types" ""))))
 
+(defcustom reftex-string-to-label-function 'reftex-string-to-label
+  "Function to turn an arbitrary string into a legal label.
+RefTeX's default function uses the variable `reftex-derive-label-parameters'."
+  :group 'reftex-making-and-inserting-labels
+  :type 'symbol)
+
+(defcustom reftex-translate-to-ascii-function nil
+  "Filter function which will process a context string before it is used
+to derive a label from it.  A useful application would be to convert ISO or
+Mule characters into something legal in labels.  By default, RefTeX just
+removes these characters.  X-Symbol (>=2.6) sets this variable to
+`x-symbol-translate-to-ascii'."
+  :group 'reftex-making-and-inserting-labels
+  :type 'symbol)
+
 (defcustom reftex-derive-label-parameters '(3 20 t 1 "-"
-         ("the" "on" "in" "off" "a" "for" "by" "of" "and" "is"))
+         ("the" "on" "in" "off" "a" "for" "by" "of" "and" "is" "to") t)
   "Parameters for converting a string into a label.
 NWORDS      Number of words to use.
 MAXCHAR     Maximum number of characters in a label string.
             not t and not nil: Abbreviate words if necessary to shorten
                                label string below MAXCHAR.
 SEPARATOR   String separating different words in the label.
-IGNOREWORDS List of words which should not be part of labels."
+IGNOREWORDS List of words which should not be part of labels.
+DOWNCASE    t:   Downcase words before using them."
   :group 'reftex-making-and-inserting-labels
   :type  '(list (integer :tag "Number of words            "  3)
                 (integer :tag "Maximum label length       " 20)
                 (string  :tag "Separator between words    " "-")
                 (repeat  :tag "Ignore words"
                          :entry-format "           %i %d %v"
-                         (string :tag ""))))
-
-(defcustom reftex-label-illegal-re "[\000-\040\177-\377\\\\#$%&~^_{}]"
+                         (string :tag ""))
+		(option (boolean :tag "Downcase words          "))))
+
+;; The following rexexp is defined negative and excludes all Mule characters.
+;; A positive way to do it and to allow Mule characters at the same time
+;; vwould be this: "[][\000-\037 !\"#$%&'()*,/<=>?@\\^`{|}~\177]"  
+(defcustom reftex-label-illegal-re "[^-a-zA-Z0-9_+=:;,.\300-\377]"
   "Regexp matching characters not legal in labels.
-For historic reasons, this character class comes *with* the [] brackets."
+For historic reasons, this character class comes *with* the [] brackets.
+The default value allows the characters \300-\377 because these are the
+european letters in ISO 8859-1."
   :group 'reftex-making-and-inserting-labels
   :type '(regexp :tag "Character class"))
 
-(defcustom reftex-abbrev-parameters '(4 2 "^saeiou" "aeiou")
+(defcustom reftex-abbrev-parameters '(4 2 "^aeiou" "aeiou")
   "Parameters for abbreviation of words.
 MIN-CHARS    Minimum number of characters remaining after abbreviation.
 MIN-KILL     Minimum number of characters to remove when abbreviating words.
 (defcustom reftex-level-indent 2
   "*Number of spaces to be used for indentation per section level."
   :group 'reftex-referencing-labels
-  :type '(integer))
+  :type 'integer)
 
 (defcustom reftex-guess-label-type t
   "*Non-nil means, `reftex-reference' will try to guess the label type.
 immediately offer the correct label menu - otherwise it will prompt you for
 a label type.  If you set this variable to nil, RefTeX will always prompt."
   :group 'reftex-referencing-labels
-  :type '(boolean))
+  :type 'boolean)
 
 (defcustom reftex-format-ref-function nil
   "Function which produces the string to insert as a reference.
   :group 'reftex-referencing-labels
   :type 'function)
 
+(defcustom reftex-select-label-mode-hook nil
+  "Mode hook for reftex-select-label-mode."
+  :group 'reftex-referencing-labels
+  :type 'hook)
+
 ;; BibteX citation configuration ----------------------------------------
 
 (defgroup reftex-citation-support nil
   :group 'reftex)
 
 (defcustom reftex-bibpath-environment-variables '("BIBINPUTS" "TEXBIB")
-  "*List of env vars which might contain the path to BibTeX database files."
+  "*List of env vars which might contain the path to BibTeX database files.
+Directories ending in `//' or `!!' will be expanded recursively when necessary
+to find files."
   :group 'reftex-citation-support
   :set 'reftex-set-dirty
   :type '(repeat (string :tag "Environment variable")))
 
-(defcustom reftex-bibfile-ignore-list nil
-  "*List of files in \\bibliography{..} RefTeX should *not* parse.
-The file names have to be in the exact same form as in the bibliography
-macro - i.e. without the `.bib' extension.
+(defvar reftex-bibfile-ignore-list nil) ; compatibility
+(defcustom reftex-bibfile-ignore-regexps nil
+  "*List of regular expressions to exclude files in \\bibliography{..}.
+File names matched by these regexps will not be parsed by RefTeX.
 Intended for files which contain only `@string' macro definitions and the
 like, which are ignored by RefTeX anyway."
   :group 'reftex-citation-support
   :set 'reftex-set-dirty
-  :type '(repeat (string :tag "File name")))
+  :type '(repeat (regexp)))
 
 (defcustom reftex-default-bibliography nil
   "*List of BibTeX database file which should be used if none are specified.
 %i institution   %j journal        %k key        %m month
 %n number        %o organization   %p pages      %P first page
 %r address       %s school         %u publisher  %t title
-%v volume        %y year
-
-Usually, only %l is needed.  Try, however, (setq reftex-comment-citations t).
-
-Beware that all this only works when using BibTeX database files.  When
+%v volume        %y year          
+%B booktitle, abbreviated          %T title, abbreviated
+
+Usually, only %l is needed.  The other stuff is mainly for the echo area
+display, and for (setq reftex-comment-citations t).
+
+%< as a special operator kills punctuation and space around it after the 
+string has been formatted.
+
+Beware that all this only works with BibTeX database files.  When
 citations are made from the \\bibitems in an explicit thebibliography
 environment, only %l is available.
 
   In order to configure this variable, you can either set
 `reftex-cite-format' directly yourself or set it to the SYMBOL of one of
 the predefined styles (see `reftex-cite-format-builtin').  E.g.:
-(setq reftex-cite-format 'harvard)"
+(setq reftex-cite-format 'natbib)"
   :group 'reftex-citation-support
   :type
   `(choice
   "*Non-nil means add a comment for each citation describing the full entry.
 The comment is formatted according to `reftex-cite-comment-format'."
   :group 'reftex-citation-support
-  :type '(boolean))
+  :type 'boolean)
 
 (defcustom reftex-cite-comment-format
-  "%% %2a %y, %j %v, %P, %e: %b, %u, %s %<\n"
-  "Citation format used for commented citations.  Must NOT contain %l."
+  "%% %2a %y, %j %v, %P, %b, %e, %u, %s %<\n"
+  "Citation format used for commented citations.  Must NOT contain %l.
+See the variable `reftex-cite-format' for possible percent escapes."
   :group 'reftex-citation-support
-  :type '(string))
+  :type 'string)
+
+(defcustom reftex-cite-view-format
+  "%2a %y, %T, %B, %j %v:%P, %s %<"
+  "Citation format used to display citation info in the message area.
+Must NOT contain %l.  See the variable `reftex-cite-format' for
+possible percent escapes."
+  :group 'reftex-citation-support
+  :group 'reftex-viewing-cross-references-and-citations
+  :type 'string)
 
 (defcustom reftex-cite-punctuation '(", " " \\& " " {\\it et al.}")
   "Punctuation for formatting of name lists in citations.
   :group 'reftex-citation-support
   :type 'function)
 
+(defcustom reftex-select-bib-mode-hook nil
+  "Mode hook for reftex-select-bib-mode."
+  :group 'reftex-citation-support
+  :type 'hook)
+
 ;; Table of contents configuration --------------------------------------
 
 (defgroup reftex-table-of-contents-browser nil
 The other window will show the corresponding part of the document.
 This flag can be toggled from within the *toc* buffer with the `f' key."
   :group 'reftex-table-of-contents-browser
-  :type '(boolean))
+  :type 'boolean)
+
+(defcustom reftex-revisit-to-follow nil
+  "*Non-nil means, follow-mode will revisit files if necessary.
+When nil, follow-mode will be suspended for stuff in unvisited files."
+  :group 'reftex-table-of-contents-browser
+  :group 'reftex-referencing-labels
+  :type 'boolean)
+
+(defcustom reftex-toc-mode-hook nil
+  "Mode hook for reftex-toc-mode."
+  :group 'reftex-table-of-contents-browser
+  :type 'hook)
+
+;; Viewing Cross References and Citations
+(defgroup reftex-viewing-cross-references-and-citations nil
+  "Displaying cross references and citations."
+  :group 'reftex)
+
+(defcustom reftex-auto-view-crossref t
+  "*Non-nil means, initially turn automatic viewing of crossref info on.
+Automatic viewing of crossref info uses the echo area.  Whenever point is in
+the argument of a \\ref or \\cite macro, and no other message is being
+displayed, the echo area will display information about that cross reference.
+This feature can be turned on and of from the menu 
+(Ref->Options->Crossref Viewing)."
+  :group 'reftex-viewing-cross-references-and-citations
+  :type 'boolean)
+
+(defcustom reftex-idle-time 1.2
+  "*Time (secs) Emacs has to be idle before automatic crossref display is done."
+  :group 'reftex-viewing-cross-references-and-citations
+  :type 'number)
+
+(defcustom reftex-revisit-to-echo nil
+  "*Non-nil means, automatic citation display will revisit files if necessary.
+When nil, citation display in echo area will only be active for cached
+entries and for BibTeX database files with live associated buffers."
+  :group 'reftex-viewing-cross-references-and-citations
+  :type 'boolean)
+
+(defcustom reftex-cache-cite-echo t
+  "*Non-nil means, the information displayed in the echo area for cite macros
+is cached and even saved along with the parsing information.  The cache
+survives document scans.  In order to clear it, use M-x reftex-reset-mode."
+  :group 'reftex-viewing-cross-references-and-citations
+  :type 'boolean)
+
+(defcustom reftex-display-copied-context-hook nil
+  "Normal Hook which is run before context is displayed anywhere.  Designed
+for X-Symbol, but may have other uses as well."
+  :group 'reftex-viewing-cross-references-and-citations
+  :group 'reftex-referencing-labels
+  :type 'hook)
 
 ;; Tuning the parser ----------------------------------------------------
 
 slow but will happen only once).
 If a buffer is to be thrown away, the initialization of the buffer depends
 upon the variable `reftex-initialize-temporary-buffers'."
-  :group 'reftex-miscellaneous-configurations
+  :group 'reftex-optimizations-for-large-documents
   :type '(choice
           (const :tag "Throw away everything" nil)
           (const :tag "Keep everything" t)
 When t, the full default initializations are done (find-file-hook etc.).
 Instead of t or nil, this variable may also be a list of hook functions to
 do a minimal initialization."
-  :group 'reftex-miscellaneous-configurations
+  :group 'reftex-optimizations-for-large-documents
   :type '(choice
           (const :tag "Read files literally" nil)
           (const :tag "Fully initialize buffers" t)
           (repeat :tag "Hook functions" :value (nil)
            (function-item))))
 
-(defcustom reftex-no-include-regexps '("\\.pstex_t\\'") ; default for x-symbol
+(defcustom reftex-no-include-regexps '("\\.pstex_t\\'")
   "*List of regular expressions to exclude certain input files from parsing.
 If the name of a file included via \\include or \\input is matched by any
 of the regular expressions in this list, that file is not parsed by RefTeX."
 information.  When this variable is t, 
 - accessing the parsing information for the first time in an editing session
   will read that file (if available) instead of parsing the document.
-- each time (part of) the document is rescanned, a new version of the file
-  is written."
+- exiting Emacs or killing a buffer in reftex-mode will cause a new version
+  of the file to be written."
   :group 'reftex-optimizations-for-large-documents
   :type 'boolean)
 
 when new labels in its category are added.  See the variable
 `reftex-auto-update-selection-buffers'."
   :group 'reftex-optimizations-for-large-documents
+  :group 'reftex-referencing-labels
   :type 'boolean)
 
 (defcustom reftex-auto-update-selection-buffers t
 The value of this variable will only have any effect when
 `reftex-use-multiple-selection-buffers' is non-nil."
   :group 'reftex-optimizations-for-large-documents
+  :group 'reftex-referencing-labels
   :type 'boolean)
 
 ;; Fontification and Faces ----------------------------------------------
 
 (defcustom reftex-use-fonts t
   "*Non-nil means, use fonts in *toc* and selection buffers.
-Font-lock must be loaded as well to actually get fontified display."
+Font-lock must be loaded as well to actually get fontified display.
+When changing this option, a rescan may be necessary to activate the change."
   :group 'reftex-fontification-configurations
-  :type '(boolean))
+  :type 'boolean)
 
 (defcustom reftex-refontify-context 1
   "*Non-nil means, re-fontify the context in the label menu with font-lock.
 This option may have 3 different values:
 nil  Never refontify.
 t    Always refontify.
-1    Refontify when absolutely necessary, e.g. when with the x-symbol package.
+1    Refontify when absolutely necessary, e.g. when old versions of X-Symbol.
 The option is ignored when `reftex-use-fonts' is nil."
   :group 'reftex-fontification-configurations
+  :group 'reftex-referencing-labels
   :type '(choice
           (const :tag "Never" nil)
           (const :tag "Always" t)
    nil      No highlighting.
    cursor   Highlighting is cursor driven.
    mouse    Highlighting is mouse driven.
-   both     Both cursor and mouse trigger highlighting."
+   both     Both cursor and mouse trigger highlighting.
+
+Changing this variable requires to rebuild the selection and *toc* buffers
+to become effective (keys `g' or `r')."
   :group 'reftex-fontification-configurations
   :type '(choice
 	  (const :tag "Never" nil)
   :group 'reftex-fontification-configurations
   :type 'symbol)
 
+(defcustom reftex-pre-refontification-functions nil
+  "X-Symbol specific hook.
+Functions get two arguments, the buffer from where the command started and a
+symbol indicating in what context the hook is called."
+  :group 'reftex-fontification-configurations
+  :type 'hook)
+
 ;; Miscellaneous configurations -----------------------------------------
 
 (defgroup reftex-miscellaneous-configurations nil
   "Non-nil means, make additional key bindings on startup.
 These extra bindings are located in the users `C-c letter' map."
   :group 'reftex-miscellaneous-configurations
-  :type '(boolean))
+  :type 'boolean)
 
 (defcustom reftex-plug-into-AUCTeX nil
   "*Plug-in flags for AUCTeX interface.
-This variable is a list of 4 boolean flags.  When a flag is non-nil, it
-means:
-
-  Flag 1:  use `reftex-label'     as `LaTeX-label-function'.
-  Flag 2:  use `reftex-arg-label' as `TeX-arg-label'
-  Flag 3:  use `reftex-arg-ref'   as `TeX-arg-ref'
-  Flag 4:  use `reftex-arg-cite'  as `TeX-arg-cite'
+This variable is a list of 4 boolean flags.  When a flag is non-nil,
+RefTeX will
+
+  - supply labels in new sections and environments  (flag 1)
+  - supply arguments for macros like `\\label'.      (flag 2)
+  - supply arguments for macros like `\\ref'.        (flag 3)
+  - supply arguments for macros like `\\cite'.       (flag 4)
 
 You may also set the variable itself to t or nil in order to turn all
 plug-ins on or off, respectively.
-\\<LaTeX-mode-map>`LaTeX-label-function' is the function used for label insertion when you
-enter a new environment in AUCTeX with \\[LaTeX-environment].
-The `TeX-arg-label' etc. functions are for entering macro arguments during
-macro insertion with \\[TeX-insert-macro].
+\\<LaTeX-mode-map>Supplying labels in new sections and environments aplies when creating
+sections with \\[LaTeX-section] and environments with \\[LaTeX-environment].
+Supplying macro arguments applies when you insert such a macro interactively
+with \\[TeX-insert-macro].
 See the AUCTeX documentation for more information.
 RefTeX uses `fset' to take over the function calls.  Changing the variable
 may require a restart of Emacs in order to become effective."
   :group 'reftex-miscellaneous-configurations
-  :type '(choice (const :tag "No plug-ins" nil)
-                 (const :tag "All possible plug-ins" t)
-                 (list
-                  :tag "Individual choice"
-                  :value (nil nil nil nil)
-                  (boolean :tag "Use reftex-label     as LaTeX-label-function")
-                  (boolean :tag "Use reftex-arg-label as TeX-arg-label       ")
-                  (boolean :tag "Use reftex-arg-ref   as TeX-arg-ref         ")
-                  (boolean :tag "Use reftex-arg-cite  as TeX-arg-cite        ")
-                  )))
-
-(defcustom reftex-auto-show-entry 'copy
-  "*Non-nil means, do something when context in other window is hidden.
-Some modes like `outline-mode' or `folding-mode' hide parts of buffers.
-When RefTeX is asked to show context for a label definition, and the context
-is invisible, it can unhide that section permanently (value t), or copy the
-context to a temporary buffer (value 'copy)."
-  :group 'reftex-miscellaneous-configurations
-  :type '(radio :value copy
-                :indent 4
-          (const :tag "Do nothing" nil)
-          (const :tag "Unhide section permanently" t)
-          (const :tag "Copy context to show" copy)))
-
-(defcustom reftex-revisit-to-follow t
-  "*Non-nil means, follow-mode will revisit files if necessary.
-When nil, follow-mode will be suspended for stuff in unvisited files."
-  :group 'reftex-miscellaneous-configurations
-  :type '(boolean))
+  :group 'LaTeX
+  :type '(choice 
+	  (const :tag "No plug-ins" nil)
+	  (const :tag "All possible plug-ins" t)
+	  (list
+	   :tag "Individual choice"
+	   :value (t t t t)
+	   (boolean :tag "supply label in new sections and environments")
+	   (boolean :tag "supply argument for macros like `\\label'     ")
+	   (boolean :tag "supply argument for macros like `\\ref'       ")
+	   (boolean :tag "supply argument for macros like `\\cite'      ")
+	   )))
+
+(defcustom reftex-allow-detached-macro-args nil
+  "*Non-nil means, allow arguments of macros to be detached by whitespace.
+When this is t, `aaa' will be considered as argument of \\bb in the following
+construct:  \\bbb [xxx] {aaa}."
+  :group 'texmathp
+  :type 'boolean)
+
 
 (defcustom reftex-load-hook nil
   "Hook which is being run when loading reftex.el."
   :group 'reftex-miscellaneous-configurations
   :type 'hook)
 
-;;; End of Configuration Section ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-;;;===========================================================================
+;;; =========================================================================
 ;;;
 ;;; Define the formal stuff for a minor mode named RefTeX.
 ;;;
 
-(defconst reftex-version "RefTeX version 3.22"
+(defconst reftex-version "RefTeX version 3.34"
   "Version string for RefTeX.")
 
 (defvar reftex-mode nil
-  "Determines if RefTeX minor mode is active.")
+  "Determines if RefTeX mode is active.")
 (make-variable-buffer-local 'reftex-mode)
 
 (defvar reftex-mode-map (make-sparse-keymap)
-  "Keymap for RefTeX minor mode.")
+  "Keymap for RefTeX mode.")
 
 (defvar reftex-mode-menu nil)
 
 ;;;###autoload
 (defun turn-on-reftex ()
-  "Turn on RefTeX minor mode."
+  "Turn on RefTeX mode."
   (reftex-mode t))
 
 ;;;###autoload
   (if reftex-mode
       (progn
         (easy-menu-add reftex-mode-menu)
-        (reftex-plug-into-AUCTeX)
+	(and reftex-plug-into-AUCTeX
+	     (reftex-plug-into-AUCTeX))
         (run-hooks 'reftex-mode-hook))
     (easy-menu-remove reftex-mode-menu)))
 
-(or (assoc 'reftex-mode minor-mode-alist)
+(if (fboundp 'add-minor-mode)
+    ;; Use it so that we get the extras
+    (progn
+      (put 'reftex-mode ':included '(memq major-mode '(latex-mode tex-mode)))
+      (put 'reftex-mode ':menu-tag "RefTeX Mode")
+      (add-minor-mode 'reftex-mode " Ref" reftex-mode-map))
+  ;; The standard way
+  (unless (assoc 'reftex-mode minor-mode-alist)
     (push '(reftex-mode " Ref") minor-mode-alist))
-
-(or (assoc 'reftex-mode minor-mode-map-alist)
-    (push (cons 'reftex-mode reftex-mode-map) minor-mode-map-alist))
-
-;;; ===========================================================================
+  (unless (assoc 'reftex-mode minor-mode-map-alist)
+    (push (cons 'reftex-mode reftex-mode-map) minor-mode-map-alist)))
+
+;;; =========================================================================
 ;;;
 ;;; Silence warnings about variables in other packages.
 (defvar TeX-master)
+(defvar LaTeX-section-hook)
 (defvar LaTeX-label-function)
 (defvar tex-main-file)
 (defvar outline-minor-mode)
 (defvar font-lock-fontify-region-function)
 (defvar font-lock-syntactic-keywords)
 
-;;; ===========================================================================
+;;; =========================================================================
 ;;;
-;;; Interfaces for other packages
-;;; -----------------------------
+;;; Multibuffer Variables
 ;;;
-;;; AUCTeX
-;;; ------
-
-(defun reftex-arg-label (optional &optional prompt definition)
-  "Use `reftex-label' to create label.  Insert it with `TeX-argument-insert'.
-This function is intended for AUCTeX macro support."
-  (let ((label (reftex-label nil t)))
-    (if (and definition (not (string-equal "" label)))
-        (LaTeX-add-labels label))
-    (TeX-argument-insert label optional optional)))
-
-(defun reftex-arg-ref (optional &optional prompt definition)
-  "Use `reftex-reference' to select label.  Insert with `TeX-argument-insert'.
-This function is intended for AUCTeX macro support."
-  (let ((label (reftex-reference nil t)))
-    (if (and definition (not (string-equal "" label)))
-        (LaTeX-add-labels label))
-    (TeX-argument-insert label optional optional)))
-
-(defun reftex-arg-cite (optional &optional prompt definition)
-  "Use reftex-citation to select a key.  Insert with `TeX-argument-insert'.
-This function is intended for AUCTeX macro support."
-  (let ((key (reftex-citation t)))
-    (TeX-argument-insert (or key "") optional optional)))
-
-(defun reftex-plug-into-AUCTeX ()
-  ;; Replace AUCTeX functions with RefTeX functions.
-  ;; Which functions are replaced is controlled by the variable
-  ;; `reftex-plug-into-AUCTeX'.
-  (let ((flags
-         (cond ((eq reftex-plug-into-AUCTeX t) '(t t t t))
-               ((eq reftex-plug-into-AUCTeX nil) '(nil nil nil nil))
-               (t reftex-plug-into-AUCTeX))))
-
-    (and (nth 0 flags)
-         (boundp 'LaTeX-label-function)
-         (setq LaTeX-label-function 'reftex-label))
-
-    (and (nth 1 flags)
-         (fboundp 'TeX-arg-label)
-         (fset 'TeX-arg-label 'reftex-arg-label))
-
-    (and (nth 2 flags)
-         (fboundp 'TeX-arg-ref)
-         (fset 'TeX-arg-ref 'reftex-arg-ref))
-
-    (and (nth 3 flags)
-         (fboundp 'TeX-arg-cite)
-         (fset 'TeX-arg-cite 'reftex-arg-cite))))
-
-
-(defvar reftex-label-alist-external-add-ons nil
-  "List of label alist entries added with reftex-add-to-label-alist.")
-
-(defun reftex-add-to-label-alist (entry-list)
-  "Add label environment descriptions to `reftex-label-alist-external-add-ons'.
-The format of ENTRY-LIST is exactly like `reftex-label-alist'.  See there
-for details.
-This function makes it possible to support RefTeX from AUCTeX style files.
-The entries in ENTRY-LIST will be processed after the user settings in
-`reftex-label-alist', and before the defaults (specified in
-`reftex-default-label-alist-entries').  Any changes made to
-`reftex-label-alist-external-add-ons' will raise a flag to the effect that a
-mode reset is done on the next occasion."
-  (let (entry)
-    (while entry-list
-      (setq entry (car entry-list)
-            entry-list (cdr entry-list))
-      (unless (member entry reftex-label-alist-external-add-ons)
-        (setq reftex-tables-dirty t)
-        (push entry reftex-label-alist-external-add-ons)))))
-
-;;; ===========================================================================
-;;;
-;;; Multifile support
-;;;
-;;; Technical notes: Multifile works as follows: We keep just one list
+;;; Technical notes: These work as follows: We keep just one list
 ;;; of labels for each master file - this can save a lot of memory.
 ;;; `reftex-master-index-list' is an alist which connects the true file name
 ;;; of each master file with the symbols holding the information on that
   (let* ((master (file-truename (reftex-TeX-master-file)))
          (index (assoc master reftex-master-index-list))
          (symlist reftex-multifile-symbols)
-         (symbol nil)
-         (symname nil)
-         (newflag nil))
+         symbol symname newflag)
     ;; Find the correct index.
     (if index
         ;; symbols do exist
       ;; Ahh, an extra .tex was missing...
       (setq master (concat master ".tex")))
      (t
-      ;; Something is wrong here.  Throw an exception.
+      ;; Use buffer file name.
       (buffer-file-name)))
-;      (error "No such master file %s" master)))
     (expand-file-name master)))
 
-(defun reftex-parse-one ()
-  "Re-parse this file."
-  (interactive)
-  (let ((reftex-enable-partial-scans t))
-    (reftex-access-scan-info '(4))))
-
-(defun reftex-parse-all ()
-  "Re-parse entire document."
-  (interactive)
-  (reftex-access-scan-info '(16)))
-
-(defun reftex-all-document-files (&optional relative)
-  ;; Return a list of all files belonging to the current document.
-  ;; When RELATIVE is non-nil, give file names relative to directory
-  ;; of master file.
-  (let* ((all (symbol-value reftex-docstruct-symbol))
-         (master-dir (file-name-directory (reftex-TeX-master-file)))
-         (re (concat "\\`" (regexp-quote master-dir)))
-        file-list tmp file)
-    (while (setq tmp (assoc 'bof all))
-      (setq file (nth 1 tmp)
-            all (cdr (memq tmp all)))
-      (and relative
-           (string-match re file)
-           (setq file (substring file (match-end 0))))
-      (push file file-list))
-    (nreverse file-list)))
-
-(defun reftex-create-tags-file ()
-  "Create TAGS file by running `etags' on the current document.
-The TAGS file is also immediately visited with `visit-tags-table'."
-  (interactive)
-  (reftex-access-scan-info current-prefix-arg)
-  (let* ((master (reftex-TeX-master-file))
-         (files  (reftex-all-document-files))
-         (cmd    (format "etags %s" (mapconcat 'identity files " "))))
-    (save-excursion
-      (set-buffer (reftex-get-buffer-visiting master))
-      (message "Running etags to create TAGS file...")
-      (shell-command cmd)
-      (visit-tags-table "TAGS"))))
-
-;; History of grep commands.
-(defvar reftex-grep-history nil)
-(defvar reftex-grep-command "grep -n "
-  "Last grep command used in \\[reftex-grep-document]; default for next grep.")
-
-(defun reftex-grep-document (grep-cmd)
-  "Run grep query through all files related to this document.
-With prefix arg, force to rescan document.
-This works also without an active TAGS table."
-
-  (interactive
-   (list (read-from-minibuffer "Run grep on document (like this): "
-                               reftex-grep-command nil nil
-                               'reftex-grep-history)))
-  (reftex-access-scan-info current-prefix-arg)
-  (let* ((files  (reftex-all-document-files t))
-         (cmd    (format
-                  "%s %s" grep-cmd
-                  (mapconcat 'identity files " "))))
-    (grep cmd)))
-
-(defun reftex-search-document (&optional regexp)
-  "Regexp search through all files of the current TeX document.
-Starts always in the master file.  Stops when a match is found.
-To continue searching for next match, use command \\[tags-loop-continue].
-This works also without an active TAGS table."
-  (interactive)
-  (let ((default (reftex-this-word)))
-    (unless regexp
-      (setq regexp (read-string (format "Search regexp in document [%s]: "
-                                        default))))
-    (if (string= regexp "") (setq regexp (regexp-quote default)))
-
-    (reftex-access-scan-info current-prefix-arg)
-    (tags-search regexp (list 'reftex-all-document-files))))
-
-(defun reftex-query-replace-document (&optional from to delimited)
-  "Run a query-replace-regexp of FROM with TO over the entire TeX document.
-Third arg DELIMITED (prefix arg) means replace only word-delimited matches.
-If you exit (\\[keyboard-quit] or ESC), you can resume the query replace
-with the command \\[tags-loop-continue].
-This works also without an active TAGS table."
-  (interactive)
-  (let ((default (reftex-this-word)))
-    (unless from
-      (setq from (read-string (format "Replace regexp in document [%s]: "
-                                      default)))
-      (if (string= from "") (setq from (regexp-quote default))))
-    (unless to
-      (setq to (read-string (format "Replace regexp %s with: " from))))
-    (reftex-access-scan-info current-prefix-arg)
-    (tags-query-replace from to (or delimited current-prefix-arg)
-                        (list 'reftex-all-document-files))))
-
-(defun reftex-change-label (&optional from to)
-  "Query replace FROM with TO in all \\label and \\ref commands.
-Works on the entire multifile document.
-If you exit (\\[keyboard-quit] or ESC), you can resume the query replace
-with the command \\[tags-loop-continue].
-This works also without an active TAGS table."
-  (interactive)
-  (let ((default (reftex-this-word "-a-zA-Z0-9_*.:")))
-    (unless from
-      (setq from (read-string (format "Replace label globally [%s]: "
-                                      default))))
-    (if (string= from "") (setq from default))
-    (unless to
-      (setq to (read-string (format "Replace label %s with: "
-                                    from))))
-    (reftex-query-replace-document
-     (concat "\\\\\\(label\\|[a-z]*ref\\){" (regexp-quote from) "}")
-     (format "\\\\\\1{%s}" to))))
-
-(defun reftex-save-all-document-buffers ()
-  "Save all documents associated with the current document.
-The function is useful after a global action like replacing or renumbering
-labels."
-  (interactive)
-  (let ((files (reftex-all-document-files))
-	file buffer)
-    (save-excursion
-      (while (setq file (pop files))
-	(setq buffer (reftex-get-buffer-visiting file))
-	(when buffer
-	  (set-buffer buffer)
-	  (save-buffer))))))
-
-;;; ===========================================================================
+;;; =========================================================================
 ;;;
-;;; Functions to create and reference automatic labels.
+;;; Functions to parse the buffer and to create and reference labels.
 
 ;; The following constants are derived from `reftex-label-alist'.
 
 ;; The last list-of-labels entry used in a reference.
 (defvar reftex-last-used-reference (list nil nil nil nil))
 
+;; The message when follow-mode is suspended
+(defconst reftex-no-follow-message
+  "No follow-mode into unvisited file.  Press SPC to visit it.")
+(defconst reftex-no-info-message
+  "%s: info not available, use `\\[reftex-view-crossref]' to get it.")
+
 ;; The regular expression used to abbreviate words.
 (defconst reftex-abbrev-regexp
   (concat
 (defvar reftex-tex-path nil)
 (defvar reftex-bib-path nil)
 (defvar reftex-last-follow-point nil)
-(defvar reftex-prefix)
+(defvar reftex-latex-syntax-table nil)
+(defvar reftex-prefix nil)
+(defvar reftex-section-levels-all nil)
+(defvar reftex-buffers-with-changed-invisibility nil)
 
 ;; List of buffers created temporarily for lookup, which should be killed.
 (defvar reftex-buffers-to-kill nil)
 
-;; Regexp to find section statements.  Computed from reftex-section-levels.
+;; Regexp to find anything.
 (defvar reftex-section-regexp nil)
 (defvar reftex-section-or-include-regexp nil)
 (defvar reftex-everything-regexp nil)
 (defvar reftex-find-label-regexp-format nil)
 (defvar reftex-find-label-regexp-format2 nil)
 
-;; The parser functions ----------------------------------
+;;; The parser functions -----------------------------------------------------
 
 (defvar reftex-memory nil
   "Memorizes old variable values to indicate changes in these variables.")
 
 (defun reftex-access-scan-info (&optional rescan file)
-  ;; Access the scanning info.  When the multifile symbols are not yet tied,
+  "Ensure access to the scanning info for the current file."
+  ;; When the multifile symbols are not yet tied,
   ;; tie them.  When they are empty or RESCAN is non-nil, scan the document.
+  ;; But, when RESCAN is -1, don't rescan even if docstruct is empty.
   ;; When FILE is non-nil, parse only from that file.
 
-  ;; Reset the mode if we had changes to important variables.
-  (when (or reftex-tables-dirty
-	    (not (eq reftex-label-alist (nth 0 reftex-memory)))
-	    (not (eq reftex-label-alist-external-add-ons
-		     (nth 1 reftex-memory)))
-	    (not (eq reftex-default-label-alist-entries
-		     (nth 2 reftex-memory))))
-    (reftex-reset-mode))
-
+  ;; Make sure we have the symbols tied
   (if (eq reftex-docstruct-symbol nil)
       ;; Symbols are not yet tied: Tie them.
       (reftex-tie-multifile-symbols))
-  
+
+  (reftex-ensure-compiled-variables)
+
   (when (or (null (symbol-value reftex-docstruct-symbol))
 	    (member rescan '(t 1 (4) (16))))
     ;; The docstruct will change: Remove selection buffers.
       (reftex-erase-all-selection-buffers)))
 
   (if (and (null (symbol-value reftex-docstruct-symbol))
+	   (not (member rescan '(t 1 (4) (16))))
            reftex-save-parse-info)
       ;; Try to read the stuff from a file
       (reftex-access-parse-file 'read))
 
   (cond
+   ((equal rescan -1))  ;; We are not allowed to scan.
    ((not (symbol-value reftex-docstruct-symbol))
+    ;; Scan the whole document
     (reftex-do-parse 1 file))
    ((member rescan '(t 1 (4) (16)))
+    ;; Scan whatever was required by the caller.
     (reftex-do-parse rescan file))))
 
+(defun reftex-parse-one ()
+  "Re-parse this file."
+  (interactive)
+  (let ((reftex-enable-partial-scans t))
+    (reftex-access-scan-info '(4))))
+
+(defun reftex-parse-all ()
+  "Re-parse entire document."
+  (interactive)
+  (reftex-access-scan-info '(16)))
+
 (defun reftex-do-parse (rescan &optional file)
-  ;; Do a rescan.  When allowed, do only a partial scan from FILE.
+  "Do a document rescan.  When allowed, do only a partial scan from FILE."
 
   ;; Normalize the rescan argument
   (setq rescan (cond ((eq rescan t) t)
 
   (let* ((old-list (symbol-value reftex-docstruct-symbol))
          (master (reftex-TeX-master-file))
+	 (true-master (file-truename master))
 	 (master-dir (file-name-as-directory (file-name-directory master)))
          (file (or file (buffer-file-name)))
+	 (true-file (file-truename file))
+	 (bibview-cache (assq 'bibview-cache old-list))
          from-file appendix docstruct tmp)
 
     ;; Make sure replacement is really an option here
     (when (and (eq rescan t)
                (not (and (member (list 'bof file) old-list)
                          (member (list 'eof file) old-list))))
-      (message "Scanning whole document (no file section %s)" file)
+      ;; Scan whole document because no such file section exists
       (setq rescan 1))
-    (when (string= file master)
-      (message "Scanning whole document (%s is master)" file)
+    (when (string= true-file true-master)
+      ;; Scan whole document because this file is the master
       (setq rescan 1))
 
     ;; From which file do we start?
     (setq from-file
           (cond ((eq rescan t) (or file master))
                 ((eq rescan 1) master)
-                (t (error "horrible!!"))))
+                (t (error "This should not happen (reftex-do-parse)"))))
 
     ;; Find active toc entry and initialize section-numbers
     (setq reftex-active-toc (reftex-last-assoc-before-elt
       (push (cons 'label-numbers nil) docstruct))
     (unless (assq 'master-dir docstruct)
       (push (cons 'master-dir master-dir) docstruct))
+    (unless (assq 'bibview-cache docstruct)
+      (push (cons 'bibview-cache (cdr bibview-cache)) docstruct))
     (let* ((bof1 (memq (assq 'bof docstruct) docstruct))
            (bof2 (assq 'bof (cdr bof1)))
            (is-multi (not (not (and bof1 bof2))))
 				   (nth 2 x))
 			  nil)))
 		    allxr))
-	     (alist (delete nil alist))
-	     (allprefix (delete nil (mapcar 'car alist)))
+	     (alist (delq nil alist))
+	     (allprefix (delq nil (mapcar 'car alist)))
 	     (regexp (if allprefix
 			 (concat "\\`\\(" 
 				 (mapconcat 'identity allprefix "\\|")
 	(push (list 'xr alist regexp) docstruct)))
 
     (set reftex-docstruct-symbol docstruct)
-
-    ;; Save the parsing information into a file?
-    (if reftex-save-parse-info
-        (reftex-access-parse-file 'write))))
-
-(defun reftex-is-multi ()
-  ;; Tell if this is a multifile document.  When not sure, say yes.
-  (let ((entry (assq 'is-multi (symbol-value reftex-docstruct-symbol))))
-    (if entry
-        (nth 1 entry)
-      t)))
+    (put reftex-docstruct-symbol 'modified t)))
 
 (defun reftex-parse-from-file (file docstruct master-dir)
   ;; Scan the buffer for labels and save them in a list.
         file-found tmp include-file
         (level 1)
         (highest-level 100)
-        toc-entry next-buf)
+        toc-entry next-buf buf)
 
     (catch 'exit
       (setq file-found (reftex-find-tex-file file master-dir))
+      (if (and (not file-found)
+	       (setq buf (reftex-get-buffer-visiting file)))
+	  (setq file-found (buffer-file-name buf)))
+
       (unless file-found
         (push (list 'file-error file) docstruct)
         (throw 'exit nil))
                 (if (= level highest-level)
                     (message
                      "Scanning %s %s ..."
-                     (car (nth level reftex-section-levels))
+                     (car (rassoc level reftex-section-levels))
                      (nth 6 toc-entry)))
 
                 (push toc-entry docstruct)
                ((match-end 7)
                 ;; It's an include or input
 		(setq include-file (reftex-match-string 7))
-		(if (delq nil (mapcar 
-			       (lambda (x) (string-match x include-file))
-			       reftex-no-include-regexps))
-		    (progn
-		      ;; Ignore the file
-		      (push (list 'bof include-file) docstruct)
-		      (push (list 'eof include-file) docstruct))
+		;; Test if this file should be ignored
+		(unless (delq nil (mapcar 
+				   (lambda (x) (string-match x include-file))
+				   reftex-no-include-regexps))
 		  ;; Parse it
 		  (setq docstruct
 			(reftex-parse-from-file
 					 (reftex-no-props
 					  (reftex-nth-arg-wrapper
 					   mac)))))
-                         (entry (progn (goto-char (match-end 0))
-                                       (reftex-label-info
-					label file bound mac))))
+			 (typekey (nth 1 (assoc mac reftex-env-or-mac-alist)))
+                         (entry (progn (if typekey
+					   ;; A typing macro
+					   (goto-char (match-end 0))
+					 ;; A newtral macro
+					 (goto-char (match-end 10))
+					 (reftex-move-over-touching-args))
+				       (reftex-label-info
+					label file bound nil nil))))
                     (push entry docstruct))))
                (t (error "This should not happen (reftex-parse-from-file)")))
               )
 
-
             ;; Find bibliography statement
             (when (setq tmp (reftex-locate-bibliography-files master-dir))
               (push (cons 'bib tmp) docstruct))
 
 (defun reftex-locate-bibliography-files (master-dir)
   ;; Scan buffer for bibliography macro and return file list.
-  (let (file-list)
+  (let (files)
     (save-excursion
       (goto-char (point-min))
-      (if (re-search-forward
-           "\\(\\`\\|[\n\r]\\)[ \t]*\\\\bibliography{[ \t]*\\([^}]+\\)" nil t)
-          (setq file-list
-                (mapcar (function (lambda (x) (concat x ".bib")))
-                        (reftex-delete-list
-                         reftex-bibfile-ignore-list
-                         (split-string
-                          (reftex-match-string 2)
-                          "[ \t\n\r]*,[ \t\n\r]*")))))
-      (delete nil
-	      (mapcar 
-	       (function 
-		(lambda (file)
-		  (reftex-find-bib-file file master-dir)))
-	       file-list)))))
-  
-(defun reftex-last-assoc-before-elt (key elt list)
-  ;; Find the last association of KEY in LIST before or at ELT
-  ;; ELT is found in LIST with equal, not eq.
-  ;; Returns nil when either KEY or elt are not found in LIST.
-  ;; On success, returns the association.
-  (let* ((elt (car (member elt list))) ass last-ass)
-
-    (while (and (setq ass (assoc key list))
-                (setq list (memq ass list))
-                (memq elt list))
-      (setq last-ass ass
-            list (cdr list)))
-    last-ass))
+      (when (re-search-forward
+	     "\\(\\`\\|[\n\r]\\)[ \t]*\\\\bibliography{[ \t]*\\([^}]+\\)" nil t)
+	(setq files (split-string (reftex-match-string 2)
+				      "[ \t\n\r]*,[ \t\n\r]*"))
+	(setq files 
+	      (mapcar
+	       (lambda (x)
+		 (if (or (member x reftex-bibfile-ignore-list)
+			 (delq nil (mapcar (lambda (re) (string-match re x))
+					   reftex-bibfile-ignore-regexps)))
+		     ;; excluded file
+		     nil
+		   ;; find the file
+		   (reftex-find-bib-file
+		    (if (string-match "\\.bib\\'" x) x (concat x ".bib"))
+		    master-dir)))
+	       files))
+	(delq nil files)))))
 
 (defun reftex-replace-label-list-segment (old insert &optional entirely)
   ;; Replace the segment in OLD which corresponds to INSERT.
         new))))
 
 (defun reftex-silence-toc-markers (list n)
-  ;; Set all markers in list to nil
+  ;; Set all toc markers in the first N entries in list to nil
   (while (and list (> (decf n) -1))
     (and (eq (car (car list)) 'toc)
          (markerp (nth 4 (car list)))
     (pop list)))
 
 (defun reftex-access-parse-file (action)
+  "Perform ACTION on the parse file (the .rel file).
+Valid actions are: readable, restore, read, kill, write."
   (let* ((list (symbol-value reftex-docstruct-symbol))
+	 (docstruct-symbol reftex-docstruct-symbol)
          (master (reftex-TeX-master-file))
 	 (enable-local-variables nil)
          (file (if (string-match "\\.[a-zA-Z]+\\'" master)
      ((eq action 'readable)
       (file-readable-p file))
      ((eq action 'restore)
+      (put reftex-docstruct-symbol 'modified nil)
       (if (eq reftex-docstruct-symbol nil)
           ;; Symbols are not yet tied: Tie them.
           (reftex-tie-multifile-symbols))
       (if (file-exists-p file)
           ;; load the file and return t for success
-          (progn (load-file file) t)
-        ;; throw an exception
+	  (condition-case nil
+	      (progn (load-file file) t)
+	    (error (set reftex-docstruct-symbol nil)
+		   (error "Error while loading file %s" file)))
+        ;; Throw an exception if the file does not exist
         (error "No restore file %s" file)))
      ((eq action 'read)
+      (put reftex-docstruct-symbol 'modified nil)
       (if (file-exists-p file)
           ;; load the file and return t for success
-          (progn (load-file file) t)
+	  (condition-case nil
+	      (progn (load-file file) t)
+	    (error (message "Error while loading file %s" file)
+		   (set reftex-docstruct-symbol nil)
+		   nil))
         ;; return nil for failure, but no exception
         nil))
+     ((eq action 'kill)
+      ;; Remove the file
+      (when (and (file-exists-p file) (file-writable-p file))
+	(message "Unlinking file %s" file)
+	(delete-file file)))
      (t
+      (put docstruct-symbol 'modified nil)
       (save-excursion
         (if (file-writable-p file)
             (progn
               (erase-buffer)
               (insert (format ";; RefTeX parse info file\n"))
               (insert (format ";; File: %s\n" master))
-              (insert (format ";; Date: %s\n"
-                              (format-time-string "%D %T"
-                                                  (current-time))))
               (insert (format ";; User: %s (%s)\n\n"
                               (user-login-name) (user-full-name)))
               (insert "(set reftex-docstruct-symbol '(\n\n")
                                             (nth 8 x)))))
                           (t (print x)))))
                  list))
-              (insert "))")
+              (insert "))\n\n")
               (save-buffer 0)
               (kill-buffer (current-buffer)))
           (error "Cannot write to file %s" file)))
       t))))
 
-;; Creating labels --------------
-
-(defun reftex-label (&optional environment no-insert)
-  "Insert a unique label.  Return the label.
-If ENVIRONMENT is given, don't bother to find out yourself.
-If NO-INSERT is non-nil, do not insert label into buffer.
-With prefix arg, force to rescan document first.
-When you are prompted to enter or confirm a label, and you reply with
-just the prefix or an empty string, no label at all will be inserted.
-A new label is also recorded into the label list.
-This function is controlled by the settings of reftex-insert-label-flags."
-
-  (interactive)
-
-  ;; Ensure access to scanning info and rescan buffer if prefix are is '(4).
-  (reftex-access-scan-info current-prefix-arg)
-
-  ;; Find out what kind of environment this is and abort if necessary.
-  (if (or (not environment)
-          (not (assoc environment reftex-env-or-mac-alist)))
-      (setq environment (reftex-label-location)))
-  (unless environment
-    (error "Can't figure out what kind of label should be inserted"))
-
-  ;; Ok, go ahead.
-  (catch 'exit
-    (let* ((entry (assoc environment reftex-env-or-mac-alist))
-	   (typekey (nth 1 entry))
-	   (format (nth 3 entry))
-	   label prefix valid default force-prompt rescan-is-useful)
-      (when (and (eq (string-to-char environment) ?\\)
-		 (nth 5 entry)
-		 (memq (preceding-char) '(?\[ ?\{)))
-	(setq format "%s"))
-
-      (setq prefix (or (cdr (assoc typekey reftex-typekey-to-prefix-alist))
-		       (concat typekey "-")))
-      ;; Replace any escapes in the prefix
-      (setq prefix (reftex-replace-prefix-escapes prefix))
-
-      ;; Make a default label.
-      (cond
-
-       ((reftex-typekey-check typekey (nth 0 reftex-insert-label-flags))
-	;; Derive a label from context.
-	(setq reftex-active-toc (reftex-last-assoc-before-elt
-				 'toc (car (reftex-where-am-I))
-				 (symbol-value reftex-docstruct-symbol)))
-	(setq default (reftex-no-props
-		       (nth 2 (reftex-label-info " " nil nil t))))
-	;; Catch the cases where the is actually no context available.
-	(if (or (string-match "NO MATCH FOR CONTEXT REGEXP" default)
-		(string-match "ILLEGAL VALUE OF PARSE" default)
-		(string-match "SECTION HEADING NOT FOUND" default)
-		(string-match "HOOK ERROR" default)
-		(string-match "^[ \t]*$" default))
-	    (setq default prefix
-		  force-prompt t)	; need to prompt
-	  (setq default (concat prefix (reftex-string-to-label default)))
-
-	  ;; Make it unique.
-	  (setq default (reftex-uniquify-label default nil "-"))))
-
-       ((reftex-typekey-check typekey (nth 1 reftex-insert-label-flags))
-	;; Minimal default: the user will be prompted.
-	(setq default prefix))
-
-       (t
-	;; Make an automatic label.
-	(setq default (reftex-uniquify-label prefix t))))
-
-      ;; Should we ask the user?
-      (if (or (reftex-typekey-check typekey
-				    (nth 1 reftex-insert-label-flags)) ; prompt
-	      force-prompt)
-
-	  (while (not valid)
-	    ;; iterate until we get a legal label
-
-	    (setq label (read-string
-			 (if (string= format "%s") "Naked Label: " "Label: ")
-			 default))
-
-	    ;; Lets make sure that this is a legal label
-	    (cond
-
-	     ((string-match (concat "\\`\\(" (regexp-quote prefix)
-				    "\\)?[ \t]*\\'")
-			    label)
-	      ;; No label at all, please
-	      (message "No label inserted.")
-	      (throw 'exit nil))
-
-	     ;; Test if label contains strange characters
-	     ((string-match reftex-label-illegal-re label)
-	      (message "Label \"%s\" contains illegal characters" label)
-	      (ding)
-	      (sit-for 2))
-
-	     ;; Look it up in the label list
-	     ((setq entry (assoc label
-				 (symbol-value reftex-docstruct-symbol)))
-	      (ding)
-	      (if (y-or-n-p 
-		   (format "Label '%s' exists. Use anyway? " label))
-		  (setq valid t)))
-
-	     ;; Label is ok
-	     (t
-	      (setq valid t))))
-	(setq label default))
-
-      ;; Insert the label into the label list
-      (let* ((here-I-am-info (reftex-where-am-I))
-	     (here-I-am (car here-I-am-info))
-	     (note (if (cdr here-I-am-info)
-		       ""
-		     "POSITION UNCERTAIN.  RESCAN TO FIX."))
-	     (file (buffer-file-name))
-	     (text nil)
-	     (tail (memq here-I-am (symbol-value reftex-docstruct-symbol))))
-
-	(or (cdr here-I-am-info) (setq rescan-is-useful t))
-
-	(if tail
-	    (setcdr tail (cons (list label typekey text file note)
-			       (cdr tail)))))
-
-      ;; Insert the label into the buffer
-      (unless no-insert
-	(insert
-	 (if reftex-format-label-function
-	     (funcall reftex-format-label-function label format)
-	   (format format label))))
-
-      ;; Delete the corresponding selection buffers to force update on next use.
-      (when reftex-auto-update-selection-buffers
-	(reftex-erase-buffer (reftex-make-selection-buffer-name typekey))
-	(reftex-erase-buffer (reftex-make-selection-buffer-name " ")))
-
-      (when (and rescan-is-useful reftex-allow-automatic-rescan)
-	(reftex-parse-one))
-
-      ;; return value of the function is the label
-      label)))
-
-(defun reftex-string-to-label (string)
-  ;; Convert a string (a sentence) to a label.
-  ;;
-  ;; Uses reftex-derive-label-parameters and reftex-abbrev-parameters
-  ;;
-
-  (let* ((words0 (split-string string "[- \t\n\r]+"))
-         (ignore-words (nth 5 reftex-derive-label-parameters))
-         words word)
-
-    ;; remove words from the ignore list or with funny characters
-    (while (setq word (pop words0))
-      (cond
-       ((member (downcase word) ignore-words))
-       ((string-match reftex-label-illegal-re word)
-        (when (nth 2 reftex-derive-label-parameters)
-          (while (string-match reftex-label-illegal-re word)
-            (setq word (replace-match "" nil nil word)))
-          (push word words)))
-       (t
-        (push word words))))
-    (setq words (nreverse words))
-
-    ;; restrict number of words
-    (if (> (length words) (nth 0 reftex-derive-label-parameters))
-        (setcdr (nthcdr (1- (nth 0 reftex-derive-label-parameters)) words) nil))
-
-    ;; First, try to use all words
-    (setq string (mapconcat 'identity words
-                            (nth 4 reftex-derive-label-parameters)))
-
-    ;; Abbreviate words if enforced by user settings or string length
-    (if (or (eq t (nth 3 reftex-derive-label-parameters))
-            (and (nth 3 reftex-derive-label-parameters)
-                 (> (length string) (nth 1 reftex-derive-label-parameters))))
-        (setq words
-              (mapcar
-	       (function
-		(lambda (w) (if (string-match reftex-abbrev-regexp w)
-				(match-string 1 w)
-			      w)))
-               words)
-              string (mapconcat 'identity words
-                                (nth 4 reftex-derive-label-parameters))))
-
-    ;; Shorten if still to long
-    (setq string
-          (if (> (length string) (nth 1 reftex-derive-label-parameters))
-              (substring string 0 (nth 1 reftex-derive-label-parameters))
-            string))
-
-    ;; Delete the final punctuation, if any
-    (if (string-match "[^a-zA-Z0-9]+\\'" string)
-        (setq string (replace-match "" nil nil string)))
-    string))
-
-(defun reftex-replace-prefix-escapes (prefix)
-  ;; Replace %escapes in a label prefix
-  (save-match-data
-    (let (letter (num 0) replace)
-      (while (string-match "\\%\\([a-zA-Z]\\)" prefix num)
-        (setq letter (match-string 1 prefix))
-        (setq replace
-              (cond
-               ((equal letter "f")
-                (file-name-sans-extension
-                 (file-name-nondirectory (buffer-file-name))))
-               ((equal letter "F")
-                (let ((masterdir (file-name-directory (reftex-TeX-master-file)))
-                      (file (file-name-sans-extension (buffer-file-name))))
-                  (if (string-match (concat "\\`" (regexp-quote masterdir))
-                                    file)
-                      (substring file (length masterdir))
-                    file)))
-               ((equal letter "u")
-                (or (user-login-name) ""))
-               (t "")))
-        (setq num (1- (+ (match-beginning 1) (length replace)))
-              prefix (replace-match replace nil nil prefix)))
-      prefix)))
-
-(defun reftex-label-location (&optional bound)
-  ;; Return the environment or macro which determines the label type at point.
-  ;; If optional BOUND is an integer, limit backward searches to that point.
-
-  (let* ((loc1 (reftex-what-macro reftex-label-mac-list bound))
-         (loc2 (reftex-what-environment reftex-label-env-list bound))
-         (p1 (or (cdr loc1) 0))
-         (p2 (or (cdr loc2) 0)))
-
-    (setq reftex-location-start (max p1 p2))
-    (if (>= p1 p2)
-        (progn
-          (setq reftex-default-context-position (+ p1 (length (car loc1))))
-          (or (car loc1) "section"))
-      (setq reftex-default-context-position (+ p2 8 (length (car loc2))))
-      (or (car loc2) "section"))))
-
-(defun reftex-uniquify-label (label &optional force separator)
-  ;; Make label unique by appending a number.
-  ;; Optional FORCE means, force appending a number, even if label is unique.
-  ;; Optional SEPARATOR is a string to stick between label and number.
-
-  ;; Ensure access to scanning info
-  (reftex-access-scan-info)
-
-  (cond
-   ((and (not force)
-         (not (assoc label (symbol-value reftex-docstruct-symbol))))
-    label)
-   (t
-    (let* ((label-numbers (assq 'label-numbers
-                                (symbol-value reftex-docstruct-symbol)))
-           (label-numbers-alist (cdr label-numbers))
-           (cell (or (assoc label label-numbers-alist)
-                     (car (setcdr label-numbers
-                                  (cons (cons label 0)
-                                        label-numbers-alist)))))
-           (num (1+ (cdr cell)))
-           (sep (or separator "")))
-      (while (assoc (concat label sep (int-to-string num))
-                    (symbol-value reftex-docstruct-symbol))
-        (incf num))
-      (setcdr cell num)
-      (concat label sep (int-to-string num))))))
-
-;; Help string for the reference label menu
-(defconst reftex-select-label-prompt
-  "Select: [n]ext [p]revious [r]escan [ ]context e[x]tern [q]uit RET [?]HELP+more")
-
-(defconst reftex-select-label-help
-  " n / p      Go to next/previous label (Cursor motion works as well)
- C-c C-n/p  Go to next/previous section heading.
- b / l      Jump back to previous selection / Reuse last referenced label
- C-s / C-r  Search forward/backward.  Use repeated C-s/C-r as in isearch.
- g / s      Update menu      / Switch label type
- r / R      Reparse document / Reparse entire document
- x          Switch to label menu of external document (with LaTeX package `xr')
- t i c # %  Toggle: [i]ncl. file borders, [t]able of contents,  [c]ontext
-                    [#] label counters,   [%] labels in comments
- SPC / f    Show full context in other window / Toggle follow mode
- v   / .    Toggle \\ref <-> \\vref / Show insertion point in other window
- TAB        Enter a label with completion
- q / RET    Quit without referencing / Accept current label (also on mouse-2)")
-
-(defvar reftex-select-label-map nil
-  "Keymap used for *RefTeX Select* buffer, when selecting a label.
-This keymap can be used to configure the label selection process which is
-started with the command \\[reftex-reference].")
-
-(defun reftex-select-label-mode ()
-  "Major mode for selecting a label in a LaTeX document.
-This buffer was created with RefTeX.
-It only has a meaningful keymap when you are in the middle of a 
-selection process.
-To select a label, move the cursor to it and press RET.
-Press `?' for a summary of important key bindings.
-
-During a selection process, these are the local bindings.
-
-\\{reftex-select-label-map}"
-
-  (interactive)
-  (kill-all-local-variables)
-  (make-local-hook 'pre-command-hook)
-  (make-local-hook 'post-command-hook)
-  (setq major-mode 'reftex-select-label-mode
-	mode-name "RefTeX Select Label")
-  ;; We do not set a local map - reftex-select-item does this.
-  (run-hooks 'reftex-select-label-mode-hook))
-
-(defun reftex-reference (&optional type no-insert cut)
-  "Make a LaTeX reference.  Look only for labels of a certain TYPE.
-With prefix arg, force to rescan buffer for labels.  This should only be
-necessary if you have recently entered labels yourself without using
-reftex-label.  Rescanning of the buffer can also be requested from the
-label selection menu.
-The function returns the selected label or nil.
-If NO-INSERT is non-nil, do not insert \\ref command, just return label.
-When called with 2 C-u prefix args, disable magic word recognition."
-
-  (interactive)
-
-  ;; check for active recursive edits
-  (reftex-check-recursive-edit)
-
-  ;; Ensure access to scanning info and rescan buffer if prefix are is '(4)
-  (reftex-access-scan-info current-prefix-arg)
-
-  (unless type
-    ;; guess type from context
-    (if (and reftex-guess-label-type
-             (setq type (reftex-guess-label-type)))
-	(setq cut (cdr type)
-	      type (car type))
-      (setq type (reftex-query-label-type))))
-
-  (let* ((varioref (if (reftex-typekey-check 
-			type reftex-vref-is-default)
-		       "\\vref" "\\ref"))
-	 (form "\\ref{%s}")
-	 label pair)
-
-    ;; Have the user select a label
-    (set-marker reftex-select-return-marker (point))
-    (setq pair (save-excursion
-		 (reftex-offer-label-menu type)))
-    (set-marker reftex-select-return-marker nil)
-    (setq label (car pair)
-	  type  (cdr pair)
-	  form (or (cdr (assoc type reftex-typekey-to-format-alist))
-		   form))
-
-    (if (and label
-             (not no-insert))
-        (progn
-	  (if cut (backward-delete-char cut))
-
-	  ;; remove ~ if we do already have a space
-	  (when (and (= ?~ (string-to-char form))
-		     (= ?\  (preceding-char)))
-	    (setq form (substring form 1)))
-	  ;; do we need to switch from \ref to \vref?
-	  (when (string= varioref "\\vref")
-	    (while (string-match "\\\\ref{" form)
-	      (setq form (replace-match "\\vref{" t t form))))
-          ;; ok, insert the reference
-	  (insert
-	   (if reftex-format-ref-function
-	       (funcall reftex-format-ref-function label form)
-	     (format form label label)))
-          (message ""))
-      (message "Quit"))
-    ;; return the label
-    label))
-
-(defun reftex-guess-label-type ()
-  (let ((words reftex-words-to-typekey-alist)
-	(case-fold-search t)
-	(bound (max (point-min) (- (point) 35)))
-	matched	cell)
-    (save-excursion
-      (while (and (setq cell (pop words))
-		  (not (setq matched 
-			     (re-search-backward (car cell) bound t))))))
-    (if matched
-	(cons (cdr cell) (- (match-end 0) (match-end 1)))
-      nil)))
-
-(defun reftex-offer-label-menu (typekey)
-  ;; Offer a menu with the appropriate labels.  Return (label . typekey).
-  (let* ((buf (current-buffer))
-	 (xr-data (assq 'xr (symbol-value reftex-docstruct-symbol)))
-	 (xr-alist (cons (cons "" (buffer-file-name)) (nth 1 xr-data)))
-	 (xr-index 0)
-         (here-I-am (car (reftex-where-am-I)))
-	 (here-I-am1 here-I-am)
-         (toc (reftex-typekey-check typekey reftex-label-menu-flags 0))
-         (files (reftex-typekey-check typekey reftex-label-menu-flags 7))
-         (context (not (reftex-typekey-check
-                        typekey reftex-label-menu-flags 3)))
-         (counter (reftex-typekey-check
-                   typekey reftex-label-menu-flags 2))
-         (follow  (reftex-typekey-check
-                   typekey reftex-label-menu-flags 4))
-         (commented (nth 5 reftex-label-menu-flags))
-	 (prefix "")
-	 selection-buffers
-         offset rtn key data last-data entry)
-
-    (setq entry (cons nil nil))
-
-    ;; The following unwind-protect kills temporary buffers after use
-    (unwind-protect
-        (catch 'exit
-          (while t
-            (save-window-excursion
-	      (delete-other-windows)
-	      (setq reftex-call-back-to-this-buffer buf)
-	      (let ((default-major-mode 'reftex-select-label-mode))
-		(if reftex-use-multiple-selection-buffers
-		    (switch-to-buffer-other-window
-		     (save-excursion
-		       (set-buffer buf)
-		       (reftex-make-selection-buffer-name typekey)))
-		  (switch-to-buffer-other-window "*RefTeX Select*")
-		  (reftex-erase-buffer)))
-	      (unless (eq major-mode 'reftex-select-label-mode)
-		(reftex-select-label-mode))
-	      (add-to-list 'selection-buffers (current-buffer))
-              (setq truncate-lines t)
-	      (setq mode-line-format
-		    (list "----  " 'mode-line-buffer-identification
-			  "   " 'varioref
-			  "   " (abbreviate-file-name
-				 (buffer-file-name buf))
-			  " -%-"))
-	      (cond
-	       ((= 0 (buffer-size))
-		(let ((buffer-read-only nil))
-		  (setq offset (reftex-make-and-insert-label-list
-				typekey buf toc files context counter commented
-				(or here-I-am offset) prefix))))
-	       (here-I-am
-		(setq offset (reftex-get-offset buf here-I-am typekey)))
-	       (t (setq offset t)))
-	      (setq buffer-read-only t)
-	      (setq offset (or offset t))
-
-              (setq here-I-am nil) ; turn off determination of offset
-              (setq rtn
-                    (reftex-select-item
-                     reftex-select-label-prompt
-                     reftex-select-label-help
-		     reftex-select-label-map
-                     offset
-                     'reftex-select-label-callback follow))
-              (setq key       (car rtn)
-                    data      (nth 1 rtn)
-                    last-data (nth 2 rtn)
-		    offset    t)
-              (unless key (throw 'exit nil))
-              (cond
-	       ((eq key ?g)
-		;; update buffer
-		(reftex-erase-buffer))
-               ((or (eq key ?r)
-                    (eq key ?R))
-                ;; rescan buffer
-		(reftex-erase-buffer)
-                (reftex-parse-document buf last-data key))
-               ((eq key ?c)
-                ;; toggle context mode
-		(reftex-erase-buffer)
-                (setq context (not context)))
-               ((eq key ?s)
-                ;; switch type
-		(setq here-I-am here-I-am1)
-                (setq typekey (reftex-query-label-type)))
-               ((eq key ?t)
-                ;; toggle table of contents display
-		(reftex-erase-buffer)
-                (setq toc (not toc)))
-               ((eq key ?i)
-                ;; toggle display of included file borders
-		(reftex-erase-buffer)
-                (setq files (not files)))
-               ((eq key ?#)
-                ;; toggle counter display
-		(reftex-erase-buffer)
-                (setq counter (not counter)))
-               ((eq key ?%)
-                ;; toggle display of commented labels
-		(reftex-erase-buffer)
-                (setq commented (not commented)))
-               ((eq key ?l)
-                ;; reuse the last referenced label again
-                (setq entry reftex-last-used-reference)
-                (throw 'exit t))
-	       ((eq key ?x)
-		;; select an external document
-		(setq xr-index (reftex-select-external-document
-				xr-alist xr-index))
-		(setq buf (or (reftex-get-file-buffer-force
-			       (cdr (nth xr-index xr-alist)))
-			      (error "Cannot switch document"))
-		      prefix (or (car (nth xr-index xr-alist)) ""))
-		(set-buffer buf)
-		(reftex-access-scan-info))
-	       ((stringp key)
-		(setq entry 
-		      (or (assoc key (symbol-value reftex-docstruct-symbol))
-			  (list key typekey)))
-		(throw 'exit t))
-               (t
-                (set-buffer buf)
-                (if data
-                    (progn
-                      (setq entry data)
-                      (setq reftex-last-used-reference entry))
-                  (setq entry nil))
-                (throw 'exit t))))))
-      (mapcar (function (lambda (buf)