Mercurial > emacs
annotate lisp/textmodes/reftex.el @ 19142:fffebc19fe53
(x-get-selection): Change default for data-type
back to `STRING'.
| author | Richard M. Stallman <rms@gnu.org> |
|---|---|
| date | Mon, 04 Aug 1997 07:46:26 +0000 |
| parents | 0ed97be54a28 |
| children | fa3d4e7a76d9 |
| rev | line source |
|---|---|
| 18123 | 1 ;; reftex.el --- Minor mode for doing \label, \ref and \cite in LaTeX |
|
18220
36a61aa59b9d
(tex-main-file, outline-minor-mode): Add defvars.
Richard M. Stallman <rms@gnu.org>
parents:
18219
diff
changeset
|
2 |
| 18050 | 3 ;; Copyright (c) 1997 Free Software Foundation, Inc. |
| 4 | |
| 5 ;; Author: Carsten Dominik <dominik@strw.LeidenUniv.nl> | |
| 6 ;; Keywords: tex | |
| 7 | |
| 8 ;; This file is part of GNU Emacs. | |
| 9 | |
| 10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
| 11 ;; it under the terms of the GNU General Public License as published by | |
| 12 ;; the Free Software Foundation; either version 2, or (at your option) | |
| 13 ;; any later version. | |
| 14 | |
| 15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
| 16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 18 ;; GNU General Public License for more details. | |
| 19 | |
| 20 ;; You should have received a copy of the GNU General Public License | |
| 21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
| 22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
| 23 ;; Boston, MA 02111-1307, USA. | |
| 24 | |
| 25 ;;--------------------------------------------------------------------------- | |
| 26 ;; | |
| 27 ;;; Commentary: | |
| 28 ;; | |
| 18123 | 29 ;; RefTeX is a minor mode with distinct support for \ref, \label and |
| 30 ;; \cite commands in (multi-file) LaTeX documents. | |
| 18050 | 31 ;; Labels are created semi-automatically. Definition context of labels is |
| 32 ;; provided when creating a reference. Citations are simplified with | |
| 33 ;; efficient database lookup. | |
| 34 ;; | |
| 35 ;; To turn RefTeX Minor Mode on and off in a particular buffer, use | |
| 36 ;; `M-x reftex-mode'. | |
| 37 ;; | |
| 38 ;; To turn on RefTeX Minor Mode for all LaTeX files, add one of the | |
| 39 ;; following lines to your .emacs file: | |
| 40 ;; | |
| 41 ;; (add-hook 'LaTeX-mode-hook 'turn-on-reftex) ; with AUCTeX LaTeX mode | |
| 42 ;; (add-hook 'latex-mode-hook 'turn-on-reftex) ; with Emacs latex mode | |
| 43 ;; | |
| 44 ;; For key bindings, see further down in this documentation. | |
| 45 ;; | |
| 46 ;;--------------------------------------------------------------------------- | |
| 47 ;; | |
| 48 ;; OVERVIEW | |
| 49 ;; | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
50 ;; 1. USING \label AND \ref. Labels and references are one of the |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
51 ;; strong points of LaTeX. But, in documents with hundreds of |
| 18050 | 52 ;; equations, figures, tables etc. it becomes quickly impossible to |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
53 ;; find good label names and to actually remember them. Then, also |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
54 ;; completion of labels in not enough. One actually needs to see the |
| 18050 | 55 ;; context of the label definition to find the right one. |
| 56 ;; | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
57 ;; - RefTeX distinguishes labels for different environments. It |
| 18050 | 58 ;; always knows if a certain label references a figure, table |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
59 ;; etc.. You can configure RefTeX to recognize any additional |
| 18050 | 60 ;; labeled environments you might have defined yourself. |
| 61 ;; | |
| 62 ;; - RefTeX defines automatically unique labels. Type `C-c (' | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
63 ;; (reftex-label) to insert a label at point. RefTeX will either |
| 18050 | 64 ;; - derive a label from context (default for section labels) |
| 65 ;; - insert a simple label consisting of a prefix and a number | |
| 66 ;; (default for equations and enumerate items) or | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
67 ;; - prompt for a label string (figures and tables). |
| 18050 | 68 ;; Which labels are created how can be controlled with the variable |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
69 ;; `reftex-insert-label-flags'. |
| 18050 | 70 ;; |
| 71 ;; - Referencing labels is a snap and I promise you'll love it. | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
72 ;; In order to make a reference, type `C-c )' (`reftex-reference'). |
| 18050 | 73 ;; This shows an outline of the documents with all labels of a |
| 74 ;; certain type (figure, equation,...) and context of the label | |
| 18123 | 75 ;; definition. Selecting one of the labels inserts a \ref macro |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
76 ;; into the original buffer. Online help during the selection is |
| 18050 | 77 ;; available with `?'. |
| 78 ;; | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
79 ;; 2. CITATIONS. After typing `C-c [' (`reftex-citation'), RefTeX will |
| 18050 | 80 ;; let you specify a regexp to search in current BibTeX database files |
| 81 ;; (as specified in the \bibliography command) and pull out a formatted | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
82 ;; list of matches for you to choose from. The list is *formatted* and |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
83 ;; thus much easier to read than the raw database entries. It can also |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
84 ;; be sorted. The text inserted into the buffer is by default just |
| 18050 | 85 ;; `\cite{KEY}', but can also contain author names and the year in a |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
86 ;; configurable way. See documentation of the variable |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
87 ;; `reftex-cite-format'. |
| 18050 | 88 ;; |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
89 ;; 3. TABLE OF CONTENTS. Typing `C-c =' (`reftex-toc') will show |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
90 ;; a table of contents of the document. From that buffer, you can |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
91 ;; jump quickly to every part of your document. This is similar to |
| 18050 | 92 ;; imenu, only it works for entire multifile documents and uses the |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
93 ;; keyboard rather than the mouse. The initial version of this |
| 18050 | 94 ;; function was contributed by Stephen Eglen. |
| 95 ;; | |
| 96 ;; 4. MULTIFILE DOCUMENTS are supported in the same way as by AUCTeX. | |
| 97 ;; I.e. if a source file is not a full LaTeX document by itself, | |
| 98 ;; but included by another file, you may specify the name of | |
| 99 ;; the (top level) master file in a local variable section at the | |
| 100 ;; end of the source file, like so: | |
| 101 ;; | |
| 102 ;; %%% Local Variables: | |
| 103 ;; %%% TeX-master: my_master.tex | |
| 104 ;; %%% End: | |
| 105 ;; | |
| 106 ;; This will only take effect when you load the file next time or when | |
| 107 ;; you reset RefTeX with M-x reftex-reset-mode. | |
| 108 ;; | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
109 ;; RefTeX will also recognize the file variable tex-main-file. This |
| 18050 | 110 ;; variable is used by the Emacs TeX modes and works just like |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
111 ;; AUCTeX's TeX-master variable. See the documentation of your TeX/LaTeX |
| 18050 | 112 ;; modes. |
| 113 ;; | |
| 114 ;; RefTeX knows about all files related to a document via input and | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
115 ;; include. It provides functions to run regular expression searches and |
| 18050 | 116 ;; replaces over the entire document and to create a TAGS file. |
| 117 ;; | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
118 ;; 5. DOCUMENT PARSING. RefTeX needs to parse the document in order to find |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
119 ;; labels and other information. It will do it automatically once, when |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
120 ;; you start working with a document. If you need to enforce reparsing |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
121 ;; later, call any of the functions `reftex-citation', `reftex-label', |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
122 ;; `reftex-reference', `reftex-toc' with a raw C-u prefix. |
| 18050 | 123 ;; |
| 124 ;;------------------------------------------------------------------------- | |
| 125 ;; | |
| 126 ;; CONFIGURATION | |
| 127 ;; | |
| 128 ;; RefTeX contains many configurable options which change the way it works. | |
| 129 ;; | |
| 130 ;; Most importantly, RefTeX needs to be configured if you use labels to | |
| 131 ;; mark non-standard environments. RefTeX always understands LaTeX section | |
| 132 ;; commands and the following environments: figure, figure*, | |
| 133 ;; sidewaysfigure, table, table*, sidewaystable, equation, eqnarray, | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
134 ;; enumerate. For everythings else, it needs to be configured. |
| 18050 | 135 ;; |
| 136 ;; A good way to configure RefTeX is with the custom.el package by Per | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
137 ;; Abrahamsen, shipped with Emacs 20 and XEmacs 19.15. To do this, just |
| 18050 | 138 ;; say `M-x reftex-customize'. This will not work with older versions |
| 139 ;; of custom.el. | |
| 140 ;; | |
| 141 ;; Here is a complete list of the RefTeX configuration variables with | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
142 ;; their default settings. You could copy this list to your .emacs file |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
143 ;; and change whatever is necessary. Each variable has an extensive |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
144 ;; documentation string. Look it up for more information! |
| 18050 | 145 ;; |
| 146 ;; ;; Configuration Variables and User Options for RefTeX ------------------ | |
|
18219
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
147 ;; ;; Support for \label and \ref -------------------------------------- |
| 18050 | 148 ;; (setq reftex-label-alist nil) |
| 149 ;; (setq reftex-default-label-alist-entries '(Sideways LaTeX)) | |
| 150 ;; (setq reftex-use-text-after-label-as-context nil) | |
| 151 ;; ;; Label insertion | |
| 152 ;; (setq reftex-insert-label-flags '("s" "sft")) | |
| 153 ;; (setq reftex-derive-label-parameters '(3 20 t 1 "-" | |
| 154 ;; ("the" "on" "in" "off" "a" "for" "by" "of" "and" "is"))) | |
| 155 ;; (setq reftex-label-illegal-re "[\000-\040\177-\377\\\\#$%&~^_{}]") | |
| 156 ;; (setq reftex-abbrev-parameters '(4 2 "^saeiou" "aeiou")) | |
| 157 ;; ;; Label referencing | |
| 158 ;; (setq reftex-label-menu-flags '(t t nil nil nil nil)) | |
| 159 ;; (setq reftex-guess-label-type t) | |
| 160 ;; ;; BibteX citation configuration ---------------------------------------- | |
| 161 ;; (setq reftex-bibpath-environment-variables '("BIBINPUTS" "TEXBIB")) | |
| 162 ;; (setq reftex-bibfile-ignore-list nil) | |
| 163 ;; (setq reftex-sort-bibtex-matches 'reverse-year) | |
| 164 ;; (setq reftex-cite-format 'reftex-cite-format-default) | |
| 165 ;; ;; Table of contents configuration -------------------------------------- | |
| 166 ;; (setq reftex-toc-follow-mode nil) | |
| 167 ;; ;; Miscellaneous configurations ----------------------------------------- | |
| 168 ;; (setq reftex-extra-bindings nil) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
169 ;; (setq reftex-plug-into-AUCTeX nil) |
| 18050 | 170 ;; (setq reftex-use-fonts t) |
| 171 ;; (setq reftex-keep-temporary-buffers t) | |
| 172 ;; (setq reftex-auto-show-entry t) | |
| 173 ;; | |
| 174 ;; CONFIGURATION EXAMPLES: | |
| 175 ;; ======================= | |
| 176 ;; | |
| 177 ;; Suppose you are working with AMS-LaTeX amsmath package (with its math | |
| 178 ;; environments like `align', `multiline' etc.). Here is how you would | |
| 179 ;; configure RefTeX to recognize these environments: | |
| 180 ;; | |
| 181 ;; (setq reftex-label-alist '(AMSTeX)) | |
| 182 ;; | |
| 183 ;; This is very easy since RefTeX has builtin support for AMS-LaTeX. | |
| 184 ;; Suppose, however, you are also | |
| 185 ;; | |
| 186 ;; - using "\newtheorem" in LaTeX in order to define two new environments | |
| 187 ;; "Theorem" and "Axiom" like this: | |
| 188 ;; | |
| 189 ;; \newtheorem{axiom}{Axiom} | |
| 190 ;; \newtheorem{theorem}{Theorem} | |
| 191 ;; | |
| 192 ;; - making your figures not directly with the figure environment, but with | |
| 193 ;; a macro like | |
| 194 ;; | |
| 195 ;; \newcommand{\myfig}[4][tbp]{ | |
| 196 ;; \begin{figure}[#1] | |
| 197 ;; \epsimp[#4]{#2} | |
| 198 ;; \caption{#3} | |
| 199 ;; \end{figure}} | |
| 200 ;; | |
| 201 ;; which would be called like | |
| 202 ;; | |
| 203 ;; \myfig{filename}{\label{fig:13} caption text}{1} | |
| 204 ;; | |
| 205 ;; Here is how to tell RefTeX to also recognize Theorem and Axiom as | |
| 206 ;; labeled environments, and that any labels defined inside the \myfig | |
| 207 ;; macro are figure labels: | |
| 208 ;; | |
| 209 ;; (setq reftex-label-alist | |
| 210 ;; '(AMSTeX | |
| 211 ;; ("axiom" ?a "ax:" "~\\ref{%s}" nil ("Axiom" "Ax.")) | |
| 212 ;; ("theorem" ?h "thr:" "~\\ref{%s}" t ("Theorem" "Theor." "Th.")) | |
| 213 ;; ("\\myfig" ?f "fig:" nil t))) | |
| 214 ;; | |
| 215 ;; The type indicator characters ?a and ?h are used for prompts when | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
216 ;; RefTeX queries for a label type. Note that "h" was chosen for "theorem" |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
217 ;; since "t" is already taken by "table". Note that also "s", "f", "e", "n" |
| 18050 | 218 ;; are taken by the standard environments. |
| 219 ;; The automatic labels for Axioms and Theorems will look like "ax:23" or | |
| 220 ;; "thr:24". | |
| 221 ;; The "\ref{%s}" is a format string indicating how to insert references to | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
222 ;; these labels. The nil format in the \myfig entry means to use the same |
| 18050 | 223 ;; format as other figure labels. |
| 224 ;; The next item indicates how to grab context of the label definition. | |
| 225 ;; - t means to get it from a default location (from the beginning of a \macro | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
226 ;; or after the \begin statement). t is *not* a good choice for eqnarray |
| 18050 | 227 ;; and similar environments. |
| 228 ;; - nil means to use the text right after the label definition. | |
| 229 ;; - For more complex ways of getting context, see the docstring of | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
230 ;; `reftex-label-alist'. |
| 18050 | 231 ;; The strings at the end of each entry are used to guess the correct label |
| 232 ;; type from the word before point when creating a reference. E.g. if you | |
| 233 ;; write: "as we have shown in Theorem" and then press `C-)', RefTeX will | |
| 234 ;; know that you are looking for a Theorem label and restrict the labels in | |
| 235 ;; the menu to only these labels without even asking. | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
236 ;; See also the documentation string of the variable `reftex-label-alist'. |
| 18050 | 237 ;; |
| 238 ;; Depending on how you would like the label insertion and selection for the | |
| 239 ;; new environments to work, you might want to add the letters "a" and "h" | |
| 240 ;; to some of the flags in the following variables: | |
| 241 ;; | |
| 242 ;; reftex-insert-label-flags | |
| 243 ;; reftex-label-menu-flags | |
| 244 ;; | |
| 245 ;; The individual flags in these variables can be set to t or nil to enable or | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
246 ;; disable the feature for all label types. They may also contain a string of |
| 18050 | 247 ;; label type letters in order to turn on the feature for those types only. |
| 248 ;; | |
| 249 ;; ----- | |
| 250 ;; If you are writing in a language different from english you might want to | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
251 ;; add magic words for that language. Here is a German example: |
| 18050 | 252 ;; |
| 253 ;; (setq reftex-label-alist | |
| 254 ;; '((nil ?s nil nil nil ("Kapitel" "Kap." "Abschnitt" "Teil")) | |
| 255 ;; (nil ?e nil nil nil ("Gleichung" "Gl.")) | |
| 256 ;; (nil ?t nil nil nil ("Tabelle")) | |
| 257 ;; (nil ?f nil nil nil ("Figur" "Abbildung" "Abb.")) | |
| 258 ;; (nil ?n nil nil nil ("Punkt")))) | |
| 259 ;; | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
260 ;; Using nil as first item in each entry makes sure that this entry does |
| 18050 | 261 ;; not replace the original entry for that label type. |
| 262 ;; | |
| 263 ;; HOOKS | |
| 264 ;; ----- | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
265 ;; Loading reftex.el runs the hook `reftex-load-hook'. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
266 ;; Turning on reftex-mode runs `reftex-mode-hook'. |
| 18050 | 267 ;; |
| 268 ;;------------------------------------------------------------------------- | |
| 269 ;; | |
| 270 ;; KEY BINDINGS | |
| 271 ;; | |
| 272 ;; All important functions of RefTeX can be reached from its menu which | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
273 ;; is installed in the menu bar as "Ref" menu. Only the more frequently used |
| 18050 | 274 ;; functions have key bindings. |
| 275 ;; | |
| 276 ;; Here is the default set of keybindings from RefTeX. | |
| 277 ;; | |
| 278 ;; C-c = reftex-toc | |
| 279 ;; C-c ( reftex-label | |
| 280 ;; C-c ) reftex-reference | |
| 281 ;; C-c [ reftex-citation | |
| 282 ;; C-c & reftex-view-crossref | |
| 283 ;; | |
| 284 ;; I've used these bindings in order to avoid interfering with AUCTeX's | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
285 ;; settings. Personally, I also bind some functions in the C-c LETTER |
| 18050 | 286 ;; map for easier access: |
| 287 ;; | |
| 288 ;; C-c t reftex-toc | |
| 289 ;; C-c l reftex-label | |
| 290 ;; C-c r reftex-reference | |
| 291 ;; C-c c reftex-citation | |
| 292 ;; C-c v reftex-view-crossref | |
| 293 ;; C-c s reftex-search-document | |
| 294 ;; C-c g reftex-grep-document | |
| 295 ;; | |
| 296 ;; If you want to copy those as well, set in your .emacs file: | |
| 297 ;; | |
| 298 ;; (setq reftex-extra-bindings t) | |
| 299 ;; | |
| 300 ;; It is possible to bind the function for viewing cross references to a | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
301 ;; mouse event. Something like the following in .emacs will do the trick: |
| 18050 | 302 ;; |
| 303 ;; (add-hook 'reftex-load-hook | |
| 304 ;; '(lambda () | |
| 305 ;; (define-key reftex-mode-map [(alt mouse-1)] | |
| 306 ;; 'reftex-mouse-view-crossref))) | |
| 307 ;; | |
| 308 ;;------------------------------------------------------------------------- | |
| 309 ;; | |
| 310 ;; RELATED PACKAGES | |
| 311 ;; | |
| 312 ;; AUCTeX | |
| 313 ;; ------ | |
| 314 ;; If you are writing any TeX or LaTeX documents with Emacs, you should | |
| 315 ;; have a look at AUCTeX, the definitive package to work with TeX and LaTeX. | |
| 316 ;; Information on AUCTeX can be found here: | |
| 317 ;; | |
| 318 ;; http://www.sunsite.auc.dk/auctex/ | |
| 319 ;; | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
320 ;; Instead of using the RefTeX functions described above directly, you |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
321 ;; can also use them indirectly through AUCTeX (>9.7p). RefTeX provides |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
322 ;; several interface functions which can be used as replacement for |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
323 ;; corresponding AUCTeX functions dealing with labels and citations. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
324 ;; In this way you can work normally with AUCTeX and use RefTeX |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
325 ;; internals to create and complete labels and citation keys. |
| 18050 | 326 ;; |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
327 ;; `reftex-label' can be used as the `LaTeX-label-function' which does |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
328 ;; label insertion when new environments are created with C-c C-e. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
329 ;; |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
330 ;; `reftex-arg-label', `reftex-arg-ref' and `reftex-arg-cite' can replace |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
331 ;; the corresponding `TeX-arg-...' functions. E.g. when you insert a |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
332 ;; label macro with `C-c RET label RET', RefTeX will be transparently used |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
333 ;; to create the label. |
| 18050 | 334 ;; |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
335 ;; In order to plug all 4 functions into AUCTeX, use in .emacs: |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
336 ;; |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
337 ;; (setq reftex-plug-into-AUCTeX t) |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
338 ;; |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
339 ;; You may also choose to plug in only some of these functions. The |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
340 ;; following setting will leave TeX-arg-cite as it was while replacing |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
341 ;; the other 3 AUCTeX functions: |
| 18050 | 342 ;; |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
343 ;; (setq reftex-plug-into-AUCTeX '(t t t nil)) |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
344 ;; |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
345 ;; AUCTeX can support RefTeX via style files. A style file may contain |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
346 ;; calls to `reftex-add-to-label-alist' which defines additions to |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
347 ;; `reftex-label-alist'. The argument taken by this function must have |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
348 ;; the same format as `reftex-label-alist'. The `amsmath.el' style file |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
349 ;; of AUCTeX (>9.7p) for example contains the following: |
| 18050 | 350 ;; |
|
18219
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
351 ;; (TeX-add-style-hook "amsmath" |
|
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
352 ;; (function |
|
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
353 ;; (lambda () |
|
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
354 ;; (if (featurep 'reftex) |
|
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
355 ;; (reftex-add-to-label-alist '(AMSTeX)))))) |
| 18050 | 356 ;; |
|
18219
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
357 ;; while a package `myprop' defining a proposition environment with |
|
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
358 ;; \newtheorem might use |
| 18050 | 359 ;; |
|
18219
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
360 ;; (TeX-add-style-hook "myprop" |
|
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
361 ;; (function |
|
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
362 ;; (lambda () |
|
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
363 ;; (if (featurep 'reftex) |
|
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
364 ;; (reftex-add-to-label-alist |
|
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
365 ;; '(("proposition" ?p "prop:" "~\\ref{%s}" t |
|
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
366 ;; ("Proposition" "Prop.")))))))) |
| 18050 | 367 ;; |
| 368 ;; Bib-cite.el | |
| 369 ;; ----------- | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
370 ;; Once you have written a document with labels, refs and citations, |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
371 ;; it can be nice to read such a file like a hypertext document. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
372 ;; RefTeX has some support for that (`reftex-view-crossref', |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
373 ;; `reftex-search-document'). A more elegant interface with mouse |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
374 ;; support and links into Hyperbole is provided (among other things) |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
375 ;; by Peter S. Galbraith's `bib-cite.el'. There is some overlap in the |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
376 ;; functionalities of Bib-cite and RefTeX. Bib-cite.el comes bundled |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
377 ;; with AUCTeX. You can also get the latest version from |
| 18050 | 378 ;; |
| 379 ;; ftp://ftp.phys.ocean.dal.ca/users/rhogee/elisp/bib-cite.el | |
| 380 ;; | |
| 381 ;;------------------------------------------------------------------------- | |
| 382 ;; | |
| 383 ;; PERFORMANCE ISSUES | |
| 384 ;; | |
| 385 ;; 1. RefTeX will load other parts of a multifile document as well as BibTeX | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
386 ;; database files for lookup purposes. These buffers are kept, so that |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
387 ;; subsequent lookup in the same files is fast. For large documents and |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
388 ;; large BibTeX databases, this can use up a lot of memory. If you have |
| 18050 | 389 ;; more time than memory, try the following option, which will remove |
| 390 ;; buffers created for lookup after use. | |
| 391 ;; | |
| 392 ;; (setq reftex-keep-temporary-buffers nil) | |
| 393 ;; | |
| 394 ;; 2. Parsing the document for labels and their context can be slow. | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
395 ;; Therefore, RefTeX does it just once automatically. Further parsing |
| 18050 | 396 ;; happens only on user request |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
397 ;; - with a raw C-u prefix arg to any of the functions `reftex-label', |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
398 ;; `reftex-reference', `reftex-citation', `reftex-toc'. |
| 18050 | 399 ;; - with the `r' key from the label selection menu or the *toc* buffer. |
| 400 ;; | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
401 ;; *** If you use `reftex-label' to create labels, the list will be |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
402 ;; *** updated internally, so that no extra parsing is required. |
| 18050 | 403 ;; |
| 404 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| 405 ;; | |
| 406 ;; KNOWN BUGS | |
| 407 ;; | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
408 ;; o If you change `reftex-label-alist' in an editing session, you need to |
| 18050 | 409 ;; reset reftex with `M-x reftex-reset-mode' in order to make these |
| 410 ;; changes effective. Changes introduced with the function | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
411 ;; `reftex-add-to-label-alist' as well as changes applied from the |
| 18050 | 412 ;; customization buffer automatically trigger a reset. |
| 413 ;; | |
| 414 ;; o At times the short context shown by RefTeX may not be what you want. | |
| 415 ;; In particular, eqnarray environments can be difficult to | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
416 ;; parse. RefTeX's default behavior for eqnarrays is to scan backwards to |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
417 ;; either a double backslash or the beginning of the environment. If this |
| 18050 | 418 ;; gives unsatisfactory results, make it a habit to place the label |
| 419 ;; *before* each equation | |
| 420 ;; | |
| 421 ;; \begin{eqnarray} | |
| 422 ;; \label{eq:1} | |
| 423 ;; E = \gamma m c^2 \\ | |
| 424 ;; \label{eq:2} | |
| 425 ;; \gamma = \sqrt{1-v^2/c^2} | |
| 426 ;; \end{eqnarray} | |
| 427 ;; | |
| 428 ;; and turn off parsing for context in equation and eqnarray environments | |
| 429 ;; with | |
| 430 ;; | |
| 431 ;; (setq reftex-use-text-after-label-as-context "e"). | |
| 432 ;; | |
| 433 ;; o RefTeX keeps only one global copy of the configuration variables. | |
| 434 ;; Also any additions from style files go into a global variable. | |
| 435 ;; Practically, this should not be a problem. Theoretically, it could | |
| 436 ;; give conflicts if two documents used environments with identical | |
| 437 ;; names, but different associated label types. | |
| 438 ;; | |
| 439 ;; o Input, include, bibliography and section statements have to be first | |
| 440 ;; on a line (except for white space) in order to be seen by reftex. | |
| 441 ;; | |
| 442 ;; o When the document is scanned, RefTeX creates a large buffer containing | |
| 443 ;; the entire document instead of scanning the individual files one by | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
444 ;; one. This is necessary since a file might not contain the context |
| 18050 | 445 ;; needed by RefTeX. |
| 446 ;; | |
| 447 ;; o If you have two identical section headings in the same file, | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
448 ;; `reftex-toc' will only let you jump to the first one because it searches |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
449 ;; for the section heading from the beginning of the file. You can work |
| 18050 | 450 ;; around this by changing one of the section titles in a way LaTeX does |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
451 ;; not see, e.g. with extra white space. RefTeX will distinguish |
| 18050 | 452 ;; \section{Introduction} from \section{ Introduction}. |
| 453 ;; | |
| 454 ;; o RefTeX sees also labels in regions commented out and will refuse to | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
455 ;; make duplicates of such a label. This is considered to be a feature. |
| 18050 | 456 ;; |
| 457 ;; o When RefTeX tries to show a window full of context from inside a | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
458 ;; section hidden with `outline-minor-mode', it will unhide that section. |
| 18050 | 459 ;; This change will not be reversed automatically. |
| 460 ;; | |
| 461 ;;--------------------------------------------------------------------------- | |
| 462 ;; | |
| 463 ;; TO DO | |
| 464 ;; | |
| 465 ;; I think I am pretty much done with this one... | |
| 466 ;; | |
| 467 ;;--------------------------------------------------------------------------- | |
| 468 ;; | |
| 469 ;; AUTHOR | |
| 470 ;; | |
| 471 ;; Carsten Dominik <dominik@strw.LeidenUniv.nl> | |
| 472 ;; | |
| 473 ;; with contributions from Stephen Eglen | |
| 474 ;; | |
| 475 ;; The newest version of RefTeX can be found at | |
| 476 ;; | |
| 477 ;; http://www.strw.leidenuniv.nl/~dominik/Tools/ | |
| 478 ;; ftp://strw.leidenuniv.nl/pub/dominik/ | |
| 479 ;; | |
| 480 ;; THANKS TO: | |
| 481 ;; --------- | |
| 482 ;; At least the following people have invested time to test and bug-fix | |
| 483 ;; reftex.el. Some have send patches for fixes or new features. | |
| 484 ;; | |
| 485 ;; Stephen Eglen <stephene@cogs.susx.ac.uk> | |
| 486 ;; F.E.Burstall <F.E.Burstall@maths.bath.ac.uk> | |
| 487 ;; Karl Eichwalder <ke@ke.Central.DE> | |
| 488 ;; Laurent Mugnier <mugnier@onera.fr> | |
| 489 ;; Rory Molinari <molinari@yunt.math.lsa.umich.edu> | |
| 490 ;; Soren Dayton <csdayton@cs.uchicago.edu> | |
| 491 ;; Daniel Polani <polani@Informatik.Uni-Mainz.DE> | |
| 492 ;; Allan Strand <astrand@trillium.NMSU.Edu> | |
| 493 ;; | |
| 494 ;; The view crossref feature was inspired by the similar function in | |
| 495 ;; Peter S. Galbraith's bib-cite.el. | |
| 496 ;; | |
| 497 ;; Finally thanks to Uwe Bolick <bolick@physik.tu-berlin.de> who first | |
| 498 ;; got me (some years ago) into supporting LaTeX labels and references | |
| 499 ;; with an Editor (which was MicroEmacs at the time). | |
|
18219
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
500 ;; |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
501 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
502 ;; |
| 18050 | 503 |
| 504 ;;; Code: | |
| 505 | |
| 506 ;; Stuff that needs to be there when we use defcustom | |
| 507 ;; -------------------------------------------------- | |
| 508 | |
| 509 (require 'custom) | |
| 510 | |
| 511 (defvar reftex-tables-dirty t | |
| 512 "Flag showing if tables need to be re-computed.") | |
| 513 | |
| 514 (eval-and-compile | |
| 515 (defun reftex-set-dirty (symbol value) | |
| 516 (setq reftex-tables-dirty t) | |
| 517 (set symbol value))) | |
| 518 | |
| 519 ;;; Begin of Configuration Section ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| 520 | |
| 521 ;; Configuration Variables and User Options for RefTeX ------------------ | |
| 522 | |
| 523 (defgroup reftex nil | |
| 524 "LaTeX label and citation support." | |
| 525 :tag "RefTeX" | |
| 526 :link '(url-link :tag "Home Page" "http://strw.leidenuniv.nl/~dominik/Tools/") | |
| 527 :prefix "reftex-" | |
| 528 :group 'tex) | |
| 529 | |
| 530 (defun reftex-customize () | |
| 531 "Call the customize function with reftex as argument." | |
| 532 (interactive) | |
| 533 (if (fboundp 'customize-group) | |
| 534 (customize-group 'reftex) | |
| 535 (customize 'reftex))) | |
| 536 | |
| 18123 | 537 ;; Support for \label and \ref -------------------------------------- |
| 18050 | 538 |
| 539 (defgroup reftex-label-support nil | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
540 "Support for creation, insertion and referencing of labels in LaTeX." |
| 18050 | 541 :group 'reftex) |
| 542 | |
| 543 (defgroup reftex-defining-label-environments nil | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
544 "Definition of environments and macros to do with label." |
| 18050 | 545 :group 'reftex-label-support) |
| 546 | |
| 547 | |
| 548 (defcustom reftex-label-alist nil | |
| 18123 | 549 "Alist with information on environments for \\label-\\ref use. |
|
18220
36a61aa59b9d
(tex-main-file, outline-minor-mode): Add defvars.
Richard M. Stallman <rms@gnu.org>
parents:
18219
diff
changeset
|
550 See the definition of `reftex-label-alist-builtin' for examples. This variable |
| 18050 | 551 should define additions and changes to the default. The only things you MUST |
|
18220
36a61aa59b9d
(tex-main-file, outline-minor-mode): Add defvars.
Richard M. Stallman <rms@gnu.org>
parents:
18219
diff
changeset
|
552 NOT change is that `?s' is the type indicator for section labels and SPACE is |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
553 for the `any' label type. These are hard-coded at other places in the code. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
554 |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
555 Changes to this variable after RefTeX has been loaded become only |
| 18050 | 556 effective when RefTeX is reset with \\[reftex-reset-mode]. |
| 557 | |
| 558 Each list entry is a list describing an environment or macro carrying a | |
|
18220
36a61aa59b9d
(tex-main-file, outline-minor-mode): Add defvars.
Richard M. Stallman <rms@gnu.org>
parents:
18219
diff
changeset
|
559 label. The elements of each list entry are: |
| 18050 | 560 |
| 561 0. Name of the environment (like \"table\") or macro (like \"\\\\myfig\"). | |
| 562 Special names: `section' for section labels, `any' to define a group | |
| 563 which contains all labels. | |
| 564 This may also be nil if this entry is only meant to change some settings | |
| 565 associated with the type indicator character (see below). | |
| 566 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
567 1. Type indicator character, like `?t'. |
| 18050 | 568 The type indicator is a single character used in prompts for |
|
18220
36a61aa59b9d
(tex-main-file, outline-minor-mode): Add defvars.
Richard M. Stallman <rms@gnu.org>
parents:
18219
diff
changeset
|
569 label types. It must be a printable character. The same character |
| 18050 | 570 may occur several times in this list, to cover cases in which different |
| 571 environments carry the same label type (like equation and eqnarray). | |
| 572 | |
| 573 2. Label prefix string, like \"tab:\". | |
|
18220
36a61aa59b9d
(tex-main-file, outline-minor-mode): Add defvars.
Richard M. Stallman <rms@gnu.org>
parents:
18219
diff
changeset
|
574 The prefix is a short string used as the start of a label. It may be the |
| 18050 | 575 empty string. |
| 576 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
577 3. Format string for reference insert in buffer. Each `%s' will be replaced |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
578 by the label (several `%s' can be there to do this: |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
579 \"\\ref{%s} on page~\\pageref{%s}\"). |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
580 When the format starts with `~', whitespace before point will be removed |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
581 so that the reference cannot be separated from the word before it. |
| 18050 | 582 |
| 583 4. Indication on how to find the short context. | |
|
18220
36a61aa59b9d
(tex-main-file, outline-minor-mode): Add defvars.
Richard M. Stallman <rms@gnu.org>
parents:
18219
diff
changeset
|
584 - If nil, use the text following the \\label{...} macro. |
|
36a61aa59b9d
(tex-main-file, outline-minor-mode): Add defvars.
Richard M. Stallman <rms@gnu.org>
parents:
18219
diff
changeset
|
585 - If t, use |
| 18050 | 586 - text following the \\begin{...} statement of environments |
| 587 (not a good choice in in eqnarray or enumerate environments!) | |
| 588 - the section heading for section labels. | |
| 589 - the begin of the macro for macros. | |
|
18220
36a61aa59b9d
(tex-main-file, outline-minor-mode): Add defvars.
Richard M. Stallman <rms@gnu.org>
parents:
18219
diff
changeset
|
590 - If a string, use as regexp to search *backward* from the label. Context |
|
36a61aa59b9d
(tex-main-file, outline-minor-mode): Add defvars.
Richard M. Stallman <rms@gnu.org>
parents:
18219
diff
changeset
|
591 is then the text following the end of the match. E.g. putting this to |
| 18050 | 592 \"\\\\\\\\caption{\" will use the beginning of the caption in a figure |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
593 or table environment. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
594 \"\\\\\\\\begin{eqnarray}\\\\|\\\\\\\\\\\\\\\\\" works for eqnarrays. |
| 18050 | 595 - If a function, call this function with the name of the environment/macro |
|
18220
36a61aa59b9d
(tex-main-file, outline-minor-mode): Add defvars.
Richard M. Stallman <rms@gnu.org>
parents:
18219
diff
changeset
|
596 as argument. On call, point will be just after the \\label macro. The |
|
36a61aa59b9d
(tex-main-file, outline-minor-mode): Add defvars.
Richard M. Stallman <rms@gnu.org>
parents:
18219
diff
changeset
|
597 function is expected to return a suitable context string. It should |
| 18050 | 598 throw an exception (error) when failing to find context. |
| 599 Consider the following example, which would return the 10 characters | |
| 600 following the label as context: | |
| 601 | |
| 602 (defun my-context-function (env-or-mac) | |
| 603 (if (> (point-max) (+ 10 (point))) | |
| 604 (buffer-substring (point) (+ 10 (point))) | |
| 605 (error \"Buffer too small\"))) | |
| 606 | |
|
18220
36a61aa59b9d
(tex-main-file, outline-minor-mode): Add defvars.
Richard M. Stallman <rms@gnu.org>
parents:
18219
diff
changeset
|
607 Setting the variable `reftex-use-text-after-label-as-context' to t |
|
36a61aa59b9d
(tex-main-file, outline-minor-mode): Add defvars.
Richard M. Stallman <rms@gnu.org>
parents:
18219
diff
changeset
|
608 overrides the setting here. |
|
36a61aa59b9d
(tex-main-file, outline-minor-mode): Add defvars.
Richard M. Stallman <rms@gnu.org>
parents:
18219
diff
changeset
|
609 |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
610 5. List of magic words which identify a reference to be of this type. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
611 If the word before point is equal to one of these words when calling |
|
18220
36a61aa59b9d
(tex-main-file, outline-minor-mode): Add defvars.
Richard M. Stallman <rms@gnu.org>
parents:
18219
diff
changeset
|
612 `reftex-reference', the label list offered will be automatically restricted |
| 18050 | 613 to labels of the correct type. |
| 614 | |
| 615 If the type indicator characters of two or more entries are the same, RefTeX | |
| 616 will use | |
| 617 - the first non-nil format and prefix | |
| 618 - the magic words of all involved entries. | |
| 619 | |
|
18220
36a61aa59b9d
(tex-main-file, outline-minor-mode): Add defvars.
Richard M. Stallman <rms@gnu.org>
parents:
18219
diff
changeset
|
620 Any list entry may also be a symbol. If that has an association in |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
621 `reftex-label-alist-builtin', the cdr of that association is spliced into the |
|
18220
36a61aa59b9d
(tex-main-file, outline-minor-mode): Add defvars.
Richard M. Stallman <rms@gnu.org>
parents:
18219
diff
changeset
|
622 list. See the AMSTeX configuration example in the comment section of |
|
36a61aa59b9d
(tex-main-file, outline-minor-mode): Add defvars.
Richard M. Stallman <rms@gnu.org>
parents:
18219
diff
changeset
|
623 `reftex.el'." |
| 18050 | 624 :group 'reftex-defining-label-environments |
| 625 :set 'reftex-set-dirty | |
| 626 :type '(list | |
| 627 :convert-widget | |
| 628 (lambda (widget) | |
| 629 (let* | |
| 630 ((args | |
| 631 (list | |
| 632 `(repeat | |
| 633 :inline t | |
| 634 (radio | |
| 635 :value ("" ?a nil nil t nil) | |
| 636 (choice | |
| 637 :tag "Builtin" | |
| 638 :value AMSTeX | |
| 639 ,@(mapcar (function (lambda (x) | |
| 640 (list 'const ':tag (nth 1 x) (car x)))) | |
| 641 reftex-label-alist-builtin)) | |
| 642 (list :tag "Detailed custom entry" | |
| 643 (choice :tag "Environment or \\macro " | |
| 644 (const :tag "Ignore, just use typekey" nil) | |
| 645 (string "")) | |
| 646 (character :tag "Typekey character " ?a) | |
| 647 (choice :tag "Label prefix string " | |
| 648 (const :tag "Copy from similar label type" nil) | |
| 649 (string :tag "Specify here" "lab:")) | |
| 650 (choice :tag "Label reference format" | |
| 651 (const :tag "Copy from similar label type" nil) | |
| 652 (string :tag "Specify here" "~\\ref{%s}")) | |
| 653 (choice :tag "Grab context method " | |
| 654 (const :tag "Default position" t) | |
| 655 (const :tag "After label" nil) | |
| 656 (regexp :tag "Regular expression" "") | |
| 657 (symbol :tag "Function" my-context-function)) | |
| 658 (repeat :tag "List of Magic Words" (string)))))))) | |
| 659 (widget-put widget :args args) | |
| 660 widget)))) | |
| 661 | |
| 662 (defcustom reftex-default-label-alist-entries '(Sideways LaTeX) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
663 "Default label alist specifications. LaTeX should be the last entry. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
664 This list describes the default label environments RefTeX should always use |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
665 in addition to the specifications in reftex-label-alist. It is probably a |
| 18050 | 666 mistake to remove the LaTeX symbol from this list. |
| 667 | |
|
18219
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
668 The options include: |
| 18050 | 669 LaTeX The standard LaTeX environments |
| 670 Sideways The sidewaysfigure and sidewaystable environments | |
| 671 AMSTeX The math environments in the AMS_LaTeX amsmath package | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
672 |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
673 For the full list of options, see the constant `reftex-label-alist-builtin'. |
|
18219
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
674 Better still, try |
|
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
675 |
|
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
676 M-x customize-variable RET reftex-default-label-alist-entries RET." |
| 18050 | 677 :group 'reftex-defining-label-environments |
| 678 :set 'reftex-set-dirty | |
| 679 :type '(list :indent 4 | |
| 680 :convert-widget | |
| 681 (lambda (widget) | |
| 682 (let* ((args | |
| 683 (list | |
| 684 `(checklist | |
| 685 :inline t | |
| 686 ,@(reverse | |
| 687 (mapcar (lambda (x) | |
| 688 (list 'const ':tag (nth 1 x) (car x))) | |
| 689 reftex-label-alist-builtin)))))) | |
| 690 (widget-put widget :args args) | |
| 691 widget)))) | |
| 692 | |
| 693 (defcustom reftex-use-text-after-label-as-context nil | |
| 694 "*t means, grab context from directly after the \\label{..} macro. | |
| 695 This is the fastest method for obtaining context of the label definition, but | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
696 requires discipline when placing labels. Setting this variable to t takes |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
697 precedence over the individual settings in `reftex-label-alist'. |
| 18050 | 698 This variable may be set to t, nil, or a string of label type letters |
| 699 indicating the label types for which it should be true." | |
| 700 :group 'reftex-defining-label-environments | |
| 701 :set 'reftex-set-dirty | |
| 702 :type '(choice | |
| 703 (const :tag "on" t) (const :tag "off" nil) | |
| 704 (string :tag "Selected label types"))) | |
| 705 | |
| 706 ;; Label insertion | |
| 707 | |
| 708 (defgroup reftex-making-and-inserting-labels nil | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
709 "Options on how to create new labels." |
| 18050 | 710 :group 'reftex-label-support) |
| 711 | |
| 712 (defcustom reftex-insert-label-flags '("s" "sft") | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
713 "Flags governing label insertion. First flag DERIVE, second flag PROMPT. |
| 18050 | 714 |
| 715 If DERIVE is t, RefTeX will try to derive a sensible label from context. | |
| 716 A section label for example will be derived from the section heading. | |
| 717 The conversion of the context to a legal label is governed by the | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
718 specifications given in `reftex-derive-label-parameters'. |
| 18050 | 719 If RefTeX fails to derive a label, it will prompt the user. |
| 720 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
721 If PROMPT is t, the user will be prompted for a label string. The prompt will |
| 18050 | 722 already contain the prefix, and (if DERIVE is t) a default label derived from |
| 723 context. When PROMPT is nil, the default label will be inserted without | |
| 724 query. | |
| 725 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
726 So the combination of DERIVE and PROMPT controls label insertion. Here is a |
| 18050 | 727 table describing all four possibilities: |
| 728 | |
| 729 DERIVE PROMPT ACTION | |
| 730 ------------------------------------------------------------------------- | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
731 nil nil Insert simple label, like eq:22 or sec:13. No query. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
732 nil t Prompt for label. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
733 t nil Derive a label from context and insert without query. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
734 t t Derive a label from context and prompt for confirmation. |
| 18050 | 735 |
| 736 Each flag may be set to t, nil, or a string of label type letters | |
| 737 indicating the label types for which it should be true. | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
738 Thus, the combination may be set differently for each label type. The |
| 18050 | 739 default settings \"s\" and \"sft\" mean: Derive section labels from headings |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
740 (with confirmation). Prompt for figure and table labels. Use simple labels |
| 18050 | 741 without confirmation for everything else." |
| 742 :group 'reftex-making-and-inserting-labels | |
| 743 :type '(list (choice :tag "Derive label from context" | |
| 744 (const :tag "always" t) | |
| 745 (const :tag "never" nil) | |
| 746 (string :tag "for selected label types" "")) | |
| 747 (choice :tag "Prompt for label string " | |
| 748 :entry-format " %b %v" | |
| 749 (const :tag "always" t) | |
| 750 (const :tag "never" nil) | |
| 751 (string :tag "for selected label types" "")))) | |
| 752 | |
| 753 (defcustom reftex-derive-label-parameters '(3 20 t 1 "-" ; continue | |
| 754 ("the" "on" "in" "off" "a" "for" "by" "of" "and" "is")) | |
| 755 "Parameters for converting a string into a label. | |
| 756 NWORDS Number of words to use. | |
| 757 MAXCHAR Maximum number of characters in a label string. | |
| 758 ILLEGAL nil: Throw away any words containing characters illegal in labels. | |
| 759 t: Throw away only the illegal characters, not the whole word. | |
| 760 ABBREV nil: Never abbreviate words. | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
761 t: Always abbreviate words (see `reftex-abbrev-parameters'). |
| 18050 | 762 not t and not nil: Abbreviate words if necessary to shorten |
| 763 label string below MAXCHAR. | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
764 SEPARATOR String separating different words in the label. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
765 IGNOREWORDS List of words which should not be part of labels." |
| 18050 | 766 :group 'reftex-making-and-inserting-labels |
| 767 :type '(list (integer :tag "Number of words " 3) | |
| 768 (integer :tag "Maximum label length " 20) | |
| 769 (choice :tag "Illegal characters in words" | |
| 770 (const :tag "throw away entire word" nil) | |
| 771 (const :tag "throw away single chars" t)) | |
| 772 (choice :tag "Abbreviate words " | |
| 773 (const :tag "never" nil) | |
| 774 (const :tag "always" t) | |
| 775 (const :tag "when label is too long" 1)) | |
| 776 (string :tag "Separator between words " "-") | |
| 777 (repeat :tag "Ignore words" | |
| 778 :entry-format " %i %d %v" | |
| 779 (string :tag "")))) | |
| 780 | |
| 781 (defcustom reftex-label-illegal-re "[\000-\040\177-\377\\\\#$%&~^_{}]" | |
| 782 "Regexp matching characters not legal in labels. | |
| 783 For historic reasons, this character class comes *with* the [] brackets." | |
| 784 :group 'reftex-making-and-inserting-labels | |
| 785 :type '(regexp :tag "Character class")) | |
| 786 | |
| 787 (defcustom reftex-abbrev-parameters '(4 2 "^saeiou" "aeiou") | |
| 788 "Parameters for abbreviation of words. | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
789 MIN-CHARS Minimum number of characters remaining after abbreviation. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
790 MIN-KILL Minimum number of characters to remove when abbreviating words. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
791 BEFORE Character class before abbrev point in word. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
792 AFTER Character class after abbrev point in word." |
| 18050 | 793 :group 'reftex-making-and-inserting-labels |
| 794 :type '(list | |
| 795 (integer :tag "Minimum chars per word" 4) | |
| 796 (integer :tag "Shorten by at least " 2) | |
| 797 (string :tag "cut before char class " "^saeiou") | |
| 798 (string :tag "cut after char class " "aeiou"))) | |
| 799 | |
| 800 | |
| 801 ;; Label referencing | |
| 802 | |
| 803 (defgroup reftex-referencing-labels nil | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
804 "Options on how to reference labels." |
| 18050 | 805 :group 'reftex-label-support) |
| 806 | |
| 807 (defcustom reftex-label-menu-flags '(t t nil nil nil nil) | |
| 808 "*List of flags governing the label menu makeup. | |
| 809 The flags are: | |
| 810 | |
| 811 TABLE-OF-CONTENTS Show the labels embedded in a table of context. | |
| 812 SECTION-NUMBERS Include section numbers (like 4.1.3) in table of contents. | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
813 COUNTERS Show counters. This just numbers the labels in the menu. |
| 18050 | 814 NO-CONTEXT Non-nil means do NOT show the short context. |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
815 FOLLOW Follow full context in other window. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
816 SHOW-COMMENTED Show labels from regions which are commented out. RefTeX |
| 18050 | 817 sees these labels, but does not normally show them. |
| 818 | |
| 819 Each of these flags can be set to t or nil, or to a string of type letters | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
820 indicating the label types for which it should be true. These strings work |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
821 like character classes in regular expressions. Thus, setting one of the |
| 18050 | 822 flags to \"sf\" makes the flag true for section and figure labels, nil |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
823 for everything else. Setting it to \"^ft\" makes it the other way round. |
| 18050 | 824 |
| 825 Most options can also be switched from the label menu itself - so if you | |
| 826 decide here to not have a table of contents in the label menu, you can still | |
| 827 get one interactively during selection from the label menu." | |
| 828 :group 'reftex-referencing-labels | |
| 829 :type '(list | |
| 830 (choice :tag "Embed in table of contents " | |
| 831 (const :tag "on" t) (const :tag "off" nil) | |
| 832 (string :tag "Selected label types")) | |
| 833 (choice :tag "Show section numbers " | |
| 834 (const :tag "on" t) (const :tag "off" nil)) | |
| 835 (choice :tag "Show individual counters " | |
| 836 (const :tag "on" t) (const :tag "off" nil) | |
| 837 (string :tag "Selected label types")) | |
| 838 (choice :tag "Hide short context " | |
| 839 (const :tag "on" t) (const :tag "off" nil) | |
| 840 (string :tag "Selected label types")) | |
| 841 (choice :tag "Follow context in other window" | |
| 842 (const :tag "on" t) (const :tag "off" nil) | |
| 843 (string :tag "Selected label types")) | |
| 844 (choice :tag "Show commented labels " | |
| 845 (const :tag "on" t) (const :tag "off" nil) | |
| 846 (string :tag "Selected label types")))) | |
| 847 | |
| 848 | |
| 849 (defcustom reftex-guess-label-type t | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
850 "*Non-nil means, `reftex-reference' will try to guess the label type. |
| 18050 | 851 To do that, RefTeX will look at the word before the cursor and compare it with |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
852 the words given in `reftex-label-alist'. When it finds a match, RefTeX will |
| 18050 | 853 immediately offer the correct label menu - otherwise it will prompt you for |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
854 a label type. If you set this variable to nil, RefTeX will always prompt." |
| 18050 | 855 :group 'reftex-referencing-labels |
| 856 :type '(boolean)) | |
| 857 | |
| 858 ;; BibteX citation configuration ---------------------------------------- | |
| 859 | |
| 860 (defgroup reftex-citation-support nil | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
861 "Support for referencing bibliographic data with BibTeX." |
| 18050 | 862 :group 'reftex) |
| 863 | |
| 864 (defcustom reftex-bibpath-environment-variables '("BIBINPUTS" "TEXBIB") | |
| 865 "*List of env vars which might contain the path to BibTeX database files." | |
| 866 :group 'reftex-citation-support | |
| 867 :set 'reftex-set-dirty | |
| 868 :type '(repeat (string :tag "Environment variable"))) | |
| 869 | |
| 870 (defcustom reftex-bibfile-ignore-list nil | |
| 871 "List of files in \\bibliography{..} RefTeX should *not* parse. | |
| 872 The file names have to be in the exact same form as in the bibliography | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
873 macro - i.e. without the `.bib' extension. |
| 18050 | 874 Intended for files which contain only `@string' macro definitions and the |
| 875 like, which are ignored by RefTeX anyway." | |
| 876 :group 'reftex-citation-support | |
| 877 :set 'reftex-set-dirty | |
| 878 :type '(repeat (string :tag "File name"))) | |
| 879 | |
| 880 (defcustom reftex-sort-bibtex-matches 'reverse-year | |
| 881 "*Sorting of the entries found in BibTeX databases by reftex-citation. | |
| 882 Possible values: | |
| 883 nil Do not sort entries. | |
| 884 'author Sort entries by author name. | |
| 885 'year Sort entries by increasing year. | |
| 886 'reverse-year Sort entries by decreasing year." | |
| 887 :group 'reftex-citation-support | |
| 888 :type '(choice (const :tag "not" nil) | |
| 889 (const :tag "by author" author) | |
| 890 (const :tag "by year" year) | |
| 891 (const :tag "by year, reversed" reverse-year))) | |
| 892 | |
| 893 (defcustom reftex-cite-format 'reftex-cite-format-default | |
| 894 "Defines the format of citations to be inserted into the buffer. | |
| 895 It can be a string, a list of strings, or an alist with characters as keys | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
896 and a list of strings in the car. In the simplest case, this can just |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
897 be the string \"\\cite{KEY}\", which is also the default. See the |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
898 definition of the `reftex-cite-format-XXXX' constants for more complex |
| 18050 | 899 examples. |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
900 If `reftex-cite-format' is a string, it will be used as the format. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
901 In the format, AUTHOR will be replaced by the last name of the |
| 18050 | 902 author, YEAR will be replaced by the year and KEY by the citation |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
903 key. If AUTHOR is present several times, it will be replaced with |
| 18050 | 904 successive author names. |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
905 See the constant `reftex-cite-format-default' for an example. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
906 If `reftex-cite-format' is a list of strings, the string used will |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
907 depend upon the number of authors of the article. No authors means, |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
908 the first string will be used; 1 author means, the second string will |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
909 be used etc.. The last string in the list will be used for all articles |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
910 with too many authors. See `reftex-cite-format-1-author-simple' for an |
| 18050 | 911 example. |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
912 If `reftex-cite-format' is a list of cons cells, the car of each cell |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
913 needs to be a character. When a selected reference is accepted by |
| 18050 | 914 pressing that key, the cdr of the associated list will be used as |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
915 described above. See `reftex-cite-format-2-authors' for an example. |
| 18050 | 916 In order to configure this variable, you can either set |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
917 `reftex-cite-format' directly yourself or set it to the SYMBOL of one of |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
918 the predefined constants. E.g.: |
| 18050 | 919 (setq reftex-cite-format 'reftex-cite-format-2-authors)" |
| 920 :group 'reftex-citation-support | |
| 921 :type | |
| 922 '(choice | |
| 923 (choice :tag "symbolic defaults" | |
| 924 :value reftex-cite-format-default | |
| 925 (const reftex-cite-format-default) | |
| 926 (const reftex-cite-format-1-author-simple) | |
| 927 (const reftex-cite-format-2-authors)) | |
| 928 (string :tag "format string" "\\cite{KEY}") | |
| 929 (repeat :tag "list of strings" | |
| 930 :value ("\cite{KEY}" "AUTHOR \cite{KEY}" "AUTHOR and AUTHOR \cite{KEY}") | |
| 931 (string :tag "format string" "")) | |
| 932 (repeat :tag "key-ed lists of strings" | |
| 933 :value ((? . ("\cite{KEY}" "AUTHOR \cite{KEY}" "AUTHOR and AUTHOR \cite{KEY}"))) | |
| 934 (cons :tag "Enter a keyed list of format strings" | |
| 935 (character :tag "Key character " ? ) | |
| 936 (repeat | |
| 937 (string :tag "format string" "")))))) | |
| 938 | |
| 939 ;; Table of contents configuration -------------------------------------- | |
| 940 | |
| 941 (defgroup reftex-table-of-contents-browser nil | |
| 942 "A multifile table of contents browser." | |
| 943 :group 'reftex) | |
| 944 | |
| 945 (defcustom reftex-toc-follow-mode nil | |
| 946 "Non-nil means, point in *toc* buffer will cause other window to follow. | |
| 947 The other window will show the corresponding part of the document. | |
| 948 This flag can be toggled from within the *toc* buffer with the `f' key." | |
| 949 :group 'reftex-table-of-contents-browser | |
| 950 :type '(boolean)) | |
| 951 | |
| 952 ;; Miscellaneous configurations ----------------------------------------- | |
| 953 | |
| 954 (defgroup reftex-miscellaneous-configurations nil | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
955 "Collection of further configurations." |
| 18050 | 956 :group 'reftex) |
| 957 | |
| 958 (defcustom reftex-extra-bindings nil | |
| 959 "Non-nil means, make additional key bindings on startup. | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
960 These extra bindings are located in the users `C-c letter' map." |
| 18050 | 961 :group 'reftex-miscellaneous-configurations |
| 962 :type '(boolean)) | |
| 963 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
964 (defcustom reftex-plug-into-AUCTeX nil |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
965 "Plug-in flags for AUCTeX interface. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
966 This variable is a list of 4 boolean flags. When a flag is non-nil, it |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
967 means: |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
968 |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
969 Flag 1: use `reftex-label' as `LaTeX-label-function'. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
970 Flag 2: use `reftex-arg-label' as `TeX-arg-label' |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
971 Flag 3: use `reftex-arg-ref' as `TeX-arg-ref' |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
972 Flag 4: use `reftex-arg-cite' as `TeX-arg-cite' |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
973 |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
974 You may also set the variable itself to t or nil in order to turn all |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
975 plug-ins on or off, respectively. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
976 \\<LaTeX-mode-map>`LaTeX-label-function' is the function used for label insertion when you |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
977 enter a new environment in AUCTeX with \\[LaTeX-environment]. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
978 The `TeX-arg-label' etc. functions are for entering macro arguments during |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
979 macro insertion with \\[TeX-insert-macro]. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
980 See the AUCTeX documentation for more information. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
981 RefTeX uses `fset' to take over the function calls. Changing the variable |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
982 may require a restart of Emacs in order to become effective." |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
983 :group 'reftex-miscellaneous-configurations |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
984 :type '(choice (const :tag "No plug-ins" nil) |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
985 (const :tag "All possible plug-ins" t) |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
986 (list |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
987 :tag "Individual choice" |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
988 :value (nil nil nil nil) |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
989 (boolean :tag "Use reftex-label as LaTeX-label-function") |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
990 (boolean :tag "Use reftex-arg-label as TeX-arg-label ") |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
991 (boolean :tag "Use reftex-arg-ref as TeX-arg-ref ") |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
992 (boolean :tag "Use reftex-arg-cite as TeX-arg-cite ") |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
993 ))) |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
994 |
| 18050 | 995 (defcustom reftex-use-fonts t |
| 996 "*Non-nil means, use fonts in label menu and on-the-fly help. | |
| 997 Font-lock must be loaded as well to actually get fontified display." | |
| 998 :group 'reftex-miscellaneous-configurations | |
| 999 :type '(boolean)) | |
| 1000 | |
| 1001 (defcustom reftex-keep-temporary-buffers t | |
| 1002 "*Non-nil means, keep any TeX and BibTeX files loaded for lookup. | |
| 1003 Nil means, kill it immediately after use unless it was already an existing | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1004 buffer before the lookup happened. It is faster to keep the buffers, but can |
| 18050 | 1005 use a lot of memory, depending on the size of your database and document." |
| 1006 :group 'reftex-miscellaneous-configurations | |
| 1007 :type '(boolean)) | |
| 1008 | |
| 1009 (defcustom reftex-auto-show-entry t | |
| 1010 "*Non-nil means, showing context in another window may unhide a section. | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1011 This is important when using outline-minor-mode. If the context to be shown |
| 18050 | 1012 is in a hidden section, RefTeX will issue a \"show-entry\" command in order |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1013 to show it. This is not reversed when the label is selected - so the section |
| 18050 | 1014 remains shown after command completion." |
| 1015 :group 'reftex-miscellaneous-configurations | |
| 1016 :type '(boolean)) | |
| 1017 | |
| 1018 | |
| 1019 ;;; End of Configuration Section ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| 1020 | |
| 1021 ;;;=========================================================================== | |
| 1022 ;;; | |
| 1023 ;;; Define the formal stuff for a minor mode named RefTeX. | |
| 1024 ;;; | |
| 1025 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1026 (defconst reftex-version "2.14 for Emacs distribution." |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1027 "Version string for RefTeX.") |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1028 |
| 18050 | 1029 (defvar reftex-mode nil |
| 1030 "Determines if RefTeX minor mode is active.") | |
| 1031 (make-variable-buffer-local 'reftex-mode) | |
| 1032 | |
| 1033 (defvar reftex-mode-map (make-sparse-keymap) | |
| 1034 "Keymap for RefTeX minor mode.") | |
| 1035 | |
| 1036 (defvar reftex-mode-menu nil) | |
| 1037 | |
| 1038 ;;;###autoload | |
| 1039 (defun turn-on-reftex () | |
| 1040 "Turn on RefTeX minor mode." | |
| 1041 (reftex-mode t)) | |
| 1042 | |
| 1043 ;;;###autoload | |
| 1044 (defun reftex-mode (&optional arg) | |
| 18123 | 1045 "Minor mode with distinct support for \\label, \\ref and \\cite in LaTeX. |
| 18050 | 1046 |
| 1047 Labels can be created with `\\[reftex-label]' and referenced with `\\[reftex-reference]'. | |
| 1048 When referencing, you get a menu with all labels of a given type and | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1049 context of the label definition. The selected label is inserted as a |
| 18123 | 1050 \\ref macro. |
| 18050 | 1051 |
| 1052 Citations can be made with `\\[reftex-citation]' which will use a regular expression | |
| 1053 to pull out a *formatted* list of articles from your BibTeX | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1054 database. The selected citation is inserted as a \\cite macro. |
| 18050 | 1055 |
| 1056 A Table of Contents of the entire (multifile) document with browsing | |
| 1057 capabilities is available with `\\[reftex-toc]'. | |
| 1058 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1059 Most command have help available on the fly. This help is accessed by |
| 18050 | 1060 pressing `?' to any prompt mentioning this feature. |
| 1061 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1062 Extensive documentation about reftex is in the file header of `reftex.el'. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1063 |
| 18050 | 1064 \\{reftex-mode-map} |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1065 Under X, these functions will also be available in a menu on the menu bar. |
| 18050 | 1066 |
| 1067 ------------------------------------------------------------------------------" | |
| 1068 | |
| 1069 (interactive "P") | |
| 1070 (setq reftex-mode (not (or (and (null arg) reftex-mode) | |
| 1071 (<= (prefix-numeric-value arg) 0)))) | |
| 1072 | |
| 1073 ; Add or remove the menu, and run the hook | |
| 1074 (if reftex-mode | |
| 1075 (progn | |
| 1076 (easy-menu-add reftex-mode-menu) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1077 (reftex-plug-into-AUCTeX) |
| 18050 | 1078 (run-hooks 'reftex-mode-hook)) |
| 1079 (easy-menu-remove reftex-mode-menu))) | |
| 1080 | |
| 1081 (or (assoc 'reftex-mode minor-mode-alist) | |
| 1082 (setq minor-mode-alist | |
| 1083 (cons '(reftex-mode " Ref") minor-mode-alist))) | |
| 1084 | |
| 1085 (or (assoc 'reftex-mode minor-mode-map-alist) | |
| 1086 (setq minor-mode-map-alist | |
| 1087 (cons (cons 'reftex-mode reftex-mode-map) | |
| 1088 minor-mode-map-alist))) | |
| 1089 | |
| 1090 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1091 |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1092 |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1093 |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1094 |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1095 |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1096 |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1097 |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1098 |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1099 ;;; =========================================================================== |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1100 ;;; |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1101 ;;; Silence warnings about variables in other packages. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1102 (defvar TeX-master) |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1103 (defvar LaTeX-label-function) |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1104 (defvar tex-main-file) |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1105 (defvar outline-minor-mode) |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1106 |
| 18050 | 1107 ;;; =========================================================================== |
| 1108 ;;; | |
| 1109 ;;; Interfaces for other packages | |
| 1110 ;;; ----------------------------- | |
| 1111 ;;; | |
| 1112 ;;; AUCTeX | |
| 1113 ;;; ------ | |
| 1114 | |
| 1115 (defun reftex-arg-label (optional &optional prompt definition) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1116 "Use `reftex-label' to create label. Insert it with `TeX-argument-insert'. |
| 18050 | 1117 This function is intended for AUCTeX macro support." |
| 1118 (let ((label (reftex-label nil t))) | |
| 1119 (if (and definition (not (string-equal "" label))) | |
| 1120 (LaTeX-add-labels label)) | |
| 1121 (TeX-argument-insert label optional optional))) | |
| 1122 | |
| 1123 (defun reftex-arg-ref (optional &optional prompt definition) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1124 "Use `reftex-reference' to select label. Insert with `TeX-argument-insert'. |
| 18050 | 1125 This function is intended for AUCTeX macro support." |
| 1126 (let ((label (reftex-reference nil t))) | |
| 1127 (if (and definition (not (string-equal "" label))) | |
| 1128 (LaTeX-add-labels label)) | |
| 1129 (TeX-argument-insert label optional optional))) | |
| 1130 | |
| 1131 (defun reftex-arg-cite (optional &optional prompt definition) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1132 "Use reftex-citation to select a key. Insert with `TeX-argument-insert'. |
| 18050 | 1133 This function is intended for AUCTeX macro support." |
| 1134 (let ((key (reftex-citation nil t))) | |
| 1135 (TeX-argument-insert (or key "") optional optional))) | |
| 1136 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1137 (defun reftex-plug-into-AUCTeX () |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1138 ;; Replace AucTeX functions with RefTeX functions. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1139 ;; Which functions are replaced is controlled by the variable |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1140 ;; `reftex-plug-into-AUCTeX'. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1141 (let ((flags |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1142 (cond ((eq reftex-plug-into-AUCTeX t) '(t t t t)) |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1143 ((eq reftex-plug-into-AUCTeX nil) '(nil nil nil nil)) |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1144 (t reftex-plug-into-AUCTeX)))) |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1145 |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1146 (and (nth 0 flags) |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1147 (boundp 'LaTeX-label-function) |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1148 (setq LaTeX-label-function 'reftex-label)) |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1149 |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1150 (and (nth 1 flags) |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1151 (fboundp 'TeX-arg-label) |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1152 (fset 'TeX-arg-label 'reftex-arg-label)) |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1153 |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1154 (and (nth 2 flags) |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1155 (fboundp 'TeX-arg-ref) |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1156 (fset 'TeX-arg-ref 'reftex-arg-ref)) |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1157 |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1158 (and (nth 3 flags) |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1159 (fboundp 'TeX-arg-cite) |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1160 (fset 'TeX-arg-cite 'reftex-arg-cite)))) |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1161 |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1162 |
| 18050 | 1163 (defvar reftex-label-alist-external-add-ons nil |
| 1164 "List of label alist entries added with reftex-add-to-label-alist.") | |
| 1165 | |
| 1166 ;;;###autoload | |
| 1167 (defun reftex-add-to-label-alist (entry-list) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1168 "Add label environment descriptions to `reftex-label-alist-external-add-ons'. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1169 The format of ENTRY-LIST is exactly like `reftex-label-alist'. See there |
| 18050 | 1170 for details. |
| 1171 This function makes it possible to support RefTeX from AUCTeX style files. | |
| 1172 The entries in ENTRY-LIST will be processed after the user settings in | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1173 `reftex-label-alist', and before the defaults (specified in |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1174 `reftex-default-label-alist-entries'). Any changes made to |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1175 `reftex-label-alist-external-add-ons' will raise a flag to the effect that a |
| 18050 | 1176 mode reset is done on the next occasion." |
| 1177 (let (entry) | |
| 1178 (while entry-list | |
| 1179 (setq entry (car entry-list) | |
| 1180 entry-list (cdr entry-list)) | |
| 1181 (if (not (member entry reftex-label-alist-external-add-ons)) | |
| 1182 (setq reftex-tables-dirty t | |
| 1183 reftex-label-alist-external-add-ons | |
| 1184 (cons entry reftex-label-alist-external-add-ons)))))) | |
| 1185 | |
| 1186 ;;; =========================================================================== | |
| 1187 ;;; | |
| 1188 ;;; Multifile support | |
| 1189 ;;; | |
| 1190 ;;; Technical notes: Multifile works as follows: We keep just one list | |
| 1191 ;;; of labels for each master file - this can save a lot of memory. | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1192 ;;; `reftex-master-index-list' is an alist which connects the true file name |
| 18050 | 1193 ;;; of each master file with the symbols holding the information on that |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1194 ;;; document. Each buffer has local variables which point to these symbols. |
| 18050 | 1195 |
| 1196 ;; List of variables which handle the multifile stuff. | |
| 1197 ;; This list is used to tie, untie, and reset these symbols. | |
| 1198 (defconst reftex-multifile-symbols | |
| 1199 '(reftex-label-numbers-symbol reftex-list-of-labels-symbol | |
| 1200 reftex-bibfile-list-symbol)) | |
| 1201 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1202 ;; Alist connecting master file names with the corresponding lisp symbols. |
| 18050 | 1203 (defvar reftex-master-index-list nil) |
| 1204 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1205 ;; Last index used for a master file. |
| 18050 | 1206 (defvar reftex-multifile-index 0) |
| 1207 | |
| 1208 ;; Alist connecting a master file with all included files. | |
| 1209 (defvar reftex-master-include-list nil) | |
| 1210 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1211 ;; Variable holding the symbol with current value of label postfix. |
| 18050 | 1212 (defvar reftex-label-numbers-symbol nil ) |
| 1213 (make-variable-buffer-local 'reftex-label-numbers-symbol) | |
| 1214 | |
| 1215 ;; Variable holding the symbol with the label list of the document. | |
| 1216 ;; Each element of the label list is again a list with the following elements: | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1217 ;; 0: One character label type indicator. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1218 ;; 1: Short context to put into label menu. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1219 ;; 2: The label. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1220 ;; 3: The name of the file where the label is defined. |
| 18050 | 1221 (defvar reftex-list-of-labels-symbol nil) |
| 1222 (make-variable-buffer-local 'reftex-list-of-labels-symbol) | |
| 1223 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1224 ;; Variable holding the symbol with a list of library files for this document. |
| 18050 | 1225 (defvar reftex-bibfile-list-symbol nil) |
| 1226 (make-variable-buffer-local 'reftex-bibfile-list-symbol) | |
| 1227 | |
| 1228 (defun reftex-next-multifile-index () | |
| 1229 ;; Return the next free index for multifile symbols. | |
| 1230 (setq reftex-multifile-index (1+ reftex-multifile-index))) | |
| 1231 | |
| 1232 (defun reftex-tie-multifile-symbols () | |
| 1233 ;; Tie the buffer-local symbols to globals connected with the master file. | |
| 1234 ;; If the symbols for the current master file do not exist, they are created. | |
| 1235 | |
| 1236 (let* ((master (file-truename (reftex-TeX-master-file))) | |
| 1237 (index (assoc master reftex-master-index-list)) | |
| 1238 (symlist reftex-multifile-symbols) | |
| 1239 (symbol nil) | |
| 1240 (symname nil) | |
| 1241 (newflag nil)) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1242 ;; Find the correct index. |
| 18050 | 1243 (if index |
| 1244 ;; symbols do exist | |
| 1245 (setq index (cdr index)) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1246 ;; Get a new index and add info to the alist. |
| 18050 | 1247 (setq index (reftex-next-multifile-index) |
| 1248 reftex-master-index-list (cons | |
| 1249 (cons master index) | |
| 1250 reftex-master-index-list) | |
| 1251 newflag t)) | |
| 1252 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1253 ;; Get/create symbols and tie them. |
| 18050 | 1254 (while symlist |
| 1255 (setq symbol (car symlist) | |
| 1256 symlist (cdr symlist) | |
| 1257 symname (symbol-name symbol)) | |
| 1258 (set symbol (intern (concat symname "-" (int-to-string index)))) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1259 ;; Initialize if new symbols. |
| 18050 | 1260 (if newflag (set (symbol-value symbol) nil))) |
| 1261 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1262 ;; Return t if the symbols did already exist, nil when we've made them. |
| 18050 | 1263 (not newflag))) |
| 1264 | |
| 1265 (defun reftex-untie-multifile-symbols () | |
| 1266 ;; Remove ties from multifile symbols, so that next use makes new ones. | |
| 1267 (let ((symlist reftex-multifile-symbols) | |
| 1268 (symbol nil)) | |
| 1269 (while symlist | |
| 1270 (setq symbol (car symlist) | |
| 1271 symlist (cdr symlist)) | |
| 1272 (set symbol nil)))) | |
| 1273 | |
| 1274 (defun reftex-TeX-master-file () | |
| 1275 ;; Return the name of the master file associated with the current buffer. | |
| 1276 ;; When AUCTeX is loaded, we will use it's more sophisticated method. | |
|
18219
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
1277 ;; We also support the default TeX and LaTeX modes by checking for a |
|
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
1278 ;; variable tex-main-file. |
| 18050 | 1279 |
| 1280 (let | |
| 1281 ((master | |
| 1282 (cond | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1283 ((fboundp 'TeX-master-file) ; AUCTeX is loaded. Use its mechanism. |
| 18050 | 1284 (TeX-master-file t)) |
| 1285 ((boundp 'TeX-master) ; The variable is defined - lets use it. | |
| 1286 (cond | |
| 1287 ((eq TeX-master t) | |
| 1288 (buffer-file-name)) | |
| 1289 ((eq TeX-master 'shared) | |
| 1290 (setq TeX-master (read-file-name "Master file: " | |
| 1291 nil nil t nil))) | |
| 1292 (TeX-master) | |
| 1293 (t | |
| 1294 (setq TeX-master (read-file-name "Master file: " | |
| 1295 nil nil t nil))))) | |
| 1296 ((boundp 'tex-main-file) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1297 ;; This is the variable from the default TeX modes. |
| 18050 | 1298 (cond |
| 1299 ((stringp tex-main-file) | |
| 1300 ;; ok, this must be it | |
| 1301 tex-main-file) | |
| 1302 (t | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1303 ;; In this case, the buffer is its own master. |
| 18050 | 1304 (buffer-file-name)))) |
| 1305 (t | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1306 ;; Know nothing about master file. Assume this is a master file. |
| 18050 | 1307 (buffer-file-name))))) |
| 1308 (cond | |
| 1309 ((null master) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1310 (error "Need a filename for this buffer. Please save it first.")) |
| 18050 | 1311 ((or (file-exists-p master) |
| 1312 (reftex-get-buffer-visiting master)) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1313 ;; We either see the file, or have a buffer on it. OK. |
| 18050 | 1314 ) |
| 1315 ((or (file-exists-p (concat master ".tex")) | |
| 1316 (reftex-get-buffer-visiting (concat master ".tex"))) | |
| 1317 ;; Ahh, an extra .tex was missing... | |
| 1318 (setq master (concat master ".tex"))) | |
| 1319 (t | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1320 ;; Something is wrong here. Throw an exception. |
| 18050 | 1321 (error "No such master file %s" master))) |
| 1322 (expand-file-name master))) | |
| 1323 | |
| 1324 (defun reftex-make-master-buffer (master-file mode) | |
| 1325 "Make a master buffer which contains the MASTER-FILE and all includes. | |
| 1326 This is to prepare a buffer containing the entire document in correct | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1327 sequence for parsing. Therefore it will even expand includes which are |
| 18050 | 1328 commented out. |
| 1329 The function returns the number of input/include files not found." | |
| 1330 | |
| 1331 (interactive "fmaster file: ") | |
| 1332 (let ((not-found 0) file file-list tmp (font-lock-maximum-size 1)) | |
| 1333 (switch-to-buffer "*reftex-master.tex*") | |
| 1334 (erase-buffer) | |
| 1335 (if (not (eq major-mode mode)) | |
| 1336 (funcall mode)) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1337 ;; First insert the master file. |
| 18050 | 1338 (if (not (file-exists-p master-file)) |
| 1339 (error "No such master file: %s" master-file)) | |
| 1340 (reftex-insert-buffer-or-file master-file) | |
| 1341 (subst-char-in-region (point-min) (point-max) ?\r ?\n t) | |
| 1342 (setq file-list (cons master-file file-list)) | |
| 1343 (goto-char 1) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1344 ;; Remember from which file these lines came. |
| 18050 | 1345 (put-text-property (point-min) (point-max) 'file |
| 1346 (expand-file-name master-file)) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1347 ;; Make the default directory that of the master file. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1348 ;; All input and include stuff works relative to that directory. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1349 (cd (file-name-directory (expand-file-name master-file))) |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1350 ;; Now find recursively all include/input statements and expand them. |
| 18050 | 1351 (while (re-search-forward |
| 1352 "^[ \t]*\\\\\\(include\\|input\\){\\([^}\n]+\\)}" nil t) | |
| 1353 (setq file (reftex-no-props (match-string 2))) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1354 (if (not (and (> (length file) 4) |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1355 (string= (substring file -4) ".tex"))) |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1356 (setq file (concat file ".tex"))) |
| 18050 | 1357 (if (file-exists-p file) |
| 1358 (progn | |
| 1359 (replace-match | |
| 1360 (format "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% START OF %s FILE: %s\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% END OF %s FILE: %s\n" | |
| 1361 (match-string 1) file | |
| 1362 (match-string 1) file)) | |
| 1363 (beginning-of-line 0) | |
| 1364 (narrow-to-region (point) (point)) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1365 ;; Insert the file. |
| 18050 | 1366 (reftex-insert-buffer-or-file file) |
| 1367 (subst-char-in-region (point-min) (point-max) ?\r ?\n t) | |
| 1368 (setq file-list (cons (expand-file-name file) file-list)) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1369 ;; Remember from which file these lines came. |
| 18050 | 1370 (put-text-property (point-min) (point-max) |
| 1371 'file (expand-file-name file)) | |
| 1372 (goto-char (point-min)) | |
| 1373 (widen)) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1374 (message "Input/include file %s not found. Ignored. Continuing..." |
| 18050 | 1375 file) |
| 1376 (setq not-found (1+ not-found)))) | |
| 1377 (setq file-list (nreverse file-list)) | |
| 1378 (while (setq tmp (assoc (car file-list) reftex-master-include-list)) | |
| 1379 (setq reftex-master-include-list (delq tmp reftex-master-include-list))) | |
| 1380 (setq reftex-master-include-list (cons file-list reftex-master-include-list)) | |
| 1381 not-found)) | |
| 1382 | |
| 1383 (defun reftex-insert-buffer-or-file (file) | |
| 1384 "If there is a buffer associated with FILE, insert it - otherwise the FILE." | |
| 1385 (let ((buffer (reftex-get-buffer-visiting file))) | |
| 1386 (if buffer | |
| 1387 (let (beg end beg1 end1) | |
| 1388 (save-excursion | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1389 ;; Make sure we get the whole buffer. |
| 18050 | 1390 (set-buffer buffer) |
| 1391 (setq beg (point-min) end (point-max)) | |
| 1392 (widen) | |
| 1393 (setq beg1 (point-min) end1 (point-max))) | |
| 1394 (insert-buffer-substring buffer beg1 end1) | |
| 1395 (save-excursion | |
| 1396 (set-buffer buffer) | |
| 1397 (narrow-to-region beg end))) | |
| 1398 (insert-file-contents file)))) | |
| 1399 | |
| 1400 | |
| 1401 (defun reftex-parse-document (&optional buffer) | |
| 1402 "Rescan the document." | |
| 1403 (interactive) | |
| 1404 (save-window-excursion | |
| 1405 (save-excursion | |
| 1406 (if buffer | |
| 1407 (if (not (bufferp buffer)) | |
| 1408 (error "No such buffer %s" (buffer-name buffer)) | |
| 1409 (set-buffer buffer))) | |
| 1410 (reftex-access-scan-info t)))) | |
| 1411 | |
| 1412 (defun reftex-access-scan-info (&optional rescan) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1413 ;; Access the scanning info. When the multifile symbols are not yet tied, |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1414 ;; tie them. When they are have to be created, do a buffer scan to |
| 18050 | 1415 ;; fill them. |
| 1416 | |
| 1417 ;; If RESCAN is non-nil, enforce document scanning | |
| 1418 | |
| 1419 (catch 'exit | |
| 1420 (let ((rescan (or (equal rescan t) (equal rescan '(4))))) | |
| 1421 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1422 ;; Reset the mode if we had changes from style hooks. |
| 18050 | 1423 (and reftex-tables-dirty |
| 1424 (reftex-reset-mode)) | |
| 1425 | |
| 1426 (if (eq reftex-list-of-labels-symbol nil) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1427 ;; Symbols are not yet tied: Tie them and see if they are set. |
| 18050 | 1428 (reftex-tie-multifile-symbols)) |
| 1429 | |
| 1430 (if (and (symbol-value reftex-list-of-labels-symbol) | |
| 1431 (not rescan)) | |
| 1432 ;; Lists do already exist and we don't need to rescan. | |
| 1433 ;; Return from here. | |
| 1434 (throw 'exit t)) | |
| 1435 | |
| 1436 ;; We need to rescan | |
| 1437 ;; ================= | |
| 1438 | |
| 1439 (unwind-protect | |
| 1440 (save-window-excursion | |
| 1441 (save-excursion | |
| 1442 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1443 ;; Do the scanning. |
| 18050 | 1444 |
| 1445 (let ((label-list-symbol reftex-list-of-labels-symbol) | |
| 1446 (label-numbers-symbol reftex-label-numbers-symbol) | |
| 1447 (bibfile-list-symbol reftex-bibfile-list-symbol)) | |
| 1448 | |
| 1449 (message "Creating master buffer...") | |
| 1450 (reftex-make-master-buffer (reftex-TeX-master-file) major-mode) | |
| 1451 | |
| 1452 (message "Scanning document...") | |
| 1453 | |
| 1454 (reftex-scan-buffer-for-labels | |
| 1455 label-numbers-symbol label-list-symbol) | |
| 1456 | |
| 1457 (reftex-scan-buffer-for-bibliography-statement | |
| 1458 bibfile-list-symbol) | |
| 1459 | |
| 1460 (message "Scanning document... done")))) | |
| 1461 | |
| 1462 (if (get-buffer "*reftex-master.tex*") | |
| 1463 (kill-buffer "*reftex-master.tex*")))))) | |
| 1464 | |
| 1465 (defun reftex-create-tags-file () | |
| 1466 "Create TAGS file by running `etags' on the current document. | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1467 The TAGS file is also immediately visited with `visit-tags-table'." |
| 18050 | 1468 (interactive) |
| 1469 (reftex-access-scan-info current-prefix-arg) | |
| 1470 (let* ((master (reftex-TeX-master-file)) | |
| 1471 (files (assoc master reftex-master-include-list)) | |
| 1472 (cmd (format "etags %s" (mapconcat 'identity files " ")))) | |
| 1473 (save-excursion | |
| 1474 (set-buffer (reftex-get-buffer-visiting master)) | |
| 1475 (message "Running etags to create TAGS file...") | |
| 1476 (shell-command cmd) | |
| 1477 (visit-tags-table "TAGS")))) | |
| 1478 | |
| 1479 ;; History of grep commands. | |
| 1480 (defvar reftex-grep-history nil) | |
| 1481 (defvar reftex-grep-command "grep -n " | |
| 1482 "Last grep command used in \\[reftex-grep-document]; default for next grep.") | |
| 1483 | |
| 1484 (defun reftex-grep-document (grep-cmd) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1485 "Run grep query through all files related to this document. |
| 18050 | 1486 With prefix arg, force to rescan document. |
| 1487 This works also without an active TAGS table." | |
| 1488 | |
| 1489 (interactive | |
| 1490 (list (read-from-minibuffer "Run grep on document (like this): " | |
| 1491 reftex-grep-command nil nil | |
| 1492 'reftex-grep-history))) | |
| 1493 (reftex-access-scan-info current-prefix-arg) | |
| 1494 (let* ((master (reftex-TeX-master-file)) | |
| 1495 (default-directory (file-name-directory master)) | |
| 1496 (re (format "\\`%s\\(.*\\)" (regexp-quote | |
| 1497 (expand-file-name default-directory)))) | |
| 1498 (files (assoc master reftex-master-include-list)) | |
| 1499 (cmd (format | |
| 1500 "%s %s" grep-cmd | |
| 1501 (mapconcat (function (lambda (x) | |
| 1502 (if (string-match re x) | |
| 1503 (match-string 1 x) | |
| 1504 x))) | |
| 1505 files " ")))) | |
| 1506 (grep cmd))) | |
| 1507 | |
| 1508 (defun reftex-search-document (&optional regexp) | |
| 1509 "Regexp search through all files of the current TeX document. | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1510 Starts always in the master file. Stops when a match is found. |
| 18050 | 1511 To continue searching for next match, use command \\[tags-loop-continue]. |
| 1512 This works also without an active TAGS table." | |
| 1513 (interactive) | |
| 1514 (let ((default (reftex-this-word))) | |
| 1515 (if (not regexp) | |
| 1516 (setq regexp (read-string (format "Search regexp in document [%s]: " | |
| 1517 default)))) | |
| 1518 (if (string= regexp "") (setq regexp (regexp-quote default))) | |
| 1519 | |
| 1520 (reftex-access-scan-info current-prefix-arg) | |
| 1521 (tags-search regexp (list 'assoc (reftex-TeX-master-file) | |
| 1522 'reftex-master-include-list)))) | |
| 1523 | |
| 1524 (defun reftex-query-replace-document (&optional from to delimited) | |
| 1525 "Run a query-replace-regexp of FROM with TO over the entire TeX document. | |
| 1526 Third arg DELIMITED (prefix arg) means replace only word-delimited matches. | |
| 1527 If you exit (\\[keyboard-quit] or ESC), you can resume the query replace | |
| 1528 with the command \\[tags-loop-continue]. | |
| 1529 This works also without an active TAGS table." | |
| 1530 (interactive) | |
| 1531 (let ((default (reftex-this-word))) | |
| 1532 (if (not from) | |
| 1533 (progn | |
| 1534 (setq from (read-string (format "Replace regexp in document [%s]: " | |
| 1535 default))) | |
| 1536 (if (string= from "") (setq from (regexp-quote default))))) | |
| 1537 (if (not to) | |
| 1538 (setq to (read-string (format "Replace regexp %s with: " from)))) | |
| 1539 (reftex-access-scan-info current-prefix-arg) | |
| 1540 (tags-query-replace from to (or delimited current-prefix-arg) | |
| 1541 (list 'assoc (reftex-TeX-master-file) | |
| 1542 'reftex-master-include-list)))) | |
| 1543 | |
| 1544 (defun reftex-change-label (&optional from to) | |
| 18123 | 1545 "Query replace FROM with TO in all \\label and \\ref commands. |
| 18050 | 1546 Works on the entire multifile document. |
| 1547 If you exit (\\[keyboard-quit] or ESC), you can resume the query replace | |
| 1548 with the command \\[tags-loop-continue]. | |
| 1549 This works also without an active TAGS table." | |
| 1550 (interactive) | |
| 1551 (let ((default (reftex-this-word "-a-zA-Z0-9_*.:"))) | |
| 1552 (if (not from) | |
| 1553 (setq from (read-string (format "Replace label globally [%s]: " | |
| 1554 default)))) | |
| 1555 (if (string= from "") (setq from default)) | |
| 1556 (if (not to) | |
| 1557 (setq to (read-string (format "Replace label %s with: " | |
| 1558 from)))) | |
| 1559 (reftex-query-replace-document | |
| 1560 (concat "\\\\\\(label\\|[a-z]*ref\\){" (regexp-quote from) "}") | |
| 1561 (format "\\\\\\1{%s}" to)))) | |
| 1562 | |
| 1563 (defun reftex-this-word (&optional class) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1564 ;; Grab the word around point. |
| 18050 | 1565 (setq class (or class "-a-zA-Z0-9:_/.*;|")) |
| 1566 (save-excursion | |
| 1567 (buffer-substring-no-properties | |
| 1568 (progn (skip-chars-backward class) (point)) | |
| 1569 (progn (skip-chars-forward class) (point))))) | |
| 1570 | |
| 1571 ;;; =========================================================================== | |
| 1572 ;;; | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1573 ;;; Functions to create and reference automatic labels. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1574 |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1575 ;; The following constants are derived from `reftex-label-alist'. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1576 |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1577 ;; Prompt used for label type querys directed to the user. |
| 18050 | 1578 (defconst reftex-type-query-prompt nil) |
| 1579 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1580 ;; Help string for label type querys. |
| 18050 | 1581 (defconst reftex-type-query-help nil) |
| 1582 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1583 ;; Alist relating label type to reference format. |
| 18050 | 1584 (defconst reftex-typekey-to-format-alist nil) |
| 1585 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1586 ;; Alist relating label type to label affix. |
| 18050 | 1587 (defconst reftex-typekey-to-prefix-alist nil) |
| 1588 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1589 ;; Alist relating environments or macros to label type and context regexp. |
| 18050 | 1590 (defconst reftex-env-or-mac-alist nil) |
| 1591 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1592 ;; List of macros carrying a label. |
| 18050 | 1593 (defconst reftex-label-mac-list nil) |
| 1594 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1595 ;; List of environments carrying a label. |
| 18050 | 1596 (defconst reftex-label-env-list nil) |
| 1597 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1598 ;; List of all typekey letters in use. |
| 18050 | 1599 (defconst reftex-typekey-list nil) |
| 1600 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1601 ;; Alist relating magic words to a label type. |
| 18050 | 1602 (defconst reftex-words-to-typekey-alist nil) |
| 1603 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1604 ;; The last list-of-labels entry used in a reference. |
| 18050 | 1605 (defvar reftex-last-used-reference (list nil nil nil nil)) |
| 1606 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1607 ;; The regular expression used to abbreviate words. |
| 18050 | 1608 (defconst reftex-abbrev-regexp |
| 1609 (concat | |
| 1610 "^\\(" | |
| 1611 (make-string (nth 0 reftex-abbrev-parameters) ?.) | |
| 1612 "[" (nth 2 reftex-abbrev-parameters) "]*" | |
| 1613 "\\)" | |
| 1614 "[" (nth 3 reftex-abbrev-parameters) "]" | |
| 1615 (make-string (1- (nth 1 reftex-abbrev-parameters)) ?.))) | |
| 1616 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1617 ;; Global variables used for communication between functions. |
| 18050 | 1618 (defvar reftex-default-context-position nil) |
| 1619 (defvar reftex-location-start nil) | |
| 1620 (defvar reftex-call-back-to-this-buffer nil) | |
| 1621 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1622 ;; List of buffers created temporarily for lookup, which should be killed. |
| 18050 | 1623 (defvar reftex-buffers-to-kill nil) |
| 1624 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1625 ;; The regexp used to find section statements. |
| 18050 | 1626 (defconst reftex-section-regexp "^[ ]*\\\\\\(part\\|chapter\\|section\\|subsection\\|subsubsection\\|paragraph\\|subparagraph\\|subsubparagraph\\)\\*?\\(\\[[^]]*\\]\\)?{") |
| 1627 | |
| 1628 ;; LaTeX section commands and level numbers | |
| 1629 (defconst reftex-section-levels | |
| 1630 '( | |
| 1631 ("part" . 0) | |
| 1632 ("chapter" . 1) | |
| 1633 ("section" . 2) | |
| 1634 ("subsection" . 3) | |
| 1635 ("subsubsection" . 4) | |
| 1636 ("paragraph" . 5) | |
| 1637 ("subparagraph" . 6) | |
| 1638 ("subsubparagraph" . 7) | |
| 1639 )) | |
| 1640 | |
| 1641 (defun reftex-label (&optional environment no-insert) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1642 "Insert a unique label. Return the label. |
| 18050 | 1643 If ENVIRONMENT is given, don't bother to find out yourself. |
| 1644 If NO-INSERT is non-nil, do not insert label into buffer. | |
| 1645 With prefix arg, force to rescan document first. | |
| 1646 The label is also inserted into the label list. | |
| 1647 This function is controlled by the settings of reftex-insert-label-flags." | |
| 1648 | |
| 1649 (interactive) | |
| 1650 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1651 ;; Ensure access to scanning info and rescan buffer if prefix are is '(4). |
| 18050 | 1652 (reftex-access-scan-info current-prefix-arg) |
| 1653 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1654 ;; Find out what kind of environment this is and abort if necessary. |
| 18050 | 1655 (if (or (not environment) |
| 1656 (not (assoc environment reftex-env-or-mac-alist))) | |
| 1657 (setq environment (reftex-label-location))) | |
| 1658 (if (not environment) | |
| 1659 (error "Can't figure out what kind of label should be inserted")) | |
| 1660 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1661 ;; Ok, go ahead. |
| 18050 | 1662 (let (label num typekey prefix entry cell lab valid default force-prompt) |
| 1663 (setq typekey (nth 1 (assoc environment | |
| 1664 reftex-env-or-mac-alist))) | |
| 1665 (setq prefix (or (cdr (assoc typekey reftex-typekey-to-prefix-alist)) | |
| 1666 (concat typekey "-"))) | |
| 1667 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1668 ;; Make a default label. |
| 18050 | 1669 (cond |
| 1670 | |
| 1671 ((reftex-typekey-check typekey (nth 0 reftex-insert-label-flags)) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1672 ;; Derive a label from context. |
| 18050 | 1673 (setq default (nth 2 (reftex-label-info " "))) |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1674 ;; Catch the cases where the is actually no context available. |
| 18050 | 1675 (if (or (string-match "NO MATCH FOR CONTEXT REGEXP" default) |
| 1676 (string-match "ILLEGAL VALUE OF PARSE" default) | |
| 1677 (string-match "SECTION HEADING NOT FOUND" default) | |
| 1678 (string-match "HOOK ERROR" default) | |
| 1679 (string-match "^[ \t]*$" default)) | |
| 1680 (setq default prefix | |
| 1681 force-prompt t) ; need to prompt | |
| 1682 (setq default (concat prefix (reftex-string-to-label default))) | |
| 1683 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1684 ;; Make it unique. |
| 18050 | 1685 (setq label default) |
| 1686 (setq num 1) | |
| 1687 (while (assoc label (symbol-value reftex-list-of-labels-symbol)) | |
| 1688 (setq label (concat default "-" (setq num (1+ num))))) | |
| 1689 (setq default label))) | |
| 1690 | |
| 1691 ((reftex-typekey-check typekey (nth 1 reftex-insert-label-flags)) ; prompt | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1692 ;; Minimal default: the user will be prompted. |
| 18050 | 1693 (setq default prefix)) |
| 1694 | |
| 1695 (t | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1696 ;; Make an automatic label. |
| 18050 | 1697 (while (assoc |
| 1698 (setq default (concat prefix (reftex-next-label-number typekey))) | |
| 1699 (symbol-value reftex-list-of-labels-symbol))))) | |
| 1700 | |
| 1701 ;; Should we ask the user? | |
| 1702 (if (or (reftex-typekey-check typekey | |
| 1703 (nth 1 reftex-insert-label-flags)) ; prompt | |
| 1704 force-prompt) | |
| 1705 | |
| 1706 (while (not valid) | |
| 1707 ;; iterate until we get a legal label | |
| 1708 | |
| 1709 (setq label (read-string "Label: " default)) | |
| 1710 | |
| 1711 ;; Lets make sure that this is a legal label | |
| 1712 (cond | |
| 1713 | |
| 1714 ;; Test if label contains strange characters | |
| 1715 ((string-match reftex-label-illegal-re label) | |
| 1716 (message "Label \"%s\" contains illegal characters" label) | |
| 1717 (ding) | |
| 1718 (sit-for 2)) | |
| 1719 | |
| 1720 ;; Look it up in the label list | |
| 1721 ((setq entry (assoc label | |
| 1722 (symbol-value reftex-list-of-labels-symbol))) | |
| 1723 (message "Label \"%s\" exists in file %s" label (nth 3 entry)) | |
| 1724 (ding) | |
| 1725 (sit-for 2)) | |
| 1726 | |
| 1727 ;; Label is ok | |
| 1728 (t | |
| 1729 (setq valid t)))) | |
| 1730 (setq label default)) | |
| 1731 | |
| 1732 ;; Insert the label | |
| 1733 (if (not no-insert) | |
| 1734 (insert "\\label{" label "}")) | |
| 1735 | |
| 1736 ;; Insert the label into the label list | |
| 1737 (if (symbol-value reftex-list-of-labels-symbol) | |
| 1738 (let ((cnt 0) | |
| 1739 (pos (point)) | |
| 1740 (all (symbol-value reftex-list-of-labels-symbol)) | |
| 1741 (look-for nil) | |
| 1742 (note nil) | |
| 1743 (text nil) | |
| 1744 (file (buffer-file-name))) | |
| 1745 | |
| 1746 ;; find the previous label in order to know where to insert new label | |
| 1747 ;; into label list | |
| 1748 (save-excursion | |
| 1749 (if (re-search-backward "\\\\label{\\([^}]+\\)}" nil 1 2) | |
| 1750 (setq look-for (reftex-no-props (match-string 1)))) | |
| 1751 (if (or (re-search-forward | |
| 1752 "\\\\\\(include\\|input\\){[^}\n]+}" pos t) | |
| 1753 (re-search-forward reftex-section-regexp pos t) | |
| 1754 (null look-for)) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1755 (setq note "POSITION UNCERTAIN. RESCAN TO FIX."))) |
| 18050 | 1756 (if (not look-for) |
| 1757 (set reftex-list-of-labels-symbol | |
| 1758 (cons (list label typekey text file note) | |
| 1759 (symbol-value reftex-list-of-labels-symbol))) | |
| 1760 (while all | |
| 1761 (setq cell (car all) | |
| 1762 all (cdr all) | |
| 1763 cnt (1+ cnt) | |
| 1764 lab (nth 0 cell)) | |
| 1765 (if (string= lab look-for) | |
| 1766 (progn | |
| 1767 (setcdr | |
| 1768 (nthcdr (1- cnt) | |
| 1769 (symbol-value reftex-list-of-labels-symbol)) | |
| 1770 (cons (list label typekey text file note) | |
| 1771 (nthcdr | |
| 1772 cnt (symbol-value reftex-list-of-labels-symbol)))) | |
| 1773 ;; to end the loop, set all to nil | |
| 1774 (setq all nil))))))) | |
| 1775 ;; return value of the function is the label | |
| 1776 label)) | |
| 1777 | |
| 1778 (defun reftex-string-to-label (string) | |
| 1779 ;; Convert a string (a sentence) to a label. | |
| 1780 ;; | |
| 1781 ;; Uses reftex-derive-label-parameters and reftex-abbrev-parameters | |
| 1782 ;; | |
| 1783 | |
| 1784 (let* ((words0 (reftex-split "[- \t\n\r]+" | |
| 1785 (reftex-no-props string))) | |
| 1786 (ignore-words (nth 5 reftex-derive-label-parameters)) | |
| 1787 words word) | |
| 1788 | |
| 1789 ;; remove words from the ignore list or with funny characters | |
| 1790 (while words0 | |
| 1791 (setq word (car words0) words0 (cdr words0)) | |
| 1792 (cond | |
| 1793 ((member (downcase word) ignore-words)) | |
| 1794 ((string-match reftex-label-illegal-re word) | |
| 1795 (if (nth 2 reftex-derive-label-parameters) | |
| 1796 (progn | |
| 1797 (while (string-match reftex-label-illegal-re word) | |
| 1798 (setq word (replace-match "" nil nil word))) | |
| 1799 (setq words (cons word words))))) | |
| 1800 (t | |
| 1801 (setq words (cons word words))))) | |
| 1802 (setq words (nreverse words)) | |
| 1803 | |
| 1804 ;; restrict number of words | |
| 1805 (if (> (length words) (nth 0 reftex-derive-label-parameters)) | |
| 1806 (setcdr (nthcdr (1- (nth 0 reftex-derive-label-parameters)) words) nil)) | |
| 1807 | |
| 1808 ;; First, try to use all words | |
| 1809 (setq string (mapconcat '(lambda(w) w) words | |
| 1810 (nth 4 reftex-derive-label-parameters))) | |
| 1811 | |
| 1812 ;; Abbreviate words if enforced by user settings or string length | |
| 1813 (if (or (eq t (nth 3 reftex-derive-label-parameters)) | |
| 1814 (and (nth 3 reftex-derive-label-parameters) | |
| 1815 (> (length string) (nth 1 reftex-derive-label-parameters)))) | |
| 1816 (setq words | |
| 1817 (mapcar | |
| 1818 '(lambda (w) (if (string-match reftex-abbrev-regexp w) | |
| 1819 (match-string 1 w) | |
| 1820 w)) | |
| 1821 words) | |
| 1822 string (mapconcat '(lambda(w) w) words | |
| 1823 (nth 4 reftex-derive-label-parameters)))) | |
| 1824 | |
| 1825 ;; Shorten if still to long | |
| 1826 (setq string | |
| 1827 (if (> (length string) (nth 1 reftex-derive-label-parameters)) | |
| 1828 (substring string 0 (nth 1 reftex-derive-label-parameters)) | |
| 1829 string)) | |
| 1830 | |
| 1831 ;; Delete the final punctuation, if any | |
| 1832 (if (string-match "[^a-zA-Z0-9]+$" string) | |
| 1833 (setq string (replace-match "" nil nil string))) | |
| 1834 string)) | |
| 1835 | |
| 1836 (defun reftex-label-location (&optional bound) | |
| 1837 ;; Return the environment or macro which determines the label type at point. | |
| 1838 ;; If optional BOUND is an integer, limit backward searches to that point. | |
| 1839 | |
| 1840 (let* ((loc1 (reftex-what-macro reftex-label-mac-list bound)) | |
| 1841 (loc2 (reftex-what-environment reftex-label-env-list bound)) | |
| 1842 (p1 (or (cdr loc1) 0)) | |
| 1843 (p2 (or (cdr loc2) 0))) | |
| 1844 | |
| 1845 (setq reftex-location-start (max p1 p2)) | |
| 1846 (if (> p1 p2) | |
| 1847 (progn | |
| 1848 (setq reftex-default-context-position p1) | |
| 1849 (car loc1)) | |
| 1850 (setq reftex-default-context-position | |
| 1851 (+ p2 8 (length (car loc2)))) | |
| 1852 (or (car loc2) "section")))) | |
| 1853 | |
| 1854 | |
| 1855 (defun reftex-next-label-number (type) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1856 ;; Increment value of automatic labels in current buffer. Return new value. |
| 18050 | 1857 |
| 1858 ;; Ensure access to scanning info | |
| 1859 (reftex-access-scan-info) | |
| 1860 | |
| 1861 (let ((n (cdr (assoc type (symbol-value reftex-label-numbers-symbol))))) | |
| 1862 (if (not (integerp n)) | |
| 1863 ;; oops - type not known - make one here | |
| 1864 (progn | |
| 1865 (set reftex-label-numbers-symbol | |
| 1866 (cons (cons type 0) | |
| 1867 (symbol-value reftex-label-numbers-symbol))) | |
| 1868 (setq n 0))) | |
| 1869 (setq n (1+ n)) | |
| 1870 (setcdr (assoc type (symbol-value reftex-label-numbers-symbol)) n) | |
| 1871 n)) | |
| 1872 | |
| 1873 ;; Help string for the reference label menu | |
| 1874 (defconst reftex-reference-label-help | |
| 1875 " AVAILABLE KEYS IN REFERENCE LABEL MENU | |
| 1876 ====================================== | |
| 1877 n / p Go to next/previous label (Cursor motion works as well) | |
| 1878 r / s Rescan document for labels / Switch label type | |
| 1879 t / # Toggle table of contents / Toggle counter mode | |
| 1880 c Toggle display of short context | |
| 1881 SPACE Show full context for current label in other window | |
| 1882 f Toggle follow mode: other window will follow context | |
| 1883 a / q Use last referenced label / Quit without accepting label | |
| 1884 ? / C-r Display this help message / Recursive Edit into other window | |
| 1885 RETURN Accept current label") | |
| 1886 | |
| 1887 (defun reftex-reference (&optional type no-insert) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1888 "Make a LaTeX reference. Look only for labels of a certain TYPE. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1889 With prefix arg, force to rescan buffer for labels. This should only be |
| 18050 | 1890 necessary if you have recently entered labels yourself without using |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1891 reftex-label. Rescanning of the buffer can also be requested from the |
| 18050 | 1892 label selection menu. |
| 1893 The function returns the selected label or nil. | |
| 18123 | 1894 If NO-INSERT is non-nil, do not insert \\ref command, just return label. |
| 18050 | 1895 When called with 2 C-u prefix args, disable magic word recognition." |
| 1896 | |
| 1897 (interactive) | |
| 1898 | |
| 1899 ;; check for active recursive edits | |
| 1900 (reftex-check-recursive-edit) | |
| 1901 | |
| 1902 ;; Ensure access to scanning info and rescan buffer if prefix are is '(4) | |
| 1903 (reftex-access-scan-info current-prefix-arg) | |
| 1904 | |
| 1905 (if (not type) | |
| 1906 ;; guess type from context | |
| 1907 (if (and reftex-guess-label-type | |
| 1908 (not (= 16 (prefix-numeric-value current-prefix-arg))) | |
| 1909 (setq type (assoc (downcase (reftex-word-before-point)) | |
| 1910 reftex-words-to-typekey-alist))) | |
| 1911 (setq type (cdr type)) | |
| 1912 (setq type (reftex-query-label-type)))) | |
| 1913 | |
| 1914 (let (label pair | |
| 1915 (form (or (cdr (assoc type reftex-typekey-to-format-alist)) | |
| 1916 "\\ref{%s}"))) | |
| 1917 | |
| 1918 ;; Have the user select a label | |
| 1919 (setq pair (reftex-offer-label-menu type)) | |
| 1920 (setq label (car pair)) | |
| 1921 | |
| 1922 (if (and label | |
| 1923 (not no-insert)) | |
| 1924 (progn | |
| 1925 ;; do we need to remove spaces? | |
| 1926 (if (string= "~" (substring form 0 1)) | |
| 1927 (while (or (= (preceding-char) ?\ ) | |
| 1928 (= (preceding-char) ?\C-i)) | |
| 1929 (backward-delete-char 1))) | |
| 1930 ;; ok, insert the reference | |
| 1931 (insert (format form label label)) | |
| 1932 (message "")) | |
| 1933 (message "Quit")) | |
| 1934 ;; return the label | |
| 1935 label)) | |
| 1936 | |
| 1937 (defun reftex-goto-label (&optional arg) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1938 "Go to a LaTeX label. With prefix ARG, go to label in another window." |
| 18050 | 1939 (interactive "P") |
| 1940 (let (type label file pair) | |
| 1941 (if (not type) | |
| 1942 (setq type (reftex-query-label-type))) | |
| 1943 | |
| 1944 (setq pair (reftex-offer-label-menu type) | |
| 1945 label (car pair) | |
| 1946 file (cdr pair)) | |
| 1947 (if (and label file (file-exists-p file)) | |
| 1948 (progn | |
| 1949 (if arg | |
| 1950 (find-file-other-window file) | |
| 1951 (find-file file)) | |
| 1952 (goto-char (point-min)) | |
| 1953 (if (not (search-forward (concat "\\label{" label "}") nil t)) | |
| 1954 (error "No such label found: %s" label) | |
| 1955 (reftex-highlight 0 (match-beginning 0) (match-end 0)) | |
| 1956 (add-hook 'pre-command-hook 'reftex-highlight-shall-die))) | |
| 1957 (message "Quit") | |
| 1958 nil))) | |
| 1959 | |
| 1960 ;; Internal list with index numbers of labels in the selection menu | |
| 1961 (defvar reftex-label-index-list nil) | |
| 1962 | |
| 1963 (defun reftex-offer-label-menu (typekey) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
1964 ;; Offer a menu with the appropriate labels. Return (label . file). |
| 18050 | 1965 (let* ((buf (current-buffer)) |
| 1966 (near-label (reftex-find-nearby-label)) | |
| 1967 (toc (reftex-typekey-check typekey reftex-label-menu-flags 0)) | |
| 1968 (context (not (reftex-typekey-check | |
| 1969 typekey reftex-label-menu-flags 3))) | |
| 1970 (counter (reftex-typekey-check | |
| 1971 typekey reftex-label-menu-flags 2)) | |
| 1972 (follow (reftex-typekey-check | |
| 1973 typekey reftex-label-menu-flags 4)) | |
| 1974 offset rtn key cnt entry) | |
| 1975 | |
| 1976 (setq reftex-call-back-to-this-buffer buf) | |
| 1977 (setq entry (cons nil nil)) | |
| 1978 | |
| 1979 (unwind-protect | |
| 1980 (catch 'exit | |
| 1981 (while t | |
| 1982 (save-window-excursion | |
| 1983 (switch-to-buffer-other-window "*RefTeX Select*") | |
| 1984 (erase-buffer) | |
| 1985 (setq truncate-lines t) | |
| 1986 (setq reftex-label-index-list (reftex-make-and-insert-label-list | |
| 1987 typekey buf toc context counter | |
| 1988 near-label)) | |
| 1989 (setq near-label "_ ") ; turn off search for near label | |
| 1990 (setq offset (or (car reftex-label-index-list) offset)) | |
| 1991 ;; use only when searched | |
| 1992 (setq reftex-label-index-list (cdr reftex-label-index-list)) | |
| 1993 ;; only this is the true list | |
| 1994 (if (not reftex-label-index-list) | |
| 1995 (error "No labels of type \"%s\"" typekey)) | |
| 1996 (setq rtn | |
| 1997 (reftex-select-item | |
| 1998 nil | |
| 1999 "Label: [n]ext [p]rev [r]escan [t]oc [ ]context [q]uit RETURN [?]HELP+more" | |
| 2000 "^>" | |
| 2001 "\n[^.]" | |
| 2002 2 | |
| 2003 reftex-reference-label-help | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
2004 '(?r ?g ?c ?t ?s ?# ?a) |
| 18050 | 2005 offset |
| 2006 'reftex-select-label-callback follow)) | |
| 2007 (setq key (car rtn) | |
| 2008 cnt (cdr rtn) | |
| 2009 offset (1+ cnt)) | |
| 2010 (if (not key) (throw 'exit nil)) | |
| 2011 (cond | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
2012 ((or (equal key ?r) |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
2013 (equal key ?g)) |
| 18050 | 2014 ;; rescan buffer |
| 2015 (reftex-parse-document buf)) | |
| 2016 ((equal key ?c) | |
| 2017 ;; toggle context mode | |
| 2018 (setq context (not context))) | |
| 2019 ((equal key ?s) | |
| 2020 ;; switch type | |
| 2021 (setq typekey (reftex-query-label-type))) | |
| 2022 ((equal key ?t) | |
| 2023 ;; toggle tabel of contents display | |
| 2024 (setq toc (not toc))) | |
| 2025 ((equal key ?#) | |
| 2026 ;; toggle counter display | |
| 2027 (setq counter (not counter))) | |
| 2028 ((equal key ?a) | |
| 2029 ;; reuse the last referenced label again | |
| 2030 (setq entry reftex-last-used-reference) | |
| 2031 (throw 'exit t)) | |
| 2032 (t | |
| 2033 (set-buffer buf) | |
| 2034 (setq entry (nth (nth cnt reftex-label-index-list) | |
| 2035 (symbol-value reftex-list-of-labels-symbol))) | |
| 2036 (setq reftex-last-used-reference entry) | |
| 2037 (throw 'exit t)))))) | |
| 2038 (kill-buffer "*RefTeX Select*") | |
| 2039 (reftex-kill-temporary-buffers)) | |
| 2040 (cons (reftex-no-props (nth 0 entry)) (nth 3 entry)))) | |
| 2041 | |
| 2042 ;; Indentation for table of context lines in the menu | |
| 2043 (defconst reftex-toc-indent " ") | |
| 2044 ;; Indentation for the lines containing the label | |
| 2045 (defconst reftex-label-indent "> ") | |
| 2046 ;; Indentation for context lines | |
| 2047 (defconst reftex-context-indent ". ") | |
| 2048 ;; Indentation per section level | |
| 2049 (defvar reftex-level-indent 2 | |
| 2050 "*Number of spaces to be used for indentation per section level. | |
| 2051 With more indentation, the label menu looks nicer, but shows less context. | |
| 2052 Changing this is only fully operational after the next buffer scan.") | |
| 2053 | |
| 2054 (defun reftex-make-and-insert-label-list (typekey0 buf toc context | |
| 2055 counter near-label) | |
| 2056 ;; Insert a menu of all labels in buffer BUF into current buffer. | |
| 2057 ;; Return the list of labels, with the index of NEAR-LABEL as extra car. | |
| 2058 (let (ins-list index-list offset) | |
| 2059 (save-excursion | |
| 2060 (set-buffer buf) | |
| 2061 (let* ((all nil) | |
| 2062 (font (reftex-use-fonts)) | |
| 2063 (cnt 0) | |
| 2064 (file nil) | |
| 2065 (index -1) | |
| 2066 (toc-indent reftex-toc-indent) | |
| 2067 (label-indent | |
| 2068 (concat reftex-label-indent | |
| 2069 (if toc (make-string (* 7 reftex-level-indent) ?\ ) ""))) | |
| 2070 (context-indent | |
| 2071 (concat reftex-context-indent | |
| 2072 (if toc (make-string (* 7 reftex-level-indent) ?\ ) ""))) | |
| 2073 cell text label typekey note comment) | |
| 2074 | |
| 2075 ; Ensure access to scanning info | |
| 2076 (reftex-access-scan-info) | |
| 2077 | |
| 2078 (setq all (symbol-value reftex-list-of-labels-symbol)) | |
| 2079 | |
| 2080 (while all | |
| 2081 | |
| 2082 (setq index (1+ index) | |
| 2083 cell (car all) | |
| 2084 all (cdr all)) | |
| 2085 | |
| 2086 (if (null (nth 2 cell)) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
2087 ;; No context yet. Quick update |
| 18050 | 2088 (progn |
| 2089 (setq cell (reftex-label-info-update cell)) | |
| 2090 (setcar (nthcdr index | |
| 2091 (symbol-value reftex-list-of-labels-symbol)) | |
| 2092 cell))) | |
| 2093 | |
| 2094 ;; in the following setq we *copy* the label, since we will change | |
| 2095 ;; its properties, and we cannot have any properties in the list | |
| 2096 ;; (because of assoc searches) | |
| 2097 (setq label (copy-sequence (nth 0 cell)) | |
| 2098 typekey (nth 1 cell) | |
| 2099 text (nth 2 cell) | |
| 2100 file (nth 3 cell) | |
| 2101 note (nth 4 cell) | |
| 2102 comment (get-text-property 0 'in-comment text)) | |
| 2103 | |
| 2104 (if (string= label near-label) | |
| 2105 (setq offset (1+ cnt))) | |
| 2106 | |
| 2107 (cond | |
| 2108 ((and toc (string= typekey "toc")) | |
| 2109 (setq ins-list | |
| 2110 (cons (concat toc-indent text "\n") | |
| 2111 ins-list))) | |
| 2112 ((string= typekey "toc")) | |
| 2113 ((and (or (string= typekey typekey0) (string= typekey0 " ")) | |
| 2114 (or (nth 5 reftex-label-menu-flags) ; show-commented? | |
| 2115 (null comment))) | |
| 2116 (setq cnt (1+ cnt)) | |
| 2117 (if comment (setq label (concat "% " label))) | |
| 2118 (if font | |
| 2119 (put-text-property | |
| 2120 0 (length label) | |
| 2121 'face | |
| 2122 (if comment | |
| 2123 'font-lock-comment-face | |
| 2124 'font-lock-reference-face) | |
| 2125 label)) | |
| 2126 (setq index-list (cons index index-list)) | |
| 2127 (setq ins-list | |
| 2128 (cons (concat | |
| 2129 label-indent | |
| 2130 label | |
| 2131 (if counter (format " (%d) " cnt)) | |
| 2132 (if comment " LABEL IS COMMENTED OUT ") | |
| 2133 (if note (concat " " note) "") | |
| 2134 "\n" | |
| 2135 (if context (concat context-indent text "\n"))) | |
| 2136 ins-list)))) | |
| 2137 ))) | |
| 2138 | |
| 2139 (apply 'insert (nreverse ins-list)) | |
| 2140 (cons offset (nreverse index-list)))) | |
| 2141 | |
| 2142 (defun reftex-query-label-type () | |
| 2143 ;; Ask for label type | |
| 2144 (message reftex-type-query-prompt) | |
| 2145 (let ((key (read-char))) | |
| 2146 (if (equal key ?\?) | |
| 2147 (progn | |
| 2148 (save-window-excursion | |
| 2149 (with-output-to-temp-buffer "*RefTeX Help*" | |
| 2150 (princ reftex-type-query-help)) | |
| 2151 (setq key (read-char)) | |
| 2152 (kill-buffer "*RefTeX Help*")))) | |
| 2153 (if (not (member (char-to-string key) reftex-typekey-list)) | |
| 2154 (error "No such label type: %s" (char-to-string key))) | |
| 2155 (char-to-string key))) | |
| 2156 | |
| 2157 (defun reftex-find-nearby-label () | |
| 2158 ;; Find a nearby label. | |
| 2159 (save-excursion | |
| 2160 (if (or (re-search-backward "\\\\label{\\([^}]+\\)}" nil t) | |
| 2161 (re-search-forward "\\\\label{\\([^}]+\\)}" nil t)) | |
| 2162 (reftex-no-props (match-string 1)) | |
| 2163 nil))) | |
| 2164 | |
| 2165 ;; Variable holding the vector with section numbers | |
| 2166 (defvar reftex-section-numbers [0 0 0 0 0 0 0 0]) | |
| 2167 | |
| 2168 (defun reftex-scan-buffer-for-labels (label-numbers-symbol label-list-symbol) | |
| 2169 ;; Scan the buffer for labels and save them in a list. | |
| 2170 (save-excursion | |
| 2171 (let ((regexp (concat "\\\\label{\\([^}]*\\)}" "\\|" | |
| 2172 reftex-section-regexp)) | |
| 2173 (font (reftex-use-fonts)) | |
| 2174 (bound 0) | |
| 2175 (highest-level 100) | |
| 2176 file (level 1) start star text text1 label section-number macro find) | |
| 2177 (set label-list-symbol nil) | |
| 2178 (goto-char 0) | |
| 2179 | |
| 2180 ;; reset label numbers | |
| 2181 (set label-numbers-symbol | |
| 2182 (mapcar '(lambda(x) (cons x 0)) reftex-typekey-list)) | |
| 2183 | |
| 2184 ;; reset section numbers | |
| 2185 (reftex-section-number reftex-section-numbers -1) | |
| 2186 | |
| 2187 (while (re-search-forward regexp nil t) | |
| 2188 (setq file (get-text-property (match-beginning 0) 'file)) | |
| 2189 (if (string= (buffer-substring (match-beginning 0) | |
| 2190 (+ 7 (match-beginning 0))) "\\label{") | |
| 2191 ;; It is a label | |
| 2192 (progn | |
| 2193 (setq label (reftex-no-props (match-string 1))) | |
| 2194 (set label-list-symbol | |
| 2195 (cons (reftex-label-info label file bound) | |
| 2196 (symbol-value label-list-symbol)))) | |
| 2197 | |
| 2198 ;; It is a section | |
| 2199 (setq bound (point)) | |
| 2200 (setq star (= ?* (char-after (match-end 2)))) | |
| 2201 (setq find (buffer-substring-no-properties | |
| 2202 (1- (match-beginning 2)) (match-end 0))) | |
| 2203 (setq macro (reftex-no-props (match-string 2))) | |
| 2204 (setq level (cdr (assoc macro reftex-section-levels))) | |
| 2205 | |
| 2206 (setq section-number (reftex-section-number | |
| 2207 reftex-section-numbers level star)) | |
| 2208 (setq highest-level (min highest-level level)) | |
| 2209 (if (= level highest-level) | |
| 2210 (message | |
| 2211 "Scanning %s %s ..." | |
| 2212 (car (nth level reftex-section-levels)) | |
| 2213 section-number)) | |
| 2214 | |
| 2215 ;; get the title | |
| 2216 (save-match-data | |
| 2217 (setq text1 (reftex-context-substring)) | |
| 2218 (setq text (reftex-nicify-text text1))) | |
| 2219 | |
| 2220 (setq find (reftex-allow-for-ctrl-m (concat find text1))) | |
| 2221 | |
| 2222 ;; add section number and indentation | |
| 2223 (setq text | |
| 2224 (concat | |
| 2225 (make-string (* reftex-level-indent level) ?\ ) | |
| 2226 (if (nth 1 reftex-label-menu-flags) ; section number flag | |
| 2227 (concat section-number " ")) | |
| 2228 text)) | |
| 2229 ;; fontify | |
| 2230 (if font (put-text-property 0 (length text) | |
| 2231 'face 'font-lock-comment-face text)) | |
| 2232 | |
| 2233 ;; insert in list | |
| 2234 (set label-list-symbol | |
| 2235 (cons (list nil "toc" text file find) | |
| 2236 (symbol-value label-list-symbol))))) | |
| 2237 (set label-list-symbol | |
| 2238 (nreverse (symbol-value label-list-symbol)))))) | |
| 2239 | |
| 2240 | |
| 2241 (defun reftex-label-info-update (cell) | |
| 2242 ;; Update information about just one label in a different file. | |
| 2243 ;; CELL contains the old info list | |
| 2244 (let* ((label (nth 0 cell)) | |
| 2245 (typekey (nth 1 cell)) | |
| 2246 (text (nth 2 cell)) | |
| 2247 (file (nth 3 cell)) | |
| 2248 (note (nth 4 cell)) | |
| 2249 (buf (reftex-get-file-buffer-force | |
| 2250 file (not reftex-keep-temporary-buffers)))) | |
| 2251 (if (not buf) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
2252 (list label typekey "" file "LOST LABEL. RESCAN TO FIX.") |
| 18050 | 2253 (save-excursion |
| 2254 (set-buffer buf) | |
| 2255 (save-restriction | |
| 2256 (widen) | |
| 2257 (goto-char 1) | |
| 2258 | |
| 2259 (if (re-search-forward (concat "\\\\label{" (regexp-quote label) "}") | |
| 2260 nil t) | |
| 2261 (append (reftex-label-info label file) (list note)) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
2262 (list label typekey "" file "LOST LABEL. RESCAN TO FIX."))))))) |
| 18050 | 2263 |
| 2264 (defun reftex-label-info (label &optional file bound) | |
| 2265 ;; Return info list on LABEL at point. | |
| 2266 (let* ((env-or-mac (reftex-label-location bound)) | |
| 2267 (typekey (nth 1 (assoc env-or-mac reftex-env-or-mac-alist))) | |
| 2268 (file (or file (buffer-file-name))) | |
| 2269 (parse (if (reftex-typekey-check | |
| 2270 typekey reftex-use-text-after-label-as-context) | |
| 2271 nil | |
| 2272 (nth 2 (assoc env-or-mac reftex-env-or-mac-alist)))) | |
| 2273 (text (reftex-short-context env-or-mac parse reftex-location-start))) | |
| 2274 (if (reftex-in-comment) | |
| 2275 (put-text-property 0 1 'in-comment t text)) | |
| 2276 (list label typekey text file))) | |
| 2277 | |
| 2278 (defun reftex-in-comment () | |
| 2279 (save-excursion | |
| 2280 (skip-chars-backward "^%\n\r") | |
| 2281 (= (preceding-char) ?%))) | |
| 2282 | |
| 2283 (defun reftex-short-context (env parse &optional bound) | |
| 2284 ;; Get about one line of useful context for the label definition at point. | |
| 2285 | |
| 2286 (reftex-nicify-text | |
| 2287 | |
| 2288 (cond | |
| 2289 | |
| 2290 ((null parse) | |
| 2291 (save-excursion | |
| 2292 (reftex-context-substring))) | |
| 2293 | |
| 2294 ((eq parse t) | |
| 2295 (if (string= env "section") | |
| 2296 ;; special treatment for section labels | |
| 2297 (save-excursion | |
| 2298 (if (re-search-backward reftex-section-regexp (point-min) t) | |
| 2299 (progn | |
| 2300 (goto-char (match-end 0)) | |
| 2301 (reftex-context-substring)) | |
| 2302 "SECTION HEADING NOT FOUND")) | |
| 2303 (save-excursion | |
| 2304 (goto-char reftex-default-context-position) | |
| 2305 (reftex-context-substring)))) | |
| 2306 | |
| 2307 ((stringp parse) | |
| 2308 (save-excursion | |
| 2309 (if (re-search-backward parse bound t) | |
| 2310 (progn | |
| 2311 (goto-char (match-end 0)) | |
| 2312 (reftex-context-substring)) | |
| 2313 "NO MATCH FOR CONTEXT REGEXP"))) | |
| 2314 ((fboundp parse) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
2315 ;; A hook function. Call it. |
| 18050 | 2316 (save-excursion |
| 2317 (condition-case error-var | |
| 2318 (funcall parse env) | |
| 2319 ('error (format "HOOK ERROR: %s" (cdr error-var)))))) | |
| 2320 (t | |
| 2321 "ILLEGAL VALUE OF PARSE")))) | |
| 2322 | |
| 2323 (defun reftex-context-substring () | |
| 2324 ;; Return up to 100 chars from point | |
| 2325 ;; When point is just after a { or [, limit string to matching parenthesis | |
| 2326 (cond | |
| 2327 ((or (= (preceding-char) ?\{) | |
| 2328 (= (preceding-char) ?\[)) | |
| 2329 ;; inside a list - get only the list, with modified syntax to be perfect | |
| 2330 (buffer-substring | |
| 2331 (point) | |
| 2332 (min (+ 100 (point)) | |
| 2333 (point-max) | |
| 2334 (condition-case nil | |
| 2335 (progn | |
| 2336 (up-list 1) | |
| 2337 (1- (point))) | |
| 2338 ('error (point-max)))))) | |
| 2339 (t | |
| 2340 ;; no list - just grab 100 characters | |
| 2341 (buffer-substring (point) (min (+ 100 (point)) (point-max)))))) | |
| 2342 | |
| 2343 (defun reftex-section-number (section-numbers &optional level star) | |
| 2344 ;; Return a string with the current section number. | |
| 2345 ;; When LEVEL is non-nil, increase section numbers on that level. | |
| 2346 (let* ((depth 6) idx n (string "")) | |
| 2347 (if level | |
| 2348 (progn | |
| 2349 (if (and (> level -1) (not star)) | |
| 2350 (aset section-numbers level (1+ (aref section-numbers level)))) | |
| 2351 (setq idx (1+ level)) | |
| 2352 (while (<= idx depth) | |
| 2353 (aset section-numbers idx 0) | |
| 2354 (setq idx (1+ idx))))) | |
| 2355 (setq idx 0) | |
| 2356 (while (<= idx depth) | |
| 2357 (setq n (aref section-numbers idx)) | |
| 2358 (setq string (concat string (if (not (string= string "")) "." "") | |
| 2359 (int-to-string n))) | |
| 2360 (setq idx (1+ idx))) | |
| 2361 (save-match-data | |
| 2362 (if (string-match "\\`\\(0\\.\\)+" string) | |
| 2363 (setq string (replace-match "" nil nil string))) | |
| 2364 (if (string-match "\\(\\.0\\)+\\'" string) | |
| 2365 (setq string (replace-match "" nil nil string)))) | |
| 2366 (if star | |
| 2367 (concat (make-string (1- (length string)) ?\ ) "*") | |
| 2368 string))) | |
| 2369 | |
| 2370 ;; A variable to remember the index of the last label context shown | |
| 2371 (defvar reftex-last-cnt 0) | |
| 2372 | |
| 2373 (defun reftex-select-label-callback (cnt) | |
| 2374 ;; Callback function called from the label selection in order to | |
| 2375 ;; show context in another window | |
| 2376 (let* ((this-window (selected-window)) | |
| 2377 index entry label file buffer) | |
| 2378 ;; pop to original buffer in order to get correct variables | |
| 2379 (catch 'exit | |
| 2380 (save-excursion | |
| 2381 (set-buffer reftex-call-back-to-this-buffer) | |
| 2382 (setq index (nth (or cnt 1) reftex-label-index-list) | |
| 2383 entry (nth index (symbol-value reftex-list-of-labels-symbol)) | |
| 2384 label (nth 0 entry) | |
| 2385 file (nth 3 entry))) | |
| 2386 | |
| 2387 ;; goto the file in another window | |
| 2388 (setq buffer (reftex-get-file-buffer-force | |
| 2389 file (not reftex-keep-temporary-buffers))) | |
| 2390 (if buffer | |
| 2391 ;; good - the file is available | |
| 2392 (switch-to-buffer-other-window buffer) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
2393 ;; we have got a problem here. The file does not exist. |
| 18050 | 2394 ;; Let' get out of here.. |
| 2395 (ding) | |
| 2396 (throw 'exit nil)) | |
| 2397 | |
| 2398 | |
| 2399 ;; search for that label | |
| 2400 (if (not (and (integerp cnt) | |
| 2401 (integerp reftex-last-cnt) | |
| 2402 (if (> cnt reftex-last-cnt) | |
| 2403 (search-forward (concat "\\label{" label "}") nil t) | |
| 2404 (search-backward (concat "\\label{" label "}") nil t)))) | |
| 2405 (progn | |
| 2406 (goto-char 1) | |
| 2407 (search-forward (concat "\\label{" label "}") nil t))) | |
| 2408 (reftex-highlight 0 (match-beginning 0) (match-end 0)) | |
| 2409 (reftex-show-entry) | |
| 2410 (recenter (/ (window-height) 2)) | |
| 2411 (select-window this-window)))) | |
| 2412 | |
| 2413 (defun reftex-pop-to-label (label file-list &optional mark-to-kill highlight) | |
| 2414 ;; Find LABEL in any file in FILE-LIST in another window. | |
| 2415 ;; If mark-to-kill is non-nil, mark new buffer for killing. | |
| 2416 ;; If HIGHLIGHT is non-nil, highlight the label definition. | |
| 2417 (let* ((re (concat "\\\\label{" (regexp-quote label) "}")) | |
| 2418 file buf) | |
| 2419 (catch 'exit | |
| 2420 (while file-list | |
| 2421 (setq file (car file-list) | |
| 2422 file-list (cdr file-list)) | |
| 2423 (if (not (setq buf (reftex-get-file-buffer-force file mark-to-kill))) | |
| 2424 (error "No such file %s" file)) | |
| 2425 (set-buffer buf) | |
| 2426 (widen) | |
| 2427 (goto-char (point-min)) | |
| 2428 (if (re-search-forward re nil t) | |
| 2429 (progn | |
| 2430 (switch-to-buffer-other-window buf) | |
| 2431 (goto-char (match-beginning 0)) | |
| 2432 (recenter (/ (window-height) 2)) | |
| 2433 (if highlight | |
| 2434 (reftex-highlight 0 (match-beginning 0) (match-end 0))) | |
| 2435 (throw 'exit (selected-window))))) | |
| 2436 (error "Label %s not found" label)))) | |
| 2437 | |
| 2438 (defun reftex-find-duplicate-labels () | |
| 2439 "Produce a list of all duplicate labels in the document." | |
| 2440 | |
| 2441 (interactive) | |
| 2442 | |
| 2443 ;; Rescan the document to make sure | |
| 2444 (reftex-access-scan-info t) | |
| 2445 | |
| 2446 (let ((master (reftex-TeX-master-file)) | |
| 2447 (dlist | |
| 2448 (mapcar | |
| 2449 '(lambda(x) | |
| 2450 (let (x1) | |
| 2451 (cond | |
| 2452 ((car x) | |
| 2453 (setq x1 (reftex-all-assoc-string | |
| 2454 (car x) (symbol-value reftex-list-of-labels-symbol))) | |
| 2455 (if (< 1 (length x1)) | |
| 2456 (append (list (reftex-no-props (car x))) | |
| 2457 (mapcar '(lambda(x) | |
| 2458 (abbreviate-file-name (nth 3 x))) x1)) | |
| 2459 (list nil))) | |
| 2460 (t nil)))) | |
| 2461 (reftex-uniquify (symbol-value reftex-list-of-labels-symbol))))) | |
| 2462 (setq dlist (reftex-uniquify dlist)) | |
| 2463 (if (null dlist) (error "No duplicate labels in document")) | |
|
18219
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
2464 (switch-to-buffer-other-window "*Duplicate Labels*") |
| 18050 | 2465 (make-local-variable 'TeX-master) |
| 2466 (setq TeX-master master) | |
| 2467 (erase-buffer) | |
| 2468 (insert " MULTIPLE LABELS IN CURRENT DOCUMENT:\n") | |
| 2469 (insert " Move point to label and type `M-x reftex-change-label'\n" | |
| 2470 " This will run a query-replace on the label and its references\n") | |
| 2471 (insert " LABEL FILE\n") | |
| 2472 (insert " -------------------------------------------------------------\n") | |
| 2473 (while dlist | |
| 2474 (if (and (car (car dlist)) | |
| 2475 (cdr (car dlist))) | |
| 2476 (progn | |
| 2477 (insert (mapconcat '(lambda(x) x) (car dlist) "\n ") "\n"))) | |
| 2478 (setq dlist (cdr dlist))) | |
| 2479 (goto-char (point-min)))) | |
| 2480 | |
| 2481 (defun reftex-all-assoc-string (key list) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
2482 ;; Return a list of all associations of KEY in LIST. Comparison with string= |
| 18050 | 2483 (let (rtn) |
| 2484 (while list | |
| 2485 (if (string= (car (car list)) key) | |
| 2486 (setq rtn (cons (car list) rtn))) | |
| 2487 (setq list (cdr list))) | |
| 2488 (nreverse rtn))) | |
| 2489 | |
| 2490 (defun reftex-kill-temporary-buffers () | |
| 2491 ;; Kill all buffers in the list reftex-kill-temporary-buffers. | |
| 2492 (while reftex-buffers-to-kill | |
| 2493 (if (bufferp (car reftex-buffers-to-kill)) | |
| 2494 (progn | |
| 2495 (and (buffer-modified-p (car reftex-buffers-to-kill)) | |
| 2496 (y-or-n-p (format "Save file %s? " | |
| 2497 (buffer-file-name | |
| 2498 (car reftex-buffers-to-kill)))) | |
| 2499 (save-excursion | |
| 2500 (set-buffer (car reftex-buffers-to-kill)) | |
| 2501 (save-buffer))) | |
| 2502 (kill-buffer (car reftex-buffers-to-kill)))) | |
| 2503 (setq reftex-buffers-to-kill (cdr reftex-buffers-to-kill)))) | |
| 2504 | |
| 2505 (defun reftex-show-entry () | |
| 2506 ;; Show entry if point is hidden by outline mode | |
| 2507 (let ((pos (point))) | |
| 2508 (if (and reftex-auto-show-entry | |
| 2509 (boundp 'outline-minor-mode) | |
| 2510 outline-minor-mode | |
| 2511 (looking-at "[^\n\r]*\r")) | |
| 2512 (progn | |
| 2513 (outline-back-to-heading) | |
| 2514 (show-entry) | |
| 2515 (goto-char pos))))) | |
| 2516 | |
| 2517 | |
| 2518 (defun reftex-nicify-text (text) | |
| 2519 ;; Make TEXT nice for inclusion into label menu | |
| 2520 (while (string-match "[\n\r\t]\\|[ \t][ \t]+" text) ; remove extra whitespace | |
| 2521 (setq text (replace-match " " nil t text))) | |
| 2522 (if (string-match "\\\\end{.*" text) ; nothing beyond \end{ | |
| 2523 (setq text (replace-match "" nil t text))) | |
| 2524 (if (string-match "\\\\label{[^}]*}" text) ; kill the label | |
| 2525 (setq text (replace-match "" nil t text))) | |
| 2526 (if (string-match "^ +" text) ; leading whitespace | |
| 2527 (setq text (replace-match "" nil t text))) | |
| 2528 (cond | |
| 2529 ((> (length text) 100) ; not to long | |
| 2530 (setq text (substring text 0 100))) | |
| 2531 ((= (length text) 0) ; not empty | |
| 2532 (setq text " "))) | |
| 2533 text) | |
| 2534 | |
| 2535 (defun reftex-typekey-check (typekey conf-variable &optional n) | |
| 2536 ;; Check if CONF-VARIABLE is true or contains TYPEKEY | |
| 2537 (and n (setq conf-variable (nth n conf-variable))) | |
| 2538 (or (equal conf-variable t) | |
| 2539 (and (stringp conf-variable) | |
| 2540 (string-match (concat "[" conf-variable "]") typekey)))) | |
| 2541 | |
| 2542 ;;; =========================================================================== | |
| 2543 ;;; | |
| 2544 ;;; Table of contents (contributed from Stephen Eglen, changed by C. Dominik) | |
| 2545 | |
| 2546 ;; We keep at most one *toc* buffer - it is easy to make them | |
| 2547 | |
| 2548 (defvar reftex-last-toc-master nil | |
| 2549 "Stores the name of the tex file that `reftex-toc' was last run on.") | |
| 2550 | |
| 2551 (defvar reftex-last-toc-file nil | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
2552 "Stores the file name from which `reftex-toc' was called. For redo command.") |
| 18050 | 2553 |
| 2554 (defvar reftex-toc-return-marker (make-marker) | |
| 2555 "Marker which makes it possible to return from toc to old position.") | |
| 2556 | |
| 2557 (defun reftex-toc () | |
| 2558 "Show the table of contents for the current document. | |
| 2559 To see the corresponding part of the LaTeX document, use within the | |
| 2560 *toc* buffer: | |
| 2561 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
2562 SPC Show the corresponding section of the LaTeX document. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
2563 RET Goto the section and hide the *toc* buffer. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
2564 q Hide the *toc* window and return to position of last reftex-toc command. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
2565 Q Kill the *toc* buffer and return to position of last reftex-toc command. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
2566 f Toggle follow mode on and off. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
2567 r Reparse the LaTeX document. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
2568 g Revert buffer (like `r'). |
| 18050 | 2569 |
| 2570 When called with a raw C-u prefix, rescan the document first." | |
| 2571 | |
| 2572 (interactive) | |
| 2573 | |
| 2574 (and (not (string= reftex-last-toc-master (reftex-TeX-master-file))) | |
| 2575 (get-buffer "*toc*") | |
| 2576 (kill-buffer "*toc*")) | |
| 2577 | |
| 2578 (setq reftex-last-toc-file (buffer-file-name)) | |
| 2579 (setq reftex-last-toc-master (reftex-TeX-master-file)) | |
| 2580 | |
| 2581 (set-marker reftex-toc-return-marker (point)) | |
| 2582 | |
| 2583 ;; if follow mode is active, arrange to delay it one command | |
| 2584 (if reftex-toc-follow-mode | |
| 2585 (setq reftex-toc-follow-mode 1)) | |
| 2586 | |
| 2587 (if (and current-prefix-arg | |
| 2588 (get-buffer "*toc*")) | |
| 2589 (kill-buffer "*toc*")) | |
| 2590 | |
| 2591 ;; Ensure access to scanning info and rescan buffer if prefix are is '(4) | |
| 2592 (reftex-access-scan-info current-prefix-arg) | |
| 2593 | |
| 2594 (let* ((all (symbol-value reftex-list-of-labels-symbol)) | |
| 2595 (where (reftex-nearest-section)) | |
| 2596 toc toc1 cell label file find startpos) | |
| 2597 | |
| 2598 (if (and (get-buffer "*toc*") | |
| 2599 (get-buffer-window (get-buffer "*toc*"))) | |
| 2600 (select-window (get-buffer-window (get-buffer "*toc*"))) | |
| 2601 (delete-other-windows) | |
| 2602 (switch-to-buffer-other-window (current-buffer)) | |
| 2603 (switch-to-buffer-other-window (get-buffer-create "*toc*"))) | |
| 2604 | |
| 2605 (cond | |
| 2606 ;; buffer is empty - fill it with the table of contents | |
| 2607 ((= (buffer-size) 0) | |
| 2608 | |
| 2609 (local-set-key " " 'reftex-toc-view-line) | |
| 2610 (local-set-key "\C-m" 'reftex-toc-goto-line-and-hide) | |
| 2611 (local-set-key "r" 'reftex-toc-redo) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
2612 (local-set-key "g" 'revert-buffer) |
| 18050 | 2613 (local-set-key "q" 'reftex-toc-quit) |
| 2614 (local-set-key "Q" 'reftex-toc-quit-and-kill) | |
| 2615 (local-set-key "f" 'reftex-toc-toggle-follow) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
2616 (make-local-variable 'revert-buffer-function) |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
2617 (setq revert-buffer-function 'reftex-toc-redo) |
| 18050 | 2618 (setq truncate-lines t) |
| 2619 (make-local-hook 'post-command-hook) | |
| 2620 (make-local-hook 'pre-command-hook) | |
| 2621 (setq post-command-hook '(reftex-toc-post-command-hook)) | |
| 2622 (setq pre-command-hook '(reftex-toc-pre-command-hook)) | |
| 2623 | |
| 2624 (insert (format | |
| 2625 "TABLE-OF-CONTENTS on %s | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
2626 MENU: SPC=view RET=goto [q]uit [Q]uit+kill [r]escan [f]ollow-mode |
| 18050 | 2627 ------------------------------------------------------------------------------- |
| 2628 " (abbreviate-file-name reftex-last-toc-master))) | |
| 2629 (setq startpos (point)) | |
| 2630 | |
| 2631 (if (reftex-use-fonts) | |
| 2632 (put-text-property 1 (point) 'face 'font-lock-keyword-face)) | |
| 2633 (put-text-property 1 (point) 'intangible t) | |
| 2634 | |
| 2635 (while all | |
| 2636 (setq cell (car all) | |
| 2637 all (cdr all)) | |
| 2638 (setq label (nth 0 cell) | |
| 2639 toc (nth 2 cell) | |
| 2640 file (nth 3 cell) | |
| 2641 find (nth 4 cell)) | |
| 2642 (if (not label) | |
| 2643 (progn | |
| 2644 (setq toc1 (concat toc "\n")) | |
| 2645 (put-text-property 0 (length toc1) | |
| 2646 'file file toc1) | |
| 2647 (put-text-property 0 (length toc1) | |
| 2648 'find find toc1) | |
| 2649 (insert toc1) | |
| 2650 ))) | |
| 2651 | |
| 2652 (backward-delete-char 1) | |
| 2653 | |
| 2654 (setq buffer-read-only t)) | |
| 2655 (t | |
| 2656 (goto-line 3) | |
| 2657 (beginning-of-line) | |
| 2658 (setq startpos (point)))) | |
| 2659 | |
| 2660 ;; Find the correct section | |
| 2661 (goto-char (point-max)) | |
| 2662 (beginning-of-line) | |
| 2663 (while (and (> (point) startpos) | |
| 2664 (or (not (string= (get-text-property (point) 'file) | |
| 2665 (car where))) | |
| 2666 (not (string= (get-text-property (point) 'find) | |
| 2667 (cdr where))))) | |
| 2668 (beginning-of-line 0)))) | |
| 2669 | |
| 2670 (defun reftex-nearest-section () | |
| 2671 ;; Return (file . find) of nearest section command | |
| 2672 (let (cell label rest) | |
| 2673 (save-excursion | |
| 2674 (cond | |
| 2675 ;; Try to find a section heading | |
| 2676 ((or (re-search-backward reftex-section-regexp nil t) | |
| 2677 (re-search-forward reftex-section-regexp nil t)) | |
| 2678 (goto-char (match-end 0)) | |
| 2679 (cons (buffer-file-name) | |
| 2680 (reftex-allow-for-ctrl-m | |
| 2681 (concat (buffer-substring-no-properties | |
| 2682 (1- (match-beginning 1)) (match-end 0)) | |
| 2683 (reftex-context-substring))))) | |
| 2684 ;; Try to find a label | |
| 2685 ((and (or (re-search-backward "\\\\label{\\([^}]+\\)}" nil t) | |
| 2686 (re-search-forward "\\\\label{\\([^}]+\\)}" nil t)) | |
| 2687 (setq label (reftex-no-props (match-string 1))) | |
| 2688 (setq cell (assoc label (symbol-value | |
| 2689 reftex-list-of-labels-symbol))) | |
| 2690 (setq rest (memq cell (symbol-value reftex-list-of-labels-symbol))) | |
| 2691 (setq cell (car (memq (assoc nil rest) rest))) | |
| 2692 (null (car cell))) | |
| 2693 (cons (nth 3 cell) (nth 4 cell))) | |
| 2694 (t nil))))) | |
| 2695 | |
| 2696 (defun reftex-toc-pre-command-hook () | |
| 2697 ;; used as pre command hook in *toc* buffer | |
| 2698 (reftex-unhighlight 0) | |
| 2699 (reftex-unhighlight 1)) | |
| 2700 | |
| 2701 (defun reftex-toc-post-command-hook () | |
| 2702 ;; used in the post-command-hook for the *toc* buffer | |
| 2703 (and (> (point) 1) | |
| 2704 (save-excursion | |
| 2705 (reftex-highlight 1 | |
| 2706 (progn (beginning-of-line) (point)) | |
| 2707 (progn (end-of-line) (point))))) | |
| 2708 (cond | |
| 2709 ((integerp reftex-toc-follow-mode) | |
| 2710 ;; remove delayed action | |
| 2711 (setq reftex-toc-follow-mode t)) | |
| 2712 (reftex-toc-follow-mode | |
| 2713 ;; show context in other window | |
| 2714 (condition-case nil | |
| 2715 (reftex-toc-visit-line) | |
| 2716 ('error t))))) | |
| 2717 | |
| 2718 (defun reftex-toc-toggle-follow () | |
| 2719 "Toggle toc-follow mode. | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
2720 (It is not really a mode, just a flag)." |
| 18050 | 2721 (interactive) |
| 2722 (setq reftex-toc-follow-mode (not reftex-toc-follow-mode))) | |
| 2723 (defun reftex-toc-view-line () | |
| 2724 "View document location in other window." | |
| 2725 (interactive) | |
| 2726 (reftex-toc-visit-line)) | |
| 2727 (defun reftex-toc-goto-line-and-hide () | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
2728 "Go to document location in other window. Hide the *toc* window." |
| 18050 | 2729 (interactive) |
| 2730 (reftex-toc-visit-line 'hide)) | |
| 2731 (defun reftex-toc-quit () | |
| 2732 "Hide the *toc* window and do not move point." | |
| 2733 (interactive) | |
| 2734 (delete-window) | |
| 2735 (switch-to-buffer (marker-buffer reftex-toc-return-marker)) | |
| 2736 (goto-char (marker-position reftex-toc-return-marker))) | |
| 2737 (defun reftex-toc-quit-and-kill () | |
| 2738 "Kill the *toc* buffer." | |
| 2739 (interactive) | |
| 2740 (kill-buffer "*toc*") | |
| 2741 (delete-window) | |
| 2742 (switch-to-buffer (marker-buffer reftex-toc-return-marker)) | |
| 2743 (goto-char (marker-position reftex-toc-return-marker))) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
2744 (defun reftex-toc-redo (&rest ignore) |
| 18050 | 2745 "Regenerate the *toc* buffer. Call only from within the *toc* buffer" |
| 2746 (interactive) | |
| 2747 (switch-to-buffer (reftex-get-file-buffer-force reftex-last-toc-file)) | |
| 2748 (delete-other-windows) | |
| 2749 (setq current-prefix-arg '(4)) | |
| 2750 (reftex-toc)) | |
| 2751 | |
| 2752 (defun reftex-toc-visit-line (&optional final) | |
| 2753 ;; Visit the tex file corresponding to the toc entry on the current line. | |
| 2754 ;; If FINAL is t, stay there | |
| 2755 ;; If FINAL is 'hide, hide the *toc* window. | |
| 2756 ;; Otherwise, move cursor back into *toc* window | |
| 2757 | |
| 2758 (let (file find beg end (toc-window (selected-window)) show-window) | |
| 2759 (save-excursion | |
| 2760 (beginning-of-line) | |
| 2761 (setq beg (point)) | |
| 2762 (end-of-line) | |
| 2763 (setq end (point))) | |
| 2764 | |
| 2765 ;; get the file and the search string | |
| 2766 (setq file (get-text-property (point) 'file)) | |
| 2767 (setq find (get-text-property (point) 'find)) | |
| 2768 (if (or (not file) (not find)) | |
| 2769 (error "Cannot visit line")) | |
| 2770 | |
| 2771 (switch-to-buffer-other-window (reftex-get-file-buffer-force file)) | |
| 2772 (setq show-window (selected-window)) | |
| 2773 (goto-char (point-min)) | |
| 2774 | |
| 2775 (if (not (re-search-forward find nil t)) | |
| 2776 (error "Cannot visit line")) | |
| 2777 | |
| 2778 (setq beg (match-beginning 0) | |
| 2779 end (match-end 0)) | |
| 2780 | |
| 2781 (goto-char beg) | |
| 2782 (recenter 1) | |
| 2783 (reftex-highlight 0 beg end (current-buffer)) | |
| 2784 | |
| 2785 (select-window toc-window) | |
| 2786 | |
| 2787 ;; use the `final' parameter to decide what to do next | |
| 2788 (cond | |
| 2789 ((equal final t) | |
| 2790 (reftex-unhighlight 0) | |
| 2791 (select-window show-window)) | |
| 2792 ((eq final 'hide) | |
| 2793 (reftex-unhighlight 0) | |
| 2794 (delete-window)) | |
| 2795 (t nil)))) | |
| 2796 | |
| 2797 ;;; =========================================================================== | |
| 2798 ;;; | |
| 2799 ;;; BibTeX citations. | |
| 2800 | |
| 2801 ;; Variables and constants | |
| 2802 | |
|
18219
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
2803 ;; Define variable to silence compiler warnings |
|
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
2804 (defvar reftex-found-list) |
|
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
2805 |
| 18050 | 2806 ;; Internal variable, but used from different functions |
| 2807 (defvar reftex-cite-format1 nil) | |
| 2808 | |
| 2809 ;; The history list of regular expressions used for citations | |
| 2810 (defvar reftex-cite-regexp-hist nil) | |
| 2811 | |
| 2812 ;; Help string for citation selection | |
| 2813 (defconst reftex-citation-help | |
| 2814 "AVAILABLE KEYS IN MAKE CITATION MENU | |
| 2815 --------------------------------------- | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
2816 n / p Go to next/previous entry (Cursor motion works as well). |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
2817 r Restrict selection with another regexp. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
2818 SPACE Show full database entry in other window. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
2819 f Toggle follow mode: Other window will follow with full db entry. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
2820 q Quit without inserting \\cite macro into buffer. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
2821 ? Display this help message. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
2822 C-r Recursive edit into other window. |
| 18050 | 2823 RETURN ... Accept current entry and insert in format according to |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
2824 `reftex-cite-format'") |
| 18050 | 2825 |
| 2826 (defconst reftex-cite-format-default "\\cite{KEY}" | |
| 2827 "The default value for reftex-cite-format. | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
2828 Uses the string version of `reftex-cite-format'.") |
| 18050 | 2829 |
| 2830 (defconst reftex-cite-format-1-author-simple | |
| 2831 '( "\\cite{KEY}" "AUTHOR \\cite{KEY}" "AUTHOR {\it et al.} \\cite{KEY}") | |
| 2832 "Value for reftex-cite format establishing a simple citation with name | |
| 2833 of the first author. | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
2834 Uses the list version of `reftex-cite-format'.") |
| 18050 | 2835 |
| 2836 (defconst reftex-cite-format-2-authors | |
| 2837 '((?\C-m | |
| 2838 . ( "\\cite{KEY}" "AUTHOR \\cite{KEY}" | |
| 2839 "AUTHOR \\& AUTHOR \\cite{KEY}" "AUTHOR \\etal{} \\cite{KEY}")) | |
| 2840 (?\, | |
| 2841 . ("\\cite{KEY}" "AUTHOR, \\cite{KEY}" | |
| 2842 "AUTHOR \\& AUTHOR, \\cite{KEY}" "AUTHOR \\etal{}, \\cite{KEY}")) | |
| 2843 (?\; | |
| 2844 . ("\\cite{KEY}" "AUTHOR; \\cite{KEY}" | |
| 2845 "AUTHOR \\& AUTHOR; \\cite{KEY}" "AUTHOR \\etal{}; \\cite{KEY}")) | |
| 2846 (?\: | |
| 2847 . ("\\cite{KEY}" "AUTHOR: \\cite{KEY}" | |
| 2848 "AUTHOR \\& AUTHOR: \\cite{KEY}" "AUTHOR \\etal{}: \\cite{KEY}")) | |
| 2849 (?\( | |
| 2850 . ("(\\cite{KEY})" "AUTHOR (\\cite{KEY})" | |
| 2851 "AUTHOR \\& AUTHOR (\\cite{KEY})" "AUTHOR \\etal{} (\\cite{KEY})")) | |
| 2852 (?\[ | |
| 2853 . ("[\\cite{KEY}]" "AUTHOR [\\cite{KEY}]" | |
| 2854 "AUTHOR \\& AUTHOR [\\cite{KEY}]" "AUTHOR \\etal{} [\\cite{KEY}]"))) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
2855 "Value for `reftex-cite-format' that estabishes an Author/Year citation |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
2856 where the year is supplied from BibTeX. Depending on which character |
| 18050 | 2857 is used during selection to accept the label, an extra ,;: or pair of |
| 2858 parenthesis will be inserted. | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
2859 Uses the list-of-cons-cells version of `reftex-cite-format'.") |
| 18050 | 2860 |
| 2861 ;; Find bibtex files | |
| 2862 | |
| 2863 (defun reftex-get-bibfile-list () | |
| 2864 ;; Return list of bibfiles for current document | |
| 2865 | |
| 2866 ;; Ensure access to scanning info | |
| 2867 (reftex-access-scan-info) | |
| 2868 | |
| 2869 (or (symbol-value reftex-bibfile-list-symbol) | |
| 2870 (error "No BibTeX files to parse. Add \\bibliography statment to document and reparse."))) | |
| 2871 | |
| 2872 (defun reftex-scan-buffer-for-bibliography-statement (bib-list-symbol) | |
| 2873 ;; Scan buffer for bibliography macro and store file list in bib-list-symbol. | |
| 2874 (let (file-list dir-list) | |
| 2875 (setq dir-list | |
| 2876 (reftex-split | |
| 2877 (concat path-separator "+") | |
| 2878 (mapconcat '(lambda(x) | |
| 2879 (if (getenv x) (getenv x) "")) | |
| 2880 reftex-bibpath-environment-variables | |
| 2881 path-separator))) | |
| 2882 (goto-char (point-min)) | |
| 2883 (if (re-search-forward "^[ \t]*\\\\bibliography{[ \t]*\\([^}]+\\)" nil t) | |
| 2884 (progn | |
| 2885 (setq dir-list | |
| 2886 (cons (file-name-directory | |
| 2887 (get-text-property (match-beginning 0) 'file)) | |
| 2888 dir-list)) | |
| 2889 (setq file-list | |
| 2890 (mapcar '(lambda (x) (concat x ".bib")) | |
| 2891 (reftex-delete-list | |
| 2892 reftex-bibfile-ignore-list | |
| 2893 (reftex-split | |
| 2894 "[ \t\n]*,[ \t\n]*" | |
| 2895 (reftex-no-props (match-string 1))))))) | |
| 2896 (message "No \\bibliography command in document.")) | |
| 2897 (set bib-list-symbol | |
| 2898 (if file-list | |
| 2899 (reftex-find-files-on-path file-list dir-list | |
| 18123 | 2900 "While parsing \\bibliography:") |
| 18050 | 2901 nil)))) |
| 2902 | |
| 2903 (defun reftex-find-files-on-path (file-list path-list &optional error-string) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
2904 ;; Search for all files in FILE-LIST on the PATH-LIST. Return absolute names. |
| 18050 | 2905 ;; A missing file throws an exception with the error message ERROR-STRING. |
| 2906 (let (found-list found file) | |
| 2907 (while file-list | |
| 2908 (setq file (car file-list) | |
| 2909 file-list (cdr file-list) | |
| 2910 found nil) | |
| 2911 (if (file-name-absolute-p file) | |
| 2912 (setq found (expand-file-name file)) | |
| 2913 (let ((dirs path-list)) | |
| 2914 (while (and dirs (not found)) | |
| 2915 (if (and (not (string= (car dirs) "")) | |
| 2916 (file-exists-p (expand-file-name file (car dirs)))) | |
| 2917 (setq found (expand-file-name file (car dirs)))) | |
| 2918 (setq dirs (cdr dirs))))) | |
| 2919 (if (and found | |
| 2920 (file-exists-p found)) | |
| 2921 (add-to-list 'found-list (expand-file-name found)) | |
| 2922 (error "%s No such file %s." | |
| 2923 (or error-string "") file))) | |
| 2924 (nreverse found-list))) | |
| 2925 | |
| 2926 ;; Find a certain reference in any of the BibTeX files. | |
| 2927 | |
| 2928 (defun reftex-pop-to-bibtex-entry (key file-list | |
| 2929 &optional mark-to-kill highlight) | |
| 2930 ;; Find BibTeX KEY in any file in FILE-LIST in another window. | |
| 2931 ;; If mark-to-kill is non-nil, mark new buffer to kill." | |
| 2932 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
2933 (let* ((re (concat "@[a-zA-Z]+[ \t\n\r]*[{(][ \t\n\r]*" (regexp-quote key) "[ \t\n\r,]")) |
| 18050 | 2934 (window-conf (current-window-configuration)) |
| 2935 file buf) | |
| 2936 (catch 'exit | |
| 2937 (switch-to-buffer-other-window (current-buffer)) | |
| 2938 (while file-list | |
| 2939 (setq file (car file-list) | |
| 2940 file-list (cdr file-list)) | |
| 2941 (if (not (setq buf (reftex-get-file-buffer-force file mark-to-kill))) | |
| 2942 (error "No such file %s" file)) | |
| 2943 (switch-to-buffer buf) | |
| 2944 (widen) | |
| 2945 (goto-char 0) | |
| 2946 (if (re-search-forward re nil t) | |
| 2947 (progn | |
| 2948 (goto-char (match-beginning 0)) | |
| 2949 (recenter 0) | |
| 2950 (if highlight | |
| 2951 (reftex-highlight 0 (match-beginning 0) (match-end 0))) | |
| 2952 (throw 'exit (selected-window))))) | |
| 2953 (set-window-configuration window-conf) | |
| 2954 (beep) | |
| 2955 (message "No BibTeX entry with citation key %s" key)))) | |
| 2956 | |
| 2957 ;; Parse bibtex buffers | |
| 2958 | |
| 2959 (defun reftex-extract-bib-entries (buffers &optional get-word) | |
| 2960 ;; Extract bib entries which match regexps from BUFFERS. | |
| 2961 ;; BUFFERS is a list of buffers or file names. | |
| 2962 ;; Return list with entries." | |
| 2963 (let* (re-list first-re rest-re | |
| 2964 ;; avoid fontification of lookup buffers | |
| 2965 (lazy-lock-minimum-size 1) | |
| 2966 (buffer-list (if (listp buffers) buffers (list buffers))) | |
| 2967 found-list entry buffer1 buffer alist | |
| 2968 key-point start-point end-point) | |
| 2969 | |
| 2970 (setq re-list (reftex-split "[ \t]*&&[ \t]*" | |
| 2971 (read-string "RegExp [ && RegExp...]: " | |
| 2972 nil 'reftex-cite-regexp-hist))) | |
| 2973 | |
| 2974 (setq first-re (car re-list) ; We'll use the first re to find things, | |
| 2975 rest-re (cdr re-list)) ; the other to narrow down. | |
| 2976 (if (string-match "\\`[ \t]*\\'" first-re) | |
| 2977 (error "Empty regular expression")) | |
| 2978 | |
| 2979 (save-excursion | |
| 2980 (save-window-excursion | |
| 2981 | |
| 2982 ;; walk through all bibtex files | |
| 2983 (while buffer-list | |
| 2984 (setq buffer (car buffer-list) | |
| 2985 buffer-list (cdr buffer-list)) | |
| 2986 (if (and (bufferp buffer) | |
| 2987 (buffer-live-p buffer)) | |
| 2988 (setq buffer1 buffer) | |
| 2989 (setq buffer1 (reftex-get-file-buffer-force | |
| 2990 buffer (not reftex-keep-temporary-buffers)))) | |
| 2991 (if (not buffer1) | |
| 2992 (error "Cannot find BibTeX file %s" buffer) | |
| 2993 (message "Scanning bibliography database %s" buffer1)) | |
| 2994 | |
| 2995 (set-buffer buffer1) | |
| 2996 (save-excursion | |
| 2997 (goto-char (point-min)) | |
| 2998 (while (re-search-forward first-re nil t) | |
| 2999 (catch 'search-again | |
| 3000 (setq key-point (point)) | |
| 3001 (if (not (re-search-backward | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
3002 "^[ \t]*@\\([a-zA-Z]+\\)[ \t\n\r]*[{(]" nil t)) |
| 18050 | 3003 (throw 'search-again nil)) |
| 3004 (setq start-point (point)) | |
| 3005 (goto-char (match-end 0)) | |
| 3006 (condition-case nil | |
| 3007 (up-list 1) | |
| 3008 ('error (goto-char key-point) | |
| 3009 (throw 'search-again nil))) | |
| 3010 (setq end-point (point)) | |
| 3011 | |
| 3012 ;; Ignore @string, @comment and @c entries or things | |
| 3013 ;; outside entries | |
| 3014 (if (or (string= (downcase (match-string 1)) "string") | |
| 3015 (string= (downcase (match-string 1)) "comment") | |
| 3016 (string= (downcase (match-string 1)) "c") | |
| 3017 (< (point) key-point)) ; this means match not in {} | |
| 3018 (progn | |
| 3019 (goto-char key-point) | |
| 3020 (throw 'search-again nil))) | |
| 3021 | |
| 3022 ;; Well, we have got a match | |
| 3023 (setq entry (concat | |
| 3024 (buffer-substring start-point (point)) "\n")) | |
| 3025 | |
| 3026 ;; Check if other regexp match as well | |
| 3027 (setq re-list rest-re) | |
| 3028 (while re-list | |
| 3029 (if (not (string-match (car re-list) entry)) | |
| 3030 ;; nope - move on | |
| 3031 (throw 'search-again nil)) | |
| 3032 (setq re-list (cdr re-list))) | |
| 3033 | |
| 3034 (setq alist (reftex-parse-bibtex-entry | |
| 3035 nil start-point end-point)) | |
| 3036 (setq alist (cons (cons "&entry" entry) alist)) | |
| 3037 | |
| 3038 ;; check for crossref entries | |
| 3039 (if (assoc "crossref" alist) | |
| 3040 (setq alist | |
| 3041 (append | |
| 3042 alist (reftex-get-crossref-alist alist)))) | |
| 3043 | |
| 3044 ;; format the entry | |
| 3045 (setq alist | |
| 3046 (cons | |
| 3047 (cons "&formatted" | |
| 3048 (reftex-format-bib-entry alist)) | |
| 3049 alist)) | |
| 3050 | |
| 3051 ;; add it to the list | |
| 3052 (setq found-list (cons alist found-list))))) | |
| 3053 (reftex-kill-temporary-buffers)))) | |
| 3054 (setq found-list (nreverse found-list)) | |
| 3055 | |
| 3056 ;; Sorting | |
| 3057 (cond | |
| 3058 ((eq 'author reftex-sort-bibtex-matches) | |
| 3059 (sort found-list 'reftex-bib-sort-author)) | |
| 3060 ((eq 'year reftex-sort-bibtex-matches) | |
| 3061 (sort found-list 'reftex-bib-sort-year)) | |
| 3062 ((eq 'reverse-year reftex-sort-bibtex-matches) | |
| 3063 (sort found-list 'reftex-bib-sort-year-reverse)) | |
| 3064 (t found-list)))) | |
| 3065 | |
| 3066 (defun reftex-bib-sort-author (e1 e2) | |
| 3067 (let ((al1 (reftex-get-bib-authors e1)) (al2 (reftex-get-bib-authors e2))) | |
| 3068 (while (and al1 al2 (string= (car al1) (car al2))) | |
| 3069 (setq al1 (cdr al1) | |
| 3070 al2 (cdr al2))) | |
| 3071 (if (and (stringp (car al1)) | |
| 3072 (stringp (car al2))) | |
| 3073 (string< (car al1) (car al2)) | |
| 3074 (not (stringp (car al1)))))) | |
| 3075 | |
| 3076 (defun reftex-bib-sort-year (e1 e2) | |
| 3077 (< (string-to-int (cdr (assoc "year" e1))) | |
| 3078 (string-to-int (cdr (assoc "year" e2))))) | |
| 3079 | |
| 3080 (defun reftex-bib-sort-year-reverse (e1 e2) | |
| 3081 (> (string-to-int (or (cdr (assoc "year" e1)) "0")) | |
| 3082 (string-to-int (or (cdr (assoc "year" e2)) "0")))) | |
| 3083 | |
| 3084 (defun reftex-get-crossref-alist (entry) | |
| 3085 ;; return the alist from a crossref entry | |
| 3086 (let ((crkey (cdr (assoc "crossref" entry))) | |
| 3087 start) | |
| 3088 (save-excursion | |
| 3089 (save-restriction | |
| 3090 (widen) | |
| 3091 (if (re-search-forward | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
3092 (concat "@\\w+[{(][ \t\n\r]*" (regexp-quote crkey) "[ \t\n\r]*,") nil t) |
| 18050 | 3093 (progn |
| 3094 (setq start (match-beginning 0)) | |
| 3095 (condition-case nil | |
| 3096 (up-list 1) | |
| 3097 ('error nil)) | |
| 3098 (reftex-parse-bibtex-entry nil start (point))) | |
| 3099 nil))))) | |
| 3100 | |
| 3101 ;; Parse and format individual entries | |
| 3102 | |
| 3103 (defun reftex-get-bib-authors (entry) | |
| 3104 ;; Return a list with the author names in ENTRY | |
| 3105 (let (authors) | |
| 3106 (setq authors (reftex-get-bib-field "author" entry)) | |
| 3107 (if (equal "" authors) | |
| 3108 (setq authors (reftex-get-bib-field "editor" entry))) | |
| 3109 (while (string-match "\\band\\b[ \t]*" authors) | |
| 3110 (setq authors (replace-match "\n" nil t authors))) | |
| 3111 (while (string-match "[\\.a-zA-Z\\-]+\\.[ \t]*\\|,.*\\|[{}]+" authors) | |
| 3112 (setq authors (replace-match "" nil t authors))) | |
| 3113 (while (string-match "^[ \t]+\\|[ \t]+$" authors) | |
| 3114 (setq authors (replace-match "" nil t authors))) | |
| 3115 (while (string-match "[ \t][ \t]+" authors) | |
| 3116 (setq authors (replace-match " " nil t authors))) | |
| 3117 (reftex-split "\n" authors))) | |
| 3118 | |
| 3119 (defun reftex-parse-bibtex-entry (entry &optional from to) | |
| 3120 (let (alist key start field) | |
| 3121 (save-excursion | |
| 3122 (save-restriction | |
| 3123 (if entry | |
| 3124 (progn | |
| 3125 (switch-to-buffer "*RefTeX-scratch*") | |
| 3126 (fundamental-mode) | |
| 3127 (erase-buffer) | |
| 3128 (insert entry)) | |
| 3129 (widen) | |
| 3130 (narrow-to-region from to)) | |
| 3131 (goto-char (point-min)) | |
| 3132 | |
| 3133 (if (re-search-forward | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
3134 "@\\(\\w+\\)[ \t\n\r]*[{(][ \t\n\r]*\\([^ \t\n\r,]+\\)" nil t) |
| 18050 | 3135 (setq alist |
| 3136 (list | |
| 3137 (cons "&type" (downcase (reftex-no-props (match-string 1)))) | |
| 3138 (cons "&key" (reftex-no-props (match-string 2)))))) | |
| 3139 (while (re-search-forward "\\(\\w+\\)[ \t\n\r]*=[ \t\n\r]*" nil t) | |
| 3140 (setq key (reftex-no-props (downcase (match-string 1)))) | |
| 3141 (cond | |
| 3142 ((= (following-char) ?{) | |
| 3143 (forward-char 1) | |
| 3144 (setq start (point)) | |
| 3145 (condition-case nil | |
| 3146 (up-list 1) | |
| 3147 ('error nil))) | |
| 3148 ((= (following-char) ?\") | |
| 3149 (forward-char 1) | |
| 3150 (setq start (point)) | |
| 3151 (while (and (search-forward "\"" nil t) | |
| 3152 (= ?\\ (char-after (- (point) 2)))))) | |
| 3153 (t | |
| 3154 (setq start (point)) | |
| 3155 (re-search-forward "[ \t\n\r,}]" nil 1))) | |
| 3156 (setq field (buffer-substring-no-properties start (1- (point)))) | |
| 3157 ;; remove extra whitesp | |
| 3158 (while (string-match "[\n\t\r]\\|[ \t][ \t]+" field) | |
| 3159 (setq field (replace-match " " nil t field))) | |
| 3160 ;; remove leading garbage | |
| 3161 (if (string-match "^[ \t{]+" field) | |
| 3162 (setq field (replace-match "" nil t field))) | |
| 3163 ;; remove trailing garbage | |
| 3164 (if (string-match "[ \t}]+$" field) | |
| 3165 (setq field (replace-match "" nil t field))) | |
| 3166 (setq alist (cons (cons key field) alist))) | |
| 3167 alist)))) | |
| 3168 | |
| 3169 (defun reftex-get-bib-field (fieldname entry) | |
| 3170 ;; Extract the field FIELDNAME from an ENTRY | |
| 3171 (or (cdr (assoc fieldname entry)) | |
| 3172 "")) | |
| 3173 | |
| 3174 (defun reftex-format-bib-entry (entry) | |
| 3175 ;; Format a BibTeX ENTRY so that it is nice to look at | |
| 3176 (let* | |
| 3177 ((rtn nil) | |
| 3178 (auth-list (reftex-get-bib-authors entry)) | |
| 3179 (authors (mapconcat '(lambda (x) x) auth-list ", ")) | |
| 3180 (year (reftex-get-bib-field "year" entry)) | |
| 3181 (title (reftex-get-bib-field "title" entry)) | |
| 3182 (type (reftex-get-bib-field "&type" entry)) | |
| 3183 (key (reftex-get-bib-field "&key" entry)) | |
| 3184 (extra | |
| 3185 (cond | |
| 3186 ((equal type "article") | |
| 3187 (concat (reftex-get-bib-field "journal" entry) " " | |
| 3188 (reftex-get-bib-field "volume" entry) ", " | |
| 3189 (reftex-get-bib-field "pages" entry))) | |
| 3190 ((equal type "book") | |
| 3191 (concat "book (" (reftex-get-bib-field "publisher" entry) ")")) | |
| 3192 ((equal type "phdthesis") | |
| 3193 (concat "PhD: " (reftex-get-bib-field "school" entry))) | |
| 3194 ((equal type "mastersthesis") | |
| 3195 (concat "Master: " (reftex-get-bib-field "school" entry))) | |
| 3196 ((equal type "inbook") | |
| 3197 (concat "Chap: " (reftex-get-bib-field "chapter" entry) | |
| 3198 ", pp. " (reftex-get-bib-field "pages" entry))) | |
| 3199 ((or (equal type "conference") | |
| 3200 (equal type "incollection") | |
| 3201 (equal type "inproceedings")) | |
| 3202 (concat "in: " (reftex-get-bib-field "booktitle" entry))) | |
| 3203 (t "")))) | |
| 3204 (setq authors | |
| 3205 (if (> (length authors) 30) | |
| 3206 (concat (substring authors 0 27) "...") | |
| 3207 (format "%-30s" authors)) | |
| 3208 title | |
| 3209 (if (> (length title) 70) | |
| 3210 (concat (substring title 0 67) "...") | |
| 3211 (format "%-70s" title)) | |
| 3212 extra | |
| 3213 (if (> (length extra) 40) | |
| 3214 (concat (substring extra 0 37) "...") | |
| 3215 (format "%-40s" extra))) | |
| 3216 (if (reftex-use-fonts) | |
| 3217 (progn | |
| 3218 (put-text-property 0 (length authors) 'face 'font-lock-keyword-face | |
| 3219 authors) | |
| 3220 (put-text-property 0 (length title) 'face 'font-lock-comment-face | |
| 3221 title) | |
| 3222 (put-text-property 0 (length extra) 'face 'font-lock-reference-face | |
| 3223 extra))) | |
| 3224 (setq rtn (concat key "\n " authors " " year " " extra | |
| 3225 "\n " title "\n\n")) | |
| 3226 rtn)) | |
| 3227 | |
| 3228 ;; Make a citation | |
| 3229 | |
| 3230 (defun reftex-citation (&optional arg no-insert) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
3231 "Make a citation using BibTeX database files. |
| 18050 | 3232 After asking for a Regular Expression, it scans the buffers with |
| 3233 bibtex entries (taken from the \\bibliography command) and offers the | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
3234 matching entries for selection. The selected entry is formated according |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
3235 to `reftex-cite-format' and inserted into the buffer. |
| 18050 | 3236 If NO-INSERT is non-nil, nothing is inserted, only the selected key returned. |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
3237 The regular expression uses an expanded syntax: && is interpreted as `and'. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
3238 Thus, `aaaa&&bbb' matches entries which contain both `aaaa' and `bbb'. |
| 18123 | 3239 When this function is called with point inside the braces of a \\cite |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
3240 command, it will add another key, ignoring the value of `reftex-cite-format'. |
| 18050 | 3241 When called with a numeric prefix, that many citations will be made and all |
| 18123 | 3242 put into the same \\cite command. |
| 18050 | 3243 When called with just C-u as prefix, enforces rescan of buffer for |
| 3244 bibliography statement (e.g. if it was changed)." | |
| 3245 | |
| 3246 (interactive "P") | |
| 3247 | |
| 3248 ;; check for recursive edit | |
| 3249 (reftex-check-recursive-edit) | |
| 3250 | |
| 3251 ;; if there is just 1 C-u prefix arg, force to rescan buffer | |
| 3252 (if (and current-prefix-arg | |
| 3253 (listp current-prefix-arg) | |
| 3254 (= 4 (prefix-numeric-value arg))) | |
| 3255 (reftex-reset-scanning-information)) | |
| 3256 | |
| 3257 ;; check if there is already a cite command at point and change cite format | |
| 3258 ;; in order to only add another reference in the same cite command. | |
| 3259 (let ((pos (point))) | |
| 3260 (search-backward "\\" (point-min) 1) | |
| 3261 (if (and (looking-at "\\\\[a-zA-Z]*cite\\*?\\(\\[[^]]*\\]\\)*{\\([^}]*\\)") | |
| 3262 (>= (match-end 0) pos) | |
| 3263 (>= pos (match-beginning 2))) | |
| 3264 (progn | |
| 3265 (goto-char pos) | |
| 3266 (cond | |
| 3267 ((or (not arg) | |
| 3268 (not (listp arg))) | |
| 3269 (setq reftex-cite-format1 | |
| 3270 (concat | |
| 3271 (if (not (or (= (preceding-char) ?{) | |
| 3272 (= (preceding-char) ?,))) | |
| 3273 "," | |
| 3274 "") | |
| 3275 "KEY" | |
| 3276 (if (not (or (= (following-char) ?}) | |
| 3277 (= (following-char) ?,))) | |
| 3278 "," | |
| 3279 "")))) | |
| 3280 (t | |
| 3281 (setq reftex-cite-format1 "KEY")))) | |
| 3282 (setq reftex-cite-format1 | |
| 3283 (if (symbolp reftex-cite-format) | |
| 3284 (symbol-value reftex-cite-format) | |
| 3285 reftex-cite-format)) | |
| 3286 (goto-char pos))) | |
| 3287 | |
| 3288 (let* (key entry cnt rtn ins-string re-list re | |
| 3289 ;; scan bibtex files | |
| 3290 (lazy-lock-minimum-size 1) | |
|
18219
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
3291 (reftex-found-list (reftex-extract-bib-entries |
|
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
3292 (reftex-get-bibfile-list))) |
| 18050 | 3293 (found-list-r nil) |
| 3294 (accept-keys | |
| 3295 (if (and (listp reftex-cite-format1) | |
| 3296 (listp (car reftex-cite-format1))) | |
| 3297 (mapcar 'car reftex-cite-format1) | |
| 3298 '(?\C-m)))) | |
|
18219
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
3299 (if (not reftex-found-list) |
| 18050 | 3300 (error "Sorry, no matches found")) |
| 3301 | |
| 3302 ;; remember where we came from | |
| 3303 (setq reftex-call-back-to-this-buffer (current-buffer)) | |
| 3304 | |
| 3305 ;; offer selection | |
| 3306 (save-window-excursion | |
| 3307 (switch-to-buffer-other-window "*RefTeX Select*") | |
| 3308 (erase-buffer) | |
| 3309 (mapcar '(lambda (x) (insert (cdr (assoc "&formatted" x)))) | |
|
18219
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
3310 reftex-found-list) |
| 18050 | 3311 (if (= 0 (buffer-size)) |
| 3312 (error "Sorry, no matches found")) | |
| 3313 (setq truncate-lines t) | |
| 3314 (goto-char 1) | |
| 3315 (if (catch 'exit | |
| 3316 (while t | |
| 3317 (setq rtn | |
| 3318 (reftex-select-item | |
| 3319 nil | |
| 3320 (concat | |
| 3321 "Select: [n]ext [p]rev [r]estrict [q]uit [?]Help ||" | |
| 3322 " RETURN " | |
| 3323 (condition-case nil | |
| 3324 (mapconcat 'char-to-string accept-keys " ") | |
| 3325 (error (error "Illegal reftex-cite-format")))) | |
| 3326 "^[^ \t\n]" | |
| 3327 "\n\n" | |
| 3328 4 | |
| 3329 reftex-citation-help | |
| 3330 (cons ?r accept-keys) | |
| 3331 nil | |
| 3332 'reftex-bibtex-selection-callback nil)) | |
| 3333 (setq key (car rtn) | |
| 3334 cnt (cdr rtn)) | |
| 3335 (if (not key) (throw 'exit nil)) | |
| 3336 (cond | |
| 3337 ((equal key ?r) | |
| 3338 ;; restrict with new regular expression | |
| 3339 (setq re-list | |
| 3340 (reftex-split "[ \t]*&&[ \t]*" | |
| 3341 (read-string "RegExp [ && RegExp...]: " | |
| 3342 nil 'reftex-cite-regexp-hist))) | |
| 3343 (while re-list | |
| 3344 (setq re (car re-list) | |
| 3345 re-list (cdr re-list)) | |
| 3346 (setq found-list-r | |
| 3347 (delete "" | |
| 3348 (mapcar | |
| 3349 '(lambda (x) | |
| 3350 (if (string-match re | |
| 3351 (cdr (assoc "&entry" x))) | |
| 3352 x | |
| 3353 "")) | |
|
18219
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
3354 reftex-found-list)))) |
| 18050 | 3355 (if found-list-r |
|
18219
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
3356 (setq reftex-found-list found-list-r) |
| 18050 | 3357 (ding)) |
| 3358 (erase-buffer) | |
| 3359 (mapcar '(lambda (x) (insert (cdr (assoc "&formatted" x)))) | |
|
18219
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
3360 reftex-found-list) |
| 18050 | 3361 (goto-char 1)) |
| 3362 ((or (member key accept-keys) | |
| 3363 (equal key ?\C-m) | |
| 3364 (equal key 'return)) | |
|
18219
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
3365 (setq entry (nth cnt reftex-found-list)) |
| 18050 | 3366 (throw 'exit t)) |
| 3367 (t | |
| 3368 (ding))))) | |
| 3369 (progn | |
| 3370 ;; format the entry | |
| 3371 (if (not (integerp key)) (setq key ?\C-m)) | |
| 3372 (setq ins-string (reftex-format-citation entry key))) | |
| 3373 (setq ins-string "") | |
| 3374 (message "Quit"))) | |
| 3375 (kill-buffer "*RefTeX Select*") | |
| 3376 | |
| 3377 (if (not no-insert) | |
| 3378 (insert ins-string)) | |
| 3379 (message "") | |
| 3380 | |
| 3381 ;; Check if the prefix arg was numeric, and call reftex-citation recursively | |
| 3382 (if (and (integerp arg) | |
| 3383 (> arg 1) | |
| 3384 (re-search-backward | |
| 3385 "\\\\[a-zA-Z]*cite\\*?\\(\\[[^]]*\\]\\)*{\\([^}]*\\)" nil t)) | |
| 3386 (progn | |
| 3387 (goto-char (match-end 0)) | |
| 3388 (setq arg (1- arg)) | |
| 3389 (reftex-citation arg)) | |
| 3390 (reftex-kill-temporary-buffers)) | |
| 3391 ;; Return the citation key | |
| 3392 (reftex-get-bib-field "&key" entry))) | |
| 3393 | |
| 3394 (defun reftex-format-citation (entry key) | |
| 3395 ;; Format a citation from the info in the BibTeX ENTRY | |
| 3396 (let* ((cite-key (reftex-get-bib-field "&key" entry)) | |
| 3397 (year (reftex-get-bib-field "year" entry)) | |
| 3398 (auth-list (reftex-get-bib-authors entry)) | |
| 3399 (nauthors (length auth-list)) | |
| 3400 format) | |
| 3401 | |
| 3402 (save-excursion | |
| 3403 ;; Find the correct format | |
| 3404 (if (and (listp reftex-cite-format1) | |
| 3405 (listp (car reftex-cite-format1))) | |
| 3406 (if (integerp (car (car reftex-cite-format1))) | |
| 3407 (if (assoc key reftex-cite-format1) | |
| 3408 (setq format (cdr (assoc key reftex-cite-format1))) | |
| 3409 (if (or (equal key ?\C-m) | |
| 3410 (equal key 'return)) | |
| 3411 (setq format (cdr (car reftex-cite-format1))) | |
| 3412 (error "Error in reftex-cite-format"))) | |
| 3413 (error "Error in reftex-cite-format")) | |
| 3414 (setq format reftex-cite-format1)) | |
| 3415 | |
| 3416 (if (listp format) | |
| 3417 (let ((nn (min nauthors (1- (length format))))) | |
| 3418 (while (and (> nn 0) (string= "" (nth nn format))) | |
| 3419 (setq nn (1- nn))) | |
| 3420 (setq format (nth nn format)))) | |
| 3421 (if (stringp format) | |
| 3422 (setq format format) | |
| 3423 (setq format "\\cite{KEY}")) | |
| 3424 | |
| 3425 ;; Insert the author names | |
| 3426 (while (string-match "\\bAUTHOR\\b" format) | |
| 3427 (setq format (replace-match (car auth-list) t t format)) | |
| 3428 (setq auth-list (cdr auth-list))) | |
| 3429 (while (string-match "\\bKEY\\b" format) | |
| 3430 (setq format (replace-match cite-key t t format))) | |
| 3431 (while (string-match "\\bYEAR\\b" format) | |
| 3432 (setq format (replace-match year t t format))) | |
| 3433 format))) | |
| 3434 | |
| 3435 ;; this is slow and not recommended for follow mode | |
| 3436 (defun reftex-bibtex-selection-callback (cnt) | |
| 3437 ;; Callback function to be called from the BibTeX selection, in | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
3438 ;; order to display context. This function is relatively slow and not |
| 18050 | 3439 ;; recommended for follow mode, just for individual lookups. |
| 3440 (let ((win (selected-window)) | |
|
18219
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
3441 (key (reftex-get-bib-field "&key" (nth cnt reftex-found-list))) |
| 18050 | 3442 (bibfile-list (save-excursion |
| 3443 (set-buffer reftex-call-back-to-this-buffer) | |
| 3444 (reftex-get-bibfile-list)))) | |
| 3445 (reftex-pop-to-bibtex-entry key bibfile-list | |
| 3446 (not reftex-keep-temporary-buffers) t) | |
| 3447 (select-window win))) | |
| 3448 | |
| 3449 ;;; =========================================================================== | |
| 3450 ;;; | |
| 3451 ;;; Here is the routine used for selection | |
| 3452 | |
| 3453 ;; Marker for return point from recursive edit | |
| 3454 (defvar reftex-recursive-edit-marker (make-marker)) | |
| 3455 | |
| 3456 (defun reftex-check-recursive-edit () | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
3457 ;; Check if we are already in a recursive edit. Abort with helpful |
| 18050 | 3458 ;; message if so. |
| 3459 (if (marker-position reftex-recursive-edit-marker) | |
| 3460 (error | |
| 3461 (substitute-command-keys | |
| 3462 "In unfinished recursive edit. Finish (\\[exit-recursive-edit]) or abort (\\[abort-recursive-edit]).")))) | |
| 3463 | |
| 3464 (defun reftex-select-item (buffer prompt next-re end-re size help-string | |
| 3465 event-list &optional offset | |
| 3466 call-back cb-flag) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
3467 ;; Select an item from the buffer BUFFER. Show PROMPT to user, find |
| 18050 | 3468 ;; next item with NEXT-RE regular expression, return on any of the |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
3469 ;; events listed in EVENT-LIST. The function returns the event along |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
3470 ;; with an integer indicating which item was selected. When OFFSET is |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
3471 ;; specified, starts at that item in the list. When CALL-BACK is |
| 18050 | 3472 ;; given, it is a function which is called with the match of the |
| 3473 ;; NEXT-RE match and the index of the element. | |
| 3474 (let* (key key-sq b e ev cnt cmd | |
| 3475 (offset1 (or offset 1))) | |
| 3476 (setq ev | |
| 3477 (catch 'exit | |
| 3478 (save-window-excursion | |
| 3479 (if buffer | |
| 3480 (switch-to-buffer-other-window buffer)) | |
| 3481 (if (= 0 (buffer-size)) | |
| 3482 (throw 'exit nil)) | |
| 3483 (setq truncate-lines t) | |
| 3484 (goto-char 1) | |
| 3485 (if (not (re-search-forward next-re nil t offset1)) | |
| 3486 (progn ; in case the offset is illegal | |
| 3487 (setq offset1 1) | |
| 3488 (if (not (re-search-forward next-re nil t offset1)) | |
| 3489 (throw 'exit nil)))) | |
| 3490 (beginning-of-line 1) | |
| 3491 (setq cnt (if offset1 (1- offset1) 0)) | |
| 3492 (while t | |
| 3493 (if (and cb-flag call-back) | |
| 3494 (funcall call-back cnt)) | |
| 3495 (setq b (point) | |
| 3496 e (save-excursion | |
| 3497 (save-match-data | |
| 3498 (re-search-forward end-re nil 1)) | |
| 3499 (point))) | |
| 3500 (reftex-highlight 1 b e) | |
| 3501 (if (or (not (pos-visible-in-window-p b)) | |
| 3502 (not (pos-visible-in-window-p e))) | |
| 3503 (recenter (/ (window-height) 2))) | |
| 3504 (setq key-sq (read-key-sequence prompt)) | |
| 3505 (setq key (car | |
| 3506 (cond | |
| 3507 ((fboundp 'listify-key-sequence) ; Emacs | |
| 3508 (listify-key-sequence key-sq)) | |
| 3509 ((fboundp 'event-to-character) ; XEmacs | |
| 3510 (mapcar 'event-to-character key-sq)) | |
| 3511 (t (error "Please report this problem to dominik@strw.leidenuniv.nl"))))) | |
| 3512 | |
| 3513 (setq cmd (key-binding key-sq)) | |
| 3514 | |
| 3515 (reftex-unhighlight 0) | |
| 3516 | |
| 3517 (cond | |
| 3518 | |
| 3519 ((or (equal key ?n) | |
| 3520 (equal key ?\C-i) | |
| 3521 (equal cmd 'next-line)) | |
| 3522 (if (re-search-forward next-re nil t 2) | |
| 3523 (setq cnt (1+ cnt))) | |
| 3524 (beginning-of-line 1)) | |
| 3525 | |
| 3526 ((equal cmd 'scroll-up) | |
| 3527 (setq cnt (1- cnt)) | |
| 3528 (while (and (pos-visible-in-window-p) | |
| 3529 (re-search-forward next-re nil t)) | |
| 3530 (setq cnt (1+ cnt))) | |
| 3531 (beginning-of-line 1) | |
| 3532 (recenter 1)) | |
| 3533 | |
| 3534 ((or (equal key ?p) | |
| 3535 (equal cmd 'previous-line)) | |
| 3536 (if (re-search-backward next-re nil t) | |
| 3537 (setq cnt (1- cnt)))) | |
| 3538 | |
| 3539 ((equal cmd 'scroll-down) | |
| 3540 (while (and (pos-visible-in-window-p) | |
| 3541 (re-search-backward next-re nil t)) | |
| 3542 (setq cnt (1- cnt))) | |
| 3543 (recenter (- (window-height) size 2))) | |
| 3544 | |
| 3545 ((equal key ?q) | |
| 3546 (throw 'exit nil)) | |
| 3547 | |
| 3548 ((equal key ?\C-g) | |
| 3549 (bury-buffer) | |
| 3550 (error "Abort")) | |
| 3551 | |
| 3552 ((or (equal key ?\C-m) | |
| 3553 (equal key 'return) | |
| 3554 (equal cmd 'newline)) | |
| 3555 (throw 'exit 'return)) | |
| 3556 | |
| 3557 ((or (equal key ?C) ; backward compatibility | |
| 3558 (equal key ?f)) | |
| 3559 (setq cb-flag (not cb-flag))) | |
| 3560 | |
| 3561 ((equal key ?\ ) | |
| 3562 (funcall call-back cnt)) | |
| 3563 | |
| 3564 ((equal key ?\?) | |
| 3565 (save-window-excursion | |
| 3566 (with-output-to-temp-buffer "*RefTeX Help*" | |
| 3567 (princ help-string)) | |
| 3568 (setq unread-command-events | |
| 3569 (cons | |
| 3570 (cond | |
| 3571 ((fboundp 'read-event) ; Emacs | |
| 3572 (read-event)) | |
| 3573 ((fboundp 'next-command-event) ; XEmacs | |
| 3574 (next-command-event)) | |
| 3575 (t (error "Please report this problem to dominik@strw.leidenuniv.nl"))) | |
| 3576 nil))) | |
| 3577 (kill-buffer "*RefTeX Help*")) | |
| 3578 | |
| 3579 ((equal key ?\C-r) | |
| 3580 ;; sje - code copied from ispell.el for | |
| 3581 ;; performing recursive edit | |
| 3582 (set-marker reftex-recursive-edit-marker (point)) | |
| 3583 (unwind-protect | |
| 3584 (progn | |
| 3585 (save-window-excursion | |
| 3586 (save-excursion | |
| 3587 (other-window 1) | |
| 3588 (message | |
| 3589 (substitute-command-keys | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
3590 "Recursive edit. Return to selection with \\[exit-recursive-edit]")) |
| 18050 | 3591 (recursive-edit))) |
| 3592 (if (not (equal (marker-buffer | |
| 3593 reftex-recursive-edit-marker) | |
| 3594 (current-buffer))) | |
| 3595 (error | |
| 3596 "Cannot continue RefTeX from this buffer.")) | |
| 3597 (goto-char reftex-recursive-edit-marker)) | |
| 3598 (set-marker reftex-recursive-edit-marker nil))) | |
| 3599 | |
| 3600 ((member key event-list) | |
| 3601 (throw 'exit key)) | |
| 3602 (t | |
| 3603 (ding))))))) | |
| 3604 (message "") | |
| 3605 (cons ev cnt))) | |
| 3606 | |
| 3607 ;;; =========================================================================== | |
| 3608 ;;; | |
| 3609 ;;; View cross references | |
| 3610 | |
| 3611 (defun reftex-view-crossref (&optional arg) | |
| 18123 | 3612 "View cross reference of \\ref or \\cite macro at point. |
| 3613 If the macro at point is a \\ref, show the corresponding label definition. | |
| 3614 If it is a \\cite, show the BibTeX database entry. | |
| 18050 | 3615 If there is no such macro at point, search forward to find one. |
| 3616 When you call this function several times in direct successtion, point will | |
| 3617 move to view subsequent cross references further down in the buffer. | |
| 3618 With argument, actually select the window showing the cross reference." | |
| 3619 | |
| 3620 (interactive "P") | |
| 3621 | |
| 3622 ;; See where we are. | |
| 3623 (let* ((pos (point)) | |
| 3624 (re "\\\\[a-z]*\\(cite\\|ref\\)\\(\\[[^{}]*\\]\\)?{\\([^}]+\\)}") | |
| 3625 (my-window (get-buffer-window (current-buffer))) | |
| 3626 pop-window cmd args macro label entry key-start point) | |
| 3627 | |
| 3628 (if (save-excursion | |
| 3629 (forward-char 1) | |
| 3630 (and (search-backward "\\" nil t) | |
| 3631 (looking-at re) | |
| 3632 (< pos (match-end 0)))) | |
| 3633 (setq macro (match-string 1) | |
| 3634 key-start (match-beginning 3))) | |
| 3635 | |
| 3636 (if (and macro (eq last-command this-command)) | |
| 3637 (if (and (string= macro "cite") | |
| 3638 (skip-chars-forward "^}, \t\n\r") | |
| 3639 (= (following-char) ?,)) | |
| 3640 (setq key-start (1+ (point))) | |
| 3641 (setq macro nil))) | |
| 3642 | |
| 3643 (if (not macro) | |
| 3644 (if (re-search-forward re nil t) | |
| 3645 (setq macro (match-string 1) | |
| 3646 key-start (match-beginning 3)) | |
| 3647 (error "No further cross references in buffer"))) | |
| 3648 | |
| 3649 (goto-char key-start) | |
| 3650 | |
| 3651 ;; Ensure access to scanning info | |
| 3652 (reftex-access-scan-info) | |
| 3653 | |
| 3654 (cond | |
| 3655 ((string= macro "cite") | |
| 3656 (setq cmd 'reftex-pop-to-bibtex-entry | |
| 3657 args (list | |
| 3658 (reftex-no-props (reftex-this-word "^{},")) | |
| 3659 (reftex-get-bibfile-list) nil t))) | |
| 3660 ((string= macro "ref") | |
| 3661 (let ((label (reftex-no-props (reftex-this-word "^{}"))) | |
| 3662 (entry (assoc label (symbol-value reftex-list-of-labels-symbol)))) | |
| 3663 (if entry | |
| 3664 (setq cmd 'reftex-pop-to-label | |
| 3665 args (list label (list (nth 3 entry)) nil t)) | |
| 3666 (error "Label %s not known - reparse document might help" label)))) | |
| 3667 (t (error "This should not happen"))) | |
| 3668 (setq point (point)) | |
| 3669 (apply cmd args) | |
| 3670 (setq pop-window (selected-window)) | |
| 3671 (add-hook 'pre-command-hook 'reftex-highlight-shall-die) | |
| 3672 (select-window my-window) | |
| 3673 (goto-char point) | |
| 3674 (and arg (select-window pop-window)))) | |
| 3675 | |
| 3676 (defun reftex-mouse-view-crossref (ev) | |
| 18123 | 3677 "View cross reference of \\ref or \\cite macro where you click. |
| 3678 If the macro at point is a \\ref, show the corresponding label definition. | |
| 3679 If it is a \\cite, show the BibTeX database entry. | |
| 18050 | 3680 If there is no such macro at point, search forward to find one. |
| 3681 With argument, actually select the window showing the cross reference." | |
| 3682 (interactive "e") | |
| 3683 (mouse-set-point ev) | |
| 3684 (reftex-view-crossref current-prefix-arg)) | |
| 3685 | |
| 3686 ;;; =========================================================================== | |
| 3687 ;;; | |
| 3688 ;;; Functions that check out the surroundings | |
| 3689 | |
| 3690 (defun reftex-what-macro (which &optional bound) | |
| 3691 ;; Find out if point is within the arguments of any TeX-macro. | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
3692 ;; The return value is either ("\\macro" . (point)) or a list of them. |
| 18050 | 3693 |
| 3694 ;; If WHICH is nil, immediately return nil. | |
| 3695 ;; If WHICH is t, return list of all macros enclosing point. | |
| 3696 ;; If WHICH is a list of macros, look only for those macros and return the | |
| 3697 ;; name of the first macro in this list found to enclose point. | |
| 3698 ;; If the optional BOUND is an integer, bound backwards directed | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
3699 ;; searches to this point. If it is nil, limit to nearest \section - |
| 18050 | 3700 ;; like statement. |
| 3701 | |
| 3702 ;; This function is pretty stable, but can be fooled if the text contains | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
3703 ;; things like \macro{aa}{bb} where \macro is defined to take only one |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
3704 ;; argument. As RefTeX cannot know this, the string "bb" would still be |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
3705 ;; considered an argument of macro \macro. |
| 18050 | 3706 |
| 3707 (catch 'exit | |
| 3708 (if (null which) (throw 'exit nil)) | |
| 3709 (let ((bound (or bound (save-excursion (re-search-backward | |
| 3710 reftex-section-regexp nil 1) | |
| 3711 (point)))) | |
| 3712 pos cmd-list cmd) | |
| 3713 (save-restriction | |
| 3714 (save-excursion | |
| 3715 (narrow-to-region (max 1 bound) (point-max)) | |
| 3716 ;; move back out of the current parenthesis | |
| 3717 (while (condition-case nil | |
| 3718 (progn (up-list -1) t) | |
| 3719 (error nil)) | |
| 3720 ;; move back over any touching sexps | |
| 3721 (while (or (= (preceding-char) ?\]) | |
| 3722 (= (preceding-char) ?\})) | |
| 3723 (backward-sexp)) | |
| 3724 (setq pos (point)) | |
| 3725 (if (and (or (= (following-char) ?\[) | |
| 3726 (= (following-char) ?\{)) | |
| 3727 (and (re-search-backward "\\(\\\\[a-zA-Z]+\\)" nil t) | |
| 3728 (= (match-end 0) pos))) | |
| 3729 (progn | |
| 3730 (setq cmd (buffer-substring-no-properties | |
| 3731 (match-beginning 0) (match-end 0))) | |
| 3732 (if (eq t which) | |
| 3733 (setq cmd-list (cons (cons cmd (point)) cmd-list)) | |
| 3734 (if (member cmd which) | |
| 3735 (throw 'exit (cons cmd (point))))))) | |
| 3736 (goto-char pos))) | |
| 3737 (nreverse cmd-list))))) | |
| 3738 | |
| 3739 (defun reftex-what-environment (which &optional bound) | |
| 3740 ;; Find out if point is inside a LaTeX environment. | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
3741 ;; The return value is (e.g.) either ("equation" . (point)) or a list of |
| 18050 | 3742 ;; them. |
| 3743 | |
| 3744 ;; If WHICH is nil, immediately return nil. | |
| 3745 ;; If WHICH is t, return list of all environments enclosing point. | |
| 3746 ;; If WHICH is a list of environments, look only for those environments and | |
| 3747 ;; return the name of the first environment in this list found to enclose | |
| 3748 ;; point. | |
| 3749 | |
| 3750 ;; If the optional BOUND is an integer, bound backwards directed searches to | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
3751 ;; this point. If it is nil, limit to nearest \section - like statement. |
| 18050 | 3752 |
| 3753 (catch 'exit | |
| 3754 (save-excursion | |
| 3755 (if (null which) (throw 'exit nil)) | |
| 3756 (let ((bound (or bound (save-excursion (re-search-backward | |
| 3757 reftex-section-regexp nil 1) | |
| 3758 (point)))) | |
| 3759 env-list end-list env) | |
| 3760 (while (re-search-backward "\\\\\\(begin\\|end\\){\\([^}]+\\)}" | |
| 3761 bound t) | |
| 3762 (setq env (buffer-substring-no-properties | |
| 3763 (match-beginning 2) (match-end 2))) | |
| 3764 (cond | |
| 3765 ((string= (match-string 1) "end") | |
| 3766 (add-to-list 'end-list env)) | |
| 3767 ((member env end-list) | |
| 3768 (setq end-list (delete env end-list))) | |
| 3769 ((eq t which) | |
| 3770 (setq env-list (cons (cons env (point)) env-list))) | |
| 3771 ((member env which) | |
| 3772 (throw 'exit (cons env (point)))))) | |
| 3773 (nreverse env-list))))) | |
| 3774 | |
| 3775 (defun reftex-word-before-point () | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
3776 ;; Return the word before point. Word means here: |
| 18050 | 3777 ;; Consists of [a-zA-Z0-9.:] and ends at point or whitespace. |
| 3778 (let ((pos (point))) | |
| 3779 (save-excursion | |
| 3780 (re-search-backward "[^ \t\n\r]" (point-min) 1) | |
| 3781 (setq pos (1+ (point))) | |
| 3782 (if (re-search-backward "[^a-zA-Z0-9\\\.:]" (point-min) 1) | |
| 3783 (forward-char 1)) | |
| 3784 (buffer-substring-no-properties (point) pos)))) | |
| 3785 | |
| 3786 ;; ============================================================================ | |
| 3787 ;; | |
| 3788 ;; Some generally useful functions | |
| 3789 | |
| 3790 (defun reftex-no-props (string) | |
| 3791 ;; Return STRING with all text properties removed | |
| 3792 (and (stringp string) | |
| 3793 (set-text-properties 0 (length string) nil string)) | |
| 3794 string) | |
| 3795 | |
| 3796 (defun reftex-split (regexp string) | |
| 3797 ;; Split like perl | |
| 3798 (let ((start 0) list) | |
| 3799 (while (string-match regexp string start) | |
| 3800 (setq list (cons (substring string start (match-beginning 0)) list)) | |
| 3801 (setq start (match-end 0))) | |
| 3802 (setq list (nreverse (cons (substring string start) list))))) | |
| 3803 | |
| 3804 (defun reftex-allow-for-ctrl-m (string) | |
| 3805 ;; convert STRING into a regexp, allowing ^M for \n | |
| 3806 (let ((start -2)) | |
| 3807 (setq string (regexp-quote string)) | |
| 3808 (while (setq start (string-match "[\n\r]" string (+ 3 start))) | |
| 3809 (setq string (replace-match "[\n\r]" nil t string))) | |
| 3810 string)) | |
| 3811 | |
| 3812 (defun reftex-delete-list (elt-list list) | |
| 3813 ;; like delete, but with a list of things to delete | |
| 3814 ;; (original code from Rory Molinari) | |
| 3815 (while elt-list | |
| 3816 (setq list (delete (car elt-list) list) | |
| 3817 elt-list (cdr elt-list))) | |
| 3818 list) | |
| 3819 | |
| 3820 (defun reftex-get-buffer-visiting (file) | |
| 3821 ;; return a buffer visiting FILE | |
| 3822 (cond | |
| 3823 ((fboundp 'find-buffer-visiting) ; Emacs | |
| 3824 (find-buffer-visiting file)) | |
| 3825 ((boundp 'find-file-compare-truenames) ; XEmacs | |
| 3826 (let ((find-file-compare-truenames t)) | |
| 3827 (get-file-buffer file))) | |
| 3828 (t (error "Please report this problem to dominik@strw.leidenuniv.nl")))) | |
| 3829 | |
| 3830 (defun reftex-get-file-buffer-force (file &optional mark-to-kill) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
3831 ;; Return a buffer visiting file. Make one, if necessary. |
| 18050 | 3832 ;; If neither such a buffer no the file exist, return nil. |
| 3833 ;; If MARK-TO-KILL in non-nil, put any new buffers into the kill list." | |
| 3834 | |
| 3835 (let ((buf (reftex-get-buffer-visiting file))) | |
| 3836 (cond | |
| 3837 (buf buf) | |
| 3838 ((file-exists-p file) | |
| 3839 (setq buf (find-file-noselect file)) | |
| 3840 (if mark-to-kill | |
| 3841 (add-to-list 'reftex-buffers-to-kill buf)) | |
| 3842 buf) | |
| 3843 (t nil)))) | |
| 3844 | |
| 3845 (defun reftex-splice-symbols-into-list (list alist) | |
| 3846 ;; Splice the association in ALIST of any symbols in LIST into the list. | |
| 3847 ;; Return new list. | |
| 3848 (let (rtn tmp) | |
| 3849 (while list | |
| 3850 (while (and (not (null (car list))) | |
| 3851 (symbolp (car list))) | |
| 3852 (setq tmp (car list)) | |
| 3853 (cond | |
| 3854 ((assoc tmp alist) | |
| 3855 (setq list (append (cdr (cdr (assoc tmp alist))) (cdr list)))) | |
| 3856 (t | |
| 3857 (error "Cannot treat symbol %s in reftex-label-alist" | |
| 3858 (symbol-name tmp))))) | |
| 3859 (setq rtn (cons (car list) rtn) | |
| 3860 list (cdr list))) | |
| 3861 (nreverse rtn))) | |
| 3862 | |
| 3863 (defun reftex-uniquify (alist &optional keep-list) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
3864 ;; Return a list of all elements in ALIST, but each car only once. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
3865 ;; Elements of KEEP-LIST are not removed even if duplicate. |
| 18050 | 3866 (let (new elm) |
| 3867 (while alist | |
| 3868 (setq elm (car alist) | |
| 3869 alist (cdr alist)) | |
| 3870 (if (or (member (car elm) keep-list) | |
| 3871 (not (assoc (car elm) new))) | |
| 3872 (setq new (cons elm new)))) | |
| 3873 (setq new (nreverse new)) | |
| 3874 new)) | |
| 3875 | |
| 3876 (defun reftex-use-fonts () | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
3877 ;; Return t if we can and want to use fonts. |
| 18050 | 3878 (and window-system |
| 3879 reftex-use-fonts | |
| 3880 (boundp 'font-lock-keyword-face))) | |
| 3881 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
3882 ;; Highlighting uses overlays. If this is for XEmacs, we need to load |
| 18050 | 3883 ;; the overlay library, available in version 19.15 |
| 3884 (and (not (fboundp 'make-overlay)) | |
| 3885 (condition-case nil | |
| 3886 (require 'overlay) | |
| 3887 ('error | |
| 3888 (error "RefTeX needs overlay emulation (available in XEmacs 19.15)")))) | |
| 3889 | |
| 3890 ;; We keep a vector with several different overlays to do our highlighting. | |
| 3891 (defvar reftex-highlight-overlays [nil nil]) | |
| 3892 | |
| 3893 ;; Initialize the overlays | |
| 3894 (aset reftex-highlight-overlays 0 (make-overlay 1 1)) | |
| 3895 (overlay-put (aref reftex-highlight-overlays 0) 'face 'highlight) | |
| 3896 (aset reftex-highlight-overlays 1 (make-overlay 1 1)) | |
| 3897 (overlay-put (aref reftex-highlight-overlays 1) 'face 'highlight) | |
| 3898 | |
| 3899 ;; Two functions for activating and deactivation highlight overlays | |
| 3900 (defun reftex-highlight (index begin end &optional buffer) | |
| 3901 "Highlight a region with overlay INDEX." | |
| 3902 (move-overlay (aref reftex-highlight-overlays index) | |
| 3903 begin end (or buffer (current-buffer)))) | |
| 3904 (defun reftex-unhighlight (index) | |
| 3905 "Detatch overlay INDEX." | |
| 3906 (delete-overlay (aref reftex-highlight-overlays index))) | |
| 3907 | |
| 3908 (defun reftex-highlight-shall-die () | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
3909 ;; Function used in pre-command-hook to remove highlights. |
| 18050 | 3910 (remove-hook 'pre-command-hook 'reftex-highlight-shall-die) |
| 3911 (reftex-unhighlight 0)) | |
| 3912 | |
| 3913 ;;; --------------------------------------------------------------------------- | |
| 3914 ;;; | |
| 3915 ;;; Cursor position after insertion of forms | |
| 3916 | |
| 3917 (defun reftex-position-cursor () | |
| 3918 ;; Search back to question mark, delete it, leave point there | |
| 3919 (if (search-backward "\?" (- (point) 100) t) | |
| 3920 (delete-char 1))) | |
| 3921 | |
| 3922 (defun reftex-item () | |
| 3923 "Insert an \\item and provide a label if the environments supports that." | |
| 3924 (interactive) | |
| 3925 (let ((env (car | |
| 3926 (reftex-what-environment '("itemize" "enumerate" "eqnarray"))))) | |
| 3927 | |
| 3928 (if (and env (not (bolp))) (newline)) | |
| 3929 | |
| 3930 (cond | |
| 3931 | |
| 3932 ((string= env "eqnarray") | |
| 3933 (if (not (bolp)) | |
| 3934 (newline)) | |
| 3935 (reftex-label env) | |
| 3936 (insert "\n & & ") | |
| 3937 (beginning-of-line 1)) | |
| 3938 | |
| 3939 ((string= env "itemize") | |
| 3940 (newline) | |
| 3941 (insert "\\item ")) | |
| 3942 | |
| 3943 ((string= env "enumerate") | |
| 3944 (newline) | |
| 3945 (insert "\\item") | |
| 3946 (reftex-label env) | |
| 3947 (insert " ")) | |
| 3948 (t | |
| 3949 (error "\\item command does not make sense here..."))))) | |
| 3950 | |
| 3951 ;;; --------------------------------------------------------------------------- | |
| 3952 ;;; --------------------------------------------------------------------------- | |
| 3953 ;;; --------------------------------------------------------------------------- | |
| 3954 ;;; | |
| 3955 ;;; Data Section: Definition of large constants | |
| 3956 | |
| 3957 | |
| 3958 (defconst reftex-label-alist-builtin | |
| 3959 '( | |
| 3960 (LaTeX | |
| 3961 "LaTeX default environments" | |
| 3962 ("section" ?s "sec:" "~\\ref{%s}" t | |
| 3963 ("Part" "Chapter" "Chap." "Section" "Sec." "Sect." "Paragraph" "Par." | |
| 3964 "\\S" "Teil" "Kapitel" "Kap." "Abschnitt" )) | |
| 3965 | |
| 3966 ("enumerate" ?n "item:" "~\\ref{%s}" "\\\\item\\(\\[[^]]*\\]\\)?" | |
| 3967 ("Item" "Punkt")) | |
| 3968 | |
| 3969 ("equation" ?e "eq:" "~(\\ref{%s})" t | |
| 3970 ("Equation" "Eq." "Eqn." "Gleichung" "Gl.")) | |
| 3971 ("eqnarray" ?e "eq:" nil "\\\\begin{eqnarray}\\|\\\\\\\\") | |
| 3972 | |
| 3973 ("figure" ?f "fig:" "~\\ref{%s}" "\\\\caption\\(\\[[^]]*\\]\\)?{" | |
| 3974 ("Figure" "Fig." "Abbildung" "Abb.")) | |
| 3975 ("figure*" ?f nil nil "\\\\caption\\(\\[[^]]*\\]\\)?{") | |
| 3976 | |
| 3977 ("table" ?t "tab:" "~\\ref{%s}" "\\\\caption\\(\\[[^]]*\\]\\)?{" | |
| 3978 ("Table" "Tab." "Tabelle")) | |
| 3979 ("table*" ?t nil nil "\\\\caption\\(\\[[^]]*\\]\\)?{") | |
| 3980 | |
| 3981 ("any" ?\ " " "\\ref{%s}" nil)) | |
| 3982 | |
| 3983 (Sideways | |
| 3984 "Sidewaysfigure and sidewaystable" | |
| 3985 ("sidewaysfigure" ?f nil nil "\\\\caption\\(\\[[^]]*\\]\\)?{") | |
| 3986 ("sidewaystable" ?t nil nil "\\\\caption\\(\\[[^]]*\\]\\)?{")) | |
| 3987 | |
|
18219
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
3988 (Subfigure |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
3989 "Subfigure environments and macro" |
|
18219
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
3990 ("subfigure" ?f nil nil "\\\\caption\\(\\[[^]]*\\]\\)?{") |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
3991 ("subfigure*" ?f nil nil "\\\\caption\\(\\[[^]]*\\]\\)?{") |
|
18219
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
3992 ("\\subfigure" ?f nil nil "\\\\subfigure[[{]")) |
|
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
3993 |
| 18050 | 3994 (AMSTeX |
| 3995 "AMS-LaTeX: amsmath package environents" | |
| 3996 ("align" ?e "eq:" "~\\eqref{%s}" "\\\\begin{align}\\|\\\\\\\\") | |
| 3997 ("gather" ?e "eq:" nil "\\\\begin{gather}\\|\\\\\\\\") | |
| 3998 ("multline" ?e "eq:" nil t) | |
| 3999 ("flalign" ?e "eq:" nil "\\\\begin{flalign}\\|\\\\\\\\") | |
| 4000 ("alignat" ?e "eq:" nil "\\\\begin{alignat}{[0-9]*}\\|\\\\\\\\")) | |
| 4001 | |
| 4002 (AASTeX | |
| 4003 "AAS deluxetable environment" | |
| 4004 ("deluxetable" ?t "tab:" nil "\\\\caption{"))) | |
| 4005 "The default label environment descriptions.") | |
| 4006 | |
| 4007 ;;; --------------------------------------------------------------------------- | |
| 4008 ;;; | |
| 4009 ;;; Functions to compile the tables, reset the mode etc. | |
| 4010 | |
| 4011 (defun reftex-reset-mode () | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
4012 "Reset RefTeX Mode. Required to implement changes to some list variables. |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
4013 This function will compile the information in `reftex-label-alist' and similar |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
4014 variables. It is called when RefTeX is first used, and after changes to |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
4015 these variables via `reftex-add-to-label-alist'." |
| 18050 | 4016 (interactive) |
| 4017 | |
|
18219
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
4018 ;; Record that we have done this |
| 18050 | 4019 (setq reftex-tables-dirty nil) |
| 4020 | |
|
18219
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
4021 ;; Kill temporary buffers associated with RefTeX - just in case they |
|
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
4022 ;; were not cleaned up properly |
|
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
4023 (let ((buffer-list '("*reftex-master.tex*" "*RefTeX Help*" "*RefTeX Select*" |
|
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
4024 "*Duplicate Labels*" "*toc*" "*RefTeX-scratch*"))) |
|
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
4025 (while buffer-list |
|
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
4026 (if (get-buffer (car buffer-list)) |
|
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
4027 (kill-buffer (car buffer-list))) |
|
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
4028 (setq buffer-list (cdr buffer-list)))) |
|
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
4029 |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
4030 ;; Plug functions into AUCTeX if the user option says so |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
4031 (reftex-plug-into-AUCTeX) |
|
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
4032 |
| 18050 | 4033 ;; To update buffer-local variables |
| 4034 (hack-local-variables) | |
| 4035 (message "updating internal tables...") | |
| 4036 (reftex-compute-ref-cite-tables) | |
| 4037 (message "updating internal tables... done") | |
| 4038 (reftex-reset-scanning-information)) | |
| 4039 | |
| 4040 (defun reftex-reset-scanning-information () | |
| 4041 "Reset the symbols containing information from buffer scanning. | |
| 4042 This enforces rescanning the buffer on next use." | |
| 4043 (if (and (string= reftex-last-toc-master (reftex-TeX-master-file)) | |
| 4044 (get-buffer "*toc*")) | |
| 4045 (kill-buffer "*toc*")) | |
| 4046 (let ((symlist reftex-multifile-symbols) | |
| 4047 symbol) | |
| 4048 (while symlist | |
| 4049 (setq symbol (car symlist) | |
| 4050 symlist (cdr symlist)) | |
| 4051 (if (and (symbolp (symbol-value symbol)) | |
| 4052 (not (null (symbol-value symbol)))) | |
| 4053 (set (symbol-value symbol) nil))))) | |
| 4054 | |
| 4055 (defun reftex-compute-ref-cite-tables () | |
| 4056 ;; Update ref and cite tables | |
| 4057 | |
| 4058 (interactive) | |
| 4059 | |
| 4060 ;; Compile information in reftex-label-alist | |
| 4061 (let ((tmp (reftex-uniquify (reftex-splice-symbols-into-list | |
| 4062 (append | |
| 4063 reftex-label-alist | |
| 4064 reftex-label-alist-external-add-ons | |
| 4065 reftex-default-label-alist-entries) | |
| 4066 reftex-label-alist-builtin) | |
| 4067 '(nil))) | |
| 4068 entry env-or-mac typekeychar typekey prefix regexp | |
| 4069 fmt wordlist cmd qh-list) | |
| 4070 | |
| 4071 (setq reftex-words-to-typekey-alist nil | |
| 4072 reftex-typekey-list nil | |
| 4073 reftex-typekey-to-format-alist nil | |
| 4074 reftex-typekey-to-prefix-alist nil | |
| 4075 reftex-env-or-mac-alist nil | |
| 4076 reftex-label-env-list nil | |
| 4077 reftex-label-mac-list nil) | |
| 4078 (while tmp | |
| 4079 (catch 'next-entry | |
| 4080 (setq entry (car tmp) | |
| 4081 env-or-mac (car entry) | |
| 4082 entry (cdr entry) | |
| 4083 tmp (cdr tmp)) | |
| 4084 (if (null env-or-mac) | |
| 4085 (setq env-or-mac "")) | |
| 4086 (if (stringp (car entry)) | |
| 4087 ;; This is before version 2.00 - convert entry to new format | |
| 4088 ;; This is just to keep old users happy | |
| 4089 (setq entry (cons (string-to-char (car entry)) | |
| 4090 (cons (concat (car entry) ":") | |
| 4091 (cdr entry))))) | |
| 4092 (setq typekeychar (nth 0 entry) | |
| 4093 typekey (char-to-string typekeychar) | |
| 4094 prefix (nth 1 entry) | |
| 4095 fmt (nth 2 entry) | |
| 4096 regexp (nth 3 entry) | |
| 4097 wordlist (nth 4 entry)) | |
| 4098 (if (stringp wordlist) | |
| 4099 ;; This is before version 2.04 - convert to new format | |
| 4100 (setq wordlist (nthcdr 4 entry))) | |
| 4101 (if typekey | |
| 4102 (add-to-list 'reftex-typekey-list typekey)) | |
| 4103 (if (and typekey prefix) | |
| 4104 (add-to-list 'reftex-typekey-to-prefix-alist (cons typekey prefix))) | |
| 4105 (cond | |
| 4106 ((string-match "\\`\\\\" env-or-mac) | |
| 4107 ;; It's a macro | |
| 4108 (add-to-list 'reftex-label-mac-list env-or-mac)) | |
| 4109 (t | |
| 4110 (or (string= env-or-mac "any") | |
| 4111 (string= env-or-mac "") | |
| 4112 (add-to-list 'reftex-label-env-list env-or-mac)))) | |
| 4113 (and fmt | |
| 4114 (not (assoc typekey reftex-typekey-to-format-alist)) | |
| 4115 (setq reftex-typekey-to-format-alist | |
| 4116 (cons (cons typekey fmt) | |
| 4117 reftex-typekey-to-format-alist))) | |
| 4118 (and (not (string= env-or-mac "any")) | |
| 4119 (not (string= env-or-mac "")) | |
| 4120 (not (assoc env-or-mac reftex-env-or-mac-alist)) | |
| 4121 (setq reftex-env-or-mac-alist | |
| 4122 (cons (list env-or-mac typekey regexp) | |
| 4123 reftex-env-or-mac-alist))) | |
| 4124 (while (and wordlist (stringp (car wordlist))) | |
| 4125 (or (assoc (car wordlist) reftex-words-to-typekey-alist) | |
| 4126 (setq reftex-words-to-typekey-alist | |
| 4127 (cons (cons (downcase (car wordlist)) typekey) | |
| 4128 reftex-words-to-typekey-alist))) | |
| 4129 (setq wordlist (cdr wordlist))) | |
| 4130 (cond | |
| 4131 ((string= "" env-or-mac) nil) | |
| 4132 ((assoc typekey qh-list) | |
| 4133 (setcdr (assoc typekey qh-list) | |
| 4134 (concat (cdr (assoc typekey qh-list)) " " env-or-mac))) | |
| 4135 (t | |
| 4136 (setq qh-list (cons (cons typekey env-or-mac) qh-list)))))) | |
| 4137 | |
| 4138 (setq qh-list (nreverse qh-list)) | |
| 4139 (setq reftex-typekey-to-prefix-alist | |
| 4140 (nreverse reftex-typekey-to-prefix-alist)) | |
| 4141 (setq reftex-type-query-prompt | |
| 4142 (concat "Label type: " | |
| 4143 (mapconcat '(lambda(x) | |
| 4144 (format "[%s]" (car x))) | |
| 4145 qh-list " ") | |
| 4146 " (?=Help)")) | |
| 4147 (setq reftex-type-query-help | |
| 4148 (concat "SELECT A LABEL TYPE:\n--------------------\n" | |
| 4149 (mapconcat '(lambda(x) | |
| 4150 (format " [%s] %s" | |
| 4151 (car x) (cdr x))) | |
| 4152 qh-list "\n"))))) | |
| 4153 | |
| 4154 ;;; Keybindings -------------------------------------------------------------- | |
| 4155 | |
| 4156 (define-key reftex-mode-map "\C-c-" 'reftex-item) | |
| 4157 (define-key reftex-mode-map "\C-c=" 'reftex-toc) | |
| 4158 (define-key reftex-mode-map "\C-c(" 'reftex-label) | |
| 4159 (define-key reftex-mode-map "\C-c)" 'reftex-reference) | |
| 4160 (define-key reftex-mode-map "\C-c[" 'reftex-citation) | |
| 4161 (define-key reftex-mode-map "\C-c&" 'reftex-view-crossref) | |
| 4162 | |
| 4163 ;; If the user requests so, she can have a few more bindings: | |
| 4164 (cond | |
| 4165 (reftex-extra-bindings | |
| 4166 (define-key reftex-mode-map "\C-ct" 'reftex-toc) | |
| 4167 (define-key reftex-mode-map "\C-cl" 'reftex-label) | |
| 4168 (define-key reftex-mode-map "\C-cr" 'reftex-reference) | |
| 4169 (define-key reftex-mode-map "\C-cc" 'reftex-citation) | |
| 4170 (define-key reftex-mode-map "\C-cv" 'reftex-view-crossref) | |
| 4171 (define-key reftex-mode-map "\C-cg" 'reftex-grep-document) | |
| 4172 (define-key reftex-mode-map "\C-cs" 'reftex-search-document))) | |
| 4173 | |
| 4174 ;;; Menus -------------------------------------------------------------------- | |
| 4175 | |
| 4176 ;; Define a menu for the menu bar if Emacs is running under X | |
| 4177 | |
| 4178 (require 'easymenu) | |
| 4179 | |
| 4180 (easy-menu-define | |
| 4181 reftex-mode-menu reftex-mode-map | |
| 4182 "Menu used in RefTeX mode" | |
| 4183 '("Ref" | |
| 4184 ["Table of Contents" reftex-toc t] | |
| 4185 "----" | |
|
18219
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
4186 ["\\label" reftex-label t] |
|
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
4187 ["\\ref" reftex-reference t] |
|
aaeaae005e98
Updated documentation at several points in the file.
Richard M. Stallman <rms@gnu.org>
parents:
18123
diff
changeset
|
4188 ["\\cite" reftex-citation t] |
| 18050 | 4189 ["View crossref" reftex-view-crossref t] |
| 4190 "----" | |
| 4191 ("Search and Replace" | |
| 4192 ["Search whole document" reftex-search-document t] | |
| 4193 ["Replace in document" reftex-query-replace-document t] | |
| 4194 ["Grep on document" reftex-grep-document t] | |
| 4195 "----" | |
| 4196 ["Find duplicate labels" reftex-find-duplicate-labels t] | |
| 4197 ["Change label and refs" reftex-change-label t] | |
| 4198 "----" | |
| 4199 ["Create TAGS file" reftex-create-tags-file t]) | |
| 4200 "----" | |
| 4201 ["Parse document" reftex-parse-document t] | |
| 4202 ["Reset RefTeX Mode" reftex-reset-mode t] | |
| 4203 ["Customize RefTeX" reftex-customize t])) | |
| 4204 | |
| 4205 ;;; Run Hook ------------------------------------------------------------------ | |
| 4206 | |
| 4207 (run-hooks 'reftex-load-hook) | |
| 4208 | |
| 4209 ;;; That's it! ---------------------------------------------------------------- | |
| 4210 | |
| 4211 ; Make sure tabels are compiled | |
| 4212 (message "updating internal tables...") | |
| 4213 (reftex-compute-ref-cite-tables) | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
4214 (message "updating internal tables...done") |
| 18050 | 4215 (setq reftex-tables-dirty nil) |
| 4216 | |
| 4217 (provide 'reftex) | |
| 4218 | |
| 4219 ;;;============================================================================ | |
| 4220 | |
|
18321
0ed97be54a28
Changed all doc strings to comply with conventions.
Richard M. Stallman <rms@gnu.org>
parents:
18220
diff
changeset
|
4221 ;;; reftex.el ends here |
