annotate lisp/modes/reftex.el @ 189:489f57a838ef r20-3b21

Import from CVS: tag r20-3b21
author cvs
date Mon, 13 Aug 2007 09:57:07 +0200
parents 5a88923fcbfe
children a2f645c6b9f8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1 ;; reftex.el --- Minor mode for doing \label, \ref and \cite in LaTeX
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3 ;; Copyright (c) 1997 Free Software Foundation, Inc.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
5 ;; Author: Carsten Dominik <dominik@strw.LeidenUniv.nl>
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
6 ;; Keywords: tex
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
7
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
9
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
13 ;; any later version.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
14
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
18 ;; GNU General Public License for more details.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
19
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
23 ;; Boston, MA 02111-1307, USA.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
24
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
25 ;;---------------------------------------------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
26 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
27 ;;; Commentary:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
28 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
29 ;; RefTeX is a minor mode with distinct support for \ref, \label and
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
30 ;; \cite commands in (multi-file) LaTeX documents.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
31 ;; Labels are created semi-automatically. Definition context of labels is
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
32 ;; provided when creating a reference. Citations are simplified with
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
33 ;; efficient database lookup.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
34 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
35 ;; To turn RefTeX Minor Mode on and off in a particular buffer, use
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
36 ;; `M-x reftex-mode'.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
37 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
38 ;; To turn on RefTeX Minor Mode for all LaTeX files, add one of the
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
39 ;; following lines to your .emacs file:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
40 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
41 ;; (add-hook 'LaTeX-mode-hook 'turn-on-reftex) ; with AUCTeX LaTeX mode
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
42 ;; (add-hook 'latex-mode-hook 'turn-on-reftex) ; with Emacs latex mode
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
43 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
44 ;; For key bindings, see further down in this documentation.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
45 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
46 ;;---------------------------------------------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
47 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
48 ;; OVERVIEW
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
49 ;;
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
50 ;; 1. USING \label AND \ref. Labels and references are one of the
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
51 ;; strong points of LaTeX. But, in documents with hundreds of
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
52 ;; equations, figures, tables etc. it becomes quickly impossible to
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
53 ;; find good label names and to actually remember them. Then, also
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
54 ;; completion of labels in not enough. One actually needs to see the
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
55 ;; context of the label definition to find the right one.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
56 ;;
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
57 ;; - RefTeX distinguishes labels for different environments. It
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
58 ;; always knows if a certain label references a figure, table
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
59 ;; etc.. You can configure RefTeX to recognize any additional
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
60 ;; labeled environments you might have defined yourself.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
61 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
62 ;; - RefTeX defines automatically unique labels. Type `C-c ('
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
63 ;; (reftex-label) to insert a label at point. RefTeX will either
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
64 ;; - derive a label from context (default for section labels)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
65 ;; - insert a simple label consisting of a prefix and a number
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
66 ;; (default for equations and enumerate items) or
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
67 ;; - prompt for a label string (figures and tables).
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
68 ;; Which labels are created how can be controlled with the variable
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
69 ;; `reftex-insert-label-flags'.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
70 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
71 ;; - Referencing labels is a snap and I promise you'll love it.
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
72 ;; In order to make a reference, type `C-c )' (`reftex-reference').
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
73 ;; This shows an outline of the documents with all labels of a
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
74 ;; certain type (figure, equation,...) and context of the label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
75 ;; definition. Selecting one of the labels inserts a \ref macro
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
76 ;; into the original buffer. Online help during the selection is
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
77 ;; available with `?'.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
78 ;;
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
79 ;; 2. CITATIONS. After typing `C-c [' (`reftex-citation'), RefTeX will
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
80 ;; let you specify a regexp to search in current BibTeX database files
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
81 ;; (as specified in the \bibliography command) and pull out a formatted
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
82 ;; list of matches for you to choose from. The list is *formatted* and
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
83 ;; thus much easier to read than the raw database entries. It can also
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
84 ;; be sorted. The text inserted into the buffer is by default just
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
85 ;; `\cite{KEY}', but can also contain author names and the year in a
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
86 ;; configurable way. See documentation of the variable
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
87 ;; `reftex-cite-format'.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
88 ;;
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
89 ;; 3. TABLE OF CONTENTS. Typing `C-c =' (`reftex-toc') will show
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
90 ;; a table of contents of the document. From that buffer, you can
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
91 ;; jump quickly to every part of your document. This is similar to
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
92 ;; imenu, only it works for entire multifile documents and uses the
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
93 ;; keyboard rather than the mouse. The initial version of this
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
94 ;; function was contributed by Stephen Eglen.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
95 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
96 ;; 4. MULTIFILE DOCUMENTS are supported in the same way as by AUCTeX.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
97 ;; I.e. if a source file is not a full LaTeX document by itself,
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
98 ;; but included by another file, you may specify the name of
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
99 ;; the (top level) master file in a local variable section at the
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
100 ;; end of the source file, like so:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
101 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
102 ;; %%% Local Variables:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
103 ;; %%% TeX-master: my_master.tex
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
104 ;; %%% End:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
105 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
106 ;; This will only take effect when you load the file next time or when
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
107 ;; you reset RefTeX with M-x reftex-reset-mode.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
108 ;;
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
109 ;; RefTeX will also recognize the file variable tex-main-file. This
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
110 ;; variable is used by the Emacs TeX modes and works just like
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
111 ;; AUCTeX's TeX-master variable. See the documentation of your TeX/LaTeX
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
112 ;; modes.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
113 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
114 ;; RefTeX knows about all files related to a document via input and
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
115 ;; include. It provides functions to run regular expression searches and
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
116 ;; replaces over the entire document and to create a TAGS file.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
117 ;;
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
118 ;; 5. DOCUMENT PARSING. RefTeX needs to parse the document in order to find
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
119 ;; labels and other information. It will do it automatically once, when
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
120 ;; you start working with a document. If you need to enforce reparsing
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
121 ;; later, call any of the functions `reftex-citation', `reftex-label',
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
122 ;; `reftex-reference', `reftex-toc' with a raw C-u prefix.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
123 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
124 ;;-------------------------------------------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
125 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
126 ;; CONFIGURATION
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
127 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
128 ;; RefTeX contains many configurable options which change the way it works.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
129 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
130 ;; Most importantly, RefTeX needs to be configured if you use labels to
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
131 ;; mark non-standard environments. RefTeX always understands LaTeX section
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
132 ;; commands and the following environments: figure, figure*,
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
133 ;; sidewaysfigure, table, table*, sidewaystable, equation, eqnarray,
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
134 ;; enumerate. For everythings else, it needs to be configured.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
135 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
136 ;; A good way to configure RefTeX is with the custom.el package by Per
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
137 ;; Abrahamsen, shipped with Emacs 20 and XEmacs 19.15. To do this, just
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
138 ;; say `M-x reftex-customize'. This will not work with older versions
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
139 ;; of custom.el.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
140 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
141 ;; Here is a complete list of the RefTeX configuration variables with
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
142 ;; their default settings. You could copy this list to your .emacs file
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
143 ;; and change whatever is necessary. Each variable has an extensive
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
144 ;; documentation string. Look it up for more information!
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
145 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
146 ;; ;; Configuration Variables and User Options for RefTeX ------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
147 ;; ;; Support for \label and \ref --------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
148 ;; (setq reftex-label-alist nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
149 ;; (setq reftex-default-label-alist-entries '(Sideways LaTeX))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
150 ;; (setq reftex-use-text-after-label-as-context nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
151 ;; ;; Label insertion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
152 ;; (setq reftex-insert-label-flags '("s" "sft"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
153 ;; (setq reftex-derive-label-parameters '(3 20 t 1 "-"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
154 ;; ("the" "on" "in" "off" "a" "for" "by" "of" "and" "is")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
155 ;; (setq reftex-label-illegal-re "[\000-\040\177-\377\\\\#$%&~^_{}]")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
156 ;; (setq reftex-abbrev-parameters '(4 2 "^saeiou" "aeiou"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
157 ;; ;; Label referencing
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
158 ;; (setq reftex-label-menu-flags '(t t nil nil nil nil))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
159 ;; (setq reftex-guess-label-type t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
160 ;; ;; BibteX citation configuration ----------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
161 ;; (setq reftex-bibpath-environment-variables '("BIBINPUTS" "TEXBIB"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
162 ;; (setq reftex-bibfile-ignore-list nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
163 ;; (setq reftex-sort-bibtex-matches 'reverse-year)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
164 ;; (setq reftex-cite-format 'reftex-cite-format-default)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
165 ;; ;; Table of contents configuration --------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
166 ;; (setq reftex-toc-follow-mode nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
167 ;; ;; Miscellaneous configurations -----------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
168 ;; (setq reftex-extra-bindings nil)
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
169 ;; (setq reftex-plug-into-AUCTeX nil)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
170 ;; (setq reftex-use-fonts t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
171 ;; (setq reftex-keep-temporary-buffers t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
172 ;; (setq reftex-auto-show-entry t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
173 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
174 ;; CONFIGURATION EXAMPLES:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
175 ;; =======================
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
176 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
177 ;; Suppose you are working with AMS-LaTeX amsmath package (with its math
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
178 ;; environments like `align', `multiline' etc.). Here is how you would
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
179 ;; configure RefTeX to recognize these environments:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
180 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
181 ;; (setq reftex-label-alist '(AMSTeX))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
182 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
183 ;; This is very easy since RefTeX has builtin support for AMS-LaTeX.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
184 ;; Suppose, however, you are also
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
185 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
186 ;; - using "\newtheorem" in LaTeX in order to define two new environments
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
187 ;; "Theorem" and "Axiom" like this:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
188 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
189 ;; \newtheorem{axiom}{Axiom}
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
190 ;; \newtheorem{theorem}{Theorem}
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
191 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
192 ;; - making your figures not directly with the figure environment, but with
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
193 ;; a macro like
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
194 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
195 ;; \newcommand{\myfig}[4][tbp]{
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
196 ;; \begin{figure}[#1]
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
197 ;; \epsimp[#4]{#2}
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
198 ;; \caption{#3}
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
199 ;; \end{figure}}
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
200 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
201 ;; which would be called like
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
202 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
203 ;; \myfig{filename}{\label{fig:13} caption text}{1}
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
204 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
205 ;; Here is how to tell RefTeX to also recognize Theorem and Axiom as
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
206 ;; labeled environments, and that any labels defined inside the \myfig
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
207 ;; macro are figure labels:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
208 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
209 ;; (setq reftex-label-alist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
210 ;; '(AMSTeX
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
211 ;; ("axiom" ?a "ax:" "~\\ref{%s}" nil ("Axiom" "Ax."))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
212 ;; ("theorem" ?h "thr:" "~\\ref{%s}" t ("Theorem" "Theor." "Th."))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
213 ;; ("\\myfig" ?f "fig:" nil t)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
214 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
215 ;; The type indicator characters ?a and ?h are used for prompts when
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
216 ;; RefTeX queries for a label type. Note that "h" was chosen for "theorem"
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
217 ;; since "t" is already taken by "table". Note that also "s", "f", "e", "n"
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
218 ;; are taken by the standard environments.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
219 ;; The automatic labels for Axioms and Theorems will look like "ax:23" or
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
220 ;; "thr:24".
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
221 ;; The "\ref{%s}" is a format string indicating how to insert references to
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
222 ;; these labels. The nil format in the \myfig entry means to use the same
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
223 ;; format as other figure labels.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
224 ;; The next item indicates how to grab context of the label definition.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
225 ;; - t means to get it from a default location (from the beginning of a \macro
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
226 ;; or after the \begin statement). t is *not* a good choice for eqnarray
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
227 ;; and similar environments.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
228 ;; - nil means to use the text right after the label definition.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
229 ;; - For more complex ways of getting context, see the docstring of
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
230 ;; `reftex-label-alist'.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
231 ;; The strings at the end of each entry are used to guess the correct label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
232 ;; type from the word before point when creating a reference. E.g. if you
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
233 ;; write: "as we have shown in Theorem" and then press `C-)', RefTeX will
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
234 ;; know that you are looking for a Theorem label and restrict the labels in
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
235 ;; the menu to only these labels without even asking.
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
236 ;; See also the documentation string of the variable `reftex-label-alist'.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
237 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
238 ;; Depending on how you would like the label insertion and selection for the
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
239 ;; new environments to work, you might want to add the letters "a" and "h"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
240 ;; to some of the flags in the following variables:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
241 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
242 ;; reftex-insert-label-flags
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
243 ;; reftex-label-menu-flags
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
244 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
245 ;; The individual flags in these variables can be set to t or nil to enable or
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
246 ;; disable the feature for all label types. They may also contain a string of
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
247 ;; label type letters in order to turn on the feature for those types only.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
248 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
249 ;; -----
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
250 ;; If you are writing in a language different from english you might want to
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
251 ;; add magic words for that language. Here is a German example:
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
252 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
253 ;; (setq reftex-label-alist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
254 ;; '((nil ?s nil nil nil ("Kapitel" "Kap." "Abschnitt" "Teil"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
255 ;; (nil ?e nil nil nil ("Gleichung" "Gl."))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
256 ;; (nil ?t nil nil nil ("Tabelle"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
257 ;; (nil ?f nil nil nil ("Figur" "Abbildung" "Abb."))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
258 ;; (nil ?n nil nil nil ("Punkt"))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
259 ;;
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
260 ;; Using nil as first item in each entry makes sure that this entry does
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
261 ;; not replace the original entry for that label type.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
262 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
263 ;; HOOKS
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
264 ;; -----
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
265 ;; Loading reftex.el runs the hook `reftex-load-hook'.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
266 ;; Turning on reftex-mode runs `reftex-mode-hook'.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
267 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
268 ;;-------------------------------------------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
269 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
270 ;; KEY BINDINGS
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
271 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
272 ;; All important functions of RefTeX can be reached from its menu which
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
273 ;; is installed in the menu bar as "Ref" menu. Only the more frequently used
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
274 ;; functions have key bindings.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
275 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
276 ;; Here is the default set of keybindings from RefTeX.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
277 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
278 ;; C-c = reftex-toc
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
279 ;; C-c ( reftex-label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
280 ;; C-c ) reftex-reference
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
281 ;; C-c [ reftex-citation
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
282 ;; C-c & reftex-view-crossref
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
283 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
284 ;; I've used these bindings in order to avoid interfering with AUCTeX's
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
285 ;; settings. Personally, I also bind some functions in the C-c LETTER
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
286 ;; map for easier access:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
287 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
288 ;; C-c t reftex-toc
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
289 ;; C-c l reftex-label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
290 ;; C-c r reftex-reference
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
291 ;; C-c c reftex-citation
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
292 ;; C-c v reftex-view-crossref
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
293 ;; C-c s reftex-search-document
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
294 ;; C-c g reftex-grep-document
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
295 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
296 ;; If you want to copy those as well, set in your .emacs file:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
297 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
298 ;; (setq reftex-extra-bindings t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
299 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
300 ;; It is possible to bind the function for viewing cross references to a
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
301 ;; mouse event. Something like the following in .emacs will do the trick:
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
302 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
303 ;; (add-hook 'reftex-load-hook
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
304 ;; '(lambda ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
305 ;; (define-key reftex-mode-map [(alt mouse-1)]
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
306 ;; 'reftex-mouse-view-crossref)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
307 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
308 ;;-------------------------------------------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
309 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
310 ;; RELATED PACKAGES
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
311 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
312 ;; AUCTeX
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
313 ;; ------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
314 ;; If you are writing any TeX or LaTeX documents with Emacs, you should
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
315 ;; have a look at AUCTeX, the definitive package to work with TeX and LaTeX.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
316 ;; Information on AUCTeX can be found here:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
317 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
318 ;; http://www.sunsite.auc.dk/auctex/
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
319 ;;
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
320 ;; Instead of using the RefTeX functions described above directly, you
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
321 ;; can also use them indirectly through AUCTeX (>9.7p). RefTeX provides
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
322 ;; several interface functions which can be used as replacement for
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
323 ;; corresponding AUCTeX functions dealing with labels and citations.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
324 ;; In this way you can work normally with AUCTeX and use RefTeX
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
325 ;; internals to create and complete labels and citation keys.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
326 ;;
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
327 ;; `reftex-label' can be used as the `LaTeX-label-function' which does
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
328 ;; label insertion when new environments are created with C-c C-e.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
329 ;;
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
330 ;; `reftex-arg-label', `reftex-arg-ref' and `reftex-arg-cite' can replace
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
331 ;; the corresponding `TeX-arg-...' functions. E.g. when you insert a
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
332 ;; label macro with `C-c RET label RET', RefTeX will be transparently used
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
333 ;; to create the label.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
334 ;;
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
335 ;; In order to plug all 4 functions into AUCTeX, use in .emacs:
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
336 ;;
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
337 ;; (setq reftex-plug-into-AUCTeX t)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
338 ;;
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
339 ;; You may also choose to plug in only some of these functions. The
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
340 ;; following setting will leave TeX-arg-cite as it was while replacing
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
341 ;; the other 3 AUCTeX functions:
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
342 ;;
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
343 ;; (setq reftex-plug-into-AUCTeX '(t t t nil))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
344 ;;
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
345 ;; AUCTeX can support RefTeX via style files. A style file may contain
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
346 ;; calls to `reftex-add-to-label-alist' which defines additions to
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
347 ;; `reftex-label-alist'. The argument taken by this function must have
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
348 ;; the same format as `reftex-label-alist'. The `amsmath.el' style file
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
349 ;; of AUCTeX (>9.7p) for example contains the following:
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
350 ;;
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
351 ;; (TeX-add-style-hook "amsmath"
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
352 ;; (function
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
353 ;; (lambda ()
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
354 ;; (if (featurep 'reftex)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
355 ;; (reftex-add-to-label-alist '(AMSTeX))))))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
356 ;;
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
357 ;; while a package `myprop' defining a proposition environment with
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
358 ;; \newtheorem might use
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
359 ;;
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
360 ;; (TeX-add-style-hook "myprop"
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
361 ;; (function
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
362 ;; (lambda ()
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
363 ;; (if (featurep 'reftex)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
364 ;; (reftex-add-to-label-alist
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
365 ;; '(("proposition" ?p "prop:" "~\\ref{%s}" t
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
366 ;; ("Proposition" "Prop."))))))))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
367 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
368 ;; Bib-cite.el
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
369 ;; -----------
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
370 ;; Once you have written a document with labels, refs and citations,
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
371 ;; it can be nice to read such a file like a hypertext document.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
372 ;; RefTeX has some support for that (`reftex-view-crossref',
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
373 ;; `reftex-search-document'). A more elegant interface with mouse
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
374 ;; support and links into Hyperbole is provided (among other things)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
375 ;; by Peter S. Galbraith's `bib-cite.el'. There is some overlap in the
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
376 ;; functionalities of Bib-cite and RefTeX. Bib-cite.el comes bundled
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
377 ;; with AUCTeX. You can also get the latest version from
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
378 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
379 ;; ftp://ftp.phys.ocean.dal.ca/users/rhogee/elisp/bib-cite.el
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
380 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
381 ;;-------------------------------------------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
382 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
383 ;; PERFORMANCE ISSUES
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
384 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
385 ;; 1. RefTeX will load other parts of a multifile document as well as BibTeX
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
386 ;; database files for lookup purposes. These buffers are kept, so that
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
387 ;; subsequent lookup in the same files is fast. For large documents and
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
388 ;; large BibTeX databases, this can use up a lot of memory. If you have
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
389 ;; more time than memory, try the following option, which will remove
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
390 ;; buffers created for lookup after use.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
391 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
392 ;; (setq reftex-keep-temporary-buffers nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
393 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
394 ;; 2. Parsing the document for labels and their context can be slow.
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
395 ;; Therefore, RefTeX does it just once automatically. Further parsing
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
396 ;; happens only on user request
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
397 ;; - with a raw C-u prefix arg to any of the functions `reftex-label',
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
398 ;; `reftex-reference', `reftex-citation', `reftex-toc'.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
399 ;; - with the `r' key from the label selection menu or the *toc* buffer.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
400 ;;
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
401 ;; *** If you use `reftex-label' to create labels, the list will be
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
402 ;; *** updated internally, so that no extra parsing is required.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
403 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
404 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
405 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
406 ;; KNOWN BUGS
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
407 ;;
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
408 ;; o If you change `reftex-label-alist' in an editing session, you need to
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
409 ;; reset reftex with `M-x reftex-reset-mode' in order to make these
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
410 ;; changes effective. Changes introduced with the function
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
411 ;; `reftex-add-to-label-alist' as well as changes applied from the
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
412 ;; customization buffer automatically trigger a reset.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
413 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
414 ;; o At times the short context shown by RefTeX may not be what you want.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
415 ;; In particular, eqnarray environments can be difficult to
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
416 ;; parse. RefTeX's default behavior for eqnarrays is to scan backwards to
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
417 ;; either a double backslash or the beginning of the environment. If this
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
418 ;; gives unsatisfactory results, make it a habit to place the label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
419 ;; *before* each equation
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
420 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
421 ;; \begin{eqnarray}
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
422 ;; \label{eq:1}
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
423 ;; E = \gamma m c^2 \\
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
424 ;; \label{eq:2}
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
425 ;; \gamma = \sqrt{1-v^2/c^2}
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
426 ;; \end{eqnarray}
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
427 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
428 ;; and turn off parsing for context in equation and eqnarray environments
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
429 ;; with
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
430 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
431 ;; (setq reftex-use-text-after-label-as-context "e").
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
432 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
433 ;; o RefTeX keeps only one global copy of the configuration variables.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
434 ;; Also any additions from style files go into a global variable.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
435 ;; Practically, this should not be a problem. Theoretically, it could
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
436 ;; give conflicts if two documents used environments with identical
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
437 ;; names, but different associated label types.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
438 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
439 ;; o Input, include, bibliography and section statements have to be first
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
440 ;; on a line (except for white space) in order to be seen by reftex.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
441 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
442 ;; o When the document is scanned, RefTeX creates a large buffer containing
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
443 ;; the entire document instead of scanning the individual files one by
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
444 ;; one. This is necessary since a file might not contain the context
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
445 ;; needed by RefTeX.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
446 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
447 ;; o If you have two identical section headings in the same file,
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
448 ;; `reftex-toc' will only let you jump to the first one because it searches
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
449 ;; for the section heading from the beginning of the file. You can work
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
450 ;; around this by changing one of the section titles in a way LaTeX does
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
451 ;; not see, e.g. with extra white space. RefTeX will distinguish
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
452 ;; \section{Introduction} from \section{ Introduction}.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
453 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
454 ;; o RefTeX sees also labels in regions commented out and will refuse to
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
455 ;; make duplicates of such a label. This is considered to be a feature.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
456 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
457 ;; o When RefTeX tries to show a window full of context from inside a
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
458 ;; section hidden with `outline-minor-mode', it will unhide that section.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
459 ;; This change will not be reversed automatically.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
460 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
461 ;;---------------------------------------------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
462 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
463 ;; TO DO
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
464 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
465 ;; I think I am pretty much done with this one...
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
466 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
467 ;;---------------------------------------------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
468 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
469 ;; AUTHOR
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
470 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
471 ;; Carsten Dominik <dominik@strw.LeidenUniv.nl>
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
472 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
473 ;; with contributions from Stephen Eglen
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
474 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
475 ;; The newest version of RefTeX can be found at
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
476 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
477 ;; http://www.strw.leidenuniv.nl/~dominik/Tools/
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
478 ;; ftp://strw.leidenuniv.nl/pub/dominik/
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
479 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
480 ;; THANKS TO:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
481 ;; ---------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
482 ;; At least the following people have invested time to test and bug-fix
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
483 ;; reftex.el. Some have send patches for fixes or new features.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
484 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
485 ;; Stephen Eglen <stephene@cogs.susx.ac.uk>
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
486 ;; F.E.Burstall <F.E.Burstall@maths.bath.ac.uk>
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
487 ;; Karl Eichwalder <ke@ke.Central.DE>
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
488 ;; Laurent Mugnier <mugnier@onera.fr>
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
489 ;; Rory Molinari <molinari@yunt.math.lsa.umich.edu>
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
490 ;; Soren Dayton <csdayton@cs.uchicago.edu>
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
491 ;; Daniel Polani <polani@Informatik.Uni-Mainz.DE>
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
492 ;; Allan Strand <astrand@trillium.NMSU.Edu>
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
493 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
494 ;; The view crossref feature was inspired by the similar function in
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
495 ;; Peter S. Galbraith's bib-cite.el.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
496 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
497 ;; Finally thanks to Uwe Bolick <bolick@physik.tu-berlin.de> who first
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
498 ;; got me (some years ago) into supporting LaTeX labels and references
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
499 ;; with an Editor (which was MicroEmacs at the time).
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
500 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
501 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
502 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
503
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
504 ;;; Code:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
505
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
506 ;; Stuff that needs to be there when we use defcustom
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
507 ;; --------------------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
508
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
509 (require 'custom)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
510
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
511 (defvar reftex-tables-dirty t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
512 "Flag showing if tables need to be re-computed.")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
513
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
514 (eval-and-compile
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
515 (defun reftex-set-dirty (symbol value)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
516 (setq reftex-tables-dirty t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
517 (set symbol value)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
518
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
519 ;;; Begin of Configuration Section ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
520
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
521 ;; Configuration Variables and User Options for RefTeX ------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
522
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
523 (defgroup reftex nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
524 "LaTeX label and citation support."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
525 :tag "RefTeX"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
526 :link '(url-link :tag "Home Page" "http://strw.leidenuniv.nl/~dominik/Tools/")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
527 :prefix "reftex-"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
528 :group 'tex)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
529
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
530 (defun reftex-customize ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
531 "Call the customize function with reftex as argument."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
532 (interactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
533 (if (fboundp 'customize-group)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
534 (customize-group 'reftex)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
535 (customize 'reftex)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
536
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
537 ;; Support for \label and \ref --------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
538
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
539 (defgroup reftex-label-support nil
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
540 "Support for creation, insertion and referencing of labels in LaTeX."
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
541 :group 'reftex)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
542
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
543 (defgroup reftex-defining-label-environments nil
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
544 "Definition of environments and macros to do with label."
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
545 :group 'reftex-label-support)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
546
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
547
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
548 (defcustom reftex-label-alist nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
549 "Alist with information on environments for \\label-\\ref use.
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
550 See the definition of `reftex-label-alist-builtin' for examples. This variable
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
551 should define additions and changes to the default. The only things you MUST
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
552 NOT change is that `?s' is the type indicator for section labels and SPACE is
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
553 for the `any' label type. These are hard-coded at other places in the code.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
554
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
555 Changes to this variable after RefTeX has been loaded become only
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
556 effective when RefTeX is reset with \\[reftex-reset-mode].
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
557
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
558 Each list entry is a list describing an environment or macro carrying a
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
559 label. The elements of each list entry are:
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
560
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
561 0. Name of the environment (like \"table\") or macro (like \"\\\\myfig\").
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
562 Special names: `section' for section labels, `any' to define a group
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
563 which contains all labels.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
564 This may also be nil if this entry is only meant to change some settings
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
565 associated with the type indicator character (see below).
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
566
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
567 1. Type indicator character, like `?t'.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
568 The type indicator is a single character used in prompts for
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
569 label types. It must be a printable character. The same character
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
570 may occur several times in this list, to cover cases in which different
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
571 environments carry the same label type (like equation and eqnarray).
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
572
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
573 2. Label prefix string, like \"tab:\".
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
574 The prefix is a short string used as the start of a label. It may be the
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
575 empty string.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
576
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
577 3. Format string for reference insert in buffer. Each `%s' will be replaced
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
578 by the label (several `%s' can be there to do this:
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
579 \"\\ref{%s} on page~\\pageref{%s}\").
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
580 When the format starts with `~', whitespace before point will be removed
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
581 so that the reference cannot be separated from the word before it.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
582
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
583 4. Indication on how to find the short context.
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
584 - If nil, use the text following the \\label{...} macro.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
585 - If t, use
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
586 - text following the \\begin{...} statement of environments
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
587 (not a good choice in in eqnarray or enumerate environments!)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
588 - the section heading for section labels.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
589 - the begin of the macro for macros.
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
590 - If a string, use as regexp to search *backward* from the label. Context
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
591 is then the text following the end of the match. E.g. putting this to
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
592 \"\\\\\\\\caption{\" will use the beginning of the caption in a figure
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
593 or table environment.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
594 \"\\\\\\\\begin{eqnarray}\\\\|\\\\\\\\\\\\\\\\\" works for eqnarrays.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
595 - If a function, call this function with the name of the environment/macro
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
596 as argument. On call, point will be just after the \\label macro. The
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
597 function is expected to return a suitable context string. It should
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
598 throw an exception (error) when failing to find context.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
599 Consider the following example, which would return the 10 characters
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
600 following the label as context:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
601
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
602 (defun my-context-function (env-or-mac)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
603 (if (> (point-max) (+ 10 (point)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
604 (buffer-substring (point) (+ 10 (point)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
605 (error \"Buffer too small\")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
606
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
607 Setting the variable `reftex-use-text-after-label-as-context' to t
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
608 overrides the setting here.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
609
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
610 5. List of magic words which identify a reference to be of this type.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
611 If the word before point is equal to one of these words when calling
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
612 `reftex-reference', the label list offered will be automatically restricted
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
613 to labels of the correct type.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
614
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
615 If the type indicator characters of two or more entries are the same, RefTeX
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
616 will use
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
617 - the first non-nil format and prefix
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
618 - the magic words of all involved entries.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
619
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
620 Any list entry may also be a symbol. If that has an association in
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
621 `reftex-label-alist-builtin', the cdr of that association is spliced into the
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
622 list. See the AMSTeX configuration example in the comment section of
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
623 `reftex.el'."
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
624 :group 'reftex-defining-label-environments
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
625 :set 'reftex-set-dirty
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
626 :type '(list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
627 :convert-widget
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
628 (lambda (widget)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
629 (let*
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
630 ((args
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
631 (list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
632 `(repeat
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
633 :inline t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
634 (radio
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
635 :value ("" ?a nil nil t nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
636 (choice
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
637 :tag "Builtin"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
638 :value AMSTeX
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
639 ,@(mapcar (function (lambda (x)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
640 (list 'const ':tag (nth 1 x) (car x))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
641 reftex-label-alist-builtin))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
642 (list :tag "Detailed custom entry"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
643 (choice :tag "Environment or \\macro "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
644 (const :tag "Ignore, just use typekey" nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
645 (string ""))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
646 (character :tag "Typekey character " ?a)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
647 (choice :tag "Label prefix string "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
648 (const :tag "Copy from similar label type" nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
649 (string :tag "Specify here" "lab:"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
650 (choice :tag "Label reference format"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
651 (const :tag "Copy from similar label type" nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
652 (string :tag "Specify here" "~\\ref{%s}"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
653 (choice :tag "Grab context method "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
654 (const :tag "Default position" t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
655 (const :tag "After label" nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
656 (regexp :tag "Regular expression" "")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
657 (symbol :tag "Function" my-context-function))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
658 (repeat :tag "List of Magic Words" (string))))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
659 (widget-put widget :args args)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
660 widget))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
661
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
662 (defcustom reftex-default-label-alist-entries '(Sideways LaTeX)
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
663 "Default label alist specifications. LaTeX should be the last entry.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
664 This list describes the default label environments RefTeX should always use
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
665 in addition to the specifications in reftex-label-alist. It is probably a
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
666 mistake to remove the LaTeX symbol from this list.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
667
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
668 The options include:
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
669 LaTeX The standard LaTeX environments
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
670 Sideways The sidewaysfigure and sidewaystable environments
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
671 AMSTeX The math environments in the AMS_LaTeX amsmath package
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
672
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
673 For the full list of options, see the constant `reftex-label-alist-builtin'.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
674 Better still, try
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
675
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
676 M-x customize-variable RET reftex-default-label-alist-entries RET."
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
677 :group 'reftex-defining-label-environments
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
678 :set 'reftex-set-dirty
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
679 :type '(list :indent 4
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
680 :convert-widget
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
681 (lambda (widget)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
682 (let* ((args
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
683 (list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
684 `(checklist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
685 :inline t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
686 ,@(reverse
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
687 (mapcar (lambda (x)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
688 (list 'const ':tag (nth 1 x) (car x)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
689 reftex-label-alist-builtin))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
690 (widget-put widget :args args)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
691 widget))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
692
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
693 (defcustom reftex-use-text-after-label-as-context nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
694 "*t means, grab context from directly after the \\label{..} macro.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
695 This is the fastest method for obtaining context of the label definition, but
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
696 requires discipline when placing labels. Setting this variable to t takes
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
697 precedence over the individual settings in `reftex-label-alist'.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
698 This variable may be set to t, nil, or a string of label type letters
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
699 indicating the label types for which it should be true."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
700 :group 'reftex-defining-label-environments
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
701 :set 'reftex-set-dirty
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
702 :type '(choice
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
703 (const :tag "on" t) (const :tag "off" nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
704 (string :tag "Selected label types")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
705
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
706 ;; Label insertion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
707
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
708 (defgroup reftex-making-and-inserting-labels nil
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
709 "Options on how to create new labels."
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
710 :group 'reftex-label-support)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
711
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
712 (defcustom reftex-insert-label-flags '("s" "sft")
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
713 "Flags governing label insertion. First flag DERIVE, second flag PROMPT.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
714
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
715 If DERIVE is t, RefTeX will try to derive a sensible label from context.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
716 A section label for example will be derived from the section heading.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
717 The conversion of the context to a legal label is governed by the
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
718 specifications given in `reftex-derive-label-parameters'.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
719 If RefTeX fails to derive a label, it will prompt the user.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
720
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
721 If PROMPT is t, the user will be prompted for a label string. The prompt will
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
722 already contain the prefix, and (if DERIVE is t) a default label derived from
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
723 context. When PROMPT is nil, the default label will be inserted without
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
724 query.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
725
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
726 So the combination of DERIVE and PROMPT controls label insertion. Here is a
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
727 table describing all four possibilities:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
728
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
729 DERIVE PROMPT ACTION
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
730 -------------------------------------------------------------------------
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
731 nil nil Insert simple label, like eq:22 or sec:13. No query.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
732 nil t Prompt for label.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
733 t nil Derive a label from context and insert without query.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
734 t t Derive a label from context and prompt for confirmation.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
735
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
736 Each flag may be set to t, nil, or a string of label type letters
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
737 indicating the label types for which it should be true.
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
738 Thus, the combination may be set differently for each label type. The
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
739 default settings \"s\" and \"sft\" mean: Derive section labels from headings
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
740 (with confirmation). Prompt for figure and table labels. Use simple labels
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
741 without confirmation for everything else."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
742 :group 'reftex-making-and-inserting-labels
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
743 :type '(list (choice :tag "Derive label from context"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
744 (const :tag "always" t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
745 (const :tag "never" nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
746 (string :tag "for selected label types" ""))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
747 (choice :tag "Prompt for label string "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
748 :entry-format " %b %v"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
749 (const :tag "always" t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
750 (const :tag "never" nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
751 (string :tag "for selected label types" ""))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
752
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
753 (defcustom reftex-derive-label-parameters '(3 20 t 1 "-" ; continue
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
754 ("the" "on" "in" "off" "a" "for" "by" "of" "and" "is"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
755 "Parameters for converting a string into a label.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
756 NWORDS Number of words to use.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
757 MAXCHAR Maximum number of characters in a label string.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
758 ILLEGAL nil: Throw away any words containing characters illegal in labels.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
759 t: Throw away only the illegal characters, not the whole word.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
760 ABBREV nil: Never abbreviate words.
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
761 t: Always abbreviate words (see `reftex-abbrev-parameters').
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
762 not t and not nil: Abbreviate words if necessary to shorten
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
763 label string below MAXCHAR.
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
764 SEPARATOR String separating different words in the label.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
765 IGNOREWORDS List of words which should not be part of labels."
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
766 :group 'reftex-making-and-inserting-labels
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
767 :type '(list (integer :tag "Number of words " 3)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
768 (integer :tag "Maximum label length " 20)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
769 (choice :tag "Illegal characters in words"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
770 (const :tag "throw away entire word" nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
771 (const :tag "throw away single chars" t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
772 (choice :tag "Abbreviate words "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
773 (const :tag "never" nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
774 (const :tag "always" t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
775 (const :tag "when label is too long" 1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
776 (string :tag "Separator between words " "-")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
777 (repeat :tag "Ignore words"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
778 :entry-format " %i %d %v"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
779 (string :tag ""))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
780
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
781 (defcustom reftex-label-illegal-re "[\000-\040\177-\377\\\\#$%&~^_{}]"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
782 "Regexp matching characters not legal in labels.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
783 For historic reasons, this character class comes *with* the [] brackets."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
784 :group 'reftex-making-and-inserting-labels
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
785 :type '(regexp :tag "Character class"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
786
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
787 (defcustom reftex-abbrev-parameters '(4 2 "^saeiou" "aeiou")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
788 "Parameters for abbreviation of words.
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
789 MIN-CHARS Minimum number of characters remaining after abbreviation.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
790 MIN-KILL Minimum number of characters to remove when abbreviating words.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
791 BEFORE Character class before abbrev point in word.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
792 AFTER Character class after abbrev point in word."
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
793 :group 'reftex-making-and-inserting-labels
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
794 :type '(list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
795 (integer :tag "Minimum chars per word" 4)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
796 (integer :tag "Shorten by at least " 2)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
797 (string :tag "cut before char class " "^saeiou")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
798 (string :tag "cut after char class " "aeiou")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
799
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
800
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
801 ;; Label referencing
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
802
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
803 (defgroup reftex-referencing-labels nil
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
804 "Options on how to reference labels."
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
805 :group 'reftex-label-support)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
806
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
807 (defcustom reftex-label-menu-flags '(t t nil nil nil nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
808 "*List of flags governing the label menu makeup.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
809 The flags are:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
810
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
811 TABLE-OF-CONTENTS Show the labels embedded in a table of context.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
812 SECTION-NUMBERS Include section numbers (like 4.1.3) in table of contents.
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
813 COUNTERS Show counters. This just numbers the labels in the menu.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
814 NO-CONTEXT Non-nil means do NOT show the short context.
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
815 FOLLOW Follow full context in other window.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
816 SHOW-COMMENTED Show labels from regions which are commented out. RefTeX
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
817 sees these labels, but does not normally show them.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
818
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
819 Each of these flags can be set to t or nil, or to a string of type letters
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
820 indicating the label types for which it should be true. These strings work
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
821 like character classes in regular expressions. Thus, setting one of the
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
822 flags to \"sf\" makes the flag true for section and figure labels, nil
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
823 for everything else. Setting it to \"^ft\" makes it the other way round.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
824
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
825 Most options can also be switched from the label menu itself - so if you
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
826 decide here to not have a table of contents in the label menu, you can still
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
827 get one interactively during selection from the label menu."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
828 :group 'reftex-referencing-labels
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
829 :type '(list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
830 (choice :tag "Embed in table of contents "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
831 (const :tag "on" t) (const :tag "off" nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
832 (string :tag "Selected label types"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
833 (choice :tag "Show section numbers "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
834 (const :tag "on" t) (const :tag "off" nil))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
835 (choice :tag "Show individual counters "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
836 (const :tag "on" t) (const :tag "off" nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
837 (string :tag "Selected label types"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
838 (choice :tag "Hide short context "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
839 (const :tag "on" t) (const :tag "off" nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
840 (string :tag "Selected label types"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
841 (choice :tag "Follow context in other window"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
842 (const :tag "on" t) (const :tag "off" nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
843 (string :tag "Selected label types"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
844 (choice :tag "Show commented labels "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
845 (const :tag "on" t) (const :tag "off" nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
846 (string :tag "Selected label types"))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
847
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
848
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
849 (defcustom reftex-guess-label-type t
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
850 "*Non-nil means, `reftex-reference' will try to guess the label type.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
851 To do that, RefTeX will look at the word before the cursor and compare it with
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
852 the words given in `reftex-label-alist'. When it finds a match, RefTeX will
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
853 immediately offer the correct label menu - otherwise it will prompt you for
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
854 a label type. If you set this variable to nil, RefTeX will always prompt."
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
855 :group 'reftex-referencing-labels
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
856 :type '(boolean))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
857
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
858 ;; BibteX citation configuration ----------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
859
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
860 (defgroup reftex-citation-support nil
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
861 "Support for referencing bibliographic data with BibTeX."
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
862 :group 'reftex)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
863
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
864 (defcustom reftex-bibpath-environment-variables '("BIBINPUTS" "TEXBIB")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
865 "*List of env vars which might contain the path to BibTeX database files."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
866 :group 'reftex-citation-support
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
867 :set 'reftex-set-dirty
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
868 :type '(repeat (string :tag "Environment variable")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
869
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
870 (defcustom reftex-bibfile-ignore-list nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
871 "List of files in \\bibliography{..} RefTeX should *not* parse.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
872 The file names have to be in the exact same form as in the bibliography
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
873 macro - i.e. without the `.bib' extension.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
874 Intended for files which contain only `@string' macro definitions and the
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
875 like, which are ignored by RefTeX anyway."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
876 :group 'reftex-citation-support
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
877 :set 'reftex-set-dirty
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
878 :type '(repeat (string :tag "File name")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
879
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
880 (defcustom reftex-sort-bibtex-matches 'reverse-year
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
881 "*Sorting of the entries found in BibTeX databases by reftex-citation.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
882 Possible values:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
883 nil Do not sort entries.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
884 'author Sort entries by author name.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
885 'year Sort entries by increasing year.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
886 'reverse-year Sort entries by decreasing year."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
887 :group 'reftex-citation-support
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
888 :type '(choice (const :tag "not" nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
889 (const :tag "by author" author)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
890 (const :tag "by year" year)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
891 (const :tag "by year, reversed" reverse-year)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
892
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
893 (defcustom reftex-cite-format 'reftex-cite-format-default
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
894 "Defines the format of citations to be inserted into the buffer.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
895 It can be a string, a list of strings, or an alist with characters as keys
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
896 and a list of strings in the car. In the simplest case, this can just
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
897 be the string \"\\cite{KEY}\", which is also the default. See the
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
898 definition of the `reftex-cite-format-XXXX' constants for more complex
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
899 examples.
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
900 If `reftex-cite-format' is a string, it will be used as the format.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
901 In the format, AUTHOR will be replaced by the last name of the
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
902 author, YEAR will be replaced by the year and KEY by the citation
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
903 key. If AUTHOR is present several times, it will be replaced with
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
904 successive author names.
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
905 See the constant `reftex-cite-format-default' for an example.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
906 If `reftex-cite-format' is a list of strings, the string used will
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
907 depend upon the number of authors of the article. No authors means,
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
908 the first string will be used; 1 author means, the second string will
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
909 be used etc.. The last string in the list will be used for all articles
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
910 with too many authors. See `reftex-cite-format-1-author-simple' for an
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
911 example.
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
912 If `reftex-cite-format' is a list of cons cells, the car of each cell
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
913 needs to be a character. When a selected reference is accepted by
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
914 pressing that key, the cdr of the associated list will be used as
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
915 described above. See `reftex-cite-format-2-authors' for an example.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
916 In order to configure this variable, you can either set
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
917 `reftex-cite-format' directly yourself or set it to the SYMBOL of one of
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
918 the predefined constants. E.g.:
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
919 (setq reftex-cite-format 'reftex-cite-format-2-authors)"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
920 :group 'reftex-citation-support
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
921 :type
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
922 '(choice
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
923 (choice :tag "symbolic defaults"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
924 :value reftex-cite-format-default
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
925 (const reftex-cite-format-default)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
926 (const reftex-cite-format-1-author-simple)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
927 (const reftex-cite-format-2-authors))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
928 (string :tag "format string" "\\cite{KEY}")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
929 (repeat :tag "list of strings"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
930 :value ("\cite{KEY}" "AUTHOR \cite{KEY}" "AUTHOR and AUTHOR \cite{KEY}")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
931 (string :tag "format string" ""))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
932 (repeat :tag "key-ed lists of strings"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
933 :value ((? . ("\cite{KEY}" "AUTHOR \cite{KEY}" "AUTHOR and AUTHOR \cite{KEY}")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
934 (cons :tag "Enter a keyed list of format strings"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
935 (character :tag "Key character " ? )
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
936 (repeat
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
937 (string :tag "format string" ""))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
938
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
939 ;; Table of contents configuration --------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
940
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
941 (defgroup reftex-table-of-contents-browser nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
942 "A multifile table of contents browser."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
943 :group 'reftex)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
944
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
945 (defcustom reftex-toc-follow-mode nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
946 "Non-nil means, point in *toc* buffer will cause other window to follow.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
947 The other window will show the corresponding part of the document.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
948 This flag can be toggled from within the *toc* buffer with the `f' key."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
949 :group 'reftex-table-of-contents-browser
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
950 :type '(boolean))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
951
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
952 ;; Miscellaneous configurations -----------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
953
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
954 (defgroup reftex-miscellaneous-configurations nil
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
955 "Collection of further configurations."
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
956 :group 'reftex)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
957
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
958 (defcustom reftex-extra-bindings nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
959 "Non-nil means, make additional key bindings on startup.
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
960 These extra bindings are located in the users `C-c letter' map."
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
961 :group 'reftex-miscellaneous-configurations
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
962 :type '(boolean))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
963
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
964 (defcustom reftex-plug-into-AUCTeX nil
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
965 "Plug-in flags for AUCTeX interface.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
966 This variable is a list of 4 boolean flags. When a flag is non-nil, it
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
967 means:
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
968
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
969 Flag 1: use `reftex-label' as `LaTeX-label-function'.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
970 Flag 2: use `reftex-arg-label' as `TeX-arg-label'
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
971 Flag 3: use `reftex-arg-ref' as `TeX-arg-ref'
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
972 Flag 4: use `reftex-arg-cite' as `TeX-arg-cite'
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
973
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
974 You may also set the variable itself to t or nil in order to turn all
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
975 plug-ins on or off, respectively.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
976 \\<LaTeX-mode-map>`LaTeX-label-function' is the function used for label insertion when you
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
977 enter a new environment in AUCTeX with \\[LaTeX-environment].
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
978 The `TeX-arg-label' etc. functions are for entering macro arguments during
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
979 macro insertion with \\[TeX-insert-macro].
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
980 See the AUCTeX documentation for more information.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
981 RefTeX uses `fset' to take over the function calls. Changing the variable
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
982 may require a restart of Emacs in order to become effective."
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
983 :group 'reftex-miscellaneous-configurations
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
984 :type '(choice (const :tag "No plug-ins" nil)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
985 (const :tag "All possible plug-ins" t)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
986 (list
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
987 :tag "Individual choice"
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
988 :value (nil nil nil nil)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
989 (boolean :tag "Use reftex-label as LaTeX-label-function")
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
990 (boolean :tag "Use reftex-arg-label as TeX-arg-label ")
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
991 (boolean :tag "Use reftex-arg-ref as TeX-arg-ref ")
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
992 (boolean :tag "Use reftex-arg-cite as TeX-arg-cite ")
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
993 )))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
994
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
995 (defcustom reftex-use-fonts t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
996 "*Non-nil means, use fonts in label menu and on-the-fly help.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
997 Font-lock must be loaded as well to actually get fontified display."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
998 :group 'reftex-miscellaneous-configurations
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
999 :type '(boolean))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1000
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1001 (defcustom reftex-keep-temporary-buffers t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1002 "*Non-nil means, keep any TeX and BibTeX files loaded for lookup.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1003 Nil means, kill it immediately after use unless it was already an existing
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1004 buffer before the lookup happened. It is faster to keep the buffers, but can
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1005 use a lot of memory, depending on the size of your database and document."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1006 :group 'reftex-miscellaneous-configurations
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1007 :type '(boolean))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1008
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1009 (defcustom reftex-auto-show-entry t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1010 "*Non-nil means, showing context in another window may unhide a section.
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1011 This is important when using outline-minor-mode. If the context to be shown
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1012 is in a hidden section, RefTeX will issue a \"show-entry\" command in order
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1013 to show it. This is not reversed when the label is selected - so the section
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1014 remains shown after command completion."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1015 :group 'reftex-miscellaneous-configurations
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1016 :type '(boolean))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1017
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1018
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1019 ;;; End of Configuration Section ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1020
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1021 ;;;===========================================================================
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1022 ;;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1023 ;;; Define the formal stuff for a minor mode named RefTeX.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1024 ;;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1025
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1026 (defconst reftex-version "2.14 for Emacs distribution."
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1027 "Version string for RefTeX.")
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1028
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1029 (defvar reftex-mode nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1030 "Determines if RefTeX minor mode is active.")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1031 (make-variable-buffer-local 'reftex-mode)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1032
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1033 (defvar reftex-mode-map (make-sparse-keymap)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1034 "Keymap for RefTeX minor mode.")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1035
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1036 (defvar reftex-mode-menu nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1037
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1038 ;;;###autoload
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1039 (defun turn-on-reftex ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1040 "Turn on RefTeX minor mode."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1041 (reftex-mode t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1042
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1043 ;;;###autoload
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1044 (defun reftex-mode (&optional arg)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1045 "Minor mode with distinct support for \\label, \\ref and \\cite in LaTeX.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1046
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1047 Labels can be created with `\\[reftex-label]' and referenced with `\\[reftex-reference]'.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1048 When referencing, you get a menu with all labels of a given type and
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1049 context of the label definition. The selected label is inserted as a
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1050 \\ref macro.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1051
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1052 Citations can be made with `\\[reftex-citation]' which will use a regular expression
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1053 to pull out a *formatted* list of articles from your BibTeX
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1054 database. The selected citation is inserted as a \\cite macro.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1055
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1056 A Table of Contents of the entire (multifile) document with browsing
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1057 capabilities is available with `\\[reftex-toc]'.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1058
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1059 Most command have help available on the fly. This help is accessed by
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1060 pressing `?' to any prompt mentioning this feature.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1061
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1062 Extensive documentation about reftex is in the file header of `reftex.el'.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1063
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1064 \\{reftex-mode-map}
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1065 Under X, these functions will also be available in a menu on the menu bar.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1066
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1067 ------------------------------------------------------------------------------"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1068
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1069 (interactive "P")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1070 (setq reftex-mode (not (or (and (null arg) reftex-mode)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1071 (<= (prefix-numeric-value arg) 0))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1072
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1073 ; Add or remove the menu, and run the hook
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1074 (if reftex-mode
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1075 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1076 (easy-menu-add reftex-mode-menu)
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1077 (reftex-plug-into-AUCTeX)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1078 (run-hooks 'reftex-mode-hook))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1079 (easy-menu-remove reftex-mode-menu)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1080
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1081 (or (assoc 'reftex-mode minor-mode-alist)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1082 (setq minor-mode-alist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1083 (cons '(reftex-mode " Ref") minor-mode-alist)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1084
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1085 (or (assoc 'reftex-mode minor-mode-map-alist)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1086 (setq minor-mode-map-alist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1087 (cons (cons 'reftex-mode reftex-mode-map)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1088 minor-mode-map-alist)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1089
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1090
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1091
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1092
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1093
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1094
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1095
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1096
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1097
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1098
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1099 ;;; ===========================================================================
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1100 ;;;
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1101 ;;; Silence warnings about variables in other packages.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1102 (defvar TeX-master)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1103 (defvar LaTeX-label-function)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1104 (defvar tex-main-file)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1105 (defvar outline-minor-mode)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1106
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1107 ;;; ===========================================================================
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1108 ;;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1109 ;;; Interfaces for other packages
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1110 ;;; -----------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1111 ;;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1112 ;;; AUCTeX
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1113 ;;; ------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1114
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1115 (defun reftex-arg-label (optional &optional prompt definition)
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1116 "Use `reftex-label' to create label. Insert it with `TeX-argument-insert'.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1117 This function is intended for AUCTeX macro support."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1118 (let ((label (reftex-label nil t)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1119 (if (and definition (not (string-equal "" label)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1120 (LaTeX-add-labels label))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1121 (TeX-argument-insert label optional optional)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1122
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1123 (defun reftex-arg-ref (optional &optional prompt definition)
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1124 "Use `reftex-reference' to select label. Insert with `TeX-argument-insert'.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1125 This function is intended for AUCTeX macro support."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1126 (let ((label (reftex-reference nil t)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1127 (if (and definition (not (string-equal "" label)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1128 (LaTeX-add-labels label))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1129 (TeX-argument-insert label optional optional)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1130
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1131 (defun reftex-arg-cite (optional &optional prompt definition)
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1132 "Use reftex-citation to select a key. Insert with `TeX-argument-insert'.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1133 This function is intended for AUCTeX macro support."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1134 (let ((key (reftex-citation nil t)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1135 (TeX-argument-insert (or key "") optional optional)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1136
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1137 (defun reftex-plug-into-AUCTeX ()
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1138 ;; Replace AucTeX functions with RefTeX functions.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1139 ;; Which functions are replaced is controlled by the variable
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1140 ;; `reftex-plug-into-AUCTeX'.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1141 (let ((flags
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1142 (cond ((eq reftex-plug-into-AUCTeX t) '(t t t t))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1143 ((eq reftex-plug-into-AUCTeX nil) '(nil nil nil nil))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1144 (t reftex-plug-into-AUCTeX))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1145
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1146 (and (nth 0 flags)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1147 (boundp 'LaTeX-label-function)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1148 (setq LaTeX-label-function 'reftex-label))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1149
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1150 (and (nth 1 flags)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1151 (fboundp 'TeX-arg-label)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1152 (fset 'TeX-arg-label 'reftex-arg-label))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1153
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1154 (and (nth 2 flags)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1155 (fboundp 'TeX-arg-ref)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1156 (fset 'TeX-arg-ref 'reftex-arg-ref))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1157
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1158 (and (nth 3 flags)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1159 (fboundp 'TeX-arg-cite)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1160 (fset 'TeX-arg-cite 'reftex-arg-cite))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1161
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1162
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1163 (defvar reftex-label-alist-external-add-ons nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1164 "List of label alist entries added with reftex-add-to-label-alist.")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1165
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1166 ;;;###autoload
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1167 (defun reftex-add-to-label-alist (entry-list)
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1168 "Add label environment descriptions to `reftex-label-alist-external-add-ons'.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1169 The format of ENTRY-LIST is exactly like `reftex-label-alist'. See there
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1170 for details.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1171 This function makes it possible to support RefTeX from AUCTeX style files.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1172 The entries in ENTRY-LIST will be processed after the user settings in
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1173 `reftex-label-alist', and before the defaults (specified in
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1174 `reftex-default-label-alist-entries'). Any changes made to
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1175 `reftex-label-alist-external-add-ons' will raise a flag to the effect that a
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1176 mode reset is done on the next occasion."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1177 (let (entry)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1178 (while entry-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1179 (setq entry (car entry-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1180 entry-list (cdr entry-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1181 (if (not (member entry reftex-label-alist-external-add-ons))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1182 (setq reftex-tables-dirty t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1183 reftex-label-alist-external-add-ons
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1184 (cons entry reftex-label-alist-external-add-ons))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1185
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1186 ;;; ===========================================================================
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1187 ;;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1188 ;;; Multifile support
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1189 ;;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1190 ;;; Technical notes: Multifile works as follows: We keep just one list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1191 ;;; of labels for each master file - this can save a lot of memory.
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1192 ;;; `reftex-master-index-list' is an alist which connects the true file name
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1193 ;;; of each master file with the symbols holding the information on that
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1194 ;;; document. Each buffer has local variables which point to these symbols.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1195
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1196 ;; List of variables which handle the multifile stuff.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1197 ;; This list is used to tie, untie, and reset these symbols.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1198 (defconst reftex-multifile-symbols
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1199 '(reftex-label-numbers-symbol reftex-list-of-labels-symbol
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1200 reftex-bibfile-list-symbol))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1201
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1202 ;; Alist connecting master file names with the corresponding lisp symbols.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1203 (defvar reftex-master-index-list nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1204
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1205 ;; Last index used for a master file.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1206 (defvar reftex-multifile-index 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1207
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1208 ;; Alist connecting a master file with all included files.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1209 (defvar reftex-master-include-list nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1210
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1211 ;; Variable holding the symbol with current value of label postfix.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1212 (defvar reftex-label-numbers-symbol nil )
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1213 (make-variable-buffer-local 'reftex-label-numbers-symbol)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1214
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1215 ;; Variable holding the symbol with the label list of the document.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1216 ;; Each element of the label list is again a list with the following elements:
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1217 ;; 0: One character label type indicator.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1218 ;; 1: Short context to put into label menu.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1219 ;; 2: The label.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1220 ;; 3: The name of the file where the label is defined.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1221 (defvar reftex-list-of-labels-symbol nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1222 (make-variable-buffer-local 'reftex-list-of-labels-symbol)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1223
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1224 ;; Variable holding the symbol with a list of library files for this document.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1225 (defvar reftex-bibfile-list-symbol nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1226 (make-variable-buffer-local 'reftex-bibfile-list-symbol)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1227
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1228 (defun reftex-next-multifile-index ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1229 ;; Return the next free index for multifile symbols.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1230 (setq reftex-multifile-index (1+ reftex-multifile-index)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1231
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1232 (defun reftex-tie-multifile-symbols ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1233 ;; Tie the buffer-local symbols to globals connected with the master file.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1234 ;; If the symbols for the current master file do not exist, they are created.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1235
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1236 (let* ((master (file-truename (reftex-TeX-master-file)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1237 (index (assoc master reftex-master-index-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1238 (symlist reftex-multifile-symbols)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1239 (symbol nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1240 (symname nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1241 (newflag nil))
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1242 ;; Find the correct index.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1243 (if index
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1244 ;; symbols do exist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1245 (setq index (cdr index))
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1246 ;; Get a new index and add info to the alist.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1247 (setq index (reftex-next-multifile-index)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1248 reftex-master-index-list (cons
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1249 (cons master index)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1250 reftex-master-index-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1251 newflag t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1252
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1253 ;; Get/create symbols and tie them.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1254 (while symlist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1255 (setq symbol (car symlist)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1256 symlist (cdr symlist)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1257 symname (symbol-name symbol))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1258 (set symbol (intern (concat symname "-" (int-to-string index))))
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1259 ;; Initialize if new symbols.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1260 (if newflag (set (symbol-value symbol) nil)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1261
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1262 ;; Return t if the symbols did already exist, nil when we've made them.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1263 (not newflag)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1264
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1265 (defun reftex-untie-multifile-symbols ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1266 ;; Remove ties from multifile symbols, so that next use makes new ones.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1267 (let ((symlist reftex-multifile-symbols)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1268 (symbol nil))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1269 (while symlist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1270 (setq symbol (car symlist)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1271 symlist (cdr symlist))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1272 (set symbol nil))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1273
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1274 (defun reftex-TeX-master-file ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1275 ;; Return the name of the master file associated with the current buffer.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1276 ;; When AUCTeX is loaded, we will use it's more sophisticated method.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1277 ;; We also support the default TeX and LaTeX modes by checking for a
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1278 ;; variable tex-main-file.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1279
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1280 (let
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1281 ((master
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1282 (cond
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1283 ((fboundp 'TeX-master-file) ; AUCTeX is loaded. Use its mechanism.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1284 (TeX-master-file t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1285 ((boundp 'TeX-master) ; The variable is defined - lets use it.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1286 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1287 ((eq TeX-master t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1288 (buffer-file-name))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1289 ((eq TeX-master 'shared)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1290 (setq TeX-master (read-file-name "Master file: "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1291 nil nil t nil)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1292 (TeX-master)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1293 (t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1294 (setq TeX-master (read-file-name "Master file: "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1295 nil nil t nil)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1296 ((boundp 'tex-main-file)
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1297 ;; This is the variable from the default TeX modes.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1298 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1299 ((stringp tex-main-file)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1300 ;; ok, this must be it
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1301 tex-main-file)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1302 (t
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1303 ;; In this case, the buffer is its own master.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1304 (buffer-file-name))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1305 (t
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1306 ;; Know nothing about master file. Assume this is a master file.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1307 (buffer-file-name)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1308 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1309 ((null master)
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1310 (error "Need a filename for this buffer. Please save it first."))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1311 ((or (file-exists-p master)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1312 (reftex-get-buffer-visiting master))
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1313 ;; We either see the file, or have a buffer on it. OK.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1314 )
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1315 ((or (file-exists-p (concat master ".tex"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1316 (reftex-get-buffer-visiting (concat master ".tex")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1317 ;; Ahh, an extra .tex was missing...
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1318 (setq master (concat master ".tex")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1319 (t
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1320 ;; Something is wrong here. Throw an exception.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1321 (error "No such master file %s" master)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1322 (expand-file-name master)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1323
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1324 (defun reftex-make-master-buffer (master-file mode)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1325 "Make a master buffer which contains the MASTER-FILE and all includes.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1326 This is to prepare a buffer containing the entire document in correct
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1327 sequence for parsing. Therefore it will even expand includes which are
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1328 commented out.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1329 The function returns the number of input/include files not found."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1330
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1331 (interactive "fmaster file: ")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1332 (let ((not-found 0) file file-list tmp (font-lock-maximum-size 1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1333 (switch-to-buffer "*reftex-master.tex*")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1334 (erase-buffer)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1335 (if (not (eq major-mode mode))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1336 (funcall mode))
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1337 ;; First insert the master file.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1338 (if (not (file-exists-p master-file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1339 (error "No such master file: %s" master-file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1340 (reftex-insert-buffer-or-file master-file)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1341 (subst-char-in-region (point-min) (point-max) ?\r ?\n t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1342 (setq file-list (cons master-file file-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1343 (goto-char 1)
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1344 ;; Remember from which file these lines came.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1345 (put-text-property (point-min) (point-max) 'file
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1346 (expand-file-name master-file))
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1347 ;; Make the default directory that of the master file.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1348 ;; All input and include stuff works relative to that directory.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1349 (cd (file-name-directory (expand-file-name master-file)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1350 ;; Now find recursively all include/input statements and expand them.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1351 (while (re-search-forward
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1352 "^[ \t]*\\\\\\(include\\|input\\){\\([^}\n]+\\)}" nil t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1353 (setq file (reftex-no-props (match-string 2)))
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1354 (if (not (and (> (length file) 4)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1355 (string= (substring file -4) ".tex")))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1356 (setq file (concat file ".tex")))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1357 (if (file-exists-p file)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1358 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1359 (replace-match
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1360 (format "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% START OF %s FILE: %s\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% END OF %s FILE: %s\n"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1361 (match-string 1) file
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1362 (match-string 1) file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1363 (beginning-of-line 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1364 (narrow-to-region (point) (point))
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1365 ;; Insert the file.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1366 (reftex-insert-buffer-or-file file)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1367 (subst-char-in-region (point-min) (point-max) ?\r ?\n t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1368 (setq file-list (cons (expand-file-name file) file-list))
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1369 ;; Remember from which file these lines came.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1370 (put-text-property (point-min) (point-max)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1371 'file (expand-file-name file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1372 (goto-char (point-min))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1373 (widen))
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1374 (message "Input/include file %s not found. Ignored. Continuing..."
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1375 file)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1376 (setq not-found (1+ not-found))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1377 (setq file-list (nreverse file-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1378 (while (setq tmp (assoc (car file-list) reftex-master-include-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1379 (setq reftex-master-include-list (delq tmp reftex-master-include-list)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1380 (setq reftex-master-include-list (cons file-list reftex-master-include-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1381 not-found))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1382
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1383 (defun reftex-insert-buffer-or-file (file)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1384 "If there is a buffer associated with FILE, insert it - otherwise the FILE."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1385 (let ((buffer (reftex-get-buffer-visiting file)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1386 (if buffer
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1387 (let (beg end beg1 end1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1388 (save-excursion
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1389 ;; Make sure we get the whole buffer.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1390 (set-buffer buffer)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1391 (setq beg (point-min) end (point-max))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1392 (widen)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1393 (setq beg1 (point-min) end1 (point-max)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1394 (insert-buffer-substring buffer beg1 end1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1395 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1396 (set-buffer buffer)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1397 (narrow-to-region beg end)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1398 (insert-file-contents file))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1399
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1400
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1401 (defun reftex-parse-document (&optional buffer)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1402 "Rescan the document."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1403 (interactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1404 (save-window-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1405 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1406 (if buffer
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1407 (if (not (bufferp buffer))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1408 (error "No such buffer %s" (buffer-name buffer))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1409 (set-buffer buffer)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1410 (reftex-access-scan-info t))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1411
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1412 (defun reftex-access-scan-info (&optional rescan)
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1413 ;; Access the scanning info. When the multifile symbols are not yet tied,
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1414 ;; tie them. When they are have to be created, do a buffer scan to
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1415 ;; fill them.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1416
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1417 ;; If RESCAN is non-nil, enforce document scanning
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1418
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1419 (catch 'exit
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1420 (let ((rescan (or (equal rescan t) (equal rescan '(4)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1421
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1422 ;; Reset the mode if we had changes from style hooks.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1423 (and reftex-tables-dirty
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1424 (reftex-reset-mode))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1425
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1426 (if (eq reftex-list-of-labels-symbol nil)
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1427 ;; Symbols are not yet tied: Tie them and see if they are set.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1428 (reftex-tie-multifile-symbols))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1429
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1430 (if (and (symbol-value reftex-list-of-labels-symbol)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1431 (not rescan))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1432 ;; Lists do already exist and we don't need to rescan.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1433 ;; Return from here.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1434 (throw 'exit t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1435
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1436 ;; We need to rescan
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1437 ;; =================
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1438
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1439 (unwind-protect
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1440 (save-window-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1441 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1442
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1443 ;; Do the scanning.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1444
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1445 (let ((label-list-symbol reftex-list-of-labels-symbol)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1446 (label-numbers-symbol reftex-label-numbers-symbol)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1447 (bibfile-list-symbol reftex-bibfile-list-symbol))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1448
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1449 (message "Creating master buffer...")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1450 (reftex-make-master-buffer (reftex-TeX-master-file) major-mode)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1451
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1452 (message "Scanning document...")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1453
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1454 (reftex-scan-buffer-for-labels
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1455 label-numbers-symbol label-list-symbol)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1456
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1457 (reftex-scan-buffer-for-bibliography-statement
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1458 bibfile-list-symbol)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1459
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1460 (message "Scanning document... done"))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1461
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1462 (if (get-buffer "*reftex-master.tex*")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1463 (kill-buffer "*reftex-master.tex*"))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1464
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1465 (defun reftex-create-tags-file ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1466 "Create TAGS file by running `etags' on the current document.
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1467 The TAGS file is also immediately visited with `visit-tags-table'."
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1468 (interactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1469 (reftex-access-scan-info current-prefix-arg)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1470 (let* ((master (reftex-TeX-master-file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1471 (files (assoc master reftex-master-include-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1472 (cmd (format "etags %s" (mapconcat 'identity files " "))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1473 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1474 (set-buffer (reftex-get-buffer-visiting master))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1475 (message "Running etags to create TAGS file...")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1476 (shell-command cmd)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1477 (visit-tags-table "TAGS"))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1478
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1479 ;; History of grep commands.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1480 (defvar reftex-grep-history nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1481 (defvar reftex-grep-command "grep -n "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1482 "Last grep command used in \\[reftex-grep-document]; default for next grep.")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1483
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1484 (defun reftex-grep-document (grep-cmd)
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1485 "Run grep query through all files related to this document.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1486 With prefix arg, force to rescan document.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1487 This works also without an active TAGS table."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1488
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1489 (interactive
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1490 (list (read-from-minibuffer "Run grep on document (like this): "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1491 reftex-grep-command nil nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1492 'reftex-grep-history)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1493 (reftex-access-scan-info current-prefix-arg)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1494 (let* ((master (reftex-TeX-master-file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1495 (default-directory (file-name-directory master))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1496 (re (format "\\`%s\\(.*\\)" (regexp-quote
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1497 (expand-file-name default-directory))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1498 (files (assoc master reftex-master-include-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1499 (cmd (format
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1500 "%s %s" grep-cmd
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1501 (mapconcat (function (lambda (x)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1502 (if (string-match re x)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1503 (match-string 1 x)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1504 x)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1505 files " "))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1506 (grep cmd)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1507
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1508 (defun reftex-search-document (&optional regexp)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1509 "Regexp search through all files of the current TeX document.
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1510 Starts always in the master file. Stops when a match is found.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1511 To continue searching for next match, use command \\[tags-loop-continue].
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1512 This works also without an active TAGS table."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1513 (interactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1514 (let ((default (reftex-this-word)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1515 (if (not regexp)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1516 (setq regexp (read-string (format "Search regexp in document [%s]: "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1517 default))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1518 (if (string= regexp "") (setq regexp (regexp-quote default)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1519
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1520 (reftex-access-scan-info current-prefix-arg)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1521 (tags-search regexp (list 'assoc (reftex-TeX-master-file)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1522 'reftex-master-include-list))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1523
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1524 (defun reftex-query-replace-document (&optional from to delimited)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1525 "Run a query-replace-regexp of FROM with TO over the entire TeX document.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1526 Third arg DELIMITED (prefix arg) means replace only word-delimited matches.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1527 If you exit (\\[keyboard-quit] or ESC), you can resume the query replace
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1528 with the command \\[tags-loop-continue].
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1529 This works also without an active TAGS table."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1530 (interactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1531 (let ((default (reftex-this-word)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1532 (if (not from)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1533 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1534 (setq from (read-string (format "Replace regexp in document [%s]: "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1535 default)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1536 (if (string= from "") (setq from (regexp-quote default)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1537 (if (not to)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1538 (setq to (read-string (format "Replace regexp %s with: " from))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1539 (reftex-access-scan-info current-prefix-arg)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1540 (tags-query-replace from to (or delimited current-prefix-arg)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1541 (list 'assoc (reftex-TeX-master-file)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1542 'reftex-master-include-list))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1543
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1544 (defun reftex-change-label (&optional from to)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1545 "Query replace FROM with TO in all \\label and \\ref commands.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1546 Works on the entire multifile document.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1547 If you exit (\\[keyboard-quit] or ESC), you can resume the query replace
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1548 with the command \\[tags-loop-continue].
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1549 This works also without an active TAGS table."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1550 (interactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1551 (let ((default (reftex-this-word "-a-zA-Z0-9_*.:")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1552 (if (not from)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1553 (setq from (read-string (format "Replace label globally [%s]: "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1554 default))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1555 (if (string= from "") (setq from default))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1556 (if (not to)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1557 (setq to (read-string (format "Replace label %s with: "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1558 from))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1559 (reftex-query-replace-document
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1560 (concat "\\\\\\(label\\|[a-z]*ref\\){" (regexp-quote from) "}")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1561 (format "\\\\\\1{%s}" to))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1562
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1563 (defun reftex-this-word (&optional class)
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1564 ;; Grab the word around point.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1565 (setq class (or class "-a-zA-Z0-9:_/.*;|"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1566 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1567 (buffer-substring-no-properties
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1568 (progn (skip-chars-backward class) (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1569 (progn (skip-chars-forward class) (point)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1570
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1571 ;;; ===========================================================================
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1572 ;;;
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1573 ;;; Functions to create and reference automatic labels.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1574
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1575 ;; The following constants are derived from `reftex-label-alist'.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1576
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1577 ;; Prompt used for label type querys directed to the user.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1578 (defconst reftex-type-query-prompt nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1579
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1580 ;; Help string for label type querys.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1581 (defconst reftex-type-query-help nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1582
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1583 ;; Alist relating label type to reference format.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1584 (defconst reftex-typekey-to-format-alist nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1585
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1586 ;; Alist relating label type to label affix.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1587 (defconst reftex-typekey-to-prefix-alist nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1588
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1589 ;; Alist relating environments or macros to label type and context regexp.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1590 (defconst reftex-env-or-mac-alist nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1591
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1592 ;; List of macros carrying a label.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1593 (defconst reftex-label-mac-list nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1594
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1595 ;; List of environments carrying a label.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1596 (defconst reftex-label-env-list nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1597
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1598 ;; List of all typekey letters in use.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1599 (defconst reftex-typekey-list nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1600
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1601 ;; Alist relating magic words to a label type.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1602 (defconst reftex-words-to-typekey-alist nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1603
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1604 ;; The last list-of-labels entry used in a reference.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1605 (defvar reftex-last-used-reference (list nil nil nil nil))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1606
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1607 ;; The regular expression used to abbreviate words.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1608 (defconst reftex-abbrev-regexp
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1609 (concat
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1610 "^\\("
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1611 (make-string (nth 0 reftex-abbrev-parameters) ?.)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1612 "[" (nth 2 reftex-abbrev-parameters) "]*"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1613 "\\)"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1614 "[" (nth 3 reftex-abbrev-parameters) "]"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1615 (make-string (1- (nth 1 reftex-abbrev-parameters)) ?.)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1616
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1617 ;; Global variables used for communication between functions.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1618 (defvar reftex-default-context-position nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1619 (defvar reftex-location-start nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1620 (defvar reftex-call-back-to-this-buffer nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1621
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1622 ;; List of buffers created temporarily for lookup, which should be killed.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1623 (defvar reftex-buffers-to-kill nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1624
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1625 ;; The regexp used to find section statements.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1626 (defconst reftex-section-regexp "^[ ]*\\\\\\(part\\|chapter\\|section\\|subsection\\|subsubsection\\|paragraph\\|subparagraph\\|subsubparagraph\\)\\*?\\(\\[[^]]*\\]\\)?{")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1627
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1628 ;; LaTeX section commands and level numbers
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1629 (defconst reftex-section-levels
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1630 '(
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1631 ("part" . 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1632 ("chapter" . 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1633 ("section" . 2)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1634 ("subsection" . 3)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1635 ("subsubsection" . 4)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1636 ("paragraph" . 5)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1637 ("subparagraph" . 6)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1638 ("subsubparagraph" . 7)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1639 ))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1640
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1641 (defun reftex-label (&optional environment no-insert)
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1642 "Insert a unique label. Return the label.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1643 If ENVIRONMENT is given, don't bother to find out yourself.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1644 If NO-INSERT is non-nil, do not insert label into buffer.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1645 With prefix arg, force to rescan document first.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1646 The label is also inserted into the label list.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1647 This function is controlled by the settings of reftex-insert-label-flags."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1648
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1649 (interactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1650
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1651 ;; Ensure access to scanning info and rescan buffer if prefix are is '(4).
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1652 (reftex-access-scan-info current-prefix-arg)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1653
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1654 ;; Find out what kind of environment this is and abort if necessary.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1655 (if (or (not environment)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1656 (not (assoc environment reftex-env-or-mac-alist)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1657 (setq environment (reftex-label-location)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1658 (if (not environment)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1659 (error "Can't figure out what kind of label should be inserted"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1660
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1661 ;; Ok, go ahead.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1662 (let (label num typekey prefix entry cell lab valid default force-prompt)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1663 (setq typekey (nth 1 (assoc environment
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1664 reftex-env-or-mac-alist)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1665 (setq prefix (or (cdr (assoc typekey reftex-typekey-to-prefix-alist))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1666 (concat typekey "-")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1667
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1668 ;; Make a default label.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1669 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1670
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1671 ((reftex-typekey-check typekey (nth 0 reftex-insert-label-flags))
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1672 ;; Derive a label from context.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1673 (setq default (nth 2 (reftex-label-info " ")))
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1674 ;; Catch the cases where the is actually no context available.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1675 (if (or (string-match "NO MATCH FOR CONTEXT REGEXP" default)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1676 (string-match "ILLEGAL VALUE OF PARSE" default)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1677 (string-match "SECTION HEADING NOT FOUND" default)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1678 (string-match "HOOK ERROR" default)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1679 (string-match "^[ \t]*$" default))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1680 (setq default prefix
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1681 force-prompt t) ; need to prompt
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1682 (setq default (concat prefix (reftex-string-to-label default)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1683
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1684 ;; Make it unique.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1685 (setq label default)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1686 (setq num 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1687 (while (assoc label (symbol-value reftex-list-of-labels-symbol))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1688 (setq label (concat default "-" (setq num (1+ num)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1689 (setq default label)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1690
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1691 ((reftex-typekey-check typekey (nth 1 reftex-insert-label-flags)) ; prompt
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1692 ;; Minimal default: the user will be prompted.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1693 (setq default prefix))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1694
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1695 (t
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1696 ;; Make an automatic label.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1697 (while (assoc
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1698 (setq default (concat prefix (reftex-next-label-number typekey)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1699 (symbol-value reftex-list-of-labels-symbol)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1700
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1701 ;; Should we ask the user?
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1702 (if (or (reftex-typekey-check typekey
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1703 (nth 1 reftex-insert-label-flags)) ; prompt
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1704 force-prompt)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1705
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1706 (while (not valid)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1707 ;; iterate until we get a legal label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1708
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1709 (setq label (read-string "Label: " default))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1710
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1711 ;; Lets make sure that this is a legal label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1712 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1713
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1714 ;; Test if label contains strange characters
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1715 ((string-match reftex-label-illegal-re label)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1716 (message "Label \"%s\" contains illegal characters" label)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1717 (ding)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1718 (sit-for 2))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1719
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1720 ;; Look it up in the label list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1721 ((setq entry (assoc label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1722 (symbol-value reftex-list-of-labels-symbol)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1723 (message "Label \"%s\" exists in file %s" label (nth 3 entry))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1724 (ding)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1725 (sit-for 2))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1726
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1727 ;; Label is ok
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1728 (t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1729 (setq valid t))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1730 (setq label default))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1731
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1732 ;; Insert the label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1733 (if (not no-insert)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1734 (insert "\\label{" label "}"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1735
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1736 ;; Insert the label into the label list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1737 (if (symbol-value reftex-list-of-labels-symbol)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1738 (let ((cnt 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1739 (pos (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1740 (all (symbol-value reftex-list-of-labels-symbol))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1741 (look-for nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1742 (note nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1743 (text nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1744 (file (buffer-file-name)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1745
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1746 ;; find the previous label in order to know where to insert new label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1747 ;; into label list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1748 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1749 (if (re-search-backward "\\\\label{\\([^}]+\\)}" nil 1 2)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1750 (setq look-for (reftex-no-props (match-string 1))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1751 (if (or (re-search-forward
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1752 "\\\\\\(include\\|input\\){[^}\n]+}" pos t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1753 (re-search-forward reftex-section-regexp pos t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1754 (null look-for))
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1755 (setq note "POSITION UNCERTAIN. RESCAN TO FIX.")))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1756 (if (not look-for)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1757 (set reftex-list-of-labels-symbol
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1758 (cons (list label typekey text file note)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1759 (symbol-value reftex-list-of-labels-symbol)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1760 (while all
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1761 (setq cell (car all)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1762 all (cdr all)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1763 cnt (1+ cnt)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1764 lab (nth 0 cell))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1765 (if (string= lab look-for)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1766 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1767 (setcdr
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1768 (nthcdr (1- cnt)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1769 (symbol-value reftex-list-of-labels-symbol))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1770 (cons (list label typekey text file note)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1771 (nthcdr
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1772 cnt (symbol-value reftex-list-of-labels-symbol))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1773 ;; to end the loop, set all to nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1774 (setq all nil)))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1775 ;; return value of the function is the label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1776 label))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1777
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1778 (defun reftex-string-to-label (string)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1779 ;; Convert a string (a sentence) to a label.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1780 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1781 ;; Uses reftex-derive-label-parameters and reftex-abbrev-parameters
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1782 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1783
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1784 (let* ((words0 (reftex-split "[- \t\n\r]+"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1785 (reftex-no-props string)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1786 (ignore-words (nth 5 reftex-derive-label-parameters))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1787 words word)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1788
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1789 ;; remove words from the ignore list or with funny characters
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1790 (while words0
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1791 (setq word (car words0) words0 (cdr words0))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1792 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1793 ((member (downcase word) ignore-words))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1794 ((string-match reftex-label-illegal-re word)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1795 (if (nth 2 reftex-derive-label-parameters)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1796 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1797 (while (string-match reftex-label-illegal-re word)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1798 (setq word (replace-match "" nil nil word)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1799 (setq words (cons word words)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1800 (t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1801 (setq words (cons word words)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1802 (setq words (nreverse words))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1803
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1804 ;; restrict number of words
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1805 (if (> (length words) (nth 0 reftex-derive-label-parameters))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1806 (setcdr (nthcdr (1- (nth 0 reftex-derive-label-parameters)) words) nil))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1807
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1808 ;; First, try to use all words
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1809 (setq string (mapconcat '(lambda(w) w) words
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1810 (nth 4 reftex-derive-label-parameters)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1811
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1812 ;; Abbreviate words if enforced by user settings or string length
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1813 (if (or (eq t (nth 3 reftex-derive-label-parameters))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1814 (and (nth 3 reftex-derive-label-parameters)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1815 (> (length string) (nth 1 reftex-derive-label-parameters))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1816 (setq words
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1817 (mapcar
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1818 '(lambda (w) (if (string-match reftex-abbrev-regexp w)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1819 (match-string 1 w)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1820 w))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1821 words)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1822 string (mapconcat '(lambda(w) w) words
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1823 (nth 4 reftex-derive-label-parameters))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1824
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1825 ;; Shorten if still to long
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1826 (setq string
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1827 (if (> (length string) (nth 1 reftex-derive-label-parameters))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1828 (substring string 0 (nth 1 reftex-derive-label-parameters))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1829 string))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1830
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1831 ;; Delete the final punctuation, if any
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1832 (if (string-match "[^a-zA-Z0-9]+$" string)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1833 (setq string (replace-match "" nil nil string)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1834 string))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1835
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1836 (defun reftex-label-location (&optional bound)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1837 ;; Return the environment or macro which determines the label type at point.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1838 ;; If optional BOUND is an integer, limit backward searches to that point.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1839
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1840 (let* ((loc1 (reftex-what-macro reftex-label-mac-list bound))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1841 (loc2 (reftex-what-environment reftex-label-env-list bound))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1842 (p1 (or (cdr loc1) 0))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1843 (p2 (or (cdr loc2) 0)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1844
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1845 (setq reftex-location-start (max p1 p2))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1846 (if (> p1 p2)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1847 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1848 (setq reftex-default-context-position p1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1849 (car loc1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1850 (setq reftex-default-context-position
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1851 (+ p2 8 (length (car loc2))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1852 (or (car loc2) "section"))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1853
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1854
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1855 (defun reftex-next-label-number (type)
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1856 ;; Increment value of automatic labels in current buffer. Return new value.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1857
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1858 ;; Ensure access to scanning info
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1859 (reftex-access-scan-info)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1860
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1861 (let ((n (cdr (assoc type (symbol-value reftex-label-numbers-symbol)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1862 (if (not (integerp n))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1863 ;; oops - type not known - make one here
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1864 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1865 (set reftex-label-numbers-symbol
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1866 (cons (cons type 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1867 (symbol-value reftex-label-numbers-symbol)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1868 (setq n 0)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1869 (setq n (1+ n))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1870 (setcdr (assoc type (symbol-value reftex-label-numbers-symbol)) n)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1871 n))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1872
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1873 ;; Help string for the reference label menu
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1874 (defconst reftex-reference-label-help
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1875 " AVAILABLE KEYS IN REFERENCE LABEL MENU
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1876 ======================================
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1877 n / p Go to next/previous label (Cursor motion works as well)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1878 r / s Rescan document for labels / Switch label type
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1879 t / # Toggle table of contents / Toggle counter mode
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1880 c Toggle display of short context
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1881 SPACE Show full context for current label in other window
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1882 f Toggle follow mode: other window will follow context
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1883 a / q Use last referenced label / Quit without accepting label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1884 ? / C-r Display this help message / Recursive Edit into other window
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1885 RETURN Accept current label")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1886
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1887 (defun reftex-reference (&optional type no-insert)
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1888 "Make a LaTeX reference. Look only for labels of a certain TYPE.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1889 With prefix arg, force to rescan buffer for labels. This should only be
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1890 necessary if you have recently entered labels yourself without using
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1891 reftex-label. Rescanning of the buffer can also be requested from the
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1892 label selection menu.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1893 The function returns the selected label or nil.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1894 If NO-INSERT is non-nil, do not insert \\ref command, just return label.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1895 When called with 2 C-u prefix args, disable magic word recognition."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1896
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1897 (interactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1898
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1899 ;; check for active recursive edits
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1900 (reftex-check-recursive-edit)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1901
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1902 ;; Ensure access to scanning info and rescan buffer if prefix are is '(4)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1903 (reftex-access-scan-info current-prefix-arg)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1904
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1905 (if (not type)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1906 ;; guess type from context
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1907 (if (and reftex-guess-label-type
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1908 (not (= 16 (prefix-numeric-value current-prefix-arg)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1909 (setq type (assoc (downcase (reftex-word-before-point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1910 reftex-words-to-typekey-alist)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1911 (setq type (cdr type))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1912 (setq type (reftex-query-label-type))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1913
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1914 (let (label pair
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1915 (form (or (cdr (assoc type reftex-typekey-to-format-alist))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1916 "\\ref{%s}")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1917
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1918 ;; Have the user select a label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1919 (setq pair (reftex-offer-label-menu type))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1920 (setq label (car pair))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1921
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1922 (if (and label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1923 (not no-insert))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1924 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1925 ;; do we need to remove spaces?
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1926 (if (string= "~" (substring form 0 1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1927 (while (or (= (preceding-char) ?\ )
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1928 (= (preceding-char) ?\C-i))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1929 (backward-delete-char 1)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1930 ;; ok, insert the reference
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1931 (insert (format form label label))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1932 (message ""))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1933 (message "Quit"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1934 ;; return the label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1935 label))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1936
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1937 (defun reftex-goto-label (&optional arg)
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1938 "Go to a LaTeX label. With prefix ARG, go to label in another window."
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1939 (interactive "P")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1940 (let (type label file pair)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1941 (if (not type)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1942 (setq type (reftex-query-label-type)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1943
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1944 (setq pair (reftex-offer-label-menu type)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1945 label (car pair)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1946 file (cdr pair))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1947 (if (and label file (file-exists-p file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1948 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1949 (if arg
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1950 (find-file-other-window file)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1951 (find-file file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1952 (goto-char (point-min))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1953 (if (not (search-forward (concat "\\label{" label "}") nil t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1954 (error "No such label found: %s" label)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1955 (reftex-highlight 0 (match-beginning 0) (match-end 0))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1956 (add-hook 'pre-command-hook 'reftex-highlight-shall-die)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1957 (message "Quit")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1958 nil)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1959
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1960 ;; Internal list with index numbers of labels in the selection menu
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1961 (defvar reftex-label-index-list nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1962
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1963 (defun reftex-offer-label-menu (typekey)
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
1964 ;; Offer a menu with the appropriate labels. Return (label . file).
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1965 (let* ((buf (current-buffer))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1966 (near-label (reftex-find-nearby-label))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1967 (toc (reftex-typekey-check typekey reftex-label-menu-flags 0))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1968 (context (not (reftex-typekey-check
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1969 typekey reftex-label-menu-flags 3)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1970 (counter (reftex-typekey-check
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1971 typekey reftex-label-menu-flags 2))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1972 (follow (reftex-typekey-check
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1973 typekey reftex-label-menu-flags 4))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1974 offset rtn key cnt entry)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1975
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1976 (setq reftex-call-back-to-this-buffer buf)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1977 (setq entry (cons nil nil))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1978
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1979 (unwind-protect
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1980 (catch 'exit
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1981 (while t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1982 (save-window-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1983 (switch-to-buffer-other-window "*RefTeX Select*")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1984 (erase-buffer)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1985 (setq truncate-lines t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1986 (setq reftex-label-index-list (reftex-make-and-insert-label-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1987 typekey buf toc context counter
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1988 near-label))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1989 (setq near-label "_ ") ; turn off search for near label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1990 (setq offset (or (car reftex-label-index-list) offset))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1991 ;; use only when searched
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1992 (setq reftex-label-index-list (cdr reftex-label-index-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1993 ;; only this is the true list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1994 (if (not reftex-label-index-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1995 (error "No labels of type \"%s\"" typekey))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1996 (setq rtn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1997 (reftex-select-item
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1998 nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1999 "Label: [n]ext [p]rev [r]escan [t]oc [ ]context [q]uit RETURN [?]HELP+more"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2000 "^>"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2001 "\n[^.]"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2002 2
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2003 reftex-reference-label-help
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2004 '(?r ?g ?c ?t ?s ?# ?a)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2005 offset
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2006 'reftex-select-label-callback follow))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2007 (setq key (car rtn)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2008 cnt (cdr rtn)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2009 offset (1+ cnt))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2010 (if (not key) (throw 'exit nil))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2011 (cond
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2012 ((or (equal key ?r)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2013 (equal key ?g))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2014 ;; rescan buffer
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2015 (reftex-parse-document buf))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2016 ((equal key ?c)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2017 ;; toggle context mode
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2018 (setq context (not context)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2019 ((equal key ?s)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2020 ;; switch type
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2021 (setq typekey (reftex-query-label-type)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2022 ((equal key ?t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2023 ;; toggle tabel of contents display
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2024 (setq toc (not toc)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2025 ((equal key ?#)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2026 ;; toggle counter display
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2027 (setq counter (not counter)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2028 ((equal key ?a)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2029 ;; reuse the last referenced label again
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2030 (setq entry reftex-last-used-reference)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2031 (throw 'exit t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2032 (t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2033 (set-buffer buf)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2034 (setq entry (nth (nth cnt reftex-label-index-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2035 (symbol-value reftex-list-of-labels-symbol)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2036 (setq reftex-last-used-reference entry)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2037 (throw 'exit t))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2038 (kill-buffer "*RefTeX Select*")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2039 (reftex-kill-temporary-buffers))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2040 (cons (reftex-no-props (nth 0 entry)) (nth 3 entry))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2041
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2042 ;; Indentation for table of context lines in the menu
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2043 (defconst reftex-toc-indent " ")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2044 ;; Indentation for the lines containing the label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2045 (defconst reftex-label-indent "> ")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2046 ;; Indentation for context lines
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2047 (defconst reftex-context-indent ". ")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2048 ;; Indentation per section level
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2049 (defvar reftex-level-indent 2
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2050 "*Number of spaces to be used for indentation per section level.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2051 With more indentation, the label menu looks nicer, but shows less context.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2052 Changing this is only fully operational after the next buffer scan.")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2053
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2054 (defun reftex-make-and-insert-label-list (typekey0 buf toc context
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2055 counter near-label)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2056 ;; Insert a menu of all labels in buffer BUF into current buffer.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2057 ;; Return the list of labels, with the index of NEAR-LABEL as extra car.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2058 (let (ins-list index-list offset)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2059 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2060 (set-buffer buf)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2061 (let* ((all nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2062 (font (reftex-use-fonts))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2063 (cnt 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2064 (file nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2065 (index -1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2066 (toc-indent reftex-toc-indent)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2067 (label-indent
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2068 (concat reftex-label-indent
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2069 (if toc (make-string (* 7 reftex-level-indent) ?\ ) "")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2070 (context-indent
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2071 (concat reftex-context-indent
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2072 (if toc (make-string (* 7 reftex-level-indent) ?\ ) "")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2073 cell text label typekey note comment)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2074
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2075 ; Ensure access to scanning info
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2076 (reftex-access-scan-info)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2077
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2078 (setq all (symbol-value reftex-list-of-labels-symbol))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2079
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2080 (while all
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2081
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2082 (setq index (1+ index)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2083 cell (car all)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2084 all (cdr all))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2085
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2086 (if (null (nth 2 cell))
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2087 ;; No context yet. Quick update
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2088 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2089 (setq cell (reftex-label-info-update cell))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2090 (setcar (nthcdr index
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2091 (symbol-value reftex-list-of-labels-symbol))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2092 cell)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2093
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2094 ;; in the following setq we *copy* the label, since we will change
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2095 ;; its properties, and we cannot have any properties in the list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2096 ;; (because of assoc searches)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2097 (setq label (copy-sequence (nth 0 cell))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2098 typekey (nth 1 cell)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2099 text (nth 2 cell)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2100 file (nth 3 cell)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2101 note (nth 4 cell)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2102 comment (get-text-property 0 'in-comment text))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2103
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2104 (if (string= label near-label)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2105 (setq offset (1+ cnt)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2106
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2107 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2108 ((and toc (string= typekey "toc"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2109 (setq ins-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2110 (cons (concat toc-indent text "\n")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2111 ins-list)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2112 ((string= typekey "toc"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2113 ((and (or (string= typekey typekey0) (string= typekey0 " "))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2114 (or (nth 5 reftex-label-menu-flags) ; show-commented?
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2115 (null comment)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2116 (setq cnt (1+ cnt))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2117 (if comment (setq label (concat "% " label)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2118 (if font
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2119 (put-text-property
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2120 0 (length label)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2121 'face
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2122 (if comment
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2123 'font-lock-comment-face
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2124 'font-lock-reference-face)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2125 label))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2126 (setq index-list (cons index index-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2127 (setq ins-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2128 (cons (concat
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2129 label-indent
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2130 label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2131 (if counter (format " (%d) " cnt))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2132 (if comment " LABEL IS COMMENTED OUT ")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2133 (if note (concat " " note) "")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2134 "\n"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2135 (if context (concat context-indent text "\n")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2136 ins-list))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2137 )))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2138
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2139 (apply 'insert (nreverse ins-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2140 (cons offset (nreverse index-list))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2141
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2142 (defun reftex-query-label-type ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2143 ;; Ask for label type
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2144 (message reftex-type-query-prompt)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2145 (let ((key (read-char)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2146 (if (equal key ?\?)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2147 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2148 (save-window-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2149 (with-output-to-temp-buffer "*RefTeX Help*"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2150 (princ reftex-type-query-help))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2151 (setq key (read-char))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2152 (kill-buffer "*RefTeX Help*"))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2153 (if (not (member (char-to-string key) reftex-typekey-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2154 (error "No such label type: %s" (char-to-string key)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2155 (char-to-string key)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2156
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2157 (defun reftex-find-nearby-label ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2158 ;; Find a nearby label.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2159 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2160 (if (or (re-search-backward "\\\\label{\\([^}]+\\)}" nil t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2161 (re-search-forward "\\\\label{\\([^}]+\\)}" nil t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2162 (reftex-no-props (match-string 1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2163 nil)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2164
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2165 ;; Variable holding the vector with section numbers
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2166 (defvar reftex-section-numbers [0 0 0 0 0 0 0 0])
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2167
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2168 (defun reftex-scan-buffer-for-labels (label-numbers-symbol label-list-symbol)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2169 ;; Scan the buffer for labels and save them in a list.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2170 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2171 (let ((regexp (concat "\\\\label{\\([^}]*\\)}" "\\|"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2172 reftex-section-regexp))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2173 (font (reftex-use-fonts))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2174 (bound 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2175 (highest-level 100)
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2176 file (level 1) star text text1 label section-number macro find)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2177 (set label-list-symbol nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2178 (goto-char 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2179
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2180 ;; reset label numbers
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2181 (set label-numbers-symbol
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2182 (mapcar '(lambda(x) (cons x 0)) reftex-typekey-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2183
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2184 ;; reset section numbers
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2185 (reftex-section-number reftex-section-numbers -1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2186
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2187 (while (re-search-forward regexp nil t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2188 (setq file (get-text-property (match-beginning 0) 'file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2189 (if (string= (buffer-substring (match-beginning 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2190 (+ 7 (match-beginning 0))) "\\label{")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2191 ;; It is a label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2192 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2193 (setq label (reftex-no-props (match-string 1)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2194 (set label-list-symbol
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2195 (cons (reftex-label-info label file bound)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2196 (symbol-value label-list-symbol))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2197
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2198 ;; It is a section
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2199 (setq bound (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2200 (setq star (= ?* (char-after (match-end 2))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2201 (setq find (buffer-substring-no-properties
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2202 (1- (match-beginning 2)) (match-end 0)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2203 (setq macro (reftex-no-props (match-string 2)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2204 (setq level (cdr (assoc macro reftex-section-levels)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2205
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2206 (setq section-number (reftex-section-number
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2207 reftex-section-numbers level star))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2208 (setq highest-level (min highest-level level))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2209 (if (= level highest-level)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2210 (message
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2211 "Scanning %s %s ..."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2212 (car (nth level reftex-section-levels))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2213 section-number))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2214
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2215 ;; get the title
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2216 (save-match-data
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2217 (setq text1 (reftex-context-substring))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2218 (setq text (reftex-nicify-text text1)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2219
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2220 (setq find (reftex-allow-for-ctrl-m (concat find text1)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2221
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2222 ;; add section number and indentation
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2223 (setq text
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2224 (concat
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2225 (make-string (* reftex-level-indent level) ?\ )
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2226 (if (nth 1 reftex-label-menu-flags) ; section number flag
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2227 (concat section-number " "))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2228 text))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2229 ;; fontify
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2230 (if font (put-text-property 0 (length text)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2231 'face 'font-lock-comment-face text))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2232
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2233 ;; insert in list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2234 (set label-list-symbol
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2235 (cons (list nil "toc" text file find)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2236 (symbol-value label-list-symbol)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2237 (set label-list-symbol
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2238 (nreverse (symbol-value label-list-symbol))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2239
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2240
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2241 (defun reftex-label-info-update (cell)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2242 ;; Update information about just one label in a different file.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2243 ;; CELL contains the old info list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2244 (let* ((label (nth 0 cell))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2245 (typekey (nth 1 cell))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2246 (text (nth 2 cell))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2247 (file (nth 3 cell))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2248 (note (nth 4 cell))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2249 (buf (reftex-get-file-buffer-force
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2250 file (not reftex-keep-temporary-buffers))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2251 (if (not buf)
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2252 (list label typekey "" file "LOST LABEL. RESCAN TO FIX.")
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2253 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2254 (set-buffer buf)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2255 (save-restriction
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2256 (widen)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2257 (goto-char 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2258
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2259 (if (re-search-forward (concat "\\\\label{" (regexp-quote label) "}")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2260 nil t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2261 (append (reftex-label-info label file) (list note))
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2262 (list label typekey "" file "LOST LABEL. RESCAN TO FIX.")))))))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2263
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2264 (defun reftex-label-info (label &optional file bound)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2265 ;; Return info list on LABEL at point.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2266 (let* ((env-or-mac (reftex-label-location bound))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2267 (typekey (nth 1 (assoc env-or-mac reftex-env-or-mac-alist)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2268 (file (or file (buffer-file-name)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2269 (parse (if (reftex-typekey-check
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2270 typekey reftex-use-text-after-label-as-context)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2271 nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2272 (nth 2 (assoc env-or-mac reftex-env-or-mac-alist))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2273 (text (reftex-short-context env-or-mac parse reftex-location-start)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2274 (if (reftex-in-comment)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2275 (put-text-property 0 1 'in-comment t text))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2276 (list label typekey text file)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2277
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2278 (defun reftex-in-comment ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2279 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2280 (skip-chars-backward "^%\n\r")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2281 (= (preceding-char) ?%)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2282
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2283 (defun reftex-short-context (env parse &optional bound)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2284 ;; Get about one line of useful context for the label definition at point.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2285
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2286 (reftex-nicify-text
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2287
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2288 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2289
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2290 ((null parse)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2291 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2292 (reftex-context-substring)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2293
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2294 ((eq parse t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2295 (if (string= env "section")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2296 ;; special treatment for section labels
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2297 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2298 (if (re-search-backward reftex-section-regexp (point-min) t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2299 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2300 (goto-char (match-end 0))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2301 (reftex-context-substring))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2302 "SECTION HEADING NOT FOUND"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2303 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2304 (goto-char reftex-default-context-position)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2305 (reftex-context-substring))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2306
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2307 ((stringp parse)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2308 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2309 (if (re-search-backward parse bound t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2310 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2311 (goto-char (match-end 0))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2312 (reftex-context-substring))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2313 "NO MATCH FOR CONTEXT REGEXP")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2314 ((fboundp parse)
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2315 ;; A hook function. Call it.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2316 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2317 (condition-case error-var
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2318 (funcall parse env)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2319 ('error (format "HOOK ERROR: %s" (cdr error-var))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2320 (t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2321 "ILLEGAL VALUE OF PARSE"))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2322
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2323 (defun reftex-context-substring ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2324 ;; Return up to 100 chars from point
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2325 ;; When point is just after a { or [, limit string to matching parenthesis
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2326 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2327 ((or (= (preceding-char) ?\{)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2328 (= (preceding-char) ?\[))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2329 ;; inside a list - get only the list, with modified syntax to be perfect
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2330 (buffer-substring
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2331 (point)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2332 (min (+ 100 (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2333 (point-max)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2334 (condition-case nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2335 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2336 (up-list 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2337 (1- (point)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2338 ('error (point-max))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2339 (t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2340 ;; no list - just grab 100 characters
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2341 (buffer-substring (point) (min (+ 100 (point)) (point-max))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2342
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2343 (defun reftex-section-number (section-numbers &optional level star)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2344 ;; Return a string with the current section number.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2345 ;; When LEVEL is non-nil, increase section numbers on that level.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2346 (let* ((depth 6) idx n (string ""))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2347 (if level
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2348 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2349 (if (and (> level -1) (not star))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2350 (aset section-numbers level (1+ (aref section-numbers level))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2351 (setq idx (1+ level))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2352 (while (<= idx depth)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2353 (aset section-numbers idx 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2354 (setq idx (1+ idx)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2355 (setq idx 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2356 (while (<= idx depth)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2357 (setq n (aref section-numbers idx))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2358 (setq string (concat string (if (not (string= string "")) "." "")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2359 (int-to-string n)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2360 (setq idx (1+ idx)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2361 (save-match-data
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2362 (if (string-match "\\`\\(0\\.\\)+" string)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2363 (setq string (replace-match "" nil nil string)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2364 (if (string-match "\\(\\.0\\)+\\'" string)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2365 (setq string (replace-match "" nil nil string))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2366 (if star
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2367 (concat (make-string (1- (length string)) ?\ ) "*")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2368 string)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2369
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2370 ;; A variable to remember the index of the last label context shown
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2371 (defvar reftex-last-cnt 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2372
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2373 (defun reftex-select-label-callback (cnt)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2374 ;; Callback function called from the label selection in order to
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2375 ;; show context in another window
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2376 (let* ((this-window (selected-window))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2377 index entry label file buffer)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2378 ;; pop to original buffer in order to get correct variables
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2379 (catch 'exit
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2380 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2381 (set-buffer reftex-call-back-to-this-buffer)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2382 (setq index (nth (or cnt 1) reftex-label-index-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2383 entry (nth index (symbol-value reftex-list-of-labels-symbol))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2384 label (nth 0 entry)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2385 file (nth 3 entry)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2386
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2387 ;; goto the file in another window
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2388 (setq buffer (reftex-get-file-buffer-force
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2389 file (not reftex-keep-temporary-buffers)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2390 (if buffer
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2391 ;; good - the file is available
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2392 (switch-to-buffer-other-window buffer)
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2393 ;; we have got a problem here. The file does not exist.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2394 ;; Let' get out of here..
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2395 (ding)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2396 (throw 'exit nil))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2397
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2398
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2399 ;; search for that label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2400 (if (not (and (integerp cnt)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2401 (integerp reftex-last-cnt)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2402 (if (> cnt reftex-last-cnt)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2403 (search-forward (concat "\\label{" label "}") nil t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2404 (search-backward (concat "\\label{" label "}") nil t))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2405 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2406 (goto-char 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2407 (search-forward (concat "\\label{" label "}") nil t)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2408 (reftex-highlight 0 (match-beginning 0) (match-end 0))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2409 (reftex-show-entry)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2410 (recenter (/ (window-height) 2))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2411 (select-window this-window))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2412
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2413 (defun reftex-pop-to-label (label file-list &optional mark-to-kill highlight)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2414 ;; Find LABEL in any file in FILE-LIST in another window.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2415 ;; If mark-to-kill is non-nil, mark new buffer for killing.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2416 ;; If HIGHLIGHT is non-nil, highlight the label definition.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2417 (let* ((re (concat "\\\\label{" (regexp-quote label) "}"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2418 file buf)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2419 (catch 'exit
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2420 (while file-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2421 (setq file (car file-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2422 file-list (cdr file-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2423 (if (not (setq buf (reftex-get-file-buffer-force file mark-to-kill)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2424 (error "No such file %s" file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2425 (set-buffer buf)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2426 (widen)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2427 (goto-char (point-min))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2428 (if (re-search-forward re nil t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2429 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2430 (switch-to-buffer-other-window buf)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2431 (goto-char (match-beginning 0))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2432 (recenter (/ (window-height) 2))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2433 (if highlight
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2434 (reftex-highlight 0 (match-beginning 0) (match-end 0)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2435 (throw 'exit (selected-window)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2436 (error "Label %s not found" label))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2437
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2438 (defun reftex-find-duplicate-labels ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2439 "Produce a list of all duplicate labels in the document."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2440
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2441 (interactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2442
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2443 ;; Rescan the document to make sure
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2444 (reftex-access-scan-info t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2445
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2446 (let ((master (reftex-TeX-master-file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2447 (dlist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2448 (mapcar
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2449 '(lambda(x)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2450 (let (x1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2451 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2452 ((car x)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2453 (setq x1 (reftex-all-assoc-string
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2454 (car x) (symbol-value reftex-list-of-labels-symbol)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2455 (if (< 1 (length x1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2456 (append (list (reftex-no-props (car x)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2457 (mapcar '(lambda(x)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2458 (abbreviate-file-name (nth 3 x))) x1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2459 (list nil)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2460 (t nil))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2461 (reftex-uniquify (symbol-value reftex-list-of-labels-symbol)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2462 (setq dlist (reftex-uniquify dlist))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2463 (if (null dlist) (error "No duplicate labels in document"))
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2464 (switch-to-buffer-other-window "*Duplicate Labels*")
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2465 (make-local-variable 'TeX-master)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2466 (setq TeX-master master)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2467 (erase-buffer)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2468 (insert " MULTIPLE LABELS IN CURRENT DOCUMENT:\n")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2469 (insert " Move point to label and type `M-x reftex-change-label'\n"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2470 " This will run a query-replace on the label and its references\n")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2471 (insert " LABEL FILE\n")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2472 (insert " -------------------------------------------------------------\n")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2473 (while dlist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2474 (if (and (car (car dlist))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2475 (cdr (car dlist)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2476 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2477 (insert (mapconcat '(lambda(x) x) (car dlist) "\n ") "\n")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2478 (setq dlist (cdr dlist)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2479 (goto-char (point-min))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2480
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2481 (defun reftex-all-assoc-string (key list)
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2482 ;; Return a list of all associations of KEY in LIST. Comparison with string=
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2483 (let (rtn)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2484 (while list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2485 (if (string= (car (car list)) key)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2486 (setq rtn (cons (car list) rtn)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2487 (setq list (cdr list)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2488 (nreverse rtn)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2489
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2490 (defun reftex-kill-temporary-buffers ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2491 ;; Kill all buffers in the list reftex-kill-temporary-buffers.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2492 (while reftex-buffers-to-kill
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2493 (if (bufferp (car reftex-buffers-to-kill))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2494 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2495 (and (buffer-modified-p (car reftex-buffers-to-kill))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2496 (y-or-n-p (format "Save file %s? "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2497 (buffer-file-name
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2498 (car reftex-buffers-to-kill))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2499 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2500 (set-buffer (car reftex-buffers-to-kill))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2501 (save-buffer)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2502 (kill-buffer (car reftex-buffers-to-kill))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2503 (setq reftex-buffers-to-kill (cdr reftex-buffers-to-kill))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2504
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2505 (defun reftex-show-entry ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2506 ;; Show entry if point is hidden by outline mode
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2507 (let ((pos (point)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2508 (if (and reftex-auto-show-entry
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2509 (boundp 'outline-minor-mode)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2510 outline-minor-mode
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2511 (looking-at "[^\n\r]*\r"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2512 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2513 (outline-back-to-heading)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2514 (show-entry)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2515 (goto-char pos)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2516
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2517
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2518 (defun reftex-nicify-text (text)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2519 ;; Make TEXT nice for inclusion into label menu
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2520 (while (string-match "[\n\r\t]\\|[ \t][ \t]+" text) ; remove extra whitespace
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2521 (setq text (replace-match " " nil t text)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2522 (if (string-match "\\\\end{.*" text) ; nothing beyond \end{
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2523 (setq text (replace-match "" nil t text)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2524 (if (string-match "\\\\label{[^}]*}" text) ; kill the label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2525 (setq text (replace-match "" nil t text)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2526 (if (string-match "^ +" text) ; leading whitespace
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2527 (setq text (replace-match "" nil t text)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2528 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2529 ((> (length text) 100) ; not to long
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2530 (setq text (substring text 0 100)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2531 ((= (length text) 0) ; not empty
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2532 (setq text " ")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2533 text)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2534
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2535 (defun reftex-typekey-check (typekey conf-variable &optional n)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2536 ;; Check if CONF-VARIABLE is true or contains TYPEKEY
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2537 (and n (setq conf-variable (nth n conf-variable)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2538 (or (equal conf-variable t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2539 (and (stringp conf-variable)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2540 (string-match (concat "[" conf-variable "]") typekey))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2541
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2542 ;;; ===========================================================================
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2543 ;;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2544 ;;; Table of contents (contributed from Stephen Eglen, changed by C. Dominik)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2545
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2546 ;; We keep at most one *toc* buffer - it is easy to make them
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2547
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2548 (defvar reftex-last-toc-master nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2549 "Stores the name of the tex file that `reftex-toc' was last run on.")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2550
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2551 (defvar reftex-last-toc-file nil
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2552 "Stores the file name from which `reftex-toc' was called. For redo command.")
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2553
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2554 (defvar reftex-toc-return-marker (make-marker)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2555 "Marker which makes it possible to return from toc to old position.")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2556
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2557 (defun reftex-toc ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2558 "Show the table of contents for the current document.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2559 To see the corresponding part of the LaTeX document, use within the
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2560 *toc* buffer:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2561
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2562 SPC Show the corresponding section of the LaTeX document.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2563 RET Goto the section and hide the *toc* buffer.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2564 q Hide the *toc* window and return to position of last reftex-toc command.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2565 Q Kill the *toc* buffer and return to position of last reftex-toc command.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2566 f Toggle follow mode on and off.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2567 r Reparse the LaTeX document.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2568 g Revert buffer (like `r').
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2569
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2570 When called with a raw C-u prefix, rescan the document first."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2571
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2572 (interactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2573
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2574 (and (not (string= reftex-last-toc-master (reftex-TeX-master-file)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2575 (get-buffer "*toc*")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2576 (kill-buffer "*toc*"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2577
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2578 (setq reftex-last-toc-file (buffer-file-name))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2579 (setq reftex-last-toc-master (reftex-TeX-master-file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2580
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2581 (set-marker reftex-toc-return-marker (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2582
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2583 ;; if follow mode is active, arrange to delay it one command
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2584 (if reftex-toc-follow-mode
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2585 (setq reftex-toc-follow-mode 1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2586
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2587 (if (and current-prefix-arg
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2588 (get-buffer "*toc*"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2589 (kill-buffer "*toc*"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2590
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2591 ;; Ensure access to scanning info and rescan buffer if prefix are is '(4)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2592 (reftex-access-scan-info current-prefix-arg)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2593
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2594 (let* ((all (symbol-value reftex-list-of-labels-symbol))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2595 (where (reftex-nearest-section))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2596 toc toc1 cell label file find startpos)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2597
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2598 (if (and (get-buffer "*toc*")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2599 (get-buffer-window (get-buffer "*toc*")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2600 (select-window (get-buffer-window (get-buffer "*toc*")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2601 (delete-other-windows)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2602 (switch-to-buffer-other-window (current-buffer))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2603 (switch-to-buffer-other-window (get-buffer-create "*toc*")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2604
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2605 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2606 ;; buffer is empty - fill it with the table of contents
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2607 ((= (buffer-size) 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2608
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2609 (local-set-key " " 'reftex-toc-view-line)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2610 (local-set-key "\C-m" 'reftex-toc-goto-line-and-hide)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2611 (local-set-key "r" 'reftex-toc-redo)
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2612 (local-set-key "g" 'revert-buffer)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2613 (local-set-key "q" 'reftex-toc-quit)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2614 (local-set-key "Q" 'reftex-toc-quit-and-kill)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2615 (local-set-key "f" 'reftex-toc-toggle-follow)
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2616 (make-local-variable 'revert-buffer-function)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2617 (setq revert-buffer-function 'reftex-toc-redo)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2618 (setq truncate-lines t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2619 (make-local-hook 'post-command-hook)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2620 (make-local-hook 'pre-command-hook)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2621 (setq post-command-hook '(reftex-toc-post-command-hook))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2622 (setq pre-command-hook '(reftex-toc-pre-command-hook))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2623
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2624 (insert (format
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2625 "TABLE-OF-CONTENTS on %s
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2626 MENU: SPC=view RET=goto [q]uit [Q]uit+kill [r]escan [f]ollow-mode
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2627 -------------------------------------------------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2628 " (abbreviate-file-name reftex-last-toc-master)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2629 (setq startpos (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2630
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2631 (if (reftex-use-fonts)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2632 (put-text-property 1 (point) 'face 'font-lock-keyword-face))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2633 (put-text-property 1 (point) 'intangible t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2634
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2635 (while all
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2636 (setq cell (car all)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2637 all (cdr all))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2638 (setq label (nth 0 cell)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2639 toc (nth 2 cell)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2640 file (nth 3 cell)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2641 find (nth 4 cell))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2642 (if (not label)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2643 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2644 (setq toc1 (concat toc "\n"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2645 (put-text-property 0 (length toc1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2646 'file file toc1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2647 (put-text-property 0 (length toc1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2648 'find find toc1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2649 (insert toc1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2650 )))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2651
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2652 (backward-delete-char 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2653
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2654 (setq buffer-read-only t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2655 (t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2656 (goto-line 3)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2657 (beginning-of-line)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2658 (setq startpos (point))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2659
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2660 ;; Find the correct section
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2661 (goto-char (point-max))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2662 (beginning-of-line)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2663 (while (and (> (point) startpos)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2664 (or (not (string= (get-text-property (point) 'file)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2665 (car where)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2666 (not (string= (get-text-property (point) 'find)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2667 (cdr where)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2668 (beginning-of-line 0))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2669
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2670 (defun reftex-nearest-section ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2671 ;; Return (file . find) of nearest section command
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2672 (let (cell label rest)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2673 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2674 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2675 ;; Try to find a section heading
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2676 ((or (re-search-backward reftex-section-regexp nil t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2677 (re-search-forward reftex-section-regexp nil t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2678 (goto-char (match-end 0))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2679 (cons (buffer-file-name)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2680 (reftex-allow-for-ctrl-m
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2681 (concat (buffer-substring-no-properties
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2682 (1- (match-beginning 1)) (match-end 0))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2683 (reftex-context-substring)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2684 ;; Try to find a label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2685 ((and (or (re-search-backward "\\\\label{\\([^}]+\\)}" nil t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2686 (re-search-forward "\\\\label{\\([^}]+\\)}" nil t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2687 (setq label (reftex-no-props (match-string 1)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2688 (setq cell (assoc label (symbol-value
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2689 reftex-list-of-labels-symbol)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2690 (setq rest (memq cell (symbol-value reftex-list-of-labels-symbol)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2691 (setq cell (car (memq (assoc nil rest) rest)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2692 (null (car cell)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2693 (cons (nth 3 cell) (nth 4 cell)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2694 (t nil)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2695
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2696 (defun reftex-toc-pre-command-hook ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2697 ;; used as pre command hook in *toc* buffer
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2698 (reftex-unhighlight 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2699 (reftex-unhighlight 1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2700
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2701 (defun reftex-toc-post-command-hook ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2702 ;; used in the post-command-hook for the *toc* buffer
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2703 (and (> (point) 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2704 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2705 (reftex-highlight 1
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2706 (progn (beginning-of-line) (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2707 (progn (end-of-line) (point)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2708 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2709 ((integerp reftex-toc-follow-mode)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2710 ;; remove delayed action
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2711 (setq reftex-toc-follow-mode t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2712 (reftex-toc-follow-mode
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2713 ;; show context in other window
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2714 (condition-case nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2715 (reftex-toc-visit-line)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2716 ('error t)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2717
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2718 (defun reftex-toc-toggle-follow ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2719 "Toggle toc-follow mode.
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2720 (It is not really a mode, just a flag)."
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2721 (interactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2722 (setq reftex-toc-follow-mode (not reftex-toc-follow-mode)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2723 (defun reftex-toc-view-line ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2724 "View document location in other window."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2725 (interactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2726 (reftex-toc-visit-line))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2727 (defun reftex-toc-goto-line-and-hide ()
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2728 "Go to document location in other window. Hide the *toc* window."
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2729 (interactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2730 (reftex-toc-visit-line 'hide))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2731 (defun reftex-toc-quit ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2732 "Hide the *toc* window and do not move point."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2733 (interactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2734 (delete-window)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2735 (switch-to-buffer (marker-buffer reftex-toc-return-marker))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2736 (goto-char (marker-position reftex-toc-return-marker)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2737 (defun reftex-toc-quit-and-kill ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2738 "Kill the *toc* buffer."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2739 (interactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2740 (kill-buffer "*toc*")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2741 (delete-window)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2742 (switch-to-buffer (marker-buffer reftex-toc-return-marker))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2743 (goto-char (marker-position reftex-toc-return-marker)))
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2744 (defun reftex-toc-redo (&rest ignore)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2745 "Regenerate the *toc* buffer. Call only from within the *toc* buffer"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2746 (interactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2747 (switch-to-buffer (reftex-get-file-buffer-force reftex-last-toc-file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2748 (delete-other-windows)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2749 (setq current-prefix-arg '(4))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2750 (reftex-toc))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2751
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2752 (defun reftex-toc-visit-line (&optional final)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2753 ;; Visit the tex file corresponding to the toc entry on the current line.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2754 ;; If FINAL is t, stay there
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2755 ;; If FINAL is 'hide, hide the *toc* window.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2756 ;; Otherwise, move cursor back into *toc* window
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2757
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2758 (let (file find beg end (toc-window (selected-window)) show-window)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2759 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2760 (beginning-of-line)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2761 (setq beg (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2762 (end-of-line)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2763 (setq end (point)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2764
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2765 ;; get the file and the search string
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2766 (setq file (get-text-property (point) 'file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2767 (setq find (get-text-property (point) 'find))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2768 (if (or (not file) (not find))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2769 (error "Cannot visit line"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2770
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2771 (switch-to-buffer-other-window (reftex-get-file-buffer-force file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2772 (setq show-window (selected-window))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2773 (goto-char (point-min))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2774
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2775 (if (not (re-search-forward find nil t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2776 (error "Cannot visit line"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2777
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2778 (setq beg (match-beginning 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2779 end (match-end 0))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2780
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2781 (goto-char beg)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2782 (recenter 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2783 (reftex-highlight 0 beg end (current-buffer))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2784
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2785 (select-window toc-window)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2786
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2787 ;; use the `final' parameter to decide what to do next
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2788 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2789 ((equal final t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2790 (reftex-unhighlight 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2791 (select-window show-window))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2792 ((eq final 'hide)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2793 (reftex-unhighlight 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2794 (delete-window))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2795 (t nil))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2796
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2797 ;;; ===========================================================================
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2798 ;;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2799 ;;; BibTeX citations.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2800
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2801 ;; Variables and constants
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2802
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2803 ;; Define variable to silence compiler warnings
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2804 (defvar reftex-found-list)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2805
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2806 ;; Internal variable, but used from different functions
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2807 (defvar reftex-cite-format1 nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2808
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2809 ;; The history list of regular expressions used for citations
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2810 (defvar reftex-cite-regexp-hist nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2811
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2812 ;; Help string for citation selection
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2813 (defconst reftex-citation-help
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2814 "AVAILABLE KEYS IN MAKE CITATION MENU
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2815 ---------------------------------------
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2816 n / p Go to next/previous entry (Cursor motion works as well).
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2817 r Restrict selection with another regexp.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2818 SPACE Show full database entry in other window.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2819 f Toggle follow mode: Other window will follow with full db entry.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2820 q Quit without inserting \\cite macro into buffer.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2821 ? Display this help message.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2822 C-r Recursive edit into other window.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2823 RETURN ... Accept current entry and insert in format according to
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2824 `reftex-cite-format'")
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2825
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2826 (defconst reftex-cite-format-default "\\cite{KEY}"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2827 "The default value for reftex-cite-format.
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2828 Uses the string version of `reftex-cite-format'.")
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2829
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2830 (defconst reftex-cite-format-1-author-simple
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2831 '( "\\cite{KEY}" "AUTHOR \\cite{KEY}" "AUTHOR {\it et al.} \\cite{KEY}")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2832 "Value for reftex-cite format establishing a simple citation with name
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2833 of the first author.
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2834 Uses the list version of `reftex-cite-format'.")
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2835
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2836 (defconst reftex-cite-format-2-authors
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2837 '((?\C-m
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2838 . ( "\\cite{KEY}" "AUTHOR \\cite{KEY}"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2839 "AUTHOR \\& AUTHOR \\cite{KEY}" "AUTHOR \\etal{} \\cite{KEY}"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2840 (?\,
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2841 . ("\\cite{KEY}" "AUTHOR, \\cite{KEY}"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2842 "AUTHOR \\& AUTHOR, \\cite{KEY}" "AUTHOR \\etal{}, \\cite{KEY}"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2843 (?\;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2844 . ("\\cite{KEY}" "AUTHOR; \\cite{KEY}"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2845 "AUTHOR \\& AUTHOR; \\cite{KEY}" "AUTHOR \\etal{}; \\cite{KEY}"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2846 (?\:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2847 . ("\\cite{KEY}" "AUTHOR: \\cite{KEY}"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2848 "AUTHOR \\& AUTHOR: \\cite{KEY}" "AUTHOR \\etal{}: \\cite{KEY}"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2849 (?\(
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2850 . ("(\\cite{KEY})" "AUTHOR (\\cite{KEY})"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2851 "AUTHOR \\& AUTHOR (\\cite{KEY})" "AUTHOR \\etal{} (\\cite{KEY})"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2852 (?\[
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2853 . ("[\\cite{KEY}]" "AUTHOR [\\cite{KEY}]"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2854 "AUTHOR \\& AUTHOR [\\cite{KEY}]" "AUTHOR \\etal{} [\\cite{KEY}]")))
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2855 "Value for `reftex-cite-format' that estabishes an Author/Year citation
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2856 where the year is supplied from BibTeX. Depending on which character
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2857 is used during selection to accept the label, an extra ,;: or pair of
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2858 parenthesis will be inserted.
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2859 Uses the list-of-cons-cells version of `reftex-cite-format'.")
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2860
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2861 ;; Find bibtex files
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2862
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2863 (defun reftex-get-bibfile-list ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2864 ;; Return list of bibfiles for current document
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2865
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2866 ;; Ensure access to scanning info
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2867 (reftex-access-scan-info)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2868
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2869 (or (symbol-value reftex-bibfile-list-symbol)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2870 (error "No BibTeX files to parse. Add \\bibliography statment to document and reparse.")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2871
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2872 (defun reftex-scan-buffer-for-bibliography-statement (bib-list-symbol)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2873 ;; Scan buffer for bibliography macro and store file list in bib-list-symbol.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2874 (let (file-list dir-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2875 (setq dir-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2876 (reftex-split
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2877 (concat path-separator "+")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2878 (mapconcat '(lambda(x)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2879 (if (getenv x) (getenv x) ""))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2880 reftex-bibpath-environment-variables
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2881 path-separator)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2882 (goto-char (point-min))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2883 (if (re-search-forward "^[ \t]*\\\\bibliography{[ \t]*\\([^}]+\\)" nil t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2884 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2885 (setq dir-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2886 (cons (file-name-directory
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2887 (get-text-property (match-beginning 0) 'file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2888 dir-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2889 (setq file-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2890 (mapcar '(lambda (x) (concat x ".bib"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2891 (reftex-delete-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2892 reftex-bibfile-ignore-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2893 (reftex-split
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2894 "[ \t\n]*,[ \t\n]*"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2895 (reftex-no-props (match-string 1)))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2896 (message "No \\bibliography command in document."))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2897 (set bib-list-symbol
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2898 (if file-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2899 (reftex-find-files-on-path file-list dir-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2900 "While parsing \\bibliography:")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2901 nil))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2902
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2903 (defun reftex-find-files-on-path (file-list path-list &optional error-string)
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2904 ;; Search for all files in FILE-LIST on the PATH-LIST. Return absolute names.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2905 ;; A missing file throws an exception with the error message ERROR-STRING.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2906 (let (found-list found file)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2907 (while file-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2908 (setq file (car file-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2909 file-list (cdr file-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2910 found nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2911 (if (file-name-absolute-p file)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2912 (setq found (expand-file-name file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2913 (let ((dirs path-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2914 (while (and dirs (not found))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2915 (if (and (not (string= (car dirs) ""))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2916 (file-exists-p (expand-file-name file (car dirs))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2917 (setq found (expand-file-name file (car dirs))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2918 (setq dirs (cdr dirs)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2919 (if (and found
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2920 (file-exists-p found))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2921 (add-to-list 'found-list (expand-file-name found))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2922 (error "%s No such file %s."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2923 (or error-string "") file)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2924 (nreverse found-list)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2925
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2926 ;; Find a certain reference in any of the BibTeX files.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2927
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2928 (defun reftex-pop-to-bibtex-entry (key file-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2929 &optional mark-to-kill highlight)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2930 ;; Find BibTeX KEY in any file in FILE-LIST in another window.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2931 ;; If mark-to-kill is non-nil, mark new buffer to kill."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2932
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
2933 (let* ((re (concat "@[a-zA-Z]+[ \t\n\r]*[{(][ \t\n\r]*" (regexp-quote key) "[ \t\n\r,]"))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2934 (window-conf (current-window-configuration))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2935 file buf)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2936 (catch 'exit
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2937 (switch-to-buffer-other-window (current-buffer))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2938 (while file-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2939 (setq file (car file-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2940 file-list (cdr file-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2941 (if (not (setq buf (reftex-get-file-buffer-force file mark-to-kill)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2942 (error "No such file %s" file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2943 (switch-to-buffer buf)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2944 (widen)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2945 (goto-char 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2946 (if (re-search-forward re nil t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2947 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2948 (goto-char (match-beginning 0))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2949 (recenter 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2950 (if highlight
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2951 (reftex-highlight 0 (match-beginning 0) (match-end 0)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2952 (throw 'exit (selected-window)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2953 (set-window-configuration window-conf)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2954 (beep)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2955 (message "No BibTeX entry with citation key %s" key))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2956
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2957 ;; Parse bibtex buffers
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2958
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2959 (defun reftex-extract-bib-entries (buffers &optional get-word)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2960 ;; Extract bib entries which match regexps from BUFFERS.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2961 ;; BUFFERS is a list of buffers or file names.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2962 ;; Return list with entries."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2963 (let* (re-list first-re rest-re
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2964 ;; avoid fontification of lookup buffers
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2965 (lazy-lock-minimum-size 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2966 (buffer-list (if (listp buffers) buffers (list buffers)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2967 found-list entry buffer1 buffer alist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2968 key-point start-point end-point)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2969
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2970 (setq re-list (reftex-split "[ \t]*&&[ \t]*"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2971 (read-string "RegExp [ && RegExp...]: "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2972 nil 'reftex-cite-regexp-hist)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2973
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2974 (setq first-re (car re-list) ; We'll use the first re to find things,
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2975 rest-re (cdr re-list)) ; the other to narrow down.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2976 (if (string-match "\\`[ \t]*\\'" first-re)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2977 (error "Empty regular expression"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2978
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2979 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2980 (save-window-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2981
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2982 ;; walk through all bibtex files
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2983 (while buffer-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2984 (setq buffer (car buffer-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2985 buffer-list (cdr buffer-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2986 (if (and (bufferp buffer)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2987 (buffer-live-p buffer))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2988 (setq buffer1 buffer)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2989 (setq buffer1 (reftex-get-file-buffer-force
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2990 buffer (not reftex-keep-temporary-buffers))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2991 (if (not buffer1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2992 (error "Cannot find BibTeX file %s" buffer)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2993 (message "Scanning bibliography database %s" buffer1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2994
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2995 (set-buffer buffer1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2996 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2997 (goto-char (point-min))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2998 (while (re-search-forward first-re nil t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2999 (catch 'search-again
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3000 (setq key-point (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3001 (if (not (re-search-backward
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3002 "^[ \t]*@\\([a-zA-Z]+\\)[ \t\n\r]*[{(]" nil t))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3003 (throw 'search-again nil))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3004 (setq start-point (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3005 (goto-char (match-end 0))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3006 (condition-case nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3007 (up-list 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3008 ('error (goto-char key-point)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3009 (throw 'search-again nil)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3010 (setq end-point (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3011
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3012 ;; Ignore @string, @comment and @c entries or things
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3013 ;; outside entries
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3014 (if (or (string= (downcase (match-string 1)) "string")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3015 (string= (downcase (match-string 1)) "comment")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3016 (string= (downcase (match-string 1)) "c")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3017 (< (point) key-point)) ; this means match not in {}
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3018 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3019 (goto-char key-point)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3020 (throw 'search-again nil)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3021
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3022 ;; Well, we have got a match
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3023 (setq entry (concat
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3024 (buffer-substring start-point (point)) "\n"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3025
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3026 ;; Check if other regexp match as well
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3027 (setq re-list rest-re)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3028 (while re-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3029 (if (not (string-match (car re-list) entry))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3030 ;; nope - move on
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3031 (throw 'search-again nil))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3032 (setq re-list (cdr re-list)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3033
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3034 (setq alist (reftex-parse-bibtex-entry
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3035 nil start-point end-point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3036 (setq alist (cons (cons "&entry" entry) alist))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3037
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3038 ;; check for crossref entries
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3039 (if (assoc "crossref" alist)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3040 (setq alist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3041 (append
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3042 alist (reftex-get-crossref-alist alist))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3043
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3044 ;; format the entry
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3045 (setq alist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3046 (cons
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3047 (cons "&formatted"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3048 (reftex-format-bib-entry alist))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3049 alist))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3050
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3051 ;; add it to the list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3052 (setq found-list (cons alist found-list)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3053 (reftex-kill-temporary-buffers))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3054 (setq found-list (nreverse found-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3055
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3056 ;; Sorting
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3057 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3058 ((eq 'author reftex-sort-bibtex-matches)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3059 (sort found-list 'reftex-bib-sort-author))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3060 ((eq 'year reftex-sort-bibtex-matches)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3061 (sort found-list 'reftex-bib-sort-year))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3062 ((eq 'reverse-year reftex-sort-bibtex-matches)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3063 (sort found-list 'reftex-bib-sort-year-reverse))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3064 (t found-list))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3065
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3066 (defun reftex-bib-sort-author (e1 e2)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3067 (let ((al1 (reftex-get-bib-authors e1)) (al2 (reftex-get-bib-authors e2)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3068 (while (and al1 al2 (string= (car al1) (car al2)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3069 (setq al1 (cdr al1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3070 al2 (cdr al2)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3071 (if (and (stringp (car al1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3072 (stringp (car al2)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3073 (string< (car al1) (car al2))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3074 (not (stringp (car al1))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3075
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3076 (defun reftex-bib-sort-year (e1 e2)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3077 (< (string-to-int (cdr (assoc "year" e1)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3078 (string-to-int (cdr (assoc "year" e2)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3079
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3080 (defun reftex-bib-sort-year-reverse (e1 e2)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3081 (> (string-to-int (or (cdr (assoc "year" e1)) "0"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3082 (string-to-int (or (cdr (assoc "year" e2)) "0"))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3083
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3084 (defun reftex-get-crossref-alist (entry)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3085 ;; return the alist from a crossref entry
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3086 (let ((crkey (cdr (assoc "crossref" entry)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3087 start)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3088 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3089 (save-restriction
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3090 (widen)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3091 (if (re-search-forward
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3092 (concat "@\\w+[{(][ \t\n\r]*" (regexp-quote crkey) "[ \t\n\r]*,") nil t)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3093 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3094 (setq start (match-beginning 0))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3095 (condition-case nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3096 (up-list 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3097 ('error nil))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3098 (reftex-parse-bibtex-entry nil start (point)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3099 nil)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3100
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3101 ;; Parse and format individual entries
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3102
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3103 (defun reftex-get-bib-authors (entry)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3104 ;; Return a list with the author names in ENTRY
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3105 (let (authors)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3106 (setq authors (reftex-get-bib-field "author" entry))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3107 (if (equal "" authors)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3108 (setq authors (reftex-get-bib-field "editor" entry)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3109 (while (string-match "\\band\\b[ \t]*" authors)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3110 (setq authors (replace-match "\n" nil t authors)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3111 (while (string-match "[\\.a-zA-Z\\-]+\\.[ \t]*\\|,.*\\|[{}]+" authors)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3112 (setq authors (replace-match "" nil t authors)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3113 (while (string-match "^[ \t]+\\|[ \t]+$" authors)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3114 (setq authors (replace-match "" nil t authors)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3115 (while (string-match "[ \t][ \t]+" authors)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3116 (setq authors (replace-match " " nil t authors)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3117 (reftex-split "\n" authors)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3118
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3119 (defun reftex-parse-bibtex-entry (entry &optional from to)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3120 (let (alist key start field)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3121 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3122 (save-restriction
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3123 (if entry
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3124 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3125 (switch-to-buffer "*RefTeX-scratch*")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3126 (fundamental-mode)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3127 (erase-buffer)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3128 (insert entry))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3129 (widen)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3130 (narrow-to-region from to))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3131 (goto-char (point-min))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3132
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3133 (if (re-search-forward
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3134 "@\\(\\w+\\)[ \t\n\r]*[{(][ \t\n\r]*\\([^ \t\n\r,]+\\)" nil t)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3135 (setq alist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3136 (list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3137 (cons "&type" (downcase (reftex-no-props (match-string 1))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3138 (cons "&key" (reftex-no-props (match-string 2))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3139 (while (re-search-forward "\\(\\w+\\)[ \t\n\r]*=[ \t\n\r]*" nil t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3140 (setq key (reftex-no-props (downcase (match-string 1))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3141 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3142 ((= (following-char) ?{)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3143 (forward-char 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3144 (setq start (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3145 (condition-case nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3146 (up-list 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3147 ('error nil)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3148 ((= (following-char) ?\")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3149 (forward-char 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3150 (setq start (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3151 (while (and (search-forward "\"" nil t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3152 (= ?\\ (char-after (- (point) 2))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3153 (t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3154 (setq start (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3155 (re-search-forward "[ \t\n\r,}]" nil 1)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3156 (setq field (buffer-substring-no-properties start (1- (point))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3157 ;; remove extra whitesp
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3158 (while (string-match "[\n\t\r]\\|[ \t][ \t]+" field)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3159 (setq field (replace-match " " nil t field)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3160 ;; remove leading garbage
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3161 (if (string-match "^[ \t{]+" field)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3162 (setq field (replace-match "" nil t field)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3163 ;; remove trailing garbage
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3164 (if (string-match "[ \t}]+$" field)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3165 (setq field (replace-match "" nil t field)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3166 (setq alist (cons (cons key field) alist)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3167 alist))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3168
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3169 (defun reftex-get-bib-field (fieldname entry)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3170 ;; Extract the field FIELDNAME from an ENTRY
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3171 (or (cdr (assoc fieldname entry))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3172 ""))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3173
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3174 (defun reftex-format-bib-entry (entry)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3175 ;; Format a BibTeX ENTRY so that it is nice to look at
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3176 (let*
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3177 ((rtn nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3178 (auth-list (reftex-get-bib-authors entry))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3179 (authors (mapconcat '(lambda (x) x) auth-list ", "))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3180 (year (reftex-get-bib-field "year" entry))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3181 (title (reftex-get-bib-field "title" entry))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3182 (type (reftex-get-bib-field "&type" entry))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3183 (key (reftex-get-bib-field "&key" entry))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3184 (extra
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3185 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3186 ((equal type "article")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3187 (concat (reftex-get-bib-field "journal" entry) " "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3188 (reftex-get-bib-field "volume" entry) ", "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3189 (reftex-get-bib-field "pages" entry)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3190 ((equal type "book")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3191 (concat "book (" (reftex-get-bib-field "publisher" entry) ")"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3192 ((equal type "phdthesis")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3193 (concat "PhD: " (reftex-get-bib-field "school" entry)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3194 ((equal type "mastersthesis")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3195 (concat "Master: " (reftex-get-bib-field "school" entry)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3196 ((equal type "inbook")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3197 (concat "Chap: " (reftex-get-bib-field "chapter" entry)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3198 ", pp. " (reftex-get-bib-field "pages" entry)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3199 ((or (equal type "conference")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3200 (equal type "incollection")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3201 (equal type "inproceedings"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3202 (concat "in: " (reftex-get-bib-field "booktitle" entry)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3203 (t ""))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3204 (setq authors
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3205 (if (> (length authors) 30)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3206 (concat (substring authors 0 27) "...")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3207 (format "%-30s" authors))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3208 title
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3209 (if (> (length title) 70)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3210 (concat (substring title 0 67) "...")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3211 (format "%-70s" title))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3212 extra
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3213 (if (> (length extra) 40)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3214 (concat (substring extra 0 37) "...")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3215 (format "%-40s" extra)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3216 (if (reftex-use-fonts)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3217 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3218 (put-text-property 0 (length authors) 'face 'font-lock-keyword-face
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3219 authors)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3220 (put-text-property 0 (length title) 'face 'font-lock-comment-face
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3221 title)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3222 (put-text-property 0 (length extra) 'face 'font-lock-reference-face
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3223 extra)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3224 (setq rtn (concat key "\n " authors " " year " " extra
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3225 "\n " title "\n\n"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3226 rtn))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3227
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3228 ;; Make a citation
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3229
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3230 (defun reftex-citation (&optional arg no-insert)
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3231 "Make a citation using BibTeX database files.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3232 After asking for a Regular Expression, it scans the buffers with
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3233 bibtex entries (taken from the \\bibliography command) and offers the
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3234 matching entries for selection. The selected entry is formated according
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3235 to `reftex-cite-format' and inserted into the buffer.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3236 If NO-INSERT is non-nil, nothing is inserted, only the selected key returned.
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3237 The regular expression uses an expanded syntax: && is interpreted as `and'.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3238 Thus, `aaaa&&bbb' matches entries which contain both `aaaa' and `bbb'.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3239 When this function is called with point inside the braces of a \\cite
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3240 command, it will add another key, ignoring the value of `reftex-cite-format'.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3241 When called with a numeric prefix, that many citations will be made and all
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3242 put into the same \\cite command.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3243 When called with just C-u as prefix, enforces rescan of buffer for
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3244 bibliography statement (e.g. if it was changed)."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3245
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3246 (interactive "P")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3247
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3248 ;; check for recursive edit
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3249 (reftex-check-recursive-edit)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3250
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3251 ;; if there is just 1 C-u prefix arg, force to rescan buffer
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3252 (if (and current-prefix-arg
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3253 (listp current-prefix-arg)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3254 (= 4 (prefix-numeric-value arg)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3255 (reftex-reset-scanning-information))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3256
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3257 ;; check if there is already a cite command at point and change cite format
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3258 ;; in order to only add another reference in the same cite command.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3259 (let ((pos (point)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3260 (search-backward "\\" (point-min) 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3261 (if (and (looking-at "\\\\[a-zA-Z]*cite\\*?\\(\\[[^]]*\\]\\)*{\\([^}]*\\)")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3262 (>= (match-end 0) pos)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3263 (>= pos (match-beginning 2)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3264 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3265 (goto-char pos)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3266 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3267 ((or (not arg)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3268 (not (listp arg)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3269 (setq reftex-cite-format1
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3270 (concat
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3271 (if (not (or (= (preceding-char) ?{)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3272 (= (preceding-char) ?,)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3273 ","
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3274 "")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3275 "KEY"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3276 (if (not (or (= (following-char) ?})
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3277 (= (following-char) ?,)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3278 ","
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3279 ""))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3280 (t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3281 (setq reftex-cite-format1 "KEY"))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3282 (setq reftex-cite-format1
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3283 (if (symbolp reftex-cite-format)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3284 (symbol-value reftex-cite-format)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3285 reftex-cite-format))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3286 (goto-char pos)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3287
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3288 (let* (key entry cnt rtn ins-string re-list re
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3289 ;; scan bibtex files
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3290 (lazy-lock-minimum-size 1)
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3291 (reftex-found-list (reftex-extract-bib-entries
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3292 (reftex-get-bibfile-list)))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3293 (found-list-r nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3294 (accept-keys
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3295 (if (and (listp reftex-cite-format1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3296 (listp (car reftex-cite-format1)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3297 (mapcar 'car reftex-cite-format1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3298 '(?\C-m))))
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3299 (if (not reftex-found-list)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3300 (error "Sorry, no matches found"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3301
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3302 ;; remember where we came from
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3303 (setq reftex-call-back-to-this-buffer (current-buffer))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3304
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3305 ;; offer selection
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3306 (save-window-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3307 (switch-to-buffer-other-window "*RefTeX Select*")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3308 (erase-buffer)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3309 (mapcar '(lambda (x) (insert (cdr (assoc "&formatted" x))))
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3310 reftex-found-list)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3311 (if (= 0 (buffer-size))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3312 (error "Sorry, no matches found"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3313 (setq truncate-lines t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3314 (goto-char 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3315 (if (catch 'exit
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3316 (while t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3317 (setq rtn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3318 (reftex-select-item
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3319 nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3320 (concat
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3321 "Select: [n]ext [p]rev [r]estrict [q]uit [?]Help ||"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3322 " RETURN "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3323 (condition-case nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3324 (mapconcat 'char-to-string accept-keys " ")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3325 (error (error "Illegal reftex-cite-format"))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3326 "^[^ \t\n]"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3327 "\n\n"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3328 4
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3329 reftex-citation-help
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3330 (cons ?r accept-keys)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3331 nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3332 'reftex-bibtex-selection-callback nil))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3333 (setq key (car rtn)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3334 cnt (cdr rtn))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3335 (if (not key) (throw 'exit nil))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3336 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3337 ((equal key ?r)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3338 ;; restrict with new regular expression
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3339 (setq re-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3340 (reftex-split "[ \t]*&&[ \t]*"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3341 (read-string "RegExp [ && RegExp...]: "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3342 nil 'reftex-cite-regexp-hist)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3343 (while re-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3344 (setq re (car re-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3345 re-list (cdr re-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3346 (setq found-list-r
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3347 (delete ""
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3348 (mapcar
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3349 '(lambda (x)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3350 (if (string-match re
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3351 (cdr (assoc "&entry" x)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3352 x
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3353 ""))
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3354 reftex-found-list))))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3355 (if found-list-r
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3356 (setq reftex-found-list found-list-r)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3357 (ding))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3358 (erase-buffer)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3359 (mapcar '(lambda (x) (insert (cdr (assoc "&formatted" x))))
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3360 reftex-found-list)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3361 (goto-char 1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3362 ((or (member key accept-keys)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3363 (equal key ?\C-m)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3364 (equal key 'return))
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3365 (setq entry (nth cnt reftex-found-list))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3366 (throw 'exit t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3367 (t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3368 (ding)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3369 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3370 ;; format the entry
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3371 (if (not (integerp key)) (setq key ?\C-m))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3372 (setq ins-string (reftex-format-citation entry key)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3373 (setq ins-string "")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3374 (message "Quit")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3375 (kill-buffer "*RefTeX Select*")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3376
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3377 (if (not no-insert)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3378 (insert ins-string))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3379 (message "")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3380
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3381 ;; Check if the prefix arg was numeric, and call reftex-citation recursively
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3382 (if (and (integerp arg)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3383 (> arg 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3384 (re-search-backward
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3385 "\\\\[a-zA-Z]*cite\\*?\\(\\[[^]]*\\]\\)*{\\([^}]*\\)" nil t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3386 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3387 (goto-char (match-end 0))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3388 (setq arg (1- arg))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3389 (reftex-citation arg))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3390 (reftex-kill-temporary-buffers))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3391 ;; Return the citation key
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3392 (reftex-get-bib-field "&key" entry)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3393
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3394 (defun reftex-format-citation (entry key)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3395 ;; Format a citation from the info in the BibTeX ENTRY
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3396 (let* ((cite-key (reftex-get-bib-field "&key" entry))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3397 (year (reftex-get-bib-field "year" entry))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3398 (auth-list (reftex-get-bib-authors entry))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3399 (nauthors (length auth-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3400 format)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3401
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3402 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3403 ;; Find the correct format
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3404 (if (and (listp reftex-cite-format1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3405 (listp (car reftex-cite-format1)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3406 (if (integerp (car (car reftex-cite-format1)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3407 (if (assoc key reftex-cite-format1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3408 (setq format (cdr (assoc key reftex-cite-format1)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3409 (if (or (equal key ?\C-m)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3410 (equal key 'return))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3411 (setq format (cdr (car reftex-cite-format1)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3412 (error "Error in reftex-cite-format")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3413 (error "Error in reftex-cite-format"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3414 (setq format reftex-cite-format1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3415
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3416 (if (listp format)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3417 (let ((nn (min nauthors (1- (length format)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3418 (while (and (> nn 0) (string= "" (nth nn format)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3419 (setq nn (1- nn)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3420 (setq format (nth nn format))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3421 (if (stringp format)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3422 (setq format format)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3423 (setq format "\\cite{KEY}"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3424
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3425 ;; Insert the author names
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3426 (while (string-match "\\bAUTHOR\\b" format)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3427 (setq format (replace-match (car auth-list) t t format))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3428 (setq auth-list (cdr auth-list)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3429 (while (string-match "\\bKEY\\b" format)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3430 (setq format (replace-match cite-key t t format)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3431 (while (string-match "\\bYEAR\\b" format)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3432 (setq format (replace-match year t t format)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3433 format)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3434
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3435 ;; this is slow and not recommended for follow mode
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3436 (defun reftex-bibtex-selection-callback (cnt)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3437 ;; Callback function to be called from the BibTeX selection, in
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3438 ;; order to display context. This function is relatively slow and not
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3439 ;; recommended for follow mode, just for individual lookups.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3440 (let ((win (selected-window))
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3441 (key (reftex-get-bib-field "&key" (nth cnt reftex-found-list)))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3442 (bibfile-list (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3443 (set-buffer reftex-call-back-to-this-buffer)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3444 (reftex-get-bibfile-list))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3445 (reftex-pop-to-bibtex-entry key bibfile-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3446 (not reftex-keep-temporary-buffers) t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3447 (select-window win)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3448
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3449 ;;; ===========================================================================
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3450 ;;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3451 ;;; Here is the routine used for selection
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3452
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3453 ;; Marker for return point from recursive edit
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3454 (defvar reftex-recursive-edit-marker (make-marker))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3455
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3456 (defun reftex-check-recursive-edit ()
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3457 ;; Check if we are already in a recursive edit. Abort with helpful
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3458 ;; message if so.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3459 (if (marker-position reftex-recursive-edit-marker)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3460 (error
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3461 (substitute-command-keys
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3462 "In unfinished recursive edit. Finish (\\[exit-recursive-edit]) or abort (\\[abort-recursive-edit])."))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3463
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3464 (defun reftex-select-item (buffer prompt next-re end-re size help-string
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3465 event-list &optional offset
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3466 call-back cb-flag)
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3467 ;; Select an item from the buffer BUFFER. Show PROMPT to user, find
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3468 ;; next item with NEXT-RE regular expression, return on any of the
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3469 ;; events listed in EVENT-LIST. The function returns the event along
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3470 ;; with an integer indicating which item was selected. When OFFSET is
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3471 ;; specified, starts at that item in the list. When CALL-BACK is
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3472 ;; given, it is a function which is called with the match of the
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3473 ;; NEXT-RE match and the index of the element.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3474 (let* (key key-sq b e ev cnt cmd
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3475 (offset1 (or offset 1)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3476 (setq ev
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3477 (catch 'exit
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3478 (save-window-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3479 (if buffer
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3480 (switch-to-buffer-other-window buffer))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3481 (if (= 0 (buffer-size))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3482 (throw 'exit nil))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3483 (setq truncate-lines t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3484 (goto-char 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3485 (if (not (re-search-forward next-re nil t offset1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3486 (progn ; in case the offset is illegal
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3487 (setq offset1 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3488 (if (not (re-search-forward next-re nil t offset1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3489 (throw 'exit nil))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3490 (beginning-of-line 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3491 (setq cnt (if offset1 (1- offset1) 0))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3492 (while t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3493 (if (and cb-flag call-back)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3494 (funcall call-back cnt))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3495 (setq b (point)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3496 e (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3497 (save-match-data
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3498 (re-search-forward end-re nil 1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3499 (point)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3500 (reftex-highlight 1 b e)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3501 (if (or (not (pos-visible-in-window-p b))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3502 (not (pos-visible-in-window-p e)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3503 (recenter (/ (window-height) 2)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3504 (setq key-sq (read-key-sequence prompt))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3505 (setq key (car
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3506 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3507 ((fboundp 'listify-key-sequence) ; Emacs
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3508 (listify-key-sequence key-sq))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3509 ((fboundp 'event-to-character) ; XEmacs
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3510 (mapcar 'event-to-character key-sq))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3511 (t (error "Please report this problem to dominik@strw.leidenuniv.nl")))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3512
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3513 (setq cmd (key-binding key-sq))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3514
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3515 (reftex-unhighlight 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3516
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3517 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3518
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3519 ((or (equal key ?n)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3520 (equal key ?\C-i)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3521 (equal cmd 'next-line))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3522 (if (re-search-forward next-re nil t 2)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3523 (setq cnt (1+ cnt)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3524 (beginning-of-line 1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3525
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3526 ((equal cmd 'scroll-up)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3527 (setq cnt (1- cnt))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3528 (while (and (pos-visible-in-window-p)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3529 (re-search-forward next-re nil t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3530 (setq cnt (1+ cnt)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3531 (beginning-of-line 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3532 (recenter 1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3533
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3534 ((or (equal key ?p)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3535 (equal cmd 'previous-line))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3536 (if (re-search-backward next-re nil t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3537 (setq cnt (1- cnt))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3538
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3539 ((equal cmd 'scroll-down)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3540 (while (and (pos-visible-in-window-p)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3541 (re-search-backward next-re nil t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3542 (setq cnt (1- cnt)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3543 (recenter (- (window-height) size 2)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3544
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3545 ((equal key ?q)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3546 (throw 'exit nil))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3547
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3548 ((equal key ?\C-g)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3549 (bury-buffer)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3550 (error "Abort"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3551
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3552 ((or (equal key ?\C-m)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3553 (equal key 'return)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3554 (equal cmd 'newline))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3555 (throw 'exit 'return))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3556
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3557 ((or (equal key ?C) ; backward compatibility
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3558 (equal key ?f))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3559 (setq cb-flag (not cb-flag)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3560
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3561 ((equal key ?\ )
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3562 (funcall call-back cnt))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3563
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3564 ((equal key ?\?)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3565 (save-window-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3566 (with-output-to-temp-buffer "*RefTeX Help*"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3567 (princ help-string))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3568 (setq unread-command-events
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3569 (cons
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3570 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3571 ((fboundp 'read-event) ; Emacs
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3572 (read-event))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3573 ((fboundp 'next-command-event) ; XEmacs
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3574 (next-command-event))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3575 (t (error "Please report this problem to dominik@strw.leidenuniv.nl")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3576 nil)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3577 (kill-buffer "*RefTeX Help*"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3578
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3579 ((equal key ?\C-r)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3580 ;; sje - code copied from ispell.el for
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3581 ;; performing recursive edit
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3582 (set-marker reftex-recursive-edit-marker (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3583 (unwind-protect
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3584 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3585 (save-window-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3586 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3587 (other-window 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3588 (message
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3589 (substitute-command-keys
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3590 "Recursive edit. Return to selection with \\[exit-recursive-edit]"))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3591 (recursive-edit)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3592 (if (not (equal (marker-buffer
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3593 reftex-recursive-edit-marker)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3594 (current-buffer)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3595 (error
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3596 "Cannot continue RefTeX from this buffer."))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3597 (goto-char reftex-recursive-edit-marker))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3598 (set-marker reftex-recursive-edit-marker nil)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3599
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3600 ((member key event-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3601 (throw 'exit key))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3602 (t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3603 (ding)))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3604 (message "")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3605 (cons ev cnt)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3606
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3607 ;;; ===========================================================================
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3608 ;;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3609 ;;; View cross references
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3610
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3611 (defun reftex-view-crossref (&optional arg)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3612 "View cross reference of \\ref or \\cite macro at point.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3613 If the macro at point is a \\ref, show the corresponding label definition.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3614 If it is a \\cite, show the BibTeX database entry.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3615 If there is no such macro at point, search forward to find one.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3616 When you call this function several times in direct successtion, point will
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3617 move to view subsequent cross references further down in the buffer.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3618 With argument, actually select the window showing the cross reference."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3619
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3620 (interactive "P")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3621
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3622 ;; See where we are.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3623 (let* ((pos (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3624 (re "\\\\[a-z]*\\(cite\\|ref\\)\\(\\[[^{}]*\\]\\)?{\\([^}]+\\)}")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3625 (my-window (get-buffer-window (current-buffer)))
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3626 pop-window cmd args macro label key-start point)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3627
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3628 (if (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3629 (forward-char 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3630 (and (search-backward "\\" nil t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3631 (looking-at re)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3632 (< pos (match-end 0))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3633 (setq macro (match-string 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3634 key-start (match-beginning 3)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3635
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3636 (if (and macro (eq last-command this-command))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3637 (if (and (string= macro "cite")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3638 (skip-chars-forward "^}, \t\n\r")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3639 (= (following-char) ?,))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3640 (setq key-start (1+ (point)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3641 (setq macro nil)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3642
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3643 (if (not macro)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3644 (if (re-search-forward re nil t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3645 (setq macro (match-string 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3646 key-start (match-beginning 3))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3647 (error "No further cross references in buffer")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3648
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3649 (goto-char key-start)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3650
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3651 ;; Ensure access to scanning info
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3652 (reftex-access-scan-info)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3653
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3654 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3655 ((string= macro "cite")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3656 (setq cmd 'reftex-pop-to-bibtex-entry
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3657 args (list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3658 (reftex-no-props (reftex-this-word "^{},"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3659 (reftex-get-bibfile-list) nil t)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3660 ((string= macro "ref")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3661 (let ((label (reftex-no-props (reftex-this-word "^{}")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3662 (entry (assoc label (symbol-value reftex-list-of-labels-symbol))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3663 (if entry
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3664 (setq cmd 'reftex-pop-to-label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3665 args (list label (list (nth 3 entry)) nil t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3666 (error "Label %s not known - reparse document might help" label))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3667 (t (error "This should not happen")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3668 (setq point (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3669 (apply cmd args)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3670 (setq pop-window (selected-window))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3671 (add-hook 'pre-command-hook 'reftex-highlight-shall-die)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3672 (select-window my-window)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3673 (goto-char point)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3674 (and arg (select-window pop-window))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3675
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3676 (defun reftex-mouse-view-crossref (ev)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3677 "View cross reference of \\ref or \\cite macro where you click.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3678 If the macro at point is a \\ref, show the corresponding label definition.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3679 If it is a \\cite, show the BibTeX database entry.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3680 If there is no such macro at point, search forward to find one.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3681 With argument, actually select the window showing the cross reference."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3682 (interactive "e")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3683 (mouse-set-point ev)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3684 (reftex-view-crossref current-prefix-arg))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3685
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3686 ;;; ===========================================================================
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3687 ;;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3688 ;;; Functions that check out the surroundings
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3689
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3690 (defun reftex-what-macro (which &optional bound)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3691 ;; Find out if point is within the arguments of any TeX-macro.
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3692 ;; The return value is either ("\\macro" . (point)) or a list of them.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3693
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3694 ;; If WHICH is nil, immediately return nil.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3695 ;; If WHICH is t, return list of all macros enclosing point.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3696 ;; If WHICH is a list of macros, look only for those macros and return the
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3697 ;; name of the first macro in this list found to enclose point.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3698 ;; If the optional BOUND is an integer, bound backwards directed
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3699 ;; searches to this point. If it is nil, limit to nearest \section -
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3700 ;; like statement.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3701
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3702 ;; This function is pretty stable, but can be fooled if the text contains
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3703 ;; things like \macro{aa}{bb} where \macro is defined to take only one
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3704 ;; argument. As RefTeX cannot know this, the string "bb" would still be
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3705 ;; considered an argument of macro \macro.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3706
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3707 (catch 'exit
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3708 (if (null which) (throw 'exit nil))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3709 (let ((bound (or bound (save-excursion (re-search-backward
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3710 reftex-section-regexp nil 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3711 (point))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3712 pos cmd-list cmd)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3713 (save-restriction
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3714 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3715 (narrow-to-region (max 1 bound) (point-max))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3716 ;; move back out of the current parenthesis
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3717 (while (condition-case nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3718 (progn (up-list -1) t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3719 (error nil))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3720 ;; move back over any touching sexps
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3721 (while (or (= (preceding-char) ?\])
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3722 (= (preceding-char) ?\}))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3723 (backward-sexp))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3724 (setq pos (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3725 (if (and (or (= (following-char) ?\[)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3726 (= (following-char) ?\{))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3727 (and (re-search-backward "\\(\\\\[a-zA-Z]+\\)" nil t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3728 (= (match-end 0) pos)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3729 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3730 (setq cmd (buffer-substring-no-properties
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3731 (match-beginning 0) (match-end 0)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3732 (if (eq t which)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3733 (setq cmd-list (cons (cons cmd (point)) cmd-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3734 (if (member cmd which)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3735 (throw 'exit (cons cmd (point)))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3736 (goto-char pos)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3737 (nreverse cmd-list)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3738
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3739 (defun reftex-what-environment (which &optional bound)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3740 ;; Find out if point is inside a LaTeX environment.
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3741 ;; The return value is (e.g.) either ("equation" . (point)) or a list of
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3742 ;; them.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3743
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3744 ;; If WHICH is nil, immediately return nil.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3745 ;; If WHICH is t, return list of all environments enclosing point.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3746 ;; If WHICH is a list of environments, look only for those environments and
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3747 ;; return the name of the first environment in this list found to enclose
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3748 ;; point.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3749
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3750 ;; If the optional BOUND is an integer, bound backwards directed searches to
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3751 ;; this point. If it is nil, limit to nearest \section - like statement.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3752
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3753 (catch 'exit
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3754 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3755 (if (null which) (throw 'exit nil))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3756 (let ((bound (or bound (save-excursion (re-search-backward
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3757 reftex-section-regexp nil 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3758 (point))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3759 env-list end-list env)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3760 (while (re-search-backward "\\\\\\(begin\\|end\\){\\([^}]+\\)}"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3761 bound t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3762 (setq env (buffer-substring-no-properties
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3763 (match-beginning 2) (match-end 2)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3764 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3765 ((string= (match-string 1) "end")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3766 (add-to-list 'end-list env))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3767 ((member env end-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3768 (setq end-list (delete env end-list)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3769 ((eq t which)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3770 (setq env-list (cons (cons env (point)) env-list)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3771 ((member env which)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3772 (throw 'exit (cons env (point))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3773 (nreverse env-list)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3774
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3775 (defun reftex-word-before-point ()
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3776 ;; Return the word before point. Word means here:
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3777 ;; Consists of [a-zA-Z0-9.:] and ends at point or whitespace.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3778 (let ((pos (point)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3779 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3780 (re-search-backward "[^ \t\n\r]" (point-min) 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3781 (setq pos (1+ (point)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3782 (if (re-search-backward "[^a-zA-Z0-9\\\.:]" (point-min) 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3783 (forward-char 1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3784 (buffer-substring-no-properties (point) pos))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3785
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3786 ;; ============================================================================
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3787 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3788 ;; Some generally useful functions
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3789
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3790 (defun reftex-no-props (string)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3791 ;; Return STRING with all text properties removed
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3792 (and (stringp string)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3793 (set-text-properties 0 (length string) nil string))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3794 string)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3795
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3796 (defun reftex-split (regexp string)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3797 ;; Split like perl
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3798 (let ((start 0) list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3799 (while (string-match regexp string start)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3800 (setq list (cons (substring string start (match-beginning 0)) list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3801 (setq start (match-end 0)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3802 (setq list (nreverse (cons (substring string start) list)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3803
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3804 (defun reftex-allow-for-ctrl-m (string)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3805 ;; convert STRING into a regexp, allowing ^M for \n
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3806 (let ((start -2))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3807 (setq string (regexp-quote string))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3808 (while (setq start (string-match "[\n\r]" string (+ 3 start)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3809 (setq string (replace-match "[\n\r]" nil t string)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3810 string))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3811
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3812 (defun reftex-delete-list (elt-list list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3813 ;; like delete, but with a list of things to delete
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3814 ;; (original code from Rory Molinari)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3815 (while elt-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3816 (setq list (delete (car elt-list) list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3817 elt-list (cdr elt-list)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3818 list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3819
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3820 (defun reftex-get-buffer-visiting (file)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3821 ;; return a buffer visiting FILE
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3822 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3823 ((fboundp 'find-buffer-visiting) ; Emacs
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3824 (find-buffer-visiting file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3825 ((boundp 'find-file-compare-truenames) ; XEmacs
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3826 (let ((find-file-compare-truenames t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3827 (get-file-buffer file)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3828 (t (error "Please report this problem to dominik@strw.leidenuniv.nl"))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3829
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3830 (defun reftex-get-file-buffer-force (file &optional mark-to-kill)
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3831 ;; Return a buffer visiting file. Make one, if necessary.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3832 ;; If neither such a buffer no the file exist, return nil.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3833 ;; If MARK-TO-KILL in non-nil, put any new buffers into the kill list."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3834
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3835 (let ((buf (reftex-get-buffer-visiting file)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3836 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3837 (buf buf)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3838 ((file-exists-p file)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3839 (setq buf (find-file-noselect file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3840 (if mark-to-kill
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3841 (add-to-list 'reftex-buffers-to-kill buf))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3842 buf)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3843 (t nil))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3844
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3845 (defun reftex-splice-symbols-into-list (list alist)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3846 ;; Splice the association in ALIST of any symbols in LIST into the list.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3847 ;; Return new list.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3848 (let (rtn tmp)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3849 (while list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3850 (while (and (not (null (car list)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3851 (symbolp (car list)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3852 (setq tmp (car list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3853 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3854 ((assoc tmp alist)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3855 (setq list (append (cdr (cdr (assoc tmp alist))) (cdr list))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3856 (t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3857 (error "Cannot treat symbol %s in reftex-label-alist"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3858 (symbol-name tmp)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3859 (setq rtn (cons (car list) rtn)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3860 list (cdr list)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3861 (nreverse rtn)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3862
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3863 (defun reftex-uniquify (alist &optional keep-list)
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3864 ;; Return a list of all elements in ALIST, but each car only once.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3865 ;; Elements of KEEP-LIST are not removed even if duplicate.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3866 (let (new elm)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3867 (while alist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3868 (setq elm (car alist)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3869 alist (cdr alist))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3870 (if (or (member (car elm) keep-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3871 (not (assoc (car elm) new)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3872 (setq new (cons elm new))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3873 (setq new (nreverse new))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3874 new))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3875
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3876 (defun reftex-use-fonts ()
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3877 ;; Return t if we can and want to use fonts.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3878 (and window-system
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3879 reftex-use-fonts
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3880 (boundp 'font-lock-keyword-face)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3881
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3882 ;; Highlighting uses overlays. If this is for XEmacs, we need to load
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3883 ;; the overlay library, available in version 19.15
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3884 (and (not (fboundp 'make-overlay))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3885 (condition-case nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3886 (require 'overlay)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3887 ('error
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3888 (error "RefTeX needs overlay emulation (available in XEmacs 19.15)"))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3889
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3890 ;; We keep a vector with several different overlays to do our highlighting.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3891 (defvar reftex-highlight-overlays [nil nil])
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3892
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3893 ;; Initialize the overlays
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3894 (aset reftex-highlight-overlays 0 (make-overlay 1 1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3895 (overlay-put (aref reftex-highlight-overlays 0) 'face 'highlight)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3896 (aset reftex-highlight-overlays 1 (make-overlay 1 1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3897 (overlay-put (aref reftex-highlight-overlays 1) 'face 'highlight)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3898
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3899 ;; Two functions for activating and deactivation highlight overlays
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3900 (defun reftex-highlight (index begin end &optional buffer)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3901 "Highlight a region with overlay INDEX."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3902 (move-overlay (aref reftex-highlight-overlays index)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3903 begin end (or buffer (current-buffer))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3904 (defun reftex-unhighlight (index)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3905 "Detatch overlay INDEX."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3906 (delete-overlay (aref reftex-highlight-overlays index)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3907
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3908 (defun reftex-highlight-shall-die ()
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3909 ;; Function used in pre-command-hook to remove highlights.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3910 (remove-hook 'pre-command-hook 'reftex-highlight-shall-die)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3911 (reftex-unhighlight 0))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3912
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3913 ;;; ---------------------------------------------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3914 ;;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3915 ;;; Cursor position after insertion of forms
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3916
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3917 (defun reftex-position-cursor ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3918 ;; Search back to question mark, delete it, leave point there
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3919 (if (search-backward "\?" (- (point) 100) t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3920 (delete-char 1)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3921
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3922 (defun reftex-item ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3923 "Insert an \\item and provide a label if the environments supports that."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3924 (interactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3925 (let ((env (car
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3926 (reftex-what-environment '("itemize" "enumerate" "eqnarray")))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3927
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3928 (if (and env (not (bolp))) (newline))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3929
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3930 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3931
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3932 ((string= env "eqnarray")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3933 (if (not (bolp))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3934 (newline))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3935 (reftex-label env)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3936 (insert "\n & & ")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3937 (beginning-of-line 1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3938
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3939 ((string= env "itemize")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3940 (newline)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3941 (insert "\\item "))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3942
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3943 ((string= env "enumerate")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3944 (newline)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3945 (insert "\\item")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3946 (reftex-label env)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3947 (insert " "))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3948 (t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3949 (error "\\item command does not make sense here...")))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3950
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3951 ;;; ---------------------------------------------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3952 ;;; ---------------------------------------------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3953 ;;; ---------------------------------------------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3954 ;;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3955 ;;; Data Section: Definition of large constants
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3956
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3957
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3958 (defconst reftex-label-alist-builtin
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3959 '(
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3960 (LaTeX
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3961 "LaTeX default environments"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3962 ("section" ?s "sec:" "~\\ref{%s}" t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3963 ("Part" "Chapter" "Chap." "Section" "Sec." "Sect." "Paragraph" "Par."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3964 "\\S" "Teil" "Kapitel" "Kap." "Abschnitt" ))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3965
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3966 ("enumerate" ?n "item:" "~\\ref{%s}" "\\\\item\\(\\[[^]]*\\]\\)?"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3967 ("Item" "Punkt"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3968
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3969 ("equation" ?e "eq:" "~(\\ref{%s})" t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3970 ("Equation" "Eq." "Eqn." "Gleichung" "Gl."))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3971 ("eqnarray" ?e "eq:" nil "\\\\begin{eqnarray}\\|\\\\\\\\")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3972
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3973 ("figure" ?f "fig:" "~\\ref{%s}" "\\\\caption\\(\\[[^]]*\\]\\)?{"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3974 ("Figure" "Fig." "Abbildung" "Abb."))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3975 ("figure*" ?f nil nil "\\\\caption\\(\\[[^]]*\\]\\)?{")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3976
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3977 ("table" ?t "tab:" "~\\ref{%s}" "\\\\caption\\(\\[[^]]*\\]\\)?{"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3978 ("Table" "Tab." "Tabelle"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3979 ("table*" ?t nil nil "\\\\caption\\(\\[[^]]*\\]\\)?{")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3980
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3981 ("any" ?\ " " "\\ref{%s}" nil))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3982
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3983 (Sideways
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3984 "Sidewaysfigure and sidewaystable"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3985 ("sidewaysfigure" ?f nil nil "\\\\caption\\(\\[[^]]*\\]\\)?{")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3986 ("sidewaystable" ?t nil nil "\\\\caption\\(\\[[^]]*\\]\\)?{"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3987
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3988 (Subfigure
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3989 "Subfigure environments and macro"
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3990 ("subfigure" ?f nil nil "\\\\caption\\(\\[[^]]*\\]\\)?{")
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3991 ("subfigure*" ?f nil nil "\\\\caption\\(\\[[^]]*\\]\\)?{")
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3992 ("\\subfigure" ?f nil nil "\\\\subfigure[[{]"))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
3993
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3994 (AMSTeX
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3995 "AMS-LaTeX: amsmath package environents"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3996 ("align" ?e "eq:" "~\\eqref{%s}" "\\\\begin{align}\\|\\\\\\\\")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3997 ("gather" ?e "eq:" nil "\\\\begin{gather}\\|\\\\\\\\")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3998 ("multline" ?e "eq:" nil t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3999 ("flalign" ?e "eq:" nil "\\\\begin{flalign}\\|\\\\\\\\")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4000 ("alignat" ?e "eq:" nil "\\\\begin{alignat}{[0-9]*}\\|\\\\\\\\"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4001
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4002 (AASTeX
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4003 "AAS deluxetable environment"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4004 ("deluxetable" ?t "tab:" nil "\\\\caption{")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4005 "The default label environment descriptions.")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4006
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4007 ;;; ---------------------------------------------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4008 ;;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4009 ;;; Functions to compile the tables, reset the mode etc.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4010
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4011 (defun reftex-reset-mode ()
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
4012 "Reset RefTeX Mode. Required to implement changes to some list variables.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
4013 This function will compile the information in `reftex-label-alist' and similar
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
4014 variables. It is called when RefTeX is first used, and after changes to
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
4015 these variables via `reftex-add-to-label-alist'."
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4016 (interactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4017
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
4018 ;; Record that we have done this
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4019 (setq reftex-tables-dirty nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4020
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
4021 ;; Kill temporary buffers associated with RefTeX - just in case they
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
4022 ;; were not cleaned up properly
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
4023 (let ((buffer-list '("*reftex-master.tex*" "*RefTeX Help*" "*RefTeX Select*"
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
4024 "*Duplicate Labels*" "*toc*" "*RefTeX-scratch*")))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
4025 (while buffer-list
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
4026 (if (get-buffer (car buffer-list))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
4027 (kill-buffer (car buffer-list)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
4028 (setq buffer-list (cdr buffer-list))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
4029
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
4030 ;; Plug functions into AUCTeX if the user option says so
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
4031 (reftex-plug-into-AUCTeX)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
4032
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4033 ;; To update buffer-local variables
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4034 (hack-local-variables)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4035 (message "updating internal tables...")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4036 (reftex-compute-ref-cite-tables)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4037 (message "updating internal tables... done")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4038 (reftex-reset-scanning-information))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4039
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4040 (defun reftex-reset-scanning-information ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4041 "Reset the symbols containing information from buffer scanning.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4042 This enforces rescanning the buffer on next use."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4043 (if (and (string= reftex-last-toc-master (reftex-TeX-master-file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4044 (get-buffer "*toc*"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4045 (kill-buffer "*toc*"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4046 (let ((symlist reftex-multifile-symbols)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4047 symbol)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4048 (while symlist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4049 (setq symbol (car symlist)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4050 symlist (cdr symlist))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4051 (if (and (symbolp (symbol-value symbol))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4052 (not (null (symbol-value symbol))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4053 (set (symbol-value symbol) nil)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4054
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4055 (defun reftex-compute-ref-cite-tables ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4056 ;; Update ref and cite tables
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4057
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4058 (interactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4059
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4060 ;; Compile information in reftex-label-alist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4061 (let ((tmp (reftex-uniquify (reftex-splice-symbols-into-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4062 (append
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4063 reftex-label-alist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4064 reftex-label-alist-external-add-ons
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4065 reftex-default-label-alist-entries)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4066 reftex-label-alist-builtin)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4067 '(nil)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4068 entry env-or-mac typekeychar typekey prefix regexp
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4069 fmt wordlist cmd qh-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4070
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4071 (setq reftex-words-to-typekey-alist nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4072 reftex-typekey-list nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4073 reftex-typekey-to-format-alist nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4074 reftex-typekey-to-prefix-alist nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4075 reftex-env-or-mac-alist nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4076 reftex-label-env-list nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4077 reftex-label-mac-list nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4078 (while tmp
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4079 (catch 'next-entry
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4080 (setq entry (car tmp)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4081 env-or-mac (car entry)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4082 entry (cdr entry)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4083 tmp (cdr tmp))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4084 (if (null env-or-mac)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4085 (setq env-or-mac ""))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4086 (if (stringp (car entry))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4087 ;; This is before version 2.00 - convert entry to new format
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4088 ;; This is just to keep old users happy
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4089 (setq entry (cons (string-to-char (car entry))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4090 (cons (concat (car entry) ":")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4091 (cdr entry)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4092 (setq typekeychar (nth 0 entry)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4093 typekey (char-to-string typekeychar)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4094 prefix (nth 1 entry)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4095 fmt (nth 2 entry)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4096 regexp (nth 3 entry)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4097 wordlist (nth 4 entry))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4098 (if (stringp wordlist)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4099 ;; This is before version 2.04 - convert to new format
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4100 (setq wordlist (nthcdr 4 entry)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4101 (if typekey
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4102 (add-to-list 'reftex-typekey-list typekey))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4103 (if (and typekey prefix)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4104 (add-to-list 'reftex-typekey-to-prefix-alist (cons typekey prefix)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4105 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4106 ((string-match "\\`\\\\" env-or-mac)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4107 ;; It's a macro
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4108 (add-to-list 'reftex-label-mac-list env-or-mac))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4109 (t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4110 (or (string= env-or-mac "any")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4111 (string= env-or-mac "")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4112 (add-to-list 'reftex-label-env-list env-or-mac))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4113 (and fmt
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4114 (not (assoc typekey reftex-typekey-to-format-alist))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4115 (setq reftex-typekey-to-format-alist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4116 (cons (cons typekey fmt)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4117 reftex-typekey-to-format-alist)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4118 (and (not (string= env-or-mac "any"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4119 (not (string= env-or-mac ""))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4120 (not (assoc env-or-mac reftex-env-or-mac-alist))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4121 (setq reftex-env-or-mac-alist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4122 (cons (list env-or-mac typekey regexp)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4123 reftex-env-or-mac-alist)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4124 (while (and wordlist (stringp (car wordlist)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4125 (or (assoc (car wordlist) reftex-words-to-typekey-alist)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4126 (setq reftex-words-to-typekey-alist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4127 (cons (cons (downcase (car wordlist)) typekey)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4128 reftex-words-to-typekey-alist)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4129 (setq wordlist (cdr wordlist)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4130 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4131 ((string= "" env-or-mac) nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4132 ((assoc typekey qh-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4133 (setcdr (assoc typekey qh-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4134 (concat (cdr (assoc typekey qh-list)) " " env-or-mac)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4135 (t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4136 (setq qh-list (cons (cons typekey env-or-mac) qh-list))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4137
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4138 (setq qh-list (nreverse qh-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4139 (setq reftex-typekey-to-prefix-alist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4140 (nreverse reftex-typekey-to-prefix-alist))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4141 (setq reftex-type-query-prompt
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4142 (concat "Label type: "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4143 (mapconcat '(lambda(x)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4144 (format "[%s]" (car x)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4145 qh-list " ")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4146 " (?=Help)"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4147 (setq reftex-type-query-help
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4148 (concat "SELECT A LABEL TYPE:\n--------------------\n"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4149 (mapconcat '(lambda(x)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4150 (format " [%s] %s"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4151 (car x) (cdr x)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4152 qh-list "\n")))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4153
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4154 ;;; Keybindings --------------------------------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4156 (define-key reftex-mode-map "\C-c-" 'reftex-item)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4157 (define-key reftex-mode-map "\C-c=" 'reftex-toc)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4158 (define-key reftex-mode-map "\C-c(" 'reftex-label)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4159 (define-key reftex-mode-map "\C-c)" 'reftex-reference)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4160 (define-key reftex-mode-map "\C-c[" 'reftex-citation)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4161 (define-key reftex-mode-map "\C-c&" 'reftex-view-crossref)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4162
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4163 ;; If the user requests so, she can have a few more bindings:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4164 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4165 (reftex-extra-bindings
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4166 (define-key reftex-mode-map "\C-ct" 'reftex-toc)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4167 (define-key reftex-mode-map "\C-cl" 'reftex-label)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4168 (define-key reftex-mode-map "\C-cr" 'reftex-reference)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4169 (define-key reftex-mode-map "\C-cc" 'reftex-citation)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4170 (define-key reftex-mode-map "\C-cv" 'reftex-view-crossref)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4171 (define-key reftex-mode-map "\C-cg" 'reftex-grep-document)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4172 (define-key reftex-mode-map "\C-cs" 'reftex-search-document)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4173
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4174 ;;; Menus --------------------------------------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4175
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4176 ;; Define a menu for the menu bar if Emacs is running under X
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4177
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4178 (require 'easymenu)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4179
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4180 (easy-menu-define
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4181 reftex-mode-menu reftex-mode-map
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4182 "Menu used in RefTeX mode"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4183 '("Ref"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4184 ["Table of Contents" reftex-toc t]
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4185 "----"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4186 ["\\label" reftex-label t]
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4187 ["\\ref" reftex-reference t]
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4188 ["\\cite" reftex-citation t]
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4189 ["View crossref" reftex-view-crossref t]
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4190 "----"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4191 ("Search and Replace"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4192 ["Search whole document" reftex-search-document t]
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4193 ["Replace in document" reftex-query-replace-document t]
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4194 ["Grep on document" reftex-grep-document t]
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4195 "----"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4196 ["Find duplicate labels" reftex-find-duplicate-labels t]
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4197 ["Change label and refs" reftex-change-label t]
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4198 "----"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4199 ["Create TAGS file" reftex-create-tags-file t])
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4200 "----"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4201 ["Parse document" reftex-parse-document t]
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4202 ["Reset RefTeX Mode" reftex-reset-mode t]
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4203 ["Customize RefTeX" reftex-customize t]))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4204
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4205 ;;; Run Hook ------------------------------------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4206
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4207 (run-hooks 'reftex-load-hook)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4208
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4209 ;;; That's it! ----------------------------------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4210
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4211 ; Make sure tabels are compiled
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4212 (message "updating internal tables...")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4213 (reftex-compute-ref-cite-tables)
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 155
diff changeset
4214 (message "updating internal tables...done")
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4215 (setq reftex-tables-dirty nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4216
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4217 (provide 'reftex)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4218
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4219 ;;;============================================================================
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4220
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4221 ;;; reftex.el end here