annotate lisp/modes/reftex.el @ 155:43dd3413c7c7 r20-3b4

Import from CVS: tag r20-3b4
author cvs
date Mon, 13 Aug 2007 09:39:39 +0200
parents
children 5a88923fcbfe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1 ;; reftex.el --- Minor mode for doing \label, \ref and \cite in LaTeX
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2 ;; Copyright (c) 1997 Free Software Foundation, Inc.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4 ;; Author: Carsten Dominik <dominik@strw.LeidenUniv.nl>
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
5 ;; Version: 2.13
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
6 ;; Keywords: tex
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
7
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
8 ;; Derived from: $Id: reftex.el,v 1.1 1997/06/04 08:26:19 steve Exp $
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
9
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
11
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
14 ;; the Free Software Foundation; either version 2, or (at your option)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
15 ;; any later version.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
16
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
20 ;; GNU General Public License for more details.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
21
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
25 ;; Boston, MA 02111-1307, USA.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
26
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
27 ;;---------------------------------------------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
28 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
29 ;;; Commentary:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
30 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
31 ;; RefTeX is a minor mode with distinct support for \ref, \label and
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
32 ;; \cite commands in (multi-file) LaTeX documents.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
33 ;; Labels are created semi-automatically. Definition context of labels is
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
34 ;; provided when creating a reference. Citations are simplified with
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
35 ;; efficient database lookup.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
36 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
37 ;; To turn RefTeX Minor Mode on and off in a particular buffer, use
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
38 ;; `M-x reftex-mode'.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
39 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
40 ;; To turn on RefTeX Minor Mode for all LaTeX files, add one of the
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
41 ;; following lines to your .emacs file:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
42 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
43 ;; (add-hook 'LaTeX-mode-hook 'turn-on-reftex) ; with AUCTeX LaTeX mode
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
44 ;; (add-hook 'latex-mode-hook 'turn-on-reftex) ; with Emacs latex mode
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
45 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
46 ;; For key bindings, see further down in this documentation.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
47 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
48 ;;---------------------------------------------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
49 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
50 ;; OVERVIEW
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
51 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
52 ;; 1. USING \label AND \ref. Labels and references are one of the
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
53 ;; strong points of LaTeX. But, in documents with hundreds of
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
54 ;; equations, figures, tables etc. it becomes quickly impossible to
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
55 ;; find good label names and to actually remember them. Then, also
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
56 ;; completion of labels in not enough. One actually needs to see the
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
57 ;; context of the label definition to find the right one.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
58 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
59 ;; - RefTeX distinguishes labels for different environments. It
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
60 ;; always knows if a certain label references a figure, table
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
61 ;; etc. You can configure RefTeX to recognize any additional
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
62 ;; labeled environments you might have defined yourself.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
63 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
64 ;; - RefTeX defines automatically unique labels. Type `C-c ('
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
65 ;; (reftex-label) to insert a label at point. RefTeX will either
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
66 ;; - derive a label from context (default for section labels)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
67 ;; - insert a simple label consisting of a prefix and a number
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
68 ;; (default for equations and enumerate items) or
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
69 ;; - prompt for a label string (figures and tables)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
70 ;; Which labels are created how can be controlled with the variable
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
71 ;; reftex-insert-label-flags.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
72 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
73 ;; - Referencing labels is a snap and I promise you'll love it.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
74 ;; In order to make a reference, type `C-c )' (reftex-reference).
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
75 ;; This shows an outline of the documents with all labels of a
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
76 ;; certain type (figure, equation,...) and context of the label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
77 ;; definition. Selecting one of the labels inserts a \ref macro
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
78 ;; into the original buffer. Online help during the selection is
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
79 ;; available with `?'.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
80 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
81 ;; 2. CITATIONS. After typing `C-c [' (reftex-citation), RefTeX will
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
82 ;; let you specify a regexp to search in current BibTeX database files
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
83 ;; (as specified in the \bibliography command) and pull out a formatted
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
84 ;; list of matches for you to choose from. The list is *formatted* and
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
85 ;; thus much easier to read than the raw database entries. It can also
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
86 ;; be sorted. The text inserted into the buffer is by default just
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
87 ;; `\cite{KEY}', but can also contain author names and the year in a
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
88 ;; configurable way. See documentation of the variable
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
89 ;; reftex-cite-format.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
90 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
91 ;; 3. TABLE OF CONTENTS. Typing `C-c =' (reftex-toc) will show
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
92 ;; a table of contents of the document. From that buffer, you can
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
93 ;; jump quickly to every part of your document. This is similar to
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
94 ;; imenu, only it works for entire multifile documents and uses the
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
95 ;; keyboard rather than the mouse. The initial version of this
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
96 ;; function was contributed by Stephen Eglen.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
97 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
98 ;; 4. MULTIFILE DOCUMENTS are supported in the same way as by AUCTeX.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
99 ;; I.e. if a source file is not a full LaTeX document by itself,
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
100 ;; but included by another file, you may specify the name of
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
101 ;; the (top level) master file in a local variable section at the
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
102 ;; end of the source file, like so:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
103 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
104 ;; %%% Local Variables:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
105 ;; %%% TeX-master: my_master.tex
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
106 ;; %%% End:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
107 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
108 ;; This will only take effect when you load the file next time or when
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
109 ;; you reset RefTeX with M-x reftex-reset-mode.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
110 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
111 ;; RefTeX will also recognize the file variable tex-main-file. This
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
112 ;; variable is used by the Emacs TeX modes and works just like AUCTeX's
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
113 ;; TeX-master variable. See the documentation of your TeX/LaTeX modes.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
114 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
115 ;; RefTeX knows about all files related to a document via input and
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
116 ;; include. It provides functions to run regular expression searches and
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
117 ;; replaces over the entire document and to create a TAGS file.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
118 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
119 ;; 5. DOCUMENT PARSING. RefTeX needs to parse the document in order to find
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
120 ;; labels and other information. It will do it automatically once, when
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
121 ;; you start working with a document. If you need to enforce reparsing
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
122 ;; later, call any of the functions reftex-citation, reftex-label,
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
123 ;; reftex-reference, reftex-toc with a raw C-u prefix.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
124 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
125 ;;-------------------------------------------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
126 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
127 ;; CONFIGURATION
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
128 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
129 ;; RefTeX contains many configurable options which change the way it works.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
130 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
131 ;; Most importantly, RefTeX needs to be configured if you use labels to
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
132 ;; mark non-standard environments. RefTeX always understands LaTeX section
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
133 ;; commands and the following environments: figure, figure*,
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
134 ;; sidewaysfigure, table, table*, sidewaystable, equation, eqnarray,
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
135 ;; enumerate. For everythings else, it needs to be configured.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
136 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
137 ;; A good way to configure RefTeX is with the custom.el package by Per
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
138 ;; Abrahamsen, shipped with Emacs 20 and XEmacs 19.15. To do this, just
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
139 ;; say `M-x reftex-customize'. This will not work with older versions
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
140 ;; of custom.el.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
141 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
142 ;; Here is a complete list of the RefTeX configuration variables with
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
143 ;; their default settings. You could copy this list to your .emacs file
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
144 ;; and change whatever is necessary. Each variable has an extensive
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
145 ;; documentation string. Look it up for more information!
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
146 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
147 ;; ;; Configuration Variables and User Options for RefTeX ------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
148 ;; ;; Support for \label and \ref --------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
149 ;; (setq reftex-label-alist nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
150 ;; (setq reftex-default-label-alist-entries '(Sideways LaTeX))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
151 ;; (setq reftex-use-text-after-label-as-context nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
152 ;; ;; Label insertion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
153 ;; (setq reftex-insert-label-flags '("s" "sft"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
154 ;; (setq reftex-derive-label-parameters '(3 20 t 1 "-"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
155 ;; ("the" "on" "in" "off" "a" "for" "by" "of" "and" "is")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
156 ;; (setq reftex-label-illegal-re "[\000-\040\177-\377\\\\#$%&~^_{}]")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
157 ;; (setq reftex-abbrev-parameters '(4 2 "^saeiou" "aeiou"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
158 ;; ;; Label referencing
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
159 ;; (setq reftex-label-menu-flags '(t t nil nil nil nil))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
160 ;; (setq reftex-guess-label-type t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
161 ;; ;; BibteX citation configuration ----------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
162 ;; (setq reftex-bibpath-environment-variables '("BIBINPUTS" "TEXBIB"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
163 ;; (setq reftex-bibfile-ignore-list nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
164 ;; (setq reftex-sort-bibtex-matches 'reverse-year)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
165 ;; (setq reftex-cite-format 'reftex-cite-format-default)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
166 ;; ;; Table of contents configuration --------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
167 ;; (setq reftex-toc-follow-mode nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
168 ;; ;; Miscellaneous configurations -----------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
169 ;; (setq reftex-extra-bindings nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
170 ;; (setq reftex-use-fonts t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
171 ;; (setq reftex-keep-temporary-buffers t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
172 ;; (setq reftex-auto-show-entry t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
173 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
174 ;; CONFIGURATION EXAMPLES:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
175 ;; =======================
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
176 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
177 ;; Suppose you are working with AMS-LaTeX amsmath package (with its math
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
178 ;; environments like `align', `multiline' etc.). Here is how you would
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
179 ;; configure RefTeX to recognize these environments:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
180 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
181 ;; (setq reftex-label-alist '(AMSTeX))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
182 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
183 ;; This is very easy since RefTeX has builtin support for AMS-LaTeX.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
184 ;; Suppose, however, you are also
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
185 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
186 ;; - using "\newtheorem" in LaTeX in order to define two new environments
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
187 ;; "Theorem" and "Axiom" like this:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
188 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
189 ;; \newtheorem{axiom}{Axiom}
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
190 ;; \newtheorem{theorem}{Theorem}
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
191 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
192 ;; - making your figures not directly with the figure environment, but with
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
193 ;; a macro like
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
194 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
195 ;; \newcommand{\myfig}[4][tbp]{
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
196 ;; \begin{figure}[#1]
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
197 ;; \epsimp[#4]{#2}
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
198 ;; \caption{#3}
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
199 ;; \end{figure}}
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
200 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
201 ;; which would be called like
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
202 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
203 ;; \myfig{filename}{\label{fig:13} caption text}{1}
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
204 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
205 ;; Here is how to tell RefTeX to also recognize Theorem and Axiom as
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
206 ;; labeled environments, and that any labels defined inside the \myfig
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
207 ;; macro are figure labels:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
208 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
209 ;; (setq reftex-label-alist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
210 ;; '(AMSTeX
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
211 ;; ("axiom" ?a "ax:" "~\\ref{%s}" nil ("Axiom" "Ax."))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
212 ;; ("theorem" ?h "thr:" "~\\ref{%s}" t ("Theorem" "Theor." "Th."))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
213 ;; ("\\myfig" ?f "fig:" nil t)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
214 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
215 ;; The type indicator characters ?a and ?h are used for prompts when
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
216 ;; RefTeX queries for a label type. Note that "h" was chosen for "theorem"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
217 ;; since "t" is already taken by "table". Note that also "s", "f", "e", "n"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
218 ;; are taken by the standard environments.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
219 ;; The automatic labels for Axioms and Theorems will look like "ax:23" or
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
220 ;; "thr:24".
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
221 ;; The "\ref{%s}" is a format string indicating how to insert references to
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
222 ;; these labels. The nil format in the \myfig entry means to use the same
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
223 ;; format as other figure labels.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
224 ;; The next item indicates how to grab context of the label definition.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
225 ;; - t means to get it from a default location (from the beginning of a \macro
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
226 ;; or after the \begin statement). t is *not* a good choice for eqnarray
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
227 ;; and similar environments.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
228 ;; - nil means to use the text right after the label definition.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
229 ;; - For more complex ways of getting context, see the docstring of
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
230 ;; reftex-label-alist.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
231 ;; The strings at the end of each entry are used to guess the correct label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
232 ;; type from the word before point when creating a reference. E.g. if you
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
233 ;; write: "as we have shown in Theorem" and then press `C-)', RefTeX will
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
234 ;; know that you are looking for a Theorem label and restrict the labels in
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
235 ;; the menu to only these labels without even asking.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
236 ;; See also the documentation string of the variable reftex-label-alist.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
237 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
238 ;; Depending on how you would like the label insertion and selection for the
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
239 ;; new environments to work, you might want to add the letters "a" and "h"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
240 ;; to some of the flags in the following variables:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
241 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
242 ;; reftex-insert-label-flags
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
243 ;; reftex-label-menu-flags
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
244 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
245 ;; The individual flags in these variables can be set to t or nil to enable or
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
246 ;; disable the feature for all label types. They may also contain a string of
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
247 ;; label type letters in order to turn on the feature for those types only.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
248 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
249 ;; -----
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
250 ;; If you are writing in a language different from english you might want to
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
251 ;; add magic words for that language. Here is a German example:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
252 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
253 ;; (setq reftex-label-alist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
254 ;; '((nil ?s nil nil nil ("Kapitel" "Kap." "Abschnitt" "Teil"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
255 ;; (nil ?e nil nil nil ("Gleichung" "Gl."))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
256 ;; (nil ?t nil nil nil ("Tabelle"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
257 ;; (nil ?f nil nil nil ("Figur" "Abbildung" "Abb."))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
258 ;; (nil ?n nil nil nil ("Punkt"))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
259 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
260 ;; Using `nil' as first item in each entry makes sure that this entry does
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
261 ;; not replace the original entry for that label type.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
262 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
263 ;; HOOKS
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
264 ;; -----
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
265 ;; Loading reftex.el runs the hook reftex-load-hook. Turning on reftex-mode
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
266 ;; runs reftex-mode-hook.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
267 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
268 ;;-------------------------------------------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
269 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
270 ;; KEY BINDINGS
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
271 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
272 ;; All important functions of RefTeX can be reached from its menu which
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
273 ;; is installed in the menu bar as "Ref" menu. Only the more frequently used
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
274 ;; functions have key bindings.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
275 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
276 ;; Here is the default set of keybindings from RefTeX.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
277 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
278 ;; C-c = reftex-toc
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
279 ;; C-c ( reftex-label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
280 ;; C-c ) reftex-reference
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
281 ;; C-c [ reftex-citation
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
282 ;; C-c & reftex-view-crossref
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
283 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
284 ;; I've used these bindings in order to avoid interfering with AUCTeX's
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
285 ;; settings. Personally, I also bind some functions in the C-c LETTER
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
286 ;; map for easier access:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
287 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
288 ;; C-c t reftex-toc
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
289 ;; C-c l reftex-label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
290 ;; C-c r reftex-reference
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
291 ;; C-c c reftex-citation
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
292 ;; C-c v reftex-view-crossref
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
293 ;; C-c s reftex-search-document
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
294 ;; C-c g reftex-grep-document
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
295 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
296 ;; If you want to copy those as well, set in your .emacs file:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
297 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
298 ;; (setq reftex-extra-bindings t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
299 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
300 ;; It is possible to bind the function for viewing cross references to a
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
301 ;; mouse event. Something like the following in .emacs will do the trick:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
302 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
303 ;; (add-hook 'reftex-load-hook
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
304 ;; '(lambda ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
305 ;; (define-key reftex-mode-map [(alt mouse-1)]
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
306 ;; 'reftex-mouse-view-crossref)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
307 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
308 ;;-------------------------------------------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
309 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
310 ;; RELATED PACKAGES
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
311 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
312 ;; AUCTeX
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
313 ;; ------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
314 ;; If you are writing any TeX or LaTeX documents with Emacs, you should
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
315 ;; have a look at AUCTeX, the definitive package to work with TeX and LaTeX.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
316 ;; Information on AUCTeX can be found here:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
317 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
318 ;; http://www.sunsite.auc.dk/auctex/
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
319 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
320 ;; AUCTeX version 9.7f and later can be configured to delegate label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
321 ;; insertion to RefTeX. Do do that, say in your .emacs file
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
322 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
323 ;; (setq LaTeX-label-function 'reftex-label)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
324 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
325 ;; RefTeX also provides functions which can replace TeX-arg-label and
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
326 ;; TeX-arg-cite in AUCTeX. These functions are compatible with the originals,
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
327 ;; but use RefTeX internals to create and select labels and citation keys.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
328 ;; There are 3 functions: reftex-arg-label, reftex-arg-ref, reftex-arg-cite.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
329 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
330 ;; AUCTeX can support RefTeX via style files. A style file may contain
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
331 ;; calls to reftex-add-to-label-alist which defines additions to
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
332 ;; reftex-label-alist. The argument taken by this function must have exactly
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
333 ;; the same format as reftex-label-alist. E.g. a good entry in a style file
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
334 ;; for the amsmath package would be
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
335 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
336 ;; (if (featurep 'reftex)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
337 ;; (reftex-add-to-label-alist '(AMSTeX)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
338 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
339 ;; while a package defining a proposition environment with \newtheorem
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
340 ;; might use
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
341 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
342 ;; (if (featurep 'reftex)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
343 ;; (reftex-add-to-label-alist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
344 ;; '(("proposition" ?p "prop:" "~\\ref{%s}" t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
345 ;; ("Proposition" "Prop.")))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
346 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
347 ;; Bib-cite.el
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
348 ;; -----------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
349 ;; Once you have written a document with labels, refs and citations, it can be
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
350 ;; nice to read such a file like a hypertext document. RefTeX has some support
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
351 ;; for that (reftex-view-crossref, reftex-search-document). A more elegant
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
352 ;; interface with mouse support and links into Hyperbole is provided (among
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
353 ;; other things) by Peter S. Galbraith's bib-cite.el. There is some overlap in
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
354 ;; the functionalities of bib-cite and RefTeX. Bib-cite.el comes bundled with
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
355 ;; AUCTeX. You can also get the latest version from
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
356 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
357 ;; ftp://ftp.phys.ocean.dal.ca/users/rhogee/elisp/bib-cite.el
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
358 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
359 ;;-------------------------------------------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
360 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
361 ;; PERFORMANCE ISSUES
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
362 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
363 ;; 1. RefTeX will load other parts of a multifile document as well as BibTeX
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
364 ;; database files for lookup purposes. These buffers are kept, so that
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
365 ;; subsequent lookup in the same files is fast. For large documents and
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
366 ;; large BibTeX databases, this can use up a lot of memory. If you have
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
367 ;; more time than memory, try the following option, which will remove
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
368 ;; buffers created for lookup after use.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
369 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
370 ;; (setq reftex-keep-temporary-buffers nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
371 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
372 ;; 2. Parsing the document for labels and their context can be slow.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
373 ;; Therefore, RefTeX does it just once automatically. Further parsing
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
374 ;; happens only on user request
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
375 ;; - with a raw C-u prefix arg to any of the functions reftex-label,
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
376 ;; reftex-reference, reftex-citation, reftex-toc.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
377 ;; - with the `r' key from the label selection menu or the *toc* buffer.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
378 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
379 ;; *** If you use reftex-label to create labels, the list will be updated
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
380 ;; *** internally, so that no extra parsing is required.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
381 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
382 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
383 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
384 ;; KNOWN BUGS
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
385 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
386 ;; o If you change reftex-label-alist in an editing session, you need to
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
387 ;; reset reftex with `M-x reftex-reset-mode' in order to make these
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
388 ;; changes effective. Changes introduced with the function
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
389 ;; reftex-add-to-label-alist as well as changes applied from the
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
390 ;; customization buffer automatically trigger a reset.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
391 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
392 ;; o At times the short context shown by RefTeX may not be what you want.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
393 ;; In particular, eqnarray environments can be difficult to
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
394 ;; parse. RefTeX's default behavior for eqnarrays is to scan backwards to
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
395 ;; either a double backslash or the beginning of the environment. If this
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
396 ;; gives unsatisfactory results, make it a habit to place the label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
397 ;; *before* each equation
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
398 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
399 ;; \begin{eqnarray}
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
400 ;; \label{eq:1}
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
401 ;; E = \gamma m c^2 \\
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
402 ;; \label{eq:2}
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
403 ;; \gamma = \sqrt{1-v^2/c^2}
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
404 ;; \end{eqnarray}
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
405 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
406 ;; and turn off parsing for context in equation and eqnarray environments
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
407 ;; with
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
408 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
409 ;; (setq reftex-use-text-after-label-as-context "e").
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
410 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
411 ;; o RefTeX keeps only one global copy of the configuration variables.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
412 ;; Also any additions from style files go into a global variable.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
413 ;; Practically, this should not be a problem. Theoretically, it could
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
414 ;; give conflicts if two documents used environments with identical
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
415 ;; names, but different associated label types.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
416 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
417 ;; o Input, include, bibliography and section statements have to be first
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
418 ;; on a line (except for white space) in order to be seen by reftex.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
419 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
420 ;; o When the document is scanned, RefTeX creates a large buffer containing
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
421 ;; the entire document instead of scanning the individual files one by
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
422 ;; one. This is necessary since a file might not contain the context
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
423 ;; needed by RefTeX.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
424 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
425 ;; o If you have two identical section headings in the same file,
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
426 ;; reftex-toc will only let you jump to the first one because it searches
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
427 ;; for the section heading from the beginning of the file. You can work
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
428 ;; around this by changing one of the section titles in a way LaTeX does
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
429 ;; not see, e.g. with extra white space. RefTeX will distinguish
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
430 ;; \section{Introduction} from \section{ Introduction}.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
431 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
432 ;; o RefTeX sees also labels in regions commented out and will refuse to
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
433 ;; make duplicates of such a label. This is considered to be a feature.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
434 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
435 ;; o When RefTeX tries to show a window full of context from inside a
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
436 ;; section hidden with outline-minor-mode, it will unhide that section.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
437 ;; This change will not be reversed automatically.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
438 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
439 ;;---------------------------------------------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
440 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
441 ;; TO DO
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
442 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
443 ;; I think I am pretty much done with this one...
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
444 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
445 ;;---------------------------------------------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
446 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
447 ;; AUTHOR
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
448 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
449 ;; Carsten Dominik <dominik@strw.LeidenUniv.nl>
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
450 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
451 ;; with contributions from Stephen Eglen
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
452 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
453 ;; The newest version of RefTeX can be found at
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
454 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
455 ;; http://www.strw.leidenuniv.nl/~dominik/Tools/
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
456 ;; ftp://strw.leidenuniv.nl/pub/dominik/
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
457 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
458 ;; THANKS TO:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
459 ;; ---------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
460 ;; At least the following people have invested time to test and bug-fix
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
461 ;; reftex.el. Some have send patches for fixes or new features.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
462 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
463 ;; Stephen Eglen <stephene@cogs.susx.ac.uk>
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
464 ;; F.E.Burstall <F.E.Burstall@maths.bath.ac.uk>
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
465 ;; Karl Eichwalder <ke@ke.Central.DE>
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
466 ;; Laurent Mugnier <mugnier@onera.fr>
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
467 ;; Rory Molinari <molinari@yunt.math.lsa.umich.edu>
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
468 ;; Soren Dayton <csdayton@cs.uchicago.edu>
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
469 ;; Daniel Polani <polani@Informatik.Uni-Mainz.DE>
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
470 ;; Allan Strand <astrand@trillium.NMSU.Edu>
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
471 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
472 ;; The view crossref feature was inspired by the similar function in
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
473 ;; Peter S. Galbraith's bib-cite.el.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
474 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
475 ;; Finally thanks to Uwe Bolick <bolick@physik.tu-berlin.de> who first
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
476 ;; got me (some years ago) into supporting LaTeX labels and references
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
477 ;; with an Editor (which was MicroEmacs at the time).
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
478 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
479 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
480 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
481
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
482 ;;; Code:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
483
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
484 ;; Stuff that needs to be there when we use defcustom
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
485 ;; --------------------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
486
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
487 (require 'custom)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
488
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
489 (defvar reftex-tables-dirty t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
490 "Flag showing if tables need to be re-computed.")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
491
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
492 (eval-and-compile
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
493 (defun reftex-set-dirty (symbol value)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
494 (setq reftex-tables-dirty t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
495 (set symbol value)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
496
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
497 ;;; Begin of Configuration Section ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
498
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
499 ;; Configuration Variables and User Options for RefTeX ------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
500
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
501 (defgroup reftex nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
502 "LaTeX label and citation support."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
503 :tag "RefTeX"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
504 :link '(url-link :tag "Home Page" "http://strw.leidenuniv.nl/~dominik/Tools/")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
505 :prefix "reftex-"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
506 :group 'tex)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
507
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
508 (defun reftex-customize ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
509 "Call the customize function with reftex as argument."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
510 (interactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
511 (if (fboundp 'customize-group)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
512 (customize-group 'reftex)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
513 (customize 'reftex)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
514
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
515 ;; Support for \label and \ref --------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
516
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
517 (defgroup reftex-label-support nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
518 "Support for creation, insertion and referencing of labels in LaTeX"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
519 :group 'reftex)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
520
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
521 (defgroup reftex-defining-label-environments nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
522 "Definition of environments and macros to do with label"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
523 :group 'reftex-label-support)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
524
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
525
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
526 (defcustom reftex-label-alist nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
527 "Alist with information on environments for \\label-\\ref use.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
528 See the definition of reftex-label-alist-builtin for examples. This variable
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
529 should define additions and changes to the default. The only things you MUST
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
530 NOT change is that '?s' is the type indicator for section labels and SPACE is
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
531 for the 'any' label type. These are hard-coded at other places in the code.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
532
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
533 Changes to this variable after reftex.el has been loaded become only
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
534 effective when RefTeX is reset with \\[reftex-reset-mode].
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
535
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
536 Each list entry is a list describing an environment or macro carrying a
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
537 label. The elements of each list entry are:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
538
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
539 0. Name of the environment (like \"table\") or macro (like \"\\\\myfig\").
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
540 Special names: `section' for section labels, `any' to define a group
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
541 which contains all labels.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
542 This may also be nil if this entry is only meant to change some settings
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
543 associated with the type indicator character (see below).
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
544
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
545 1. Type indicator character, like ?t.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
546 The type indicator is a single character used in prompts for
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
547 label types. It must be a printable character. The same character
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
548 may occur several times in this list, to cover cases in which different
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
549 environments carry the same label type (like equation and eqnarray).
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
550
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
551 2. Label prefix string, like \"tab:\".
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
552 The prefix is a short string used as the start of a label. It may be the
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
553 empty string.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
554
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
555 3. Format string for reference insert in buffer. Each %s will be replaced by
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
556 the label (yes, several %s can be in there, so that you can set this to:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
557 \"\\ref{%s} on page~\\pageref{%s}\").
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
558 When the format starts with ~, whitespace before point will be removed so
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
559 that the reference cannot be separated from the word before it.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
560
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
561 4. Indication on how to find the short context.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
562 - If `nil', use the text following the \\label{...} macro.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
563 - If `t', use
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
564 - text following the \\begin{...} statement of environments
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
565 (not a good choice in in eqnarray or enumerate environments!)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
566 - the section heading for section labels.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
567 - the begin of the macro for macros.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
568 - If a string, use as regexp to search *backward* from the label. Context
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
569 is then the text following the end of the match. E.g. putting this to
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
570 \"\\\\\\\\caption{\" will use the beginning of the caption in a figure
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
571 or table environment. \"\\\\\\\\begin{eqnarray}\\\\|\\\\\\\\\\\\\\\\\"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
572 works for eqnarrays.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
573 - If a function, call this function with the name of the environment/macro
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
574 as argument. On call, point will be just after the \\label macro. The
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
575 function is expected to return a suitable context string. It should
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
576 throw an exception (error) when failing to find context.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
577 Consider the following example, which would return the 10 characters
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
578 following the label as context:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
579
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
580 (defun my-context-function (env-or-mac)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
581 (if (> (point-max) (+ 10 (point)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
582 (buffer-substring (point) (+ 10 (point)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
583 (error \"Buffer too small\")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
584
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
585 Setting the variable reftex-use-text-after-label-as-context to t overrides
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
586 the setting here.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
587
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
588 5. List of magic words which identify a reference to be of this type. If the
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
589 word before point is equal to one of these words when calling
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
590 reftex-reference, the label list offered will be automatically restricted
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
591 to labels of the correct type.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
592
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
593 If the type indicator characters of two or more entries are the same, RefTeX
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
594 will use
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
595 - the first non-nil format and prefix
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
596 - the magic words of all involved entries.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
597
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
598 Any list entry may also be a symbol. If that has an association in
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
599 reftex-label-alist-builtin, the cdr of that association is spliced into the
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
600 list. See the AMSTeX configuration example in the comment section of
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
601 reftex.el."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
602 :group 'reftex-defining-label-environments
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
603 :set 'reftex-set-dirty
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
604 :type '(list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
605 :convert-widget
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
606 (lambda (widget)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
607 (let*
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
608 ((args
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
609 (list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
610 `(repeat
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
611 :inline t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
612 (radio
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
613 :value ("" ?a nil nil t nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
614 (choice
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
615 :tag "Builtin"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
616 :value AMSTeX
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
617 ,@(mapcar (function (lambda (x)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
618 (list 'const ':tag (nth 1 x) (car x))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
619 reftex-label-alist-builtin))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
620 (list :tag "Detailed custom entry"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
621 (choice :tag "Environment or \\macro "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
622 (const :tag "Ignore, just use typekey" nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
623 (string ""))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
624 (character :tag "Typekey character " ?a)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
625 (choice :tag "Label prefix string "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
626 (const :tag "Copy from similar label type" nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
627 (string :tag "Specify here" "lab:"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
628 (choice :tag "Label reference format"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
629 (const :tag "Copy from similar label type" nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
630 (string :tag "Specify here" "~\\ref{%s}"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
631 (choice :tag "Grab context method "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
632 (const :tag "Default position" t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
633 (const :tag "After label" nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
634 (regexp :tag "Regular expression" "")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
635 (symbol :tag "Function" my-context-function))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
636 (repeat :tag "List of Magic Words" (string))))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
637 (widget-put widget :args args)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
638 widget))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
639
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
640 (defcustom reftex-default-label-alist-entries '(Sideways LaTeX)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
641 "Default label alist specifications. LaTeX should be the last entry.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
642 This list describes the default label environments RefTeX should always use in
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
643 addition to the specifications in reftex-label-alist. It is probably a
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
644 mistake to remove the LaTeX symbol from this list.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
645
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
646 Here are the current options:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
647
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
648 LaTeX The standard LaTeX environments
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
649 Sideways The sidewaysfigure and sidewaystable environments
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
650 AMSTeX The math environments in the AMS_LaTeX amsmath package
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
651 AAS The deluxetable environment from the American Astronomical Society"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
652 :group 'reftex-defining-label-environments
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
653 :set 'reftex-set-dirty
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
654 :type '(list :indent 4
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
655 :convert-widget
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
656 (lambda (widget)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
657 (let* ((args
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
658 (list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
659 `(checklist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
660 :inline t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
661 ,@(reverse
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
662 (mapcar (lambda (x)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
663 (list 'const ':tag (nth 1 x) (car x)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
664 reftex-label-alist-builtin))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
665 (widget-put widget :args args)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
666 widget))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
667
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
668 (defcustom reftex-use-text-after-label-as-context nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
669 "*t means, grab context from directly after the \\label{..} macro.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
670 This is the fastest method for obtaining context of the label definition, but
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
671 requires discipline when placing labels. Setting this variable to t takes
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
672 precedence over the individual settings in reftex-label-alist.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
673 This variable may be set to t, nil, or a string of label type letters
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
674 indicating the label types for which it should be true."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
675 :group 'reftex-defining-label-environments
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
676 :set 'reftex-set-dirty
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
677 :type '(choice
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
678 (const :tag "on" t) (const :tag "off" nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
679 (string :tag "Selected label types")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
680
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
681 ;; Label insertion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
682
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
683 (defgroup reftex-making-and-inserting-labels nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
684 "Options on how to create new labels"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
685 :group 'reftex-label-support)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
686
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
687 (defcustom reftex-insert-label-flags '("s" "sft")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
688 "Flags governing label insertion. First flag DERIVE, second flag PROMPT.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
689
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
690 If DERIVE is t, RefTeX will try to derive a sensible label from context.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
691 A section label for example will be derived from the section heading.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
692 The conversion of the context to a legal label is governed by the
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
693 specifications given in reftex-derive-label-parameters.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
694 If RefTeX fails to derive a label, it will prompt the user.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
695
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
696 If PROMPT is t, the user will be prompted for a label string. The prompt will
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
697 already contain the prefix, and (if DERIVE is t) a default label derived from
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
698 context. When PROMPT is nil, the default label will be inserted without
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
699 query.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
700
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
701 So the combination of DERIVE and PROMPT controls label insertion. Here is a
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
702 table describing all four possibilities:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
703
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
704 DERIVE PROMPT ACTION
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
705 -------------------------------------------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
706 nil nil Insert simple label, like eq:22 or sec:13. No query.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
707 nil t Prompt for label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
708 t nil Derive a label from context and insert without query
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
709 t t Derive a label from context and prompt for confirmation
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
710
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
711 Each flag may be set to t, nil, or a string of label type letters
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
712 indicating the label types for which it should be true.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
713 Thus, the combination may be set differently for each label type. The
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
714 default settings \"s\" and \"sft\" mean: Derive section labels from headings
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
715 (with confirmation). Prompt for figure and table labels. Use simple labels
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
716 without confirmation for everything else."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
717 :group 'reftex-making-and-inserting-labels
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
718 :type '(list (choice :tag "Derive label from context"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
719 (const :tag "always" t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
720 (const :tag "never" nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
721 (string :tag "for selected label types" ""))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
722 (choice :tag "Prompt for label string "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
723 :entry-format " %b %v"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
724 (const :tag "always" t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
725 (const :tag "never" nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
726 (string :tag "for selected label types" ""))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
727
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
728 (defcustom reftex-derive-label-parameters '(3 20 t 1 "-" ; continue
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
729 ("the" "on" "in" "off" "a" "for" "by" "of" "and" "is"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
730 "Parameters for converting a string into a label.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
731 NWORDS Number of words to use.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
732 MAXCHAR Maximum number of characters in a label string.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
733 ILLEGAL nil: Throw away any words containing characters illegal in labels.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
734 t: Throw away only the illegal characters, not the whole word.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
735 ABBREV nil: Never abbreviate words.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
736 t: Always abbreviate words (see reftex-abbrev-parameters).
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
737 not t and not nil: Abbreviate words if necessary to shorten
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
738 label string below MAXCHAR.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
739 SEPARATOR String separating different words in the label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
740 IGNOREWORDS List of words which should not be part of labels"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
741 :group 'reftex-making-and-inserting-labels
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
742 :type '(list (integer :tag "Number of words " 3)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
743 (integer :tag "Maximum label length " 20)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
744 (choice :tag "Illegal characters in words"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
745 (const :tag "throw away entire word" nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
746 (const :tag "throw away single chars" t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
747 (choice :tag "Abbreviate words "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
748 (const :tag "never" nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
749 (const :tag "always" t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
750 (const :tag "when label is too long" 1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
751 (string :tag "Separator between words " "-")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
752 (repeat :tag "Ignore words"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
753 :entry-format " %i %d %v"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
754 (string :tag ""))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
755
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
756 (defcustom reftex-label-illegal-re "[\000-\040\177-\377\\\\#$%&~^_{}]"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
757 "Regexp matching characters not legal in labels.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
758 For historic reasons, this character class comes *with* the [] brackets."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
759 :group 'reftex-making-and-inserting-labels
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
760 :type '(regexp :tag "Character class"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
761
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
762 (defcustom reftex-abbrev-parameters '(4 2 "^saeiou" "aeiou")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
763 "Parameters for abbreviation of words.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
764 MIN-CHARS minimum number of characters remaining after abbreviation
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
765 MIN-KILL minimum number of characters to remove when abbreviating words
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
766 BEFORE character class before abbrev point in word
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
767 AFTER character class after abbrev point in word"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
768 :group 'reftex-making-and-inserting-labels
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
769 :type '(list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
770 (integer :tag "Minimum chars per word" 4)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
771 (integer :tag "Shorten by at least " 2)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
772 (string :tag "cut before char class " "^saeiou")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
773 (string :tag "cut after char class " "aeiou")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
774
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
775
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
776 ;; Label referencing
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
777
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
778 (defgroup reftex-referencing-labels nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
779 "Options on how to reference labels"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
780 :group 'reftex-label-support)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
781
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
782 (defcustom reftex-label-menu-flags '(t t nil nil nil nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
783 "*List of flags governing the label menu makeup.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
784 The flags are:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
785
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
786 TABLE-OF-CONTENTS Show the labels embedded in a table of context.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
787 SECTION-NUMBERS Include section numbers (like 4.1.3) in table of contents.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
788 COUNTERS Show counters. This just numbers the labels in the menu.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
789 NO-CONTEXT Non-nil means do NOT show the short context.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
790 FOLLOW follow full context in other window.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
791 SHOW-COMMENTED Show labels from regions which are commented out. RefTeX
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
792 sees these labels, but does not normally show them.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
793
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
794 Each of these flags can be set to t or nil, or to a string of type letters
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
795 indicating the label types for which it should be true. These strings work
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
796 like character classes in regular expressions. Thus, setting one of the
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
797 flags to \"sf\" makes the flag true for section and figure labels, nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
798 for everything else. Setting it to \"^ft\" makes it the other way round.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
799
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
800 Most options can also be switched from the label menu itself - so if you
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
801 decide here to not have a table of contents in the label menu, you can still
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
802 get one interactively during selection from the label menu."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
803 :group 'reftex-referencing-labels
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
804 :type '(list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
805 (choice :tag "Embed in table of contents "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
806 (const :tag "on" t) (const :tag "off" nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
807 (string :tag "Selected label types"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
808 (choice :tag "Show section numbers "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
809 (const :tag "on" t) (const :tag "off" nil))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
810 (choice :tag "Show individual counters "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
811 (const :tag "on" t) (const :tag "off" nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
812 (string :tag "Selected label types"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
813 (choice :tag "Hide short context "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
814 (const :tag "on" t) (const :tag "off" nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
815 (string :tag "Selected label types"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
816 (choice :tag "Follow context in other window"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
817 (const :tag "on" t) (const :tag "off" nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
818 (string :tag "Selected label types"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
819 (choice :tag "Show commented labels "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
820 (const :tag "on" t) (const :tag "off" nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
821 (string :tag "Selected label types"))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
822
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
823
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
824 (defcustom reftex-guess-label-type t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
825 "*Non-nil means, reftex-reference will try to guess the label type.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
826 To do that, RefTeX will look at the word before the cursor and compare it with
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
827 the words given in reftex-label-alist. When it finds a match, RefTeX will
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
828 immediately offer the correct label menu - otherwise it will prompt you for
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
829 a label type. If you set this variable to nil, RefTeX will always prompt."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
830 :group 'reftex-referencing-labels
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
831 :type '(boolean))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
832
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
833 ;; BibteX citation configuration ----------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
834
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
835 (defgroup reftex-citation-support nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
836 "Support for referencing bibliographic data with BibTeX"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
837 :group 'reftex)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
838
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
839 (defcustom reftex-bibpath-environment-variables '("BIBINPUTS" "TEXBIB")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
840 "*List of env vars which might contain the path to BibTeX database files."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
841 :group 'reftex-citation-support
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
842 :set 'reftex-set-dirty
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
843 :type '(repeat (string :tag "Environment variable")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
844
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
845 (defcustom reftex-bibfile-ignore-list nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
846 "List of files in \\bibliography{..} RefTeX should *not* parse.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
847 The file names have to be in the exact same form as in the bibliography
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
848 macro - i.e. without the .bib extension.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
849 Intended for files which contain only `@string' macro definitions and the
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
850 like, which are ignored by RefTeX anyway."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
851 :group 'reftex-citation-support
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
852 :set 'reftex-set-dirty
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
853 :type '(repeat (string :tag "File name")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
854
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
855 (defcustom reftex-sort-bibtex-matches 'reverse-year
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
856 "*Sorting of the entries found in BibTeX databases by reftex-citation.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
857 Possible values:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
858 nil Do not sort entries.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
859 'author Sort entries by author name.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
860 'year Sort entries by increasing year.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
861 'reverse-year Sort entries by decreasing year."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
862 :group 'reftex-citation-support
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
863 :type '(choice (const :tag "not" nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
864 (const :tag "by author" author)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
865 (const :tag "by year" year)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
866 (const :tag "by year, reversed" reverse-year)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
867
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
868 (defcustom reftex-cite-format 'reftex-cite-format-default
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
869 "Defines the format of citations to be inserted into the buffer.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
870 It can be a string, a list of strings, or an alist with characters as keys
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
871 and a list of strings in the car. In the simplest case, this can just
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
872 be the string \"\\cite{KEY}\", which is also the default. See the
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
873 definition of the reftex-cite-format-XXXX constants for more complex
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
874 examples.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
875 If reftex-cite-format is a string, it will be used as the format. In
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
876 the format, AUTHOR will be replaced by the last name of the
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
877 author, YEAR will be replaced by the year and KEY by the citation
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
878 key. If AUTHOR is present several times, it will be replaced with
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
879 successive author names.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
880 See the constant reftex-cite-format-default for an example.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
881 If reftex-cite-format is a list of strings, the string used will
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
882 depend upon the number of authors of the article. No authors means,
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
883 the first string will be used, 1 author means, the second string will
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
884 be used etc. The last string in the list will be used for all articles
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
885 with too many authors. See reftex-cite-format-1-author-simple for an
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
886 example.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
887 If reftex-cite-format is a list of cons cells, the car of each cell
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
888 needs to be a character. When a selected reference is accepted by
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
889 pressing that key, the cdr of the associated list will be used as
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
890 described above. See reftex-cite-format-2-authors for an example.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
891 In order to configure this variable, you can either set
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
892 reftex-cite-format directly yourself or set it to the SYMBOL of one of
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
893 the predefined constants. E.g.:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
894 (setq reftex-cite-format 'reftex-cite-format-2-authors)"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
895 :group 'reftex-citation-support
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
896 :type
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
897 '(choice
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
898 (choice :tag "symbolic defaults"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
899 :value reftex-cite-format-default
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
900 (const reftex-cite-format-default)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
901 (const reftex-cite-format-1-author-simple)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
902 (const reftex-cite-format-2-authors))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
903 (string :tag "format string" "\\cite{KEY}")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
904 (repeat :tag "list of strings"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
905 :value ("\cite{KEY}" "AUTHOR \cite{KEY}" "AUTHOR and AUTHOR \cite{KEY}")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
906 (string :tag "format string" ""))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
907 (repeat :tag "key-ed lists of strings"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
908 :value ((? . ("\cite{KEY}" "AUTHOR \cite{KEY}" "AUTHOR and AUTHOR \cite{KEY}")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
909 (cons :tag "Enter a keyed list of format strings"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
910 (character :tag "Key character " ? )
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
911 (repeat
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
912 (string :tag "format string" ""))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
913
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
914 ;; Table of contents configuration --------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
915
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
916 (defgroup reftex-table-of-contents-browser nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
917 "A multifile table of contents browser."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
918 :group 'reftex)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
919
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
920 (defcustom reftex-toc-follow-mode nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
921 "Non-nil means, point in *toc* buffer will cause other window to follow.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
922 The other window will show the corresponding part of the document.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
923 This flag can be toggled from within the *toc* buffer with the `f' key."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
924 :group 'reftex-table-of-contents-browser
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
925 :type '(boolean))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
926
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
927 ;; Miscellaneous configurations -----------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
928
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
929 (defgroup reftex-miscellaneous-configurations nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
930 "Collection of further configurations"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
931 :group 'reftex)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
932
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
933 (defcustom reftex-extra-bindings nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
934 "Non-nil means, make additional key bindings on startup.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
935 These extra bindings are located in the users C-c letter map."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
936 :group 'reftex-miscellaneous-configurations
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
937 :type '(boolean))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
938
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
939 (defcustom reftex-use-fonts t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
940 "*Non-nil means, use fonts in label menu and on-the-fly help.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
941 Font-lock must be loaded as well to actually get fontified display."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
942 :group 'reftex-miscellaneous-configurations
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
943 :type '(boolean))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
944
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
945 (defcustom reftex-keep-temporary-buffers t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
946 "*Non-nil means, keep any TeX and BibTeX files loaded for lookup.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
947 Nil means, kill it immediately after use unless it was already an existing
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
948 buffer before the lookup happened. It is faster to keep the buffers, but can
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
949 use a lot of memory, depending on the size of your database and document."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
950 :group 'reftex-miscellaneous-configurations
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
951 :type '(boolean))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
952
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
953 (defcustom reftex-auto-show-entry t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
954 "*Non-nil means, showing context in another window may unhide a section.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
955 This is important when using outline-minor-mode. If the context to be shown
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
956 is in a hidden section, RefTeX will issue a \"show-entry\" command in order
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
957 to show it. This is not reversed when the label is selected - so the section
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
958 remains shown after command completion."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
959 :group 'reftex-miscellaneous-configurations
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
960 :type '(boolean))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
961
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
962
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
963 ;;; End of Configuration Section ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
964
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
965 ;;;===========================================================================
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
966 ;;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
967 ;;; Define the formal stuff for a minor mode named RefTeX.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
968 ;;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
969
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
970 (defvar reftex-mode nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
971 "Determines if RefTeX minor mode is active.")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
972 (make-variable-buffer-local 'reftex-mode)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
973
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
974 (defvar reftex-mode-map (make-sparse-keymap)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
975 "Keymap for RefTeX minor mode.")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
976
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
977 (defvar reftex-mode-menu nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
978
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
979 ;;;###autoload
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
980 (defun turn-on-reftex ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
981 "Turn on RefTeX minor mode."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
982 (reftex-mode t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
983
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
984 ;;;###autoload
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
985 (defun reftex-mode (&optional arg)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
986 "Minor mode with distinct support for \\label, \\ref and \\cite in LaTeX.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
987
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
988 Labels can be created with `\\[reftex-label]' and referenced with `\\[reftex-reference]'.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
989 When referencing, you get a menu with all labels of a given type and
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
990 context of the label definition. The selected label is inserted as a
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
991 \\ref macro.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
992
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
993 Citations can be made with `\\[reftex-citation]' which will use a regular expression
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
994 to pull out a *formatted* list of articles from your BibTeX
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
995 database. The selected citation is inserted as a \\cite macro.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
996
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
997 A Table of Contents of the entire (multifile) document with browsing
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
998 capabilities is available with `\\[reftex-toc]'.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
999
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1000 Most command have help available on the fly. This help is accessed by
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1001 pressing `?' to any prompt mentioning this feature.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1002
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1003 \\{reftex-mode-map}
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1004 Under X, these functions will be available also in a menu on the menu bar.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1005
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1006 ------------------------------------------------------------------------------"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1007
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1008 (interactive "P")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1009 (setq reftex-mode (not (or (and (null arg) reftex-mode)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1010 (<= (prefix-numeric-value arg) 0))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1011
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1012 ; Add or remove the menu, and run the hook
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1013 (if reftex-mode
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1014 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1015 (easy-menu-add reftex-mode-menu)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1016 (run-hooks 'reftex-mode-hook))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1017 (easy-menu-remove reftex-mode-menu)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1018
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1019 (or (assoc 'reftex-mode minor-mode-alist)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1020 (setq minor-mode-alist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1021 (cons '(reftex-mode " Ref") minor-mode-alist)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1022
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1023 (or (assoc 'reftex-mode minor-mode-map-alist)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1024 (setq minor-mode-map-alist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1025 (cons (cons 'reftex-mode reftex-mode-map)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1026 minor-mode-map-alist)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1027
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1028
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1029 ;;; ===========================================================================
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1030 ;;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1031 ;;; Interfaces for other packages
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1032 ;;; -----------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1033 ;;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1034 ;;; AUCTeX
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1035 ;;; ------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1036
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1037 (defun reftex-arg-label (optional &optional prompt definition)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1038 "Use reftex-label to create a label and insert it with TeX-argument-insert.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1039 This function is intended for AUCTeX macro support."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1040 (let ((label (reftex-label nil t)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1041 (if (and definition (not (string-equal "" label)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1042 (LaTeX-add-labels label))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1043 (TeX-argument-insert label optional optional)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1044
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1045 (defun reftex-arg-ref (optional &optional prompt definition)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1046 "Use reftex-reference to select a label, insert it with TeX-argument-insert.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1047 This function is intended for AUCTeX macro support."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1048 (let ((label (reftex-reference nil t)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1049 (if (and definition (not (string-equal "" label)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1050 (LaTeX-add-labels label))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1051 (TeX-argument-insert label optional optional)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1052
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1053 (defun reftex-arg-cite (optional &optional prompt definition)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1054 "Use reftex-citation to select a key, insert it with TeX-argument-insert.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1055 This function is intended for AUCTeX macro support."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1056 (let ((key (reftex-citation nil t)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1057 (TeX-argument-insert (or key "") optional optional)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1058
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1059 (defvar reftex-label-alist-external-add-ons nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1060 "List of label alist entries added with reftex-add-to-label-alist.")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1061
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1062 ;;;###autoload
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1063 (defun reftex-add-to-label-alist (entry-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1064 "Add label environment descriptions to reftex-label-alist-external-add-ons.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1065 The format of ENTRY-LIST is exactly like reftex-label-alist. See there
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1066 for details.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1067 This function makes it possible to support RefTeX from AUCTeX style files.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1068 The entries in ENTRY-LIST will be processed after the user settings in
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1069 reftex-label-alist, and before the defaults (specified in
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1070 reftex-default-label-alist-entries). Any changes made to
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1071 reftex-label-alist-external-add-ons will raise a flag to the effect that a
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1072 mode reset is done on the next occasion."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1073 (let (entry)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1074 (while entry-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1075 (setq entry (car entry-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1076 entry-list (cdr entry-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1077 (if (not (member entry reftex-label-alist-external-add-ons))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1078 (setq reftex-tables-dirty t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1079 reftex-label-alist-external-add-ons
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1080 (cons entry reftex-label-alist-external-add-ons))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1081
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1082 ;;; ===========================================================================
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1083 ;;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1084 ;;; Multifile support
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1085 ;;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1086 ;;; Technical notes: Multifile works as follows: We keep just one list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1087 ;;; of labels for each master file - this can save a lot of memory.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1088 ;;; reftex-master-index-list is an alist which connects the true file name
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1089 ;;; of each master file with the symbols holding the information on that
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1090 ;;; document. Each buffer has local variables which point to these symbols.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1091
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1092
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1093 ;; List of variables which handle the multifile stuff.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1094 ;; This list is used to tie, untie, and reset these symbols.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1095 (defconst reftex-multifile-symbols
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1096 '(reftex-label-numbers-symbol reftex-list-of-labels-symbol
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1097 reftex-bibfile-list-symbol))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1098
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1099 ;; Alist connecting master file names with the corresponding lisp symbols
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1100 (defvar reftex-master-index-list nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1101
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1102 ;; Last index used for a master file
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1103 (defvar reftex-multifile-index 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1104
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1105 ;; Alist connecting a master file with all included files.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1106 ;; This information is not yet used, just collected.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1107 (defvar reftex-master-include-list nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1108
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1109 ;; Variable holding the symbol with current value of label postfix
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1110 (defvar reftex-label-numbers-symbol nil )
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1111 (make-variable-buffer-local 'reftex-label-numbers-symbol)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1112
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1113 ;; Variable holding the symbol with the label list of the document.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1114 ;; Each element of the label list is again a list with the following elements:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1115 ;; 0: One character label type indicator
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1116 ;; 1: Short context to put into label menu
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1117 ;; 2: The label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1118 ;; 3: The name of the file where the label is defined
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1119 (defvar reftex-list-of-labels-symbol nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1120 (make-variable-buffer-local 'reftex-list-of-labels-symbol)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1121
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1122 ;; Variable holding the symbol with a list of library files for this document
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1123 (defvar reftex-bibfile-list-symbol nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1124 (make-variable-buffer-local 'reftex-bibfile-list-symbol)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1125
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1126 (defun reftex-next-multifile-index ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1127 ;; Return the next free index for multifile symbols.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1128 (setq reftex-multifile-index (1+ reftex-multifile-index)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1129
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1130 (defun reftex-tie-multifile-symbols ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1131 ;; Tie the buffer-local symbols to globals connected with the master file.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1132 ;; If the symbols for the current master file do not exist, they are created.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1133
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1134 (let* ((master (file-truename (reftex-TeX-master-file)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1135 (index (assoc master reftex-master-index-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1136 (symlist reftex-multifile-symbols)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1137 (symbol nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1138 (symname nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1139 (newflag nil))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1140 ;; find the correct index
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1141 (if index
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1142 ;; symbols do exist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1143 (setq index (cdr index))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1144 ;; get a new index and add info to the alist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1145 (setq index (reftex-next-multifile-index)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1146 reftex-master-index-list (cons
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1147 (cons master index)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1148 reftex-master-index-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1149 newflag t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1150
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1151 ;; get/create symbols and tie them
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1152 (while symlist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1153 (setq symbol (car symlist)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1154 symlist (cdr symlist)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1155 symname (symbol-name symbol))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1156 (set symbol (intern (concat symname "-" (int-to-string index))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1157 ;; initialize if new symbols
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1158 (if newflag (set (symbol-value symbol) nil)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1159
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1160 ;; Return t if the symbols did already exist, nil when we've made them
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1161 (not newflag)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1162
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1163 (defun reftex-untie-multifile-symbols ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1164 ;; Remove ties from multifile symbols, so that next use makes new ones.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1165 (let ((symlist reftex-multifile-symbols)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1166 (symbol nil))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1167 (while symlist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1168 (setq symbol (car symlist)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1169 symlist (cdr symlist))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1170 (set symbol nil))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1171
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1172 (defun reftex-TeX-master-file ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1173 ;; Return the name of the master file associated with the current buffer.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1174 ;; When AUCTeX is loaded, we will use it's more sophisticated method.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1175 ;; We also support the default TeX and LaTeX modes by checking for a
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1176 ;; variable tex-main-file.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1177
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1178 (let
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1179 ((master
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1180 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1181 ((fboundp 'TeX-master-file) ; AUCTeX is loaded. Use its mechanism.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1182 (TeX-master-file t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1183 ((boundp 'TeX-master) ; The variable is defined - lets use it.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1184 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1185 ((eq TeX-master t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1186 (buffer-file-name))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1187 ((eq TeX-master 'shared)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1188 (setq TeX-master (read-file-name "Master file: "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1189 nil nil t nil)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1190 (TeX-master)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1191 (t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1192 (setq TeX-master (read-file-name "Master file: "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1193 nil nil t nil)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1194 ((boundp 'tex-main-file)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1195 ;; This is the variable from the default TeX modes
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1196 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1197 ((stringp tex-main-file)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1198 ;; ok, this must be it
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1199 tex-main-file)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1200 (t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1201 ;; In this case, the buffer is its own master
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1202 (buffer-file-name))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1203 (t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1204 ;; Know nothing about master file. Assume this is a master file.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1205 (buffer-file-name)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1206 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1207 ((null master)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1208 (error "Need a filename for this buffer. Please save it first."))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1209 ((or (file-exists-p master)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1210 (reftex-get-buffer-visiting master))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1211 ;; We either see the file, or have a buffer on it. OK.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1212 )
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1213 ((or (file-exists-p (concat master ".tex"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1214 (reftex-get-buffer-visiting (concat master ".tex")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1215 ;; Ahh, an extra .tex was missing...
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1216 (setq master (concat master ".tex")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1217 (t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1218 ;; Something is wrong here. Throw an exception.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1219 (error "No such master file %s" master)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1220 (expand-file-name master)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1221
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1222 (defun reftex-make-master-buffer (master-file mode)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1223 "Make a master buffer which contains the MASTER-FILE and all includes.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1224 This is to prepare a buffer containing the entire document in correct
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1225 sequence for parsing. Therefore it will even expand includes which are
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1226 commented out.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1227 The function returns the number of input/include files not found."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1228
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1229 (interactive "fmaster file: ")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1230 (let ((not-found 0) file file-list tmp (font-lock-maximum-size 1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1231 (switch-to-buffer "*reftex-master.tex*")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1232 (erase-buffer)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1233 (if (not (eq major-mode mode))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1234 (funcall mode))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1235 ;; first insert the master file
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1236 (if (not (file-exists-p master-file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1237 (error "No such master file: %s" master-file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1238 (reftex-insert-buffer-or-file master-file)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1239 (subst-char-in-region (point-min) (point-max) ?\r ?\n t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1240 (setq file-list (cons master-file file-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1241 (goto-char 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1242 ;; remember from which file these lines came
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1243 (put-text-property (point-min) (point-max) 'file
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1244 (expand-file-name master-file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1245 ;; Now find recursively all include/input statements and expand them
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1246 (while (re-search-forward
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1247 "^[ \t]*\\\\\\(include\\|input\\){\\([^}\n]+\\)}" nil t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1248 ;; Change default directory, so that relative fine names work correctly
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1249 (setq file (reftex-no-props (match-string 2)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1250 (save-match-data
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1251 (cd (file-name-directory
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1252 (get-text-property (match-beginning 0) 'file)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1253 (if (not (string-match "\\.tex$" file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1254 (setq file (concat file ".tex"))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1255 (if (file-exists-p file)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1256 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1257 (replace-match
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1258 (format "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% START OF %s FILE: %s\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% END OF %s FILE: %s\n"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1259 (match-string 1) file
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1260 (match-string 1) file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1261 (beginning-of-line 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1262 (narrow-to-region (point) (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1263 ;; insert the file
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1264 (reftex-insert-buffer-or-file file)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1265 (subst-char-in-region (point-min) (point-max) ?\r ?\n t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1266 (setq file-list (cons (expand-file-name file) file-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1267 ;; remember from which file these lines came
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1268 (put-text-property (point-min) (point-max)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1269 'file (expand-file-name file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1270 (goto-char (point-min))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1271 (widen))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1272 (message "Input/include file %s not found. Ignored. Continuing..."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1273 file)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1274 (setq not-found (1+ not-found))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1275 (setq file-list (nreverse file-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1276 (while (setq tmp (assoc (car file-list) reftex-master-include-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1277 (setq reftex-master-include-list (delq tmp reftex-master-include-list)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1278 (setq reftex-master-include-list (cons file-list reftex-master-include-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1279 not-found))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1280
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1281 (defun reftex-insert-buffer-or-file (file)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1282 "If there is a buffer associated with FILE, insert it - otherwise the FILE."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1283 (let ((buffer (reftex-get-buffer-visiting file)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1284 (if buffer
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1285 (let (beg end beg1 end1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1286 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1287 ;; make sure we get the whole buffer
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1288 (set-buffer buffer)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1289 (setq beg (point-min) end (point-max))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1290 (widen)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1291 (setq beg1 (point-min) end1 (point-max)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1292 (insert-buffer-substring buffer beg1 end1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1293 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1294 (set-buffer buffer)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1295 (narrow-to-region beg end)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1296 (insert-file-contents file))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1297
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1298
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1299 (defun reftex-parse-document (&optional buffer)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1300 "Rescan the document."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1301 (interactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1302 (save-window-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1303 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1304 (if buffer
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1305 (if (not (bufferp buffer))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1306 (error "No such buffer %s" (buffer-name buffer))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1307 (set-buffer buffer)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1308 (reftex-access-scan-info t))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1309
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1310 (defun reftex-access-scan-info (&optional rescan)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1311 ;; Access the scanning info. When the multifile symbols are not yet tied,
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1312 ;; tie them. When they are have to be created, do a buffer scan to
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1313 ;; fill them.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1314
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1315 ;; If RESCAN is non-nil, enforce document scanning
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1316
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1317 (catch 'exit
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1318 (let ((rescan (or (equal rescan t) (equal rescan '(4)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1319
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1320 ;; Reset the mode if we had changes from style hooks
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1321 (and reftex-tables-dirty
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1322 (reftex-reset-mode))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1323
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1324 (if (eq reftex-list-of-labels-symbol nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1325 ;; Symbols are not yet tied: Tie them and see if they are set
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1326 (reftex-tie-multifile-symbols))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1327
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1328 (if (and (symbol-value reftex-list-of-labels-symbol)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1329 (not rescan))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1330 ;; Lists do already exist and we don't need to rescan.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1331 ;; Return from here.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1332 (throw 'exit t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1333
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1334 ;; We need to rescan
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1335 ;; =================
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1336
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1337 (unwind-protect
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1338 (save-window-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1339 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1340
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1341 ;; do the scanning
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1342
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1343 (let ((label-list-symbol reftex-list-of-labels-symbol)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1344 (label-numbers-symbol reftex-label-numbers-symbol)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1345 (bibfile-list-symbol reftex-bibfile-list-symbol))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1346
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1347 (message "Creating master buffer...")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1348 (reftex-make-master-buffer (reftex-TeX-master-file) major-mode)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1349
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1350 (message "Scanning document...")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1351
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1352 (reftex-scan-buffer-for-labels
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1353 label-numbers-symbol label-list-symbol)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1354
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1355 (reftex-scan-buffer-for-bibliography-statement
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1356 bibfile-list-symbol)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1357
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1358 (message "Scanning document... done"))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1359
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1360 (if (get-buffer "*reftex-master.tex*")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1361 (kill-buffer "*reftex-master.tex*"))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1362
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1363 (defun reftex-create-tags-file ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1364 "Create TAGS file by running `etags' on the current document.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1365 The TAGS file is also immediately visited with `visit-tags-table."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1366 (interactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1367 (reftex-access-scan-info current-prefix-arg)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1368 (let* ((master (reftex-TeX-master-file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1369 (files (assoc master reftex-master-include-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1370 (cmd (format "etags %s" (mapconcat 'identity files " "))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1371 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1372 (set-buffer (reftex-get-buffer-visiting master))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1373 (message "Running etags to create TAGS file...")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1374 (shell-command cmd)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1375 (visit-tags-table "TAGS"))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1376
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1377 ;; History of grep commands.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1378 (defvar reftex-grep-history nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1379 (defvar reftex-grep-command "grep -n "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1380 "Last grep command used in \\[reftex-grep-document]; default for next grep.")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1381
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1382 (defun reftex-grep-document (grep-cmd)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1383 "Run grep query through all files related to this document.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1384 With prefix arg, force to rescan document.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1385 This works also without an active TAGS table."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1386
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1387 (interactive
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1388 (list (read-from-minibuffer "Run grep on document (like this): "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1389 reftex-grep-command nil nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1390 'reftex-grep-history)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1391 (reftex-access-scan-info current-prefix-arg)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1392 (let* ((master (reftex-TeX-master-file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1393 (default-directory (file-name-directory master))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1394 (re (format "\\`%s\\(.*\\)" (regexp-quote
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1395 (expand-file-name default-directory))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1396 (files (assoc master reftex-master-include-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1397 (cmd (format
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1398 "%s %s" grep-cmd
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1399 (mapconcat (function (lambda (x)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1400 (if (string-match re x)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1401 (match-string 1 x)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1402 x)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1403 files " "))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1404 (grep cmd)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1405
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1406 (defun reftex-search-document (&optional regexp)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1407 "Regexp search through all files of the current TeX document.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1408 Starts always in the master file. Stops when a match is found.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1409 To continue searching for next match, use command \\[tags-loop-continue].
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1410 This works also without an active TAGS table."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1411 (interactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1412 (let ((default (reftex-this-word)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1413 (if (not regexp)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1414 (setq regexp (read-string (format "Search regexp in document [%s]: "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1415 default))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1416 (if (string= regexp "") (setq regexp (regexp-quote default)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1417
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1418 (reftex-access-scan-info current-prefix-arg)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1419 (tags-search regexp (list 'assoc (reftex-TeX-master-file)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1420 'reftex-master-include-list))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1421
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1422 (defun reftex-query-replace-document (&optional from to delimited)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1423 "Run a query-replace-regexp of FROM with TO over the entire TeX document.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1424 Third arg DELIMITED (prefix arg) means replace only word-delimited matches.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1425 If you exit (\\[keyboard-quit] or ESC), you can resume the query replace
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1426 with the command \\[tags-loop-continue].
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1427 This works also without an active TAGS table."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1428 (interactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1429 (let ((default (reftex-this-word)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1430 (if (not from)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1431 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1432 (setq from (read-string (format "Replace regexp in document [%s]: "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1433 default)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1434 (if (string= from "") (setq from (regexp-quote default)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1435 (if (not to)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1436 (setq to (read-string (format "Replace regexp %s with: " from))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1437 (reftex-access-scan-info current-prefix-arg)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1438 (tags-query-replace from to (or delimited current-prefix-arg)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1439 (list 'assoc (reftex-TeX-master-file)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1440 'reftex-master-include-list))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1441
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1442 (defun reftex-change-label (&optional from to)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1443 "Query replace FROM with TO in all \\label and \\ref commands.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1444 Works on the entire multifile document.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1445 If you exit (\\[keyboard-quit] or ESC), you can resume the query replace
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1446 with the command \\[tags-loop-continue].
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1447 This works also without an active TAGS table."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1448 (interactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1449 (let ((default (reftex-this-word "-a-zA-Z0-9_*.:")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1450 (if (not from)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1451 (setq from (read-string (format "Replace label globally [%s]: "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1452 default))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1453 (if (string= from "") (setq from default))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1454 (if (not to)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1455 (setq to (read-string (format "Replace label %s with: "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1456 from))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1457 (reftex-query-replace-document
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1458 (concat "\\\\\\(label\\|[a-z]*ref\\){" (regexp-quote from) "}")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1459 (format "\\\\\\1{%s}" to))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1460
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1461 (defun reftex-this-word (&optional class)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1462 ;; grab the word around point
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1463 (setq class (or class "-a-zA-Z0-9:_/.*;|"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1464 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1465 (buffer-substring-no-properties
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1466 (progn (skip-chars-backward class) (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1467 (progn (skip-chars-forward class) (point)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1468
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1469 ;;; ===========================================================================
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1470 ;;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1471 ;;; Functions to create and reference automatic labels
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1472
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1473 ;; The following constants are derived from reftex-label-alist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1474
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1475 ;; Prompt used for label type querys directed to the user
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1476 (defconst reftex-type-query-prompt nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1477
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1478 ;; Help string for label type querys
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1479 (defconst reftex-type-query-help nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1480
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1481 ;; Alist relating label type to reference format
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1482 (defconst reftex-typekey-to-format-alist nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1483
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1484 ;; Alist relating label type to label affix
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1485 (defconst reftex-typekey-to-prefix-alist nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1486
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1487 ;; Alist relating environments or macros to label type and context regexp
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1488 (defconst reftex-env-or-mac-alist nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1489
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1490 ;; List of macros carrying a label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1491 (defconst reftex-label-mac-list nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1492
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1493 ;; List of environments carrying a label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1494 (defconst reftex-label-env-list nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1495
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1496 ;; List of all typekey letters in use
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1497 (defconst reftex-typekey-list nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1498
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1499 ;; Alist relating magic words to a label type
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1500 (defconst reftex-words-to-typekey-alist nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1501
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1502 ;; The last list-of-labels entry used in a reference
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1503 (defvar reftex-last-used-reference (list nil nil nil nil))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1504
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1505 ;; The regular expression used to abbreviate words
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1506 (defconst reftex-abbrev-regexp
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1507 (concat
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1508 "^\\("
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1509 (make-string (nth 0 reftex-abbrev-parameters) ?.)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1510 "[" (nth 2 reftex-abbrev-parameters) "]*"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1511 "\\)"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1512 "[" (nth 3 reftex-abbrev-parameters) "]"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1513 (make-string (1- (nth 1 reftex-abbrev-parameters)) ?.)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1514
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1515 ;; Global variables used for communication between functions
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1516 (defvar reftex-default-context-position nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1517 (defvar reftex-location-start nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1518 (defvar reftex-call-back-to-this-buffer nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1519
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1520 ;; List of buffers created temporarily for lookup, which should be killed
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1521 (defvar reftex-buffers-to-kill nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1522
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1523 ;; The regexp used to find section statements
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1524 (defconst reftex-section-regexp "^[ ]*\\\\\\(part\\|chapter\\|section\\|subsection\\|subsubsection\\|paragraph\\|subparagraph\\|subsubparagraph\\)\\*?\\(\\[[^]]*\\]\\)?{")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1525
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1526 ;; LaTeX section commands and level numbers
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1527 (defconst reftex-section-levels
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1528 '(
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1529 ("part" . 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1530 ("chapter" . 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1531 ("section" . 2)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1532 ("subsection" . 3)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1533 ("subsubsection" . 4)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1534 ("paragraph" . 5)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1535 ("subparagraph" . 6)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1536 ("subsubparagraph" . 7)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1537 ))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1538
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1539 (defun reftex-label (&optional environment no-insert)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1540 "Insert a unique label. Return the label.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1541 If ENVIRONMENT is given, don't bother to find out yourself.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1542 If NO-INSERT is non-nil, do not insert label into buffer.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1543 With prefix arg, force to rescan document first.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1544 The label is also inserted into the label list.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1545 This function is controlled by the settings of reftex-insert-label-flags."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1546
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1547 (interactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1548
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1549 ;; Ensure access to scanning info and rescan buffer if prefix are is '(4)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1550 (reftex-access-scan-info current-prefix-arg)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1551
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1552 ;; Find out what kind of environment this is and abort if necessary
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1553 (if (or (not environment)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1554 (not (assoc environment reftex-env-or-mac-alist)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1555 (setq environment (reftex-label-location)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1556 (if (not environment)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1557 (error "Can't figure out what kind of label should be inserted"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1558
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1559 ;; Ok, go ahead
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1560 (let (label num typekey prefix entry cell lab valid default force-prompt)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1561 (setq typekey (nth 1 (assoc environment
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1562 reftex-env-or-mac-alist)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1563 (setq prefix (or (cdr (assoc typekey reftex-typekey-to-prefix-alist))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1564 (concat typekey "-")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1565
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1566 ;; make a default label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1567 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1568
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1569 ((reftex-typekey-check typekey (nth 0 reftex-insert-label-flags))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1570 ;; derive a label from context
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1571 (setq default (nth 2 (reftex-label-info " ")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1572 ;; catch the cases where the is actually no context available
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1573 (if (or (string-match "NO MATCH FOR CONTEXT REGEXP" default)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1574 (string-match "ILLEGAL VALUE OF PARSE" default)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1575 (string-match "SECTION HEADING NOT FOUND" default)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1576 (string-match "HOOK ERROR" default)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1577 (string-match "^[ \t]*$" default))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1578 (setq default prefix
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1579 force-prompt t) ; need to prompt
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1580 (setq default (concat prefix (reftex-string-to-label default)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1581
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1582 ;; make it unique
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1583 (setq label default)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1584 (setq num 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1585 (while (assoc label (symbol-value reftex-list-of-labels-symbol))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1586 (setq label (concat default "-" (setq num (1+ num)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1587 (setq default label)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1588
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1589 ((reftex-typekey-check typekey (nth 1 reftex-insert-label-flags)) ; prompt
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1590 ;; Minimal default: the user will be prompted
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1591 (setq default prefix))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1592
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1593 (t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1594 ;; make an automatic label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1595 (while (assoc
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1596 (setq default (concat prefix (reftex-next-label-number typekey)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1597 (symbol-value reftex-list-of-labels-symbol)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1598
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1599 ;; Should we ask the user?
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1600 (if (or (reftex-typekey-check typekey
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1601 (nth 1 reftex-insert-label-flags)) ; prompt
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1602 force-prompt)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1603
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1604 (while (not valid)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1605 ;; iterate until we get a legal label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1606
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1607 (setq label (read-string "Label: " default))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1608
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1609 ;; Lets make sure that this is a legal label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1610 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1611
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1612 ;; Test if label contains strange characters
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1613 ((string-match reftex-label-illegal-re label)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1614 (message "Label \"%s\" contains illegal characters" label)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1615 (ding)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1616 (sit-for 2))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1617
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1618 ;; Look it up in the label list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1619 ((setq entry (assoc label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1620 (symbol-value reftex-list-of-labels-symbol)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1621 (message "Label \"%s\" exists in file %s" label (nth 3 entry))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1622 (ding)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1623 (sit-for 2))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1624
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1625 ;; Label is ok
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1626 (t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1627 (setq valid t))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1628 (setq label default))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1629
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1630 ;; Insert the label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1631 (if (not no-insert)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1632 (insert "\\label{" label "}"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1633
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1634 ;; Insert the label into the label list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1635 (if (symbol-value reftex-list-of-labels-symbol)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1636 (let ((cnt 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1637 (pos (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1638 (all (symbol-value reftex-list-of-labels-symbol))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1639 (look-for nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1640 (note nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1641 (text nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1642 (file (buffer-file-name)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1643
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1644 ;; find the previous label in order to know where to insert new label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1645 ;; into label list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1646 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1647 (if (re-search-backward "\\\\label{\\([^}]+\\)}" nil 1 2)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1648 (setq look-for (reftex-no-props (match-string 1))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1649 (if (or (re-search-forward
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1650 "\\\\\\(include\\|input\\){[^}\n]+}" pos t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1651 (re-search-forward reftex-section-regexp pos t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1652 (null look-for))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1653 (setq note "POSITION UNCERTAIN. RESCAN TO FIX.")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1654 (if (not look-for)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1655 (set reftex-list-of-labels-symbol
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1656 (cons (list label typekey text file note)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1657 (symbol-value reftex-list-of-labels-symbol)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1658 (while all
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1659 (setq cell (car all)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1660 all (cdr all)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1661 cnt (1+ cnt)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1662 lab (nth 0 cell))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1663 (if (string= lab look-for)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1664 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1665 (setcdr
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1666 (nthcdr (1- cnt)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1667 (symbol-value reftex-list-of-labels-symbol))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1668 (cons (list label typekey text file note)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1669 (nthcdr
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1670 cnt (symbol-value reftex-list-of-labels-symbol))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1671 ;; to end the loop, set all to nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1672 (setq all nil)))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1673 ;; return value of the function is the label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1674 label))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1675
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1676 (defun reftex-string-to-label (string)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1677 ;; Convert a string (a sentence) to a label.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1678 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1679 ;; Uses reftex-derive-label-parameters and reftex-abbrev-parameters
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1680 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1681
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1682 (let* ((words0 (reftex-split "[- \t\n\r]+"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1683 (reftex-no-props string)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1684 (ignore-words (nth 5 reftex-derive-label-parameters))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1685 words word)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1686
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1687 ;; remove words from the ignore list or with funny characters
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1688 (while words0
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1689 (setq word (car words0) words0 (cdr words0))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1690 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1691 ((member (downcase word) ignore-words))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1692 ((string-match reftex-label-illegal-re word)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1693 (if (nth 2 reftex-derive-label-parameters)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1694 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1695 (while (string-match reftex-label-illegal-re word)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1696 (setq word (replace-match "" nil nil word)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1697 (setq words (cons word words)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1698 (t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1699 (setq words (cons word words)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1700 (setq words (nreverse words))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1701
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1702 ;; restrict number of words
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1703 (if (> (length words) (nth 0 reftex-derive-label-parameters))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1704 (setcdr (nthcdr (1- (nth 0 reftex-derive-label-parameters)) words) nil))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1705
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1706 ;; First, try to use all words
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1707 (setq string (mapconcat '(lambda(w) w) words
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1708 (nth 4 reftex-derive-label-parameters)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1709
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1710 ;; Abbreviate words if enforced by user settings or string length
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1711 (if (or (eq t (nth 3 reftex-derive-label-parameters))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1712 (and (nth 3 reftex-derive-label-parameters)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1713 (> (length string) (nth 1 reftex-derive-label-parameters))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1714 (setq words
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1715 (mapcar
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1716 '(lambda (w) (if (string-match reftex-abbrev-regexp w)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1717 (match-string 1 w)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1718 w))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1719 words)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1720 string (mapconcat '(lambda(w) w) words
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1721 (nth 4 reftex-derive-label-parameters))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1722
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1723 ;; Shorten if still to long
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1724 (setq string
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1725 (if (> (length string) (nth 1 reftex-derive-label-parameters))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1726 (substring string 0 (nth 1 reftex-derive-label-parameters))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1727 string))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1728
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1729 ;; Delete the final punctuation, if any
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1730 (if (string-match "[^a-zA-Z0-9]+$" string)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1731 (setq string (replace-match "" nil nil string)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1732 string))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1733
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1734 (defun reftex-label-location (&optional bound)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1735 ;; Return the environment or macro which determines the label type at point.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1736 ;; If optional BOUND is an integer, limit backward searches to that point.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1737
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1738 (let* ((loc1 (reftex-what-macro reftex-label-mac-list bound))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1739 (loc2 (reftex-what-environment reftex-label-env-list bound))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1740 (p1 (or (cdr loc1) 0))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1741 (p2 (or (cdr loc2) 0)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1742
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1743 (setq reftex-location-start (max p1 p2))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1744 (if (> p1 p2)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1745 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1746 (setq reftex-default-context-position p1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1747 (car loc1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1748 (setq reftex-default-context-position
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1749 (+ p2 8 (length (car loc2))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1750 (or (car loc2) "section"))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1751
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1752
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1753 (defun reftex-next-label-number (type)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1754 ;; Increment value of automatic labels in current buffer. Return new value.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1755
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1756 ;; Ensure access to scanning info
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1757 (reftex-access-scan-info)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1758
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1759 (let ((n (cdr (assoc type (symbol-value reftex-label-numbers-symbol)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1760 (if (not (integerp n))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1761 ;; oops - type not known - make one here
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1762 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1763 (set reftex-label-numbers-symbol
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1764 (cons (cons type 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1765 (symbol-value reftex-label-numbers-symbol)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1766 (setq n 0)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1767 (setq n (1+ n))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1768 (setcdr (assoc type (symbol-value reftex-label-numbers-symbol)) n)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1769 n))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1770
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1771 ;; Help string for the reference label menu
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1772 (defconst reftex-reference-label-help
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1773 " AVAILABLE KEYS IN REFERENCE LABEL MENU
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1774 ======================================
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1775 n / p Go to next/previous label (Cursor motion works as well)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1776 r / s Rescan document for labels / Switch label type
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1777 t / # Toggle table of contents / Toggle counter mode
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1778 c Toggle display of short context
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1779 SPACE Show full context for current label in other window
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1780 f Toggle follow mode: other window will follow context
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1781 a / q Use last referenced label / Quit without accepting label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1782 ? / C-r Display this help message / Recursive Edit into other window
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1783 RETURN Accept current label")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1784
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1785 (defun reftex-reference (&optional type no-insert)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1786 "Make a LaTeX reference. Look only for labels of a certain TYPE.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1787 With prefix arg, force to rescan buffer for labels. This should only be
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1788 necessary if you have recently entered labels yourself without using
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1789 reftex-label. Rescanning of the buffer can also be requested from the
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1790 label selection menu.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1791 The function returns the selected label or nil.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1792 If NO-INSERT is non-nil, do not insert \\ref command, just return label.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1793 When called with 2 C-u prefix args, disable magic word recognition."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1794
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1795 (interactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1796
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1797 ;; check for active recursive edits
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1798 (reftex-check-recursive-edit)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1799
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1800 ;; Ensure access to scanning info and rescan buffer if prefix are is '(4)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1801 (reftex-access-scan-info current-prefix-arg)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1802
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1803 (if (not type)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1804 ;; guess type from context
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1805 (if (and reftex-guess-label-type
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1806 (not (= 16 (prefix-numeric-value current-prefix-arg)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1807 (setq type (assoc (downcase (reftex-word-before-point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1808 reftex-words-to-typekey-alist)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1809 (setq type (cdr type))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1810 (setq type (reftex-query-label-type))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1811
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1812 (let (label pair
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1813 (form (or (cdr (assoc type reftex-typekey-to-format-alist))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1814 "\\ref{%s}")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1815
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1816 ;; Have the user select a label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1817 (setq pair (reftex-offer-label-menu type))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1818 (setq label (car pair))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1819
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1820 (if (and label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1821 (not no-insert))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1822 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1823 ;; do we need to remove spaces?
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1824 (if (string= "~" (substring form 0 1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1825 (while (or (= (preceding-char) ?\ )
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1826 (= (preceding-char) ?\C-i))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1827 (backward-delete-char 1)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1828 ;; ok, insert the reference
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1829 (insert (format form label label))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1830 (message ""))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1831 (message "Quit"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1832 ;; return the label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1833 label))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1834
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1835 (defun reftex-goto-label (&optional arg)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1836 "Go to a LaTeX label. With prefix ARG: go to label in another window."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1837 (interactive "P")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1838 (let (type label file pair)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1839 (if (not type)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1840 (setq type (reftex-query-label-type)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1841
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1842 (setq pair (reftex-offer-label-menu type)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1843 label (car pair)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1844 file (cdr pair))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1845 (if (and label file (file-exists-p file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1846 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1847 (if arg
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1848 (find-file-other-window file)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1849 (find-file file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1850 (goto-char (point-min))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1851 (if (not (search-forward (concat "\\label{" label "}") nil t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1852 (error "No such label found: %s" label)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1853 (reftex-highlight 0 (match-beginning 0) (match-end 0))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1854 (add-hook 'pre-command-hook 'reftex-highlight-shall-die)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1855 (message "Quit")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1856 nil)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1857
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1858 ;; Internal list with index numbers of labels in the selection menu
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1859 (defvar reftex-label-index-list nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1860
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1861 (defun reftex-offer-label-menu (typekey)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1862 ;; Offer a menu with the appropriate labels. Return (label . file).
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1863 (let* ((buf (current-buffer))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1864 (near-label (reftex-find-nearby-label))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1865 (toc (reftex-typekey-check typekey reftex-label-menu-flags 0))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1866 (context (not (reftex-typekey-check
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1867 typekey reftex-label-menu-flags 3)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1868 (counter (reftex-typekey-check
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1869 typekey reftex-label-menu-flags 2))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1870 (follow (reftex-typekey-check
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1871 typekey reftex-label-menu-flags 4))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1872 offset rtn key cnt entry)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1873
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1874 (setq reftex-call-back-to-this-buffer buf)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1875 (setq entry (cons nil nil))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1876
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1877 (unwind-protect
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1878 (catch 'exit
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1879 (while t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1880 (save-window-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1881 (switch-to-buffer-other-window "*RefTeX Select*")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1882 (erase-buffer)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1883 (setq truncate-lines t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1884 (setq reftex-label-index-list (reftex-make-and-insert-label-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1885 typekey buf toc context counter
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1886 near-label))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1887 (setq near-label "_ ") ; turn off search for near label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1888 (setq offset (or (car reftex-label-index-list) offset))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1889 ;; use only when searched
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1890 (setq reftex-label-index-list (cdr reftex-label-index-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1891 ;; only this is the true list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1892 (if (not reftex-label-index-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1893 (error "No labels of type \"%s\"" typekey))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1894 (setq rtn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1895 (reftex-select-item
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1896 nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1897 "Label: [n]ext [p]rev [r]escan [t]oc [ ]context [q]uit RETURN [?]HELP+more"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1898 "^>"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1899 "\n[^.]"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1900 2
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1901 reftex-reference-label-help
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1902 '(?r ?c ?t ?s ?# ?a)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1903 offset
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1904 'reftex-select-label-callback follow))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1905 (setq key (car rtn)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1906 cnt (cdr rtn)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1907 offset (1+ cnt))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1908 (if (not key) (throw 'exit nil))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1909 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1910 ((equal key ?r)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1911 ;; rescan buffer
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1912 (reftex-parse-document buf))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1913 ((equal key ?c)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1914 ;; toggle context mode
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1915 (setq context (not context)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1916 ((equal key ?s)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1917 ;; switch type
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1918 (setq typekey (reftex-query-label-type)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1919 ((equal key ?t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1920 ;; toggle tabel of contents display
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1921 (setq toc (not toc)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1922 ((equal key ?#)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1923 ;; toggle counter display
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1924 (setq counter (not counter)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1925 ((equal key ?a)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1926 ;; reuse the last referenced label again
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1927 (setq entry reftex-last-used-reference)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1928 (throw 'exit t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1929 (t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1930 (set-buffer buf)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1931 (setq entry (nth (nth cnt reftex-label-index-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1932 (symbol-value reftex-list-of-labels-symbol)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1933 (setq reftex-last-used-reference entry)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1934 (throw 'exit t))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1935 (kill-buffer "*RefTeX Select*")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1936 (reftex-kill-temporary-buffers))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1937 (cons (reftex-no-props (nth 0 entry)) (nth 3 entry))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1938
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1939 ;; Indentation for table of context lines in the menu
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1940 (defconst reftex-toc-indent " ")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1941 ;; Indentation for the lines containing the label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1942 (defconst reftex-label-indent "> ")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1943 ;; Indentation for context lines
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1944 (defconst reftex-context-indent ". ")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1945 ;; Indentation per section level
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1946 (defvar reftex-level-indent 2
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1947 "*Number of spaces to be used for indentation per section level.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1948 With more indentation, the label menu looks nicer, but shows less context.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1949 Changing this is only fully operational after the next buffer scan.")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1950
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1951 (defun reftex-make-and-insert-label-list (typekey0 buf toc context
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1952 counter near-label)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1953 ;; Insert a menu of all labels in buffer BUF into current buffer.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1954 ;; Return the list of labels, with the index of NEAR-LABEL as extra car.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1955 (let (ins-list index-list offset)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1956 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1957 (set-buffer buf)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1958 (let* ((all nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1959 (font (reftex-use-fonts))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1960 (cnt 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1961 (file nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1962 (index -1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1963 (toc-indent reftex-toc-indent)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1964 (label-indent
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1965 (concat reftex-label-indent
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1966 (if toc (make-string (* 7 reftex-level-indent) ?\ ) "")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1967 (context-indent
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1968 (concat reftex-context-indent
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1969 (if toc (make-string (* 7 reftex-level-indent) ?\ ) "")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1970 cell text label typekey note comment)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1971
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1972 ; Ensure access to scanning info
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1973 (reftex-access-scan-info)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1974
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1975 (setq all (symbol-value reftex-list-of-labels-symbol))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1976
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1977 (while all
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1978
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1979 (setq index (1+ index)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1980 cell (car all)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1981 all (cdr all))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1982
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1983 (if (null (nth 2 cell))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1984 ;; No context yet. Quick update
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1985 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1986 (setq cell (reftex-label-info-update cell))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1987 (setcar (nthcdr index
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1988 (symbol-value reftex-list-of-labels-symbol))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1989 cell)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1990
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1991 ;; in the following setq we *copy* the label, since we will change
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1992 ;; its properties, and we cannot have any properties in the list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1993 ;; (because of assoc searches)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1994 (setq label (copy-sequence (nth 0 cell))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1995 typekey (nth 1 cell)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1996 text (nth 2 cell)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1997 file (nth 3 cell)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1998 note (nth 4 cell)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
1999 comment (get-text-property 0 'in-comment text))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2000
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2001 (if (string= label near-label)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2002 (setq offset (1+ cnt)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2003
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2004 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2005 ((and toc (string= typekey "toc"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2006 (setq ins-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2007 (cons (concat toc-indent text "\n")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2008 ins-list)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2009 ((string= typekey "toc"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2010 ((and (or (string= typekey typekey0) (string= typekey0 " "))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2011 (or (nth 5 reftex-label-menu-flags) ; show-commented?
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2012 (null comment)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2013 (setq cnt (1+ cnt))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2014 (if comment (setq label (concat "% " label)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2015 (if font
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2016 (put-text-property
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2017 0 (length label)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2018 'face
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2019 (if comment
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2020 'font-lock-comment-face
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2021 'font-lock-reference-face)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2022 label))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2023 (setq index-list (cons index index-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2024 (setq ins-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2025 (cons (concat
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2026 label-indent
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2027 label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2028 (if counter (format " (%d) " cnt))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2029 (if comment " LABEL IS COMMENTED OUT ")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2030 (if note (concat " " note) "")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2031 "\n"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2032 (if context (concat context-indent text "\n")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2033 ins-list))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2034 )))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2035
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2036 (apply 'insert (nreverse ins-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2037 (cons offset (nreverse index-list))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2038
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2039 (defun reftex-query-label-type ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2040 ;; Ask for label type
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2041 (message reftex-type-query-prompt)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2042 (let ((key (read-char)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2043 (if (equal key ?\?)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2044 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2045 (save-window-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2046 (with-output-to-temp-buffer "*RefTeX Help*"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2047 (princ reftex-type-query-help))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2048 (setq key (read-char))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2049 (kill-buffer "*RefTeX Help*"))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2050 (if (not (member (char-to-string key) reftex-typekey-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2051 (error "No such label type: %s" (char-to-string key)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2052 (char-to-string key)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2053
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2054 (defun reftex-find-nearby-label ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2055 ;; Find a nearby label.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2056 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2057 (if (or (re-search-backward "\\\\label{\\([^}]+\\)}" nil t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2058 (re-search-forward "\\\\label{\\([^}]+\\)}" nil t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2059 (reftex-no-props (match-string 1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2060 nil)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2061
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2062 ;; Variable holding the vector with section numbers
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2063 (defvar reftex-section-numbers [0 0 0 0 0 0 0 0])
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2064
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2065 (defun reftex-scan-buffer-for-labels (label-numbers-symbol label-list-symbol)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2066 ;; Scan the buffer for labels and save them in a list.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2067 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2068 (let ((regexp (concat "\\\\label{\\([^}]*\\)}" "\\|"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2069 reftex-section-regexp))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2070 (font (reftex-use-fonts))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2071 (bound 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2072 (highest-level 100)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2073 file (level 1) start star text text1 label section-number macro find)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2074 (set label-list-symbol nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2075 (goto-char 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2076
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2077 ;; reset label numbers
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2078 (set label-numbers-symbol
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2079 (mapcar '(lambda(x) (cons x 0)) reftex-typekey-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2080
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2081 ;; reset section numbers
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2082 (reftex-section-number reftex-section-numbers -1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2083
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2084 (while (re-search-forward regexp nil t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2085 (setq file (get-text-property (match-beginning 0) 'file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2086 (if (string= (buffer-substring (match-beginning 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2087 (+ 7 (match-beginning 0))) "\\label{")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2088 ;; It is a label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2089 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2090 (setq label (reftex-no-props (match-string 1)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2091 (set label-list-symbol
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2092 (cons (reftex-label-info label file bound)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2093 (symbol-value label-list-symbol))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2094
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2095 ;; It is a section
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2096 (setq bound (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2097 (setq star (= ?* (char-after (match-end 2))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2098 (setq find (buffer-substring-no-properties
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2099 (1- (match-beginning 2)) (match-end 0)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2100 (setq macro (reftex-no-props (match-string 2)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2101 (setq level (cdr (assoc macro reftex-section-levels)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2102
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2103 (setq section-number (reftex-section-number
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2104 reftex-section-numbers level star))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2105 (setq highest-level (min highest-level level))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2106 (if (= level highest-level)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2107 (message
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2108 "Scanning %s %s ..."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2109 (car (nth level reftex-section-levels))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2110 section-number))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2111
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2112 ;; get the title
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2113 (save-match-data
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2114 (setq text1 (reftex-context-substring))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2115 (setq text (reftex-nicify-text text1)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2116
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2117 (setq find (reftex-allow-for-ctrl-m (concat find text1)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2118
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2119 ;; add section number and indentation
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2120 (setq text
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2121 (concat
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2122 (make-string (* reftex-level-indent level) ?\ )
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2123 (if (nth 1 reftex-label-menu-flags) ; section number flag
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2124 (concat section-number " "))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2125 text))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2126 ;; fontify
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2127 (if font (put-text-property 0 (length text)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2128 'face 'font-lock-comment-face text))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2129
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2130 ;; insert in list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2131 (set label-list-symbol
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2132 (cons (list nil "toc" text file find)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2133 (symbol-value label-list-symbol)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2134 (set label-list-symbol
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2135 (nreverse (symbol-value label-list-symbol))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2136
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2137
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2138 (defun reftex-label-info-update (cell)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2139 ;; Update information about just one label in a different file.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2140 ;; CELL contains the old info list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2141 (let* ((label (nth 0 cell))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2142 (typekey (nth 1 cell))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2143 (text (nth 2 cell))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2144 (file (nth 3 cell))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2145 (note (nth 4 cell))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2146 (buf (reftex-get-file-buffer-force
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2147 file (not reftex-keep-temporary-buffers))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2148 (if (not buf)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2149 (list label typekey "" file "LOST LABEL. RESCAN TO FIX.")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2150 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2151 (set-buffer buf)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2152 (save-restriction
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2153 (widen)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2154 (goto-char 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2156 (if (re-search-forward (concat "\\\\label{" (regexp-quote label) "}")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2157 nil t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2158 (append (reftex-label-info label file) (list note))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2159 (list label typekey "" file "LOST LABEL. RESCAN TO FIX.")))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2160
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2161 (defun reftex-label-info (label &optional file bound)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2162 ;; Return info list on LABEL at point.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2163 (let* ((env-or-mac (reftex-label-location bound))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2164 (typekey (nth 1 (assoc env-or-mac reftex-env-or-mac-alist)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2165 (file (or file (buffer-file-name)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2166 (parse (if (reftex-typekey-check
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2167 typekey reftex-use-text-after-label-as-context)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2168 nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2169 (nth 2 (assoc env-or-mac reftex-env-or-mac-alist))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2170 (text (reftex-short-context env-or-mac parse reftex-location-start)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2171 (if (reftex-in-comment)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2172 (put-text-property 0 1 'in-comment t text))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2173 (list label typekey text file)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2174
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2175 (defun reftex-in-comment ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2176 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2177 (skip-chars-backward "^%\n\r")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2178 (= (preceding-char) ?%)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2179
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2180 (defun reftex-short-context (env parse &optional bound)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2181 ;; Get about one line of useful context for the label definition at point.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2182
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2183 (reftex-nicify-text
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2184
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2185 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2186
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2187 ((null parse)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2188 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2189 (reftex-context-substring)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2190
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2191 ((eq parse t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2192 (if (string= env "section")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2193 ;; special treatment for section labels
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2194 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2195 (if (re-search-backward reftex-section-regexp (point-min) t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2196 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2197 (goto-char (match-end 0))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2198 (reftex-context-substring))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2199 "SECTION HEADING NOT FOUND"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2200 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2201 (goto-char reftex-default-context-position)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2202 (reftex-context-substring))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2203
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2204 ((stringp parse)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2205 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2206 (if (re-search-backward parse bound t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2207 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2208 (goto-char (match-end 0))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2209 (reftex-context-substring))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2210 "NO MATCH FOR CONTEXT REGEXP")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2211 ((fboundp parse)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2212 ;; A hook function. Call it.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2213 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2214 (condition-case error-var
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2215 (funcall parse env)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2216 ('error (format "HOOK ERROR: %s" (cdr error-var))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2217 (t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2218 "ILLEGAL VALUE OF PARSE"))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2219
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2220 (defun reftex-context-substring ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2221 ;; Return up to 100 chars from point
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2222 ;; When point is just after a { or [, limit string to matching parenthesis
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2223 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2224 ((or (= (preceding-char) ?\{)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2225 (= (preceding-char) ?\[))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2226 ;; inside a list - get only the list, with modified syntax to be perfect
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2227 (buffer-substring
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2228 (point)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2229 (min (+ 100 (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2230 (point-max)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2231 (condition-case nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2232 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2233 (up-list 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2234 (1- (point)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2235 ('error (point-max))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2236 (t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2237 ;; no list - just grab 100 characters
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2238 (buffer-substring (point) (min (+ 100 (point)) (point-max))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2239
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2240 (defun reftex-section-number (section-numbers &optional level star)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2241 ;; Return a string with the current section number.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2242 ;; When LEVEL is non-nil, increase section numbers on that level.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2243 (let* ((depth 6) idx n (string ""))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2244 (if level
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2245 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2246 (if (and (> level -1) (not star))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2247 (aset section-numbers level (1+ (aref section-numbers level))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2248 (setq idx (1+ level))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2249 (while (<= idx depth)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2250 (aset section-numbers idx 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2251 (setq idx (1+ idx)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2252 (setq idx 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2253 (while (<= idx depth)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2254 (setq n (aref section-numbers idx))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2255 (setq string (concat string (if (not (string= string "")) "." "")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2256 (int-to-string n)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2257 (setq idx (1+ idx)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2258 (save-match-data
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2259 (if (string-match "\\`\\(0\\.\\)+" string)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2260 (setq string (replace-match "" nil nil string)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2261 (if (string-match "\\(\\.0\\)+\\'" string)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2262 (setq string (replace-match "" nil nil string))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2263 (if star
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2264 (concat (make-string (1- (length string)) ?\ ) "*")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2265 string)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2266
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2267 ;; A variable to remember the index of the last label context shown
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2268 (defvar reftex-last-cnt 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2269
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2270 (defun reftex-select-label-callback (cnt)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2271 ;; Callback function called from the label selection in order to
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2272 ;; show context in another window
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2273 (let* ((this-window (selected-window))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2274 index entry label file buffer)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2275 ;; pop to original buffer in order to get correct variables
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2276 (catch 'exit
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2277 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2278 (set-buffer reftex-call-back-to-this-buffer)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2279 (setq index (nth (or cnt 1) reftex-label-index-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2280 entry (nth index (symbol-value reftex-list-of-labels-symbol))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2281 label (nth 0 entry)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2282 file (nth 3 entry)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2283
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2284 ;; goto the file in another window
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2285 (setq buffer (reftex-get-file-buffer-force
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2286 file (not reftex-keep-temporary-buffers)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2287 (if buffer
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2288 ;; good - the file is available
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2289 (switch-to-buffer-other-window buffer)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2290 ;; we have got a problem here. The file does not exist.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2291 ;; Let' get out of here..
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2292 (ding)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2293 (throw 'exit nil))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2294
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2295
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2296 ;; search for that label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2297 (if (not (and (integerp cnt)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2298 (integerp reftex-last-cnt)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2299 (if (> cnt reftex-last-cnt)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2300 (search-forward (concat "\\label{" label "}") nil t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2301 (search-backward (concat "\\label{" label "}") nil t))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2302 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2303 (goto-char 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2304 (search-forward (concat "\\label{" label "}") nil t)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2305 (reftex-highlight 0 (match-beginning 0) (match-end 0))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2306 (reftex-show-entry)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2307 (recenter (/ (window-height) 2))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2308 (select-window this-window))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2309
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2310 (defun reftex-pop-to-label (label file-list &optional mark-to-kill highlight)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2311 ;; Find LABEL in any file in FILE-LIST in another window.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2312 ;; If mark-to-kill is non-nil, mark new buffer for killing.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2313 ;; If HIGHLIGHT is non-nil, highlight the label definition.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2314 (let* ((re (concat "\\\\label{" (regexp-quote label) "}"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2315 file buf)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2316 (catch 'exit
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2317 (while file-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2318 (setq file (car file-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2319 file-list (cdr file-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2320 (if (not (setq buf (reftex-get-file-buffer-force file mark-to-kill)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2321 (error "No such file %s" file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2322 (set-buffer buf)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2323 (widen)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2324 (goto-char (point-min))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2325 (if (re-search-forward re nil t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2326 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2327 (switch-to-buffer-other-window buf)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2328 (goto-char (match-beginning 0))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2329 (recenter (/ (window-height) 2))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2330 (if highlight
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2331 (reftex-highlight 0 (match-beginning 0) (match-end 0)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2332 (throw 'exit (selected-window)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2333 (error "Label %s not found" label))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2334
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2335 (defun reftex-find-duplicate-labels ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2336 "Produce a list of all duplicate labels in the document."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2337
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2338 (interactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2339
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2340 ;; Rescan the document to make sure
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2341 (reftex-access-scan-info t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2342
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2343 (let ((master (reftex-TeX-master-file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2344 (dlist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2345 (mapcar
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2346 '(lambda(x)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2347 (let (x1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2348 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2349 ((car x)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2350 (setq x1 (reftex-all-assoc-string
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2351 (car x) (symbol-value reftex-list-of-labels-symbol)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2352 (if (< 1 (length x1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2353 (append (list (reftex-no-props (car x)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2354 (mapcar '(lambda(x)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2355 (abbreviate-file-name (nth 3 x))) x1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2356 (list nil)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2357 (t nil))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2358 (reftex-uniquify (symbol-value reftex-list-of-labels-symbol)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2359 (setq dlist (reftex-uniquify dlist))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2360 (if (null dlist) (error "No duplicate labels in document"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2361 (switch-to-buffer-other-window "*Help*")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2362 (make-local-variable 'TeX-master)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2363 (setq TeX-master master)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2364 (erase-buffer)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2365 (insert " MULTIPLE LABELS IN CURRENT DOCUMENT:\n")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2366 (insert " Move point to label and type `M-x reftex-change-label'\n"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2367 " This will run a query-replace on the label and its references\n")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2368 (insert " LABEL FILE\n")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2369 (insert " -------------------------------------------------------------\n")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2370 (while dlist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2371 (if (and (car (car dlist))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2372 (cdr (car dlist)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2373 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2374 (insert (mapconcat '(lambda(x) x) (car dlist) "\n ") "\n")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2375 (setq dlist (cdr dlist)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2376 (goto-char (point-min))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2377
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2378 (defun reftex-all-assoc-string (key list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2379 ;; Return a list of all associations of KEY in LIST. Comparison with string=
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2380 (let (rtn)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2381 (while list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2382 (if (string= (car (car list)) key)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2383 (setq rtn (cons (car list) rtn)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2384 (setq list (cdr list)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2385 (nreverse rtn)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2386
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2387 (defun reftex-kill-temporary-buffers ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2388 ;; Kill all buffers in the list reftex-kill-temporary-buffers.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2389 (while reftex-buffers-to-kill
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2390 (if (bufferp (car reftex-buffers-to-kill))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2391 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2392 (and (buffer-modified-p (car reftex-buffers-to-kill))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2393 (y-or-n-p (format "Save file %s? "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2394 (buffer-file-name
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2395 (car reftex-buffers-to-kill))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2396 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2397 (set-buffer (car reftex-buffers-to-kill))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2398 (save-buffer)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2399 (kill-buffer (car reftex-buffers-to-kill))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2400 (setq reftex-buffers-to-kill (cdr reftex-buffers-to-kill))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2401
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2402 (defun reftex-show-entry ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2403 ;; Show entry if point is hidden by outline mode
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2404 (let ((pos (point)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2405 (if (and reftex-auto-show-entry
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2406 (boundp 'outline-minor-mode)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2407 outline-minor-mode
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2408 (looking-at "[^\n\r]*\r"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2409 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2410 (outline-back-to-heading)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2411 (show-entry)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2412 (goto-char pos)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2413
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2414
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2415 (defun reftex-nicify-text (text)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2416 ;; Make TEXT nice for inclusion into label menu
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2417 (while (string-match "[\n\r\t]\\|[ \t][ \t]+" text) ; remove extra whitespace
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2418 (setq text (replace-match " " nil t text)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2419 (if (string-match "\\\\end{.*" text) ; nothing beyond \end{
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2420 (setq text (replace-match "" nil t text)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2421 (if (string-match "\\\\label{[^}]*}" text) ; kill the label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2422 (setq text (replace-match "" nil t text)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2423 (if (string-match "^ +" text) ; leading whitespace
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2424 (setq text (replace-match "" nil t text)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2425 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2426 ((> (length text) 100) ; not to long
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2427 (setq text (substring text 0 100)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2428 ((= (length text) 0) ; not empty
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2429 (setq text " ")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2430 text)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2431
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2432 (defun reftex-typekey-check (typekey conf-variable &optional n)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2433 ;; Check if CONF-VARIABLE is true or contains TYPEKEY
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2434 (and n (setq conf-variable (nth n conf-variable)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2435 (or (equal conf-variable t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2436 (and (stringp conf-variable)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2437 (string-match (concat "[" conf-variable "]") typekey))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2438
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2439 ;;; ===========================================================================
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2440 ;;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2441 ;;; Table of contents (contributed from Stephen Eglen, changed by C. Dominik)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2442
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2443 ;; We keep at most one *toc* buffer - it is easy to make them
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2444
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2445 (defvar reftex-last-toc-master nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2446 "Stores the name of the tex file that `reftex-toc' was last run on.")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2447
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2448 (defvar reftex-last-toc-file nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2449 "Stores the file name from which `reftex-toc' was called. For redo command.")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2450
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2451 (defvar reftex-toc-return-marker (make-marker)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2452 "Marker which makes it possible to return from toc to old position.")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2453
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2454 (defun reftex-toc ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2455 "Show the table of contents for the current document.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2456 To see the corresponding part of the LaTeX document, use within the
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2457 *toc* buffer:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2458
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2459 SPC Show the corresponding section of the LaTeX document
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2460 RET Goto the section and hide the *toc* buffer
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2461 q Hide the *toc* window and return to position of last reftex-toc command
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2462 Q Kill the *toc* buffer and return to position of last reftex-toc command
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2463 f Toggle follow mode on and off
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2464
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2465 When called with a raw C-u prefix, rescan the document first."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2466
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2467 (interactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2468
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2469 (and (not (string= reftex-last-toc-master (reftex-TeX-master-file)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2470 (get-buffer "*toc*")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2471 (kill-buffer "*toc*"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2472
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2473 (setq reftex-last-toc-file (buffer-file-name))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2474 (setq reftex-last-toc-master (reftex-TeX-master-file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2475
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2476 (set-marker reftex-toc-return-marker (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2477
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2478 ;; if follow mode is active, arrange to delay it one command
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2479 (if reftex-toc-follow-mode
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2480 (setq reftex-toc-follow-mode 1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2481
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2482 (if (and current-prefix-arg
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2483 (get-buffer "*toc*"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2484 (kill-buffer "*toc*"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2485
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2486 ;; Ensure access to scanning info and rescan buffer if prefix are is '(4)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2487 (reftex-access-scan-info current-prefix-arg)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2488
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2489 (let* ((all (symbol-value reftex-list-of-labels-symbol))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2490 (where (reftex-nearest-section))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2491 toc toc1 cell label file find startpos)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2492
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2493 (if (and (get-buffer "*toc*")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2494 (get-buffer-window (get-buffer "*toc*")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2495 (select-window (get-buffer-window (get-buffer "*toc*")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2496 (delete-other-windows)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2497 (switch-to-buffer-other-window (current-buffer))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2498 (switch-to-buffer-other-window (get-buffer-create "*toc*")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2499
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2500 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2501 ;; buffer is empty - fill it with the table of contents
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2502 ((= (buffer-size) 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2503
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2504 (local-set-key " " 'reftex-toc-view-line)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2505 (local-set-key "\C-m" 'reftex-toc-goto-line-and-hide)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2506 (local-set-key "r" 'reftex-toc-redo)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2507 (local-set-key "q" 'reftex-toc-quit)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2508 (local-set-key "Q" 'reftex-toc-quit-and-kill)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2509 (local-set-key "f" 'reftex-toc-toggle-follow)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2510 (setq truncate-lines t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2511 (make-local-hook 'post-command-hook)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2512 (make-local-hook 'pre-command-hook)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2513 (setq post-command-hook '(reftex-toc-post-command-hook))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2514 (setq pre-command-hook '(reftex-toc-pre-command-hook))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2515
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2516 (insert (format
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2517 "TABLE-OF-CONTENTS on %s
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2518 MENU: SPC=view RET=goto [q]uit [Q]uit+kill [r]escan [f]ollow-mode on/off
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2519 -------------------------------------------------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2520 " (abbreviate-file-name reftex-last-toc-master)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2521 (setq startpos (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2522
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2523 (if (reftex-use-fonts)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2524 (put-text-property 1 (point) 'face 'font-lock-keyword-face))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2525 (put-text-property 1 (point) 'intangible t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2526
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2527 (while all
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2528 (setq cell (car all)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2529 all (cdr all))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2530 (setq label (nth 0 cell)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2531 toc (nth 2 cell)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2532 file (nth 3 cell)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2533 find (nth 4 cell))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2534 (if (not label)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2535 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2536 (setq toc1 (concat toc "\n"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2537 (put-text-property 0 (length toc1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2538 'file file toc1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2539 (put-text-property 0 (length toc1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2540 'find find toc1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2541 (insert toc1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2542 )))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2543
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2544 (backward-delete-char 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2545
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2546 (setq buffer-read-only t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2547 (t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2548 (goto-line 3)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2549 (beginning-of-line)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2550 (setq startpos (point))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2551
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2552 ;; Find the correct section
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2553 (goto-char (point-max))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2554 (beginning-of-line)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2555 (while (and (> (point) startpos)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2556 (or (not (string= (get-text-property (point) 'file)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2557 (car where)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2558 (not (string= (get-text-property (point) 'find)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2559 (cdr where)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2560 (beginning-of-line 0))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2561
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2562 (defun reftex-nearest-section ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2563 ;; Return (file . find) of nearest section command
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2564 (let (cell label rest)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2565 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2566 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2567 ;; Try to find a section heading
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2568 ((or (re-search-backward reftex-section-regexp nil t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2569 (re-search-forward reftex-section-regexp nil t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2570 (goto-char (match-end 0))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2571 (cons (buffer-file-name)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2572 (reftex-allow-for-ctrl-m
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2573 (concat (buffer-substring-no-properties
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2574 (1- (match-beginning 1)) (match-end 0))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2575 (reftex-context-substring)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2576 ;; Try to find a label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2577 ((and (or (re-search-backward "\\\\label{\\([^}]+\\)}" nil t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2578 (re-search-forward "\\\\label{\\([^}]+\\)}" nil t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2579 (setq label (reftex-no-props (match-string 1)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2580 (setq cell (assoc label (symbol-value
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2581 reftex-list-of-labels-symbol)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2582 (setq rest (memq cell (symbol-value reftex-list-of-labels-symbol)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2583 (setq cell (car (memq (assoc nil rest) rest)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2584 (null (car cell)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2585 (cons (nth 3 cell) (nth 4 cell)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2586 (t nil)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2587
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2588 (defun reftex-toc-pre-command-hook ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2589 ;; used as pre command hook in *toc* buffer
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2590 (reftex-unhighlight 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2591 (reftex-unhighlight 1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2592
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2593 (defun reftex-toc-post-command-hook ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2594 ;; used in the post-command-hook for the *toc* buffer
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2595 (and (> (point) 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2596 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2597 (reftex-highlight 1
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2598 (progn (beginning-of-line) (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2599 (progn (end-of-line) (point)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2600 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2601 ((integerp reftex-toc-follow-mode)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2602 ;; remove delayed action
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2603 (setq reftex-toc-follow-mode t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2604 (reftex-toc-follow-mode
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2605 ;; show context in other window
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2606 (condition-case nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2607 (reftex-toc-visit-line)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2608 ('error t)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2609
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2610 (defun reftex-toc-toggle-follow ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2611 "Toggle toc-follow mode.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2612 (it is not really a mode, just a flag)."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2613 (interactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2614 (setq reftex-toc-follow-mode (not reftex-toc-follow-mode)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2615 (defun reftex-toc-view-line ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2616 "View document location in other window."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2617 (interactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2618 (reftex-toc-visit-line))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2619 (defun reftex-toc-goto-line-and-hide ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2620 "Go to document location in other window. Hide the *toc* window."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2621 (interactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2622 (reftex-toc-visit-line 'hide))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2623 (defun reftex-toc-quit ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2624 "Hide the *toc* window and do not move point."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2625 (interactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2626 (delete-window)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2627 (switch-to-buffer (marker-buffer reftex-toc-return-marker))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2628 (goto-char (marker-position reftex-toc-return-marker)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2629 (defun reftex-toc-quit-and-kill ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2630 "Kill the *toc* buffer."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2631 (interactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2632 (kill-buffer "*toc*")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2633 (delete-window)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2634 (switch-to-buffer (marker-buffer reftex-toc-return-marker))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2635 (goto-char (marker-position reftex-toc-return-marker)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2636 (defun reftex-toc-redo ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2637 "Regenerate the *toc* buffer. Call only from within the *toc* buffer"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2638 (interactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2639 (switch-to-buffer (reftex-get-file-buffer-force reftex-last-toc-file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2640 (delete-other-windows)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2641 (setq current-prefix-arg '(4))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2642 (reftex-toc))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2643
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2644 (defun reftex-toc-visit-line (&optional final)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2645 ;; Visit the tex file corresponding to the toc entry on the current line.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2646 ;; If FINAL is t, stay there
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2647 ;; If FINAL is 'hide, hide the *toc* window.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2648 ;; Otherwise, move cursor back into *toc* window
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2649
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2650 (let (file find beg end (toc-window (selected-window)) show-window)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2651 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2652 (beginning-of-line)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2653 (setq beg (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2654 (end-of-line)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2655 (setq end (point)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2656
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2657 ;; get the file and the search string
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2658 (setq file (get-text-property (point) 'file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2659 (setq find (get-text-property (point) 'find))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2660 (if (or (not file) (not find))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2661 (error "Cannot visit line"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2662
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2663 (switch-to-buffer-other-window (reftex-get-file-buffer-force file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2664 (setq show-window (selected-window))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2665 (goto-char (point-min))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2666
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2667 (if (not (re-search-forward find nil t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2668 (error "Cannot visit line"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2669
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2670 (setq beg (match-beginning 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2671 end (match-end 0))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2672
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2673 (goto-char beg)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2674 (recenter 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2675 (reftex-highlight 0 beg end (current-buffer))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2676
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2677 (select-window toc-window)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2678
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2679 ;; use the `final' parameter to decide what to do next
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2680 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2681 ((equal final t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2682 (reftex-unhighlight 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2683 (select-window show-window))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2684 ((eq final 'hide)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2685 (reftex-unhighlight 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2686 (delete-window))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2687 (t nil))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2688
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2689 ;;; ===========================================================================
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2690 ;;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2691 ;;; BibTeX citations.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2692
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2693 ;; Variables and constants
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2694
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2695 ;; Internal variable, but used from different functions
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2696 (defvar reftex-cite-format1 nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2697
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2698 ;; The history list of regular expressions used for citations
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2699 (defvar reftex-cite-regexp-hist nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2700
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2701 ;; Help string for citation selection
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2702 (defconst reftex-citation-help
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2703 "AVAILABLE KEYS IN MAKE CITATION MENU
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2704 ---------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2705 n / p Go to next/previous entry (Cursor motion works as well)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2706 r restrict selection with another regexp
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2707 SPACE Show full database entry in other window
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2708 f Toggle follow mode: Other window will follow with full db entry
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2709 q Quit without inserting \\cite macro into buffer
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2710 ? Display this help message
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2711 C-r Recursive edit into other window
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2712 RETURN ... Accept current entry and insert in format according to
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2713 reftex-cite-format")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2714
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2715 (defconst reftex-cite-format-default "\\cite{KEY}"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2716 "The default value for reftex-cite-format.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2717 Uses the string version of scitex-cite-format.")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2718
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2719 (defconst reftex-cite-format-1-author-simple
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2720 '( "\\cite{KEY}" "AUTHOR \\cite{KEY}" "AUTHOR {\it et al.} \\cite{KEY}")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2721 "Value for reftex-cite format establishing a simple citation with name
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2722 of the first author.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2723 Uses the list version of reftex-cite-format.")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2724
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2725 (defconst reftex-cite-format-2-authors
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2726 '((?\C-m
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2727 . ( "\\cite{KEY}" "AUTHOR \\cite{KEY}"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2728 "AUTHOR \\& AUTHOR \\cite{KEY}" "AUTHOR \\etal{} \\cite{KEY}"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2729 (?\,
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2730 . ("\\cite{KEY}" "AUTHOR, \\cite{KEY}"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2731 "AUTHOR \\& AUTHOR, \\cite{KEY}" "AUTHOR \\etal{}, \\cite{KEY}"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2732 (?\;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2733 . ("\\cite{KEY}" "AUTHOR; \\cite{KEY}"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2734 "AUTHOR \\& AUTHOR; \\cite{KEY}" "AUTHOR \\etal{}; \\cite{KEY}"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2735 (?\:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2736 . ("\\cite{KEY}" "AUTHOR: \\cite{KEY}"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2737 "AUTHOR \\& AUTHOR: \\cite{KEY}" "AUTHOR \\etal{}: \\cite{KEY}"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2738 (?\(
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2739 . ("(\\cite{KEY})" "AUTHOR (\\cite{KEY})"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2740 "AUTHOR \\& AUTHOR (\\cite{KEY})" "AUTHOR \\etal{} (\\cite{KEY})"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2741 (?\[
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2742 . ("[\\cite{KEY}]" "AUTHOR [\\cite{KEY}]"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2743 "AUTHOR \\& AUTHOR [\\cite{KEY}]" "AUTHOR \\etal{} [\\cite{KEY}]")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2744 "Value for reftex-cite-format that estabishes an Author/Year citation
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2745 where the year is supplied from BibTeX. Depending on which character
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2746 is used during selection to accept the label, an extra ,;: or pair of
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2747 parenthesis will be inserted.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2748 Uses the list-of-cons-cells version of reftex-cite-format.")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2749
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2750 ;; Find bibtex files
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2751
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2752 (defun reftex-get-bibfile-list ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2753 ;; Return list of bibfiles for current document
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2754
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2755 ;; Ensure access to scanning info
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2756 (reftex-access-scan-info)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2757
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2758 (or (symbol-value reftex-bibfile-list-symbol)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2759 (error "No BibTeX files to parse. Add \\bibliography statment to document and reparse.")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2760
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2761 (defun reftex-scan-buffer-for-bibliography-statement (bib-list-symbol)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2762 ;; Scan buffer for bibliography macro and store file list in bib-list-symbol.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2763 (let (file-list dir-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2764 (setq dir-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2765 (reftex-split
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2766 (concat path-separator "+")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2767 (mapconcat '(lambda(x)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2768 (if (getenv x) (getenv x) ""))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2769 reftex-bibpath-environment-variables
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2770 path-separator)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2771 (goto-char (point-min))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2772 (if (re-search-forward "^[ \t]*\\\\bibliography{[ \t]*\\([^}]+\\)" nil t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2773 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2774 (setq dir-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2775 (cons (file-name-directory
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2776 (get-text-property (match-beginning 0) 'file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2777 dir-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2778 (setq file-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2779 (mapcar '(lambda (x) (concat x ".bib"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2780 (reftex-delete-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2781 reftex-bibfile-ignore-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2782 (reftex-split
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2783 "[ \t\n]*,[ \t\n]*"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2784 (reftex-no-props (match-string 1)))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2785 (message "No \\bibliography command in document."))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2786 (set bib-list-symbol
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2787 (if file-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2788 (reftex-find-files-on-path file-list dir-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2789 "While parsing \\bibliography:")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2790 nil))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2791
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2792 (defun reftex-find-files-on-path (file-list path-list &optional error-string)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2793 ;; Search for all files in FILE-LIST on the PATH-LIST. Return absolute names.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2794 ;; A missing file throws an exception with the error message ERROR-STRING.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2795 (let (found-list found file)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2796 (while file-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2797 (setq file (car file-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2798 file-list (cdr file-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2799 found nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2800 (if (file-name-absolute-p file)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2801 (setq found (expand-file-name file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2802 (let ((dirs path-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2803 (while (and dirs (not found))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2804 (if (and (not (string= (car dirs) ""))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2805 (file-exists-p (expand-file-name file (car dirs))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2806 (setq found (expand-file-name file (car dirs))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2807 (setq dirs (cdr dirs)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2808 (if (and found
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2809 (file-exists-p found))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2810 (add-to-list 'found-list (expand-file-name found))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2811 (error "%s No such file %s."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2812 (or error-string "") file)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2813 (nreverse found-list)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2814
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2815 ;; Find a certain reference in any of the BibTeX files.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2816
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2817 (defun reftex-pop-to-bibtex-entry (key file-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2818 &optional mark-to-kill highlight)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2819 ;; Find BibTeX KEY in any file in FILE-LIST in another window.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2820 ;; If mark-to-kill is non-nil, mark new buffer to kill."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2821
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2822 (let* ((re (concat "@[a-zA-Z]+[ \t\n\r]*{[ \t\n\r]*" (regexp-quote key) "[ \t\n\r,]"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2823 (window-conf (current-window-configuration))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2824 file buf)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2825 (catch 'exit
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2826 (switch-to-buffer-other-window (current-buffer))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2827 (while file-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2828 (setq file (car file-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2829 file-list (cdr file-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2830 (if (not (setq buf (reftex-get-file-buffer-force file mark-to-kill)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2831 (error "No such file %s" file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2832 (switch-to-buffer buf)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2833 (widen)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2834 (goto-char 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2835 (if (re-search-forward re nil t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2836 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2837 (goto-char (match-beginning 0))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2838 (recenter 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2839 (if highlight
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2840 (reftex-highlight 0 (match-beginning 0) (match-end 0)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2841 (throw 'exit (selected-window)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2842 (set-window-configuration window-conf)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2843 (beep)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2844 (message "No BibTeX entry with citation key %s" key))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2845
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2846 ;; Parse bibtex buffers
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2847
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2848 (defun reftex-extract-bib-entries (buffers &optional get-word)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2849 ;; Extract bib entries which match regexps from BUFFERS.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2850 ;; BUFFERS is a list of buffers or file names.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2851 ;; Return list with entries."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2852 (let* (re-list first-re rest-re
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2853 ;; avoid fontification of lookup buffers
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2854 (lazy-lock-minimum-size 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2855 (buffer-list (if (listp buffers) buffers (list buffers)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2856 found-list entry buffer1 buffer alist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2857 key-point start-point end-point)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2858
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2859 (setq re-list (reftex-split "[ \t]*&&[ \t]*"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2860 (read-string "RegExp [ && RegExp...]: "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2861 nil 'reftex-cite-regexp-hist)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2862
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2863 (setq first-re (car re-list) ; We'll use the first re to find things,
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2864 rest-re (cdr re-list)) ; the other to narrow down.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2865 (if (string-match "\\`[ \t]*\\'" first-re)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2866 (error "Empty regular expression"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2867
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2868 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2869 (save-window-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2870
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2871 ;; walk through all bibtex files
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2872 (while buffer-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2873 (setq buffer (car buffer-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2874 buffer-list (cdr buffer-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2875 (if (and (bufferp buffer)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2876 (buffer-live-p buffer))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2877 (setq buffer1 buffer)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2878 (setq buffer1 (reftex-get-file-buffer-force
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2879 buffer (not reftex-keep-temporary-buffers))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2880 (if (not buffer1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2881 (error "Cannot find BibTeX file %s" buffer)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2882 (message "Scanning bibliography database %s" buffer1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2883
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2884 (set-buffer buffer1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2885 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2886 (goto-char (point-min))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2887 (while (re-search-forward first-re nil t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2888 (catch 'search-again
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2889 (setq key-point (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2890 (if (not (re-search-backward
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2891 "^[ \t]*@\\([a-zA-Z]+\\)[ \t\n\r]*{" nil t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2892 (throw 'search-again nil))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2893 (setq start-point (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2894 (goto-char (match-end 0))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2895 (condition-case nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2896 (up-list 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2897 ('error (goto-char key-point)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2898 (throw 'search-again nil)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2899 (setq end-point (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2900
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2901 ;; Ignore @string, @comment and @c entries or things
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2902 ;; outside entries
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2903 (if (or (string= (downcase (match-string 1)) "string")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2904 (string= (downcase (match-string 1)) "comment")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2905 (string= (downcase (match-string 1)) "c")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2906 (< (point) key-point)) ; this means match not in {}
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2907 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2908 (goto-char key-point)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2909 (throw 'search-again nil)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2910
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2911 ;; Well, we have got a match
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2912 (setq entry (concat
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2913 (buffer-substring start-point (point)) "\n"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2914
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2915 ;; Check if other regexp match as well
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2916 (setq re-list rest-re)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2917 (while re-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2918 (if (not (string-match (car re-list) entry))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2919 ;; nope - move on
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2920 (throw 'search-again nil))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2921 (setq re-list (cdr re-list)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2922
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2923 (setq alist (reftex-parse-bibtex-entry
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2924 nil start-point end-point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2925 (setq alist (cons (cons "&entry" entry) alist))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2926
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2927 ;; check for crossref entries
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2928 (if (assoc "crossref" alist)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2929 (setq alist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2930 (append
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2931 alist (reftex-get-crossref-alist alist))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2932
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2933 ;; format the entry
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2934 (setq alist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2935 (cons
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2936 (cons "&formatted"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2937 (reftex-format-bib-entry alist))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2938 alist))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2939
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2940 ;; add it to the list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2941 (setq found-list (cons alist found-list)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2942 (reftex-kill-temporary-buffers))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2943 (setq found-list (nreverse found-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2944
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2945 ;; Sorting
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2946 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2947 ((eq 'author reftex-sort-bibtex-matches)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2948 (sort found-list 'reftex-bib-sort-author))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2949 ((eq 'year reftex-sort-bibtex-matches)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2950 (sort found-list 'reftex-bib-sort-year))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2951 ((eq 'reverse-year reftex-sort-bibtex-matches)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2952 (sort found-list 'reftex-bib-sort-year-reverse))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2953 (t found-list))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2954
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2955 (defun reftex-bib-sort-author (e1 e2)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2956 (let ((al1 (reftex-get-bib-authors e1)) (al2 (reftex-get-bib-authors e2)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2957 (while (and al1 al2 (string= (car al1) (car al2)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2958 (setq al1 (cdr al1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2959 al2 (cdr al2)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2960 (if (and (stringp (car al1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2961 (stringp (car al2)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2962 (string< (car al1) (car al2))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2963 (not (stringp (car al1))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2964
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2965 (defun reftex-bib-sort-year (e1 e2)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2966 (< (string-to-int (cdr (assoc "year" e1)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2967 (string-to-int (cdr (assoc "year" e2)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2968
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2969 (defun reftex-bib-sort-year-reverse (e1 e2)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2970 (> (string-to-int (or (cdr (assoc "year" e1)) "0"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2971 (string-to-int (or (cdr (assoc "year" e2)) "0"))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2972
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2973 (defun reftex-get-crossref-alist (entry)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2974 ;; return the alist from a crossref entry
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2975 (let ((crkey (cdr (assoc "crossref" entry)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2976 start)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2977 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2978 (save-restriction
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2979 (widen)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2980 (if (re-search-forward
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2981 (concat "@\\w+{[ \t\n\r]*" (regexp-quote crkey) "[ \t\n\r]*,") nil t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2982 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2983 (setq start (match-beginning 0))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2984 (condition-case nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2985 (up-list 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2986 ('error nil))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2987 (reftex-parse-bibtex-entry nil start (point)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2988 nil)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2989
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2990 ;; Parse and format individual entries
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2991
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2992 (defun reftex-get-bib-authors (entry)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2993 ;; Return a list with the author names in ENTRY
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2994 (let (authors)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2995 (setq authors (reftex-get-bib-field "author" entry))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2996 (if (equal "" authors)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2997 (setq authors (reftex-get-bib-field "editor" entry)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2998 (while (string-match "\\band\\b[ \t]*" authors)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
2999 (setq authors (replace-match "\n" nil t authors)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3000 (while (string-match "[\\.a-zA-Z\\-]+\\.[ \t]*\\|,.*\\|[{}]+" authors)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3001 (setq authors (replace-match "" nil t authors)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3002 (while (string-match "^[ \t]+\\|[ \t]+$" authors)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3003 (setq authors (replace-match "" nil t authors)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3004 (while (string-match "[ \t][ \t]+" authors)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3005 (setq authors (replace-match " " nil t authors)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3006 (reftex-split "\n" authors)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3007
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3008 (defun reftex-parse-bibtex-entry (entry &optional from to)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3009 (let (alist key start field)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3010 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3011 (save-restriction
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3012 (if entry
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3013 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3014 (switch-to-buffer "*RefTeX-scratch*")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3015 (fundamental-mode)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3016 (erase-buffer)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3017 (insert entry))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3018 (widen)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3019 (narrow-to-region from to))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3020 (goto-char (point-min))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3021
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3022 (if (re-search-forward
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3023 "@\\(\\w+\\)[ \t\n\r]*{[ \t\n\r]*\\([^ \t\n\r,]+\\)" nil t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3024 (setq alist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3025 (list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3026 (cons "&type" (downcase (reftex-no-props (match-string 1))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3027 (cons "&key" (reftex-no-props (match-string 2))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3028 (while (re-search-forward "\\(\\w+\\)[ \t\n\r]*=[ \t\n\r]*" nil t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3029 (setq key (reftex-no-props (downcase (match-string 1))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3030 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3031 ((= (following-char) ?{)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3032 (forward-char 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3033 (setq start (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3034 (condition-case nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3035 (up-list 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3036 ('error nil)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3037 ((= (following-char) ?\")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3038 (forward-char 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3039 (setq start (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3040 (while (and (search-forward "\"" nil t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3041 (= ?\\ (char-after (- (point) 2))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3042 (t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3043 (setq start (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3044 (re-search-forward "[ \t\n\r,}]" nil 1)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3045 (setq field (buffer-substring-no-properties start (1- (point))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3046 ;; remove extra whitesp
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3047 (while (string-match "[\n\t\r]\\|[ \t][ \t]+" field)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3048 (setq field (replace-match " " nil t field)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3049 ;; remove leading garbage
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3050 (if (string-match "^[ \t{]+" field)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3051 (setq field (replace-match "" nil t field)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3052 ;; remove trailing garbage
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3053 (if (string-match "[ \t}]+$" field)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3054 (setq field (replace-match "" nil t field)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3055 (setq alist (cons (cons key field) alist)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3056 alist))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3057
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3058 (defun reftex-get-bib-field (fieldname entry)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3059 ;; Extract the field FIELDNAME from an ENTRY
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3060 (or (cdr (assoc fieldname entry))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3061 ""))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3062
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3063 (defun reftex-format-bib-entry (entry)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3064 ;; Format a BibTeX ENTRY so that it is nice to look at
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3065 (let*
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3066 ((rtn nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3067 (auth-list (reftex-get-bib-authors entry))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3068 (authors (mapconcat '(lambda (x) x) auth-list ", "))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3069 (year (reftex-get-bib-field "year" entry))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3070 (title (reftex-get-bib-field "title" entry))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3071 (type (reftex-get-bib-field "&type" entry))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3072 (key (reftex-get-bib-field "&key" entry))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3073 (extra
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3074 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3075 ((equal type "article")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3076 (concat (reftex-get-bib-field "journal" entry) " "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3077 (reftex-get-bib-field "volume" entry) ", "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3078 (reftex-get-bib-field "pages" entry)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3079 ((equal type "book")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3080 (concat "book (" (reftex-get-bib-field "publisher" entry) ")"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3081 ((equal type "phdthesis")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3082 (concat "PhD: " (reftex-get-bib-field "school" entry)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3083 ((equal type "mastersthesis")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3084 (concat "Master: " (reftex-get-bib-field "school" entry)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3085 ((equal type "inbook")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3086 (concat "Chap: " (reftex-get-bib-field "chapter" entry)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3087 ", pp. " (reftex-get-bib-field "pages" entry)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3088 ((or (equal type "conference")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3089 (equal type "incollection")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3090 (equal type "inproceedings"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3091 (concat "in: " (reftex-get-bib-field "booktitle" entry)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3092 (t ""))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3093 (setq authors
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3094 (if (> (length authors) 30)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3095 (concat (substring authors 0 27) "...")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3096 (format "%-30s" authors))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3097 title
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3098 (if (> (length title) 70)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3099 (concat (substring title 0 67) "...")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3100 (format "%-70s" title))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3101 extra
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3102 (if (> (length extra) 40)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3103 (concat (substring extra 0 37) "...")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3104 (format "%-40s" extra)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3105 (if (reftex-use-fonts)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3106 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3107 (put-text-property 0 (length authors) 'face 'font-lock-keyword-face
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3108 authors)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3109 (put-text-property 0 (length title) 'face 'font-lock-comment-face
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3110 title)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3111 (put-text-property 0 (length extra) 'face 'font-lock-reference-face
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3112 extra)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3113 (setq rtn (concat key "\n " authors " " year " " extra
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3114 "\n " title "\n\n"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3115 rtn))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3116
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3117 ;; Make a citation
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3118
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3119 (defun reftex-citation (&optional arg no-insert)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3120 "Make a citation unsing BibTeX database files.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3121 After asking for a Regular Expression, it scans the buffers with
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3122 bibtex entries (taken from the \\bibliography command) and offers the
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3123 matching entries for selection. The selected entry is formated according
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3124 to reftex-cite-format and inserted into the buffer.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3125 If NO-INSERT is non-nil, nothing is inserted, only the selected key returned.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3126 The regular expression uses an expanded syntax: && is interpreted as 'and'.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3127 Thus, aaaa&&bbb matches entries which contain both aaaa and bbb.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3128 When this function is called with point inside the braces of a \\cite
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3129 command, it will add another key, ignoring the value of reftex-cite-format.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3130 When called with a numeric prefix, that many citations will be made and all
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3131 put into the same \\cite command.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3132 When called with just C-u as prefix, enforces rescan of buffer for
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3133 bibliography statement (e.g. if it was changed)."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3134
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3135 (interactive "P")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3136
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3137 ;; check for recursive edit
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3138 (reftex-check-recursive-edit)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3139
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3140 ;; if there is just 1 C-u prefix arg, force to rescan buffer
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3141 (if (and current-prefix-arg
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3142 (listp current-prefix-arg)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3143 (= 4 (prefix-numeric-value arg)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3144 (reftex-reset-scanning-information))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3145
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3146 ;; check if there is already a cite command at point and change cite format
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3147 ;; in order to only add another reference in the same cite command.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3148 (let ((pos (point)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3149 (search-backward "\\" (point-min) 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3150 (if (and (looking-at "\\\\[a-zA-Z]*cite\\*?\\(\\[[^]]*\\]\\)*{\\([^}]*\\)")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3151 (>= (match-end 0) pos)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3152 (>= pos (match-beginning 2)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3153 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3154 (goto-char pos)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3155 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3156 ((or (not arg)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3157 (not (listp arg)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3158 (setq reftex-cite-format1
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3159 (concat
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3160 (if (not (or (= (preceding-char) ?{)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3161 (= (preceding-char) ?,)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3162 ","
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3163 "")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3164 "KEY"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3165 (if (not (or (= (following-char) ?})
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3166 (= (following-char) ?,)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3167 ","
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3168 ""))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3169 (t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3170 (setq reftex-cite-format1 "KEY"))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3171 (setq reftex-cite-format1
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3172 (if (symbolp reftex-cite-format)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3173 (symbol-value reftex-cite-format)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3174 reftex-cite-format))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3175 (goto-char pos)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3176
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3177 (let* (key entry cnt rtn ins-string re-list re
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3178 ;; scan bibtex files
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3179 (lazy-lock-minimum-size 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3180 (found-list (reftex-extract-bib-entries
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3181 (reftex-get-bibfile-list)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3182 (found-list-r nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3183 (accept-keys
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3184 (if (and (listp reftex-cite-format1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3185 (listp (car reftex-cite-format1)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3186 (mapcar 'car reftex-cite-format1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3187 '(?\C-m))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3188 (if (not found-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3189 (error "Sorry, no matches found"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3190
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3191 ;; remember where we came from
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3192 (setq reftex-call-back-to-this-buffer (current-buffer))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3193
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3194 ;; offer selection
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3195 (save-window-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3196 (switch-to-buffer-other-window "*RefTeX Select*")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3197 (erase-buffer)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3198 (mapcar '(lambda (x) (insert (cdr (assoc "&formatted" x))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3199 found-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3200 (if (= 0 (buffer-size))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3201 (error "Sorry, no matches found"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3202 (setq truncate-lines t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3203 (goto-char 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3204 (if (catch 'exit
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3205 (while t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3206 (setq rtn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3207 (reftex-select-item
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3208 nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3209 (concat
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3210 "Select: [n]ext [p]rev [r]estrict [q]uit [?]Help ||"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3211 " RETURN "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3212 (condition-case nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3213 (mapconcat 'char-to-string accept-keys " ")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3214 (error (error "Illegal reftex-cite-format"))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3215 "^[^ \t\n]"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3216 "\n\n"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3217 4
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3218 reftex-citation-help
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3219 (cons ?r accept-keys)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3220 nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3221 'reftex-bibtex-selection-callback nil))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3222 (setq key (car rtn)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3223 cnt (cdr rtn))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3224 (if (not key) (throw 'exit nil))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3225 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3226 ((equal key ?r)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3227 ;; restrict with new regular expression
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3228 (setq re-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3229 (reftex-split "[ \t]*&&[ \t]*"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3230 (read-string "RegExp [ && RegExp...]: "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3231 nil 'reftex-cite-regexp-hist)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3232 (while re-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3233 (setq re (car re-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3234 re-list (cdr re-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3235 (setq found-list-r
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3236 (delete ""
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3237 (mapcar
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3238 '(lambda (x)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3239 (if (string-match re
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3240 (cdr (assoc "&entry" x)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3241 x
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3242 ""))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3243 found-list))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3244 (if found-list-r
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3245 (setq found-list found-list-r)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3246 (ding))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3247 (erase-buffer)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3248 (mapcar '(lambda (x) (insert (cdr (assoc "&formatted" x))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3249 found-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3250 (goto-char 1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3251 ((or (member key accept-keys)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3252 (equal key ?\C-m)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3253 (equal key 'return))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3254 (setq entry (nth cnt found-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3255 (throw 'exit t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3256 (t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3257 (ding)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3258 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3259 ;; format the entry
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3260 (if (not (integerp key)) (setq key ?\C-m))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3261 (setq ins-string (reftex-format-citation entry key)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3262 (setq ins-string "")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3263 (message "Quit")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3264 (kill-buffer "*RefTeX Select*")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3265
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3266 (if (not no-insert)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3267 (insert ins-string))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3268 (message "")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3269
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3270 ;; Check if the prefix arg was numeric, and call reftex-citation recursively
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3271 (if (and (integerp arg)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3272 (> arg 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3273 (re-search-backward
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3274 "\\\\[a-zA-Z]*cite\\*?\\(\\[[^]]*\\]\\)*{\\([^}]*\\)" nil t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3275 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3276 (goto-char (match-end 0))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3277 (setq arg (1- arg))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3278 (reftex-citation arg))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3279 (reftex-kill-temporary-buffers))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3280 ;; Return the citation key
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3281 (reftex-get-bib-field "&key" entry)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3282
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3283 (defun reftex-format-citation (entry key)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3284 ;; Format a citation from the info in the BibTeX ENTRY
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3285 (let* ((cite-key (reftex-get-bib-field "&key" entry))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3286 (year (reftex-get-bib-field "year" entry))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3287 (auth-list (reftex-get-bib-authors entry))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3288 (nauthors (length auth-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3289 format)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3290
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3291 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3292 ;; Find the correct format
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3293 (if (and (listp reftex-cite-format1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3294 (listp (car reftex-cite-format1)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3295 (if (integerp (car (car reftex-cite-format1)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3296 (if (assoc key reftex-cite-format1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3297 (setq format (cdr (assoc key reftex-cite-format1)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3298 (if (or (equal key ?\C-m)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3299 (equal key 'return))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3300 (setq format (cdr (car reftex-cite-format1)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3301 (error "Error in reftex-cite-format")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3302 (error "Error in reftex-cite-format"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3303 (setq format reftex-cite-format1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3304
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3305 (if (listp format)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3306 (let ((nn (min nauthors (1- (length format)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3307 (while (and (> nn 0) (string= "" (nth nn format)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3308 (setq nn (1- nn)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3309 (setq format (nth nn format))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3310 (if (stringp format)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3311 (setq format format)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3312 (setq format "\\cite{KEY}"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3313
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3314 ;; Insert the author names
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3315 (while (string-match "\\bAUTHOR\\b" format)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3316 (setq format (replace-match (car auth-list) t t format))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3317 (setq auth-list (cdr auth-list)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3318 (while (string-match "\\bKEY\\b" format)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3319 (setq format (replace-match cite-key t t format)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3320 (while (string-match "\\bYEAR\\b" format)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3321 (setq format (replace-match year t t format)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3322 format)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3323
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3324 ;; this is slow and not recommended for follow mode
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3325 (defun reftex-bibtex-selection-callback (cnt)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3326 ;; Callback function to be called from the BibTeX selection, in
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3327 ;; order to display context. This function is relatively slow and not
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3328 ;; recommended for follow mode, just for individual lookups.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3329 ;; When compiled, this gives a warning about found-list. However,
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3330 ;; the calling function binds found-list with let.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3331 (let ((win (selected-window))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3332 (key (reftex-get-bib-field "&key" (nth cnt found-list)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3333 (bibfile-list (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3334 (set-buffer reftex-call-back-to-this-buffer)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3335 (reftex-get-bibfile-list))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3336 (reftex-pop-to-bibtex-entry key bibfile-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3337 (not reftex-keep-temporary-buffers) t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3338 (select-window win)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3339
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3340 ;;; ===========================================================================
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3341 ;;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3342 ;;; Here is the routine used for selection
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3343
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3344 ;; Marker for return point from recursive edit
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3345 (defvar reftex-recursive-edit-marker (make-marker))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3346
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3347 (defun reftex-check-recursive-edit ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3348 ;; Check if we are already in a recursive edit. Abort with helpful
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3349 ;; message if so.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3350 (if (marker-position reftex-recursive-edit-marker)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3351 (error
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3352 (substitute-command-keys
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3353 "In unfinished recursive edit. Finish (\\[exit-recursive-edit]) or abort (\\[abort-recursive-edit])."))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3354
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3355 (defun reftex-select-item (buffer prompt next-re end-re size help-string
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3356 event-list &optional offset
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3357 call-back cb-flag)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3358 ;; Select an item from the buffer BUFFER. Show PROMPT to user, find
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3359 ;; next item with NEXT-RE regular expression, return on any of the
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3360 ;; events listed in EVENT-LIST. The function returns the event along
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3361 ;; with an integer indicating which item was selected. When OFFSET is
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3362 ;; specified, starts at that item in the list. When CALL-BACK is
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3363 ;; given, it is a function which is called with the match of the
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3364 ;; NEXT-RE match and the index of the element.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3365 (let* (key key-sq b e ev cnt cmd
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3366 (offset1 (or offset 1)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3367 (setq ev
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3368 (catch 'exit
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3369 (save-window-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3370 (if buffer
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3371 (switch-to-buffer-other-window buffer))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3372 (if (= 0 (buffer-size))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3373 (throw 'exit nil))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3374 (setq truncate-lines t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3375 (goto-char 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3376 (if (not (re-search-forward next-re nil t offset1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3377 (progn ; in case the offset is illegal
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3378 (setq offset1 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3379 (if (not (re-search-forward next-re nil t offset1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3380 (throw 'exit nil))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3381 (beginning-of-line 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3382 (setq cnt (if offset1 (1- offset1) 0))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3383 (while t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3384 (if (and cb-flag call-back)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3385 (funcall call-back cnt))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3386 (setq b (point)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3387 e (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3388 (save-match-data
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3389 (re-search-forward end-re nil 1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3390 (point)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3391 (reftex-highlight 1 b e)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3392 (if (or (not (pos-visible-in-window-p b))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3393 (not (pos-visible-in-window-p e)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3394 (recenter (/ (window-height) 2)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3395 (setq key-sq (read-key-sequence prompt))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3396 (setq key (car
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3397 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3398 ((fboundp 'listify-key-sequence) ; Emacs
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3399 (listify-key-sequence key-sq))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3400 ((fboundp 'event-to-character) ; XEmacs
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3401 (mapcar 'event-to-character key-sq))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3402 (t (error "Please report this problem to dominik@strw.leidenuniv.nl")))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3403
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3404 (setq cmd (key-binding key-sq))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3405
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3406 (reftex-unhighlight 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3407
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3408 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3409
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3410 ((or (equal key ?n)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3411 (equal key ?\C-i)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3412 (equal cmd 'next-line))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3413 (if (re-search-forward next-re nil t 2)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3414 (setq cnt (1+ cnt)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3415 (beginning-of-line 1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3416
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3417 ((equal cmd 'scroll-up)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3418 (setq cnt (1- cnt))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3419 (while (and (pos-visible-in-window-p)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3420 (re-search-forward next-re nil t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3421 (setq cnt (1+ cnt)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3422 (beginning-of-line 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3423 (recenter 1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3424
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3425 ((or (equal key ?p)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3426 (equal cmd 'previous-line))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3427 (if (re-search-backward next-re nil t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3428 (setq cnt (1- cnt))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3429
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3430 ((equal cmd 'scroll-down)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3431 (while (and (pos-visible-in-window-p)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3432 (re-search-backward next-re nil t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3433 (setq cnt (1- cnt)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3434 (recenter (- (window-height) size 2)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3435
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3436 ((equal key ?q)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3437 (throw 'exit nil))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3438
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3439 ((equal key ?\C-g)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3440 (bury-buffer)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3441 (error "Abort"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3442
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3443 ((or (equal key ?\C-m)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3444 (equal key 'return)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3445 (equal cmd 'newline))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3446 (throw 'exit 'return))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3447
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3448 ((or (equal key ?C) ; backward compatibility
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3449 (equal key ?f))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3450 (setq cb-flag (not cb-flag)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3451
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3452 ((equal key ?\ )
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3453 (funcall call-back cnt))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3454
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3455 ((equal key ?\?)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3456 (save-window-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3457 (with-output-to-temp-buffer "*RefTeX Help*"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3458 (princ help-string))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3459 (setq unread-command-events
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3460 (cons
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3461 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3462 ((fboundp 'read-event) ; Emacs
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3463 (read-event))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3464 ((fboundp 'next-command-event) ; XEmacs
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3465 (next-command-event))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3466 (t (error "Please report this problem to dominik@strw.leidenuniv.nl")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3467 nil)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3468 (kill-buffer "*RefTeX Help*"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3469
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3470 ((equal key ?\C-r)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3471 ;; sje - code copied from ispell.el for
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3472 ;; performing recursive edit
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3473 (set-marker reftex-recursive-edit-marker (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3474 (unwind-protect
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3475 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3476 (save-window-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3477 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3478 (other-window 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3479 (message
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3480 (substitute-command-keys
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3481 "Recursive edit. Return to selection with \\[exit-recursive-edit]"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3482 (recursive-edit)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3483 (if (not (equal (marker-buffer
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3484 reftex-recursive-edit-marker)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3485 (current-buffer)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3486 (error
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3487 "Cannot continue RefTeX from this buffer."))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3488 (goto-char reftex-recursive-edit-marker))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3489 (set-marker reftex-recursive-edit-marker nil)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3490
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3491 ((member key event-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3492 (throw 'exit key))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3493 (t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3494 (ding)))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3495 (message "")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3496 (cons ev cnt)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3497
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3498 ;;; ===========================================================================
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3499 ;;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3500 ;;; View cross references
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3501
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3502 (defun reftex-view-crossref (&optional arg)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3503 "View cross reference of \\ref or \\cite macro at point.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3504 If the macro at point is a \\ref, show the corresponding label definition.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3505 If it is a \\cite, show the BibTeX database entry.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3506 If there is no such macro at point, search forward to find one.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3507 When you call this function several times in direct successtion, point will
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3508 move to view subsequent cross references further down in the buffer.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3509 With argument, actually select the window showing the cross reference."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3510
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3511 (interactive "P")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3512
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3513 ;; See where we are.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3514 (let* ((pos (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3515 (re "\\\\[a-z]*\\(cite\\|ref\\)\\(\\[[^{}]*\\]\\)?{\\([^}]+\\)}")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3516 (my-window (get-buffer-window (current-buffer)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3517 pop-window cmd args macro label entry key-start point)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3518
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3519 (if (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3520 (forward-char 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3521 (and (search-backward "\\" nil t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3522 (looking-at re)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3523 (< pos (match-end 0))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3524 (setq macro (match-string 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3525 key-start (match-beginning 3)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3526
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3527 (if (and macro (eq last-command this-command))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3528 (if (and (string= macro "cite")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3529 (skip-chars-forward "^}, \t\n\r")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3530 (= (following-char) ?,))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3531 (setq key-start (1+ (point)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3532 (setq macro nil)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3533
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3534 (if (not macro)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3535 (if (re-search-forward re nil t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3536 (setq macro (match-string 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3537 key-start (match-beginning 3))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3538 (error "No further cross references in buffer")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3539
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3540 (goto-char key-start)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3541
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3542 ;; Ensure access to scanning info
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3543 (reftex-access-scan-info)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3544
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3545 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3546 ((string= macro "cite")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3547 (setq cmd 'reftex-pop-to-bibtex-entry
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3548 args (list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3549 (reftex-no-props (reftex-this-word "^{},"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3550 (reftex-get-bibfile-list) nil t)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3551 ((string= macro "ref")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3552 (let ((label (reftex-no-props (reftex-this-word "^{}")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3553 (entry (assoc label (symbol-value reftex-list-of-labels-symbol))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3554 (if entry
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3555 (setq cmd 'reftex-pop-to-label
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3556 args (list label (list (nth 3 entry)) nil t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3557 (error "Label %s not known - reparse document might help" label))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3558 (t (error "This should not happen")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3559 (setq point (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3560 (apply cmd args)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3561 (setq pop-window (selected-window))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3562 (add-hook 'pre-command-hook 'reftex-highlight-shall-die)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3563 (select-window my-window)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3564 (goto-char point)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3565 (and arg (select-window pop-window))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3566
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3567 (defun reftex-mouse-view-crossref (ev)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3568 "View cross reference of \\ref or \\cite macro where you click.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3569 If the macro at point is a \\ref, show the corresponding label definition.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3570 If it is a \\cite, show the BibTeX database entry.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3571 If there is no such macro at point, search forward to find one.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3572 With argument, actually select the window showing the cross reference."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3573 (interactive "e")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3574 (mouse-set-point ev)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3575 (reftex-view-crossref current-prefix-arg))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3576
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3577 ;;; ===========================================================================
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3578 ;;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3579 ;;; Functions that check out the surroundings
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3580
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3581 (defun reftex-what-macro (which &optional bound)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3582 ;; Find out if point is within the arguments of any TeX-macro.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3583 ;; The return value is either (\"\\\\macro\" . (point)) or a list of them.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3584
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3585 ;; If WHICH is nil, immediately return nil.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3586 ;; If WHICH is t, return list of all macros enclosing point.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3587 ;; If WHICH is a list of macros, look only for those macros and return the
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3588 ;; name of the first macro in this list found to enclose point.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3589 ;; If the optional BOUND is an integer, bound backwards directed
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3590 ;; searches to this point. If it is nil, limit to nearest \\section -
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3591 ;; like statement.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3592
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3593 ;; This function is pretty stable, but can be fooled if the text contains
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3594 ;; things like \\macro{aa}{bb} where \\macro is defined to take only one
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3595 ;; argument. As RefTeX cannot know this, the string \"bb\" would still be
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3596 ;; considered an argument of macro \\macro.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3597
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3598 (catch 'exit
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3599 (if (null which) (throw 'exit nil))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3600 (let ((bound (or bound (save-excursion (re-search-backward
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3601 reftex-section-regexp nil 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3602 (point))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3603 pos cmd-list cmd)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3604 (save-restriction
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3605 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3606 (narrow-to-region (max 1 bound) (point-max))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3607 ;; move back out of the current parenthesis
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3608 (while (condition-case nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3609 (progn (up-list -1) t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3610 (error nil))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3611 ;; move back over any touching sexps
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3612 (while (or (= (preceding-char) ?\])
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3613 (= (preceding-char) ?\}))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3614 (backward-sexp))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3615 (setq pos (point))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3616 (if (and (or (= (following-char) ?\[)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3617 (= (following-char) ?\{))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3618 (and (re-search-backward "\\(\\\\[a-zA-Z]+\\)" nil t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3619 (= (match-end 0) pos)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3620 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3621 (setq cmd (buffer-substring-no-properties
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3622 (match-beginning 0) (match-end 0)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3623 (if (eq t which)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3624 (setq cmd-list (cons (cons cmd (point)) cmd-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3625 (if (member cmd which)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3626 (throw 'exit (cons cmd (point)))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3627 (goto-char pos)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3628 (nreverse cmd-list)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3629
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3630 (defun reftex-what-environment (which &optional bound)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3631 ;; Find out if point is inside a LaTeX environment.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3632 ;; The return value is (e.g.) either (\"equation\" . (point)) or a list of
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3633 ;; them.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3634
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3635 ;; If WHICH is nil, immediately return nil.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3636 ;; If WHICH is t, return list of all environments enclosing point.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3637 ;; If WHICH is a list of environments, look only for those environments and
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3638 ;; return the name of the first environment in this list found to enclose
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3639 ;; point.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3640
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3641 ;; If the optional BOUND is an integer, bound backwards directed searches to
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3642 ;; this point. If it is nil, limit to nearest \\section - like statement.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3643
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3644 (catch 'exit
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3645 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3646 (if (null which) (throw 'exit nil))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3647 (let ((bound (or bound (save-excursion (re-search-backward
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3648 reftex-section-regexp nil 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3649 (point))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3650 env-list end-list env)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3651 (while (re-search-backward "\\\\\\(begin\\|end\\){\\([^}]+\\)}"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3652 bound t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3653 (setq env (buffer-substring-no-properties
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3654 (match-beginning 2) (match-end 2)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3655 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3656 ((string= (match-string 1) "end")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3657 (add-to-list 'end-list env))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3658 ((member env end-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3659 (setq end-list (delete env end-list)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3660 ((eq t which)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3661 (setq env-list (cons (cons env (point)) env-list)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3662 ((member env which)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3663 (throw 'exit (cons env (point))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3664 (nreverse env-list)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3665
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3666 (defun reftex-word-before-point ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3667 ;; Return the word before point. Word means here:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3668 ;; Consists of [a-zA-Z0-9.:] and ends at point or whitespace.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3669 (let ((pos (point)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3670 (save-excursion
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3671 (re-search-backward "[^ \t\n\r]" (point-min) 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3672 (setq pos (1+ (point)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3673 (if (re-search-backward "[^a-zA-Z0-9\\\.:]" (point-min) 1)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3674 (forward-char 1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3675 (buffer-substring-no-properties (point) pos))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3676
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3677 ;; ============================================================================
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3678 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3679 ;; Some generally useful functions
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3680
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3681 (defun reftex-no-props (string)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3682 ;; Return STRING with all text properties removed
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3683 (and (stringp string)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3684 (set-text-properties 0 (length string) nil string))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3685 string)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3686
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3687 (defun reftex-split (regexp string)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3688 ;; Split like perl
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3689 (let ((start 0) list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3690 (while (string-match regexp string start)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3691 (setq list (cons (substring string start (match-beginning 0)) list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3692 (setq start (match-end 0)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3693 (setq list (nreverse (cons (substring string start) list)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3694
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3695 (defun reftex-allow-for-ctrl-m (string)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3696 ;; convert STRING into a regexp, allowing ^M for \n
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3697 (let ((start -2))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3698 (setq string (regexp-quote string))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3699 (while (setq start (string-match "[\n\r]" string (+ 3 start)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3700 (setq string (replace-match "[\n\r]" nil t string)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3701 string))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3702
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3703 (defun reftex-delete-list (elt-list list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3704 ;; like delete, but with a list of things to delete
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3705 ;; (original code from Rory Molinari)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3706 (while elt-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3707 (setq list (delete (car elt-list) list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3708 elt-list (cdr elt-list)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3709 list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3710
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3711 (defun reftex-get-buffer-visiting (file)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3712 ;; return a buffer visiting FILE
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3713 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3714 ((fboundp 'find-buffer-visiting) ; Emacs
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3715 (find-buffer-visiting file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3716 ((boundp 'find-file-compare-truenames) ; XEmacs
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3717 (let ((find-file-compare-truenames t))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3718 (get-file-buffer file)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3719 (t (error "Please report this problem to dominik@strw.leidenuniv.nl"))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3720
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3721 (defun reftex-get-file-buffer-force (file &optional mark-to-kill)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3722 ;; Return a buffer visiting file. Make one, if necessary.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3723 ;; If neither such a buffer no the file exist, return nil.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3724 ;; If MARK-TO-KILL in non-nil, put any new buffers into the kill list."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3725
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3726 (let ((buf (reftex-get-buffer-visiting file)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3727 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3728 (buf buf)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3729 ((file-exists-p file)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3730 (setq buf (find-file-noselect file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3731 (if mark-to-kill
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3732 (add-to-list 'reftex-buffers-to-kill buf))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3733 buf)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3734 (t nil))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3735
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3736 (defun reftex-splice-symbols-into-list (list alist)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3737 ;; Splice the association in ALIST of any symbols in LIST into the list.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3738 ;; Return new list.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3739 (let (rtn tmp)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3740 (while list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3741 (while (and (not (null (car list)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3742 (symbolp (car list)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3743 (setq tmp (car list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3744 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3745 ((assoc tmp alist)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3746 (setq list (append (cdr (cdr (assoc tmp alist))) (cdr list))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3747 (t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3748 (error "Cannot treat symbol %s in reftex-label-alist"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3749 (symbol-name tmp)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3750 (setq rtn (cons (car list) rtn)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3751 list (cdr list)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3752 (nreverse rtn)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3753
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3754 (defun reftex-uniquify (alist &optional keep-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3755 ;; Return a list of all elements in ALIST, but each car only once
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3756 ;; Elements of KEEP-LIST are not removed even if duplicate
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3757 (let (new elm)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3758 (while alist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3759 (setq elm (car alist)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3760 alist (cdr alist))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3761 (if (or (member (car elm) keep-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3762 (not (assoc (car elm) new)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3763 (setq new (cons elm new))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3764 (setq new (nreverse new))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3765 new))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3766
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3767 (defun reftex-use-fonts ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3768 ;; Return t if we can and want to use fonts
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3769 (and window-system
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3770 reftex-use-fonts
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3771 (boundp 'font-lock-keyword-face)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3772
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3773 ;; Highlighting uses overlays. If this is for XEmacs, we need to load
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3774 ;; the overlay library, available in version 19.15
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3775 (and (not (fboundp 'make-overlay))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3776 (condition-case nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3777 (require 'overlay)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3778 ('error
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3779 (error "RefTeX needs overlay emulation (available in XEmacs 19.15)"))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3780
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3781 ;; We keep a vector with several different overlays to do our highlighting.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3782 (defvar reftex-highlight-overlays [nil nil])
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3783
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3784 ;; Initialize the overlays
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3785 (aset reftex-highlight-overlays 0 (make-overlay 1 1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3786 (overlay-put (aref reftex-highlight-overlays 0) 'face 'highlight)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3787 (aset reftex-highlight-overlays 1 (make-overlay 1 1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3788 (overlay-put (aref reftex-highlight-overlays 1) 'face 'highlight)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3789
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3790 ;; Two functions for activating and deactivation highlight overlays
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3791 (defun reftex-highlight (index begin end &optional buffer)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3792 "Highlight a region with overlay INDEX."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3793 (move-overlay (aref reftex-highlight-overlays index)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3794 begin end (or buffer (current-buffer))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3795 (defun reftex-unhighlight (index)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3796 "Detatch overlay INDEX."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3797 (delete-overlay (aref reftex-highlight-overlays index)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3798
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3799 (defun reftex-highlight-shall-die ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3800 ;; Function used in pre-command-hook to remove highlights
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3801 (remove-hook 'pre-command-hook 'reftex-highlight-shall-die)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3802 (reftex-unhighlight 0))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3803
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3804 ;;; ---------------------------------------------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3805 ;;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3806 ;;; Cursor position after insertion of forms
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3807
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3808 (defun reftex-position-cursor ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3809 ;; Search back to question mark, delete it, leave point there
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3810 (if (search-backward "\?" (- (point) 100) t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3811 (delete-char 1)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3812
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3813 (defun reftex-item ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3814 "Insert an \\item and provide a label if the environments supports that."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3815 (interactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3816 (let ((env (car
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3817 (reftex-what-environment '("itemize" "enumerate" "eqnarray")))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3818
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3819 (if (and env (not (bolp))) (newline))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3820
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3821 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3822
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3823 ((string= env "eqnarray")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3824 (if (not (bolp))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3825 (newline))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3826 (reftex-label env)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3827 (insert "\n & & ")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3828 (beginning-of-line 1))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3829
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3830 ((string= env "itemize")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3831 (newline)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3832 (insert "\\item "))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3833
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3834 ((string= env "enumerate")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3835 (newline)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3836 (insert "\\item")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3837 (reftex-label env)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3838 (insert " "))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3839 (t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3840 (error "\\item command does not make sense here...")))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3841
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3842 ;;; ---------------------------------------------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3843 ;;; ---------------------------------------------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3844 ;;; ---------------------------------------------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3845 ;;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3846 ;;; Data Section: Definition of large constants
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3847
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3848
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3849 (defconst reftex-label-alist-builtin
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3850 '(
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3851 (LaTeX
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3852 "LaTeX default environments"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3853 ("section" ?s "sec:" "~\\ref{%s}" t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3854 ("Part" "Chapter" "Chap." "Section" "Sec." "Sect." "Paragraph" "Par."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3855 "\\S" "Teil" "Kapitel" "Kap." "Abschnitt" ))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3856
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3857 ("enumerate" ?n "item:" "~\\ref{%s}" "\\\\item\\(\\[[^]]*\\]\\)?"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3858 ("Item" "Punkt"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3859
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3860 ("equation" ?e "eq:" "~(\\ref{%s})" t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3861 ("Equation" "Eq." "Eqn." "Gleichung" "Gl."))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3862 ("eqnarray" ?e "eq:" nil "\\\\begin{eqnarray}\\|\\\\\\\\")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3863
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3864 ("figure" ?f "fig:" "~\\ref{%s}" "\\\\caption\\(\\[[^]]*\\]\\)?{"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3865 ("Figure" "Fig." "Abbildung" "Abb."))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3866 ("figure*" ?f nil nil "\\\\caption\\(\\[[^]]*\\]\\)?{")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3867
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3868 ("table" ?t "tab:" "~\\ref{%s}" "\\\\caption\\(\\[[^]]*\\]\\)?{"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3869 ("Table" "Tab." "Tabelle"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3870 ("table*" ?t nil nil "\\\\caption\\(\\[[^]]*\\]\\)?{")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3871
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3872 ("any" ?\ " " "\\ref{%s}" nil))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3873
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3874 (Sideways
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3875 "Sidewaysfigure and sidewaystable"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3876 ("sidewaysfigure" ?f nil nil "\\\\caption\\(\\[[^]]*\\]\\)?{")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3877 ("sidewaystable" ?t nil nil "\\\\caption\\(\\[[^]]*\\]\\)?{"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3878
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3879 (AMSTeX
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3880 "AMS-LaTeX: amsmath package environents"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3881 ("align" ?e "eq:" "~\\eqref{%s}" "\\\\begin{align}\\|\\\\\\\\")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3882 ("gather" ?e "eq:" nil "\\\\begin{gather}\\|\\\\\\\\")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3883 ("multline" ?e "eq:" nil t)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3884 ("flalign" ?e "eq:" nil "\\\\begin{flalign}\\|\\\\\\\\")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3885 ("alignat" ?e "eq:" nil "\\\\begin{alignat}{[0-9]*}\\|\\\\\\\\"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3886
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3887 (AASTeX
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3888 "AAS deluxetable environment"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3889 ("deluxetable" ?t "tab:" nil "\\\\caption{")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3890 "The default label environment descriptions.")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3891
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3892 ;;; ---------------------------------------------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3893 ;;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3894 ;;; Functions to compile the tables, reset the mode etc.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3895
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3896 (defun reftex-reset-mode ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3897 "Reset RefTeX Mode. Required to implement changes to some list variables.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3898 This function will compile the information in reftex-label-alist and similar
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3899 variables. It is called when RefTeX is first used, and after changes to
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3900 these variables via reftex-add-to-label-alist."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3901 (interactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3902
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3903 ; record that we have done this
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3904 (setq reftex-tables-dirty nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3905
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3906 ;; To update buffer-local variables
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3907 (hack-local-variables)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3908 (message "updating internal tables...")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3909 (reftex-compute-ref-cite-tables)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3910 (message "updating internal tables... done")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3911 (reftex-reset-scanning-information))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3912
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3913 (defun reftex-reset-scanning-information ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3914 "Reset the symbols containing information from buffer scanning.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3915 This enforces rescanning the buffer on next use."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3916 (if (and (string= reftex-last-toc-master (reftex-TeX-master-file))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3917 (get-buffer "*toc*"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3918 (kill-buffer "*toc*"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3919 (let ((symlist reftex-multifile-symbols)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3920 symbol)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3921 (while symlist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3922 (setq symbol (car symlist)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3923 symlist (cdr symlist))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3924 (if (and (symbolp (symbol-value symbol))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3925 (not (null (symbol-value symbol))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3926 (set (symbol-value symbol) nil)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3927
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3928 (defun reftex-compute-ref-cite-tables ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3929 ;; Update ref and cite tables
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3930
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3931 (interactive)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3932
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3933 ;; Compile information in reftex-label-alist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3934 (let ((tmp (reftex-uniquify (reftex-splice-symbols-into-list
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3935 (append
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3936 reftex-label-alist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3937 reftex-label-alist-external-add-ons
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3938 reftex-default-label-alist-entries)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3939 reftex-label-alist-builtin)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3940 '(nil)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3941 entry env-or-mac typekeychar typekey prefix regexp
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3942 fmt wordlist cmd qh-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3943
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3944 (setq reftex-words-to-typekey-alist nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3945 reftex-typekey-list nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3946 reftex-typekey-to-format-alist nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3947 reftex-typekey-to-prefix-alist nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3948 reftex-env-or-mac-alist nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3949 reftex-label-env-list nil
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3950 reftex-label-mac-list nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3951 (while tmp
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3952 (catch 'next-entry
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3953 (setq entry (car tmp)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3954 env-or-mac (car entry)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3955 entry (cdr entry)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3956 tmp (cdr tmp))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3957 (if (null env-or-mac)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3958 (setq env-or-mac ""))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3959 (if (stringp (car entry))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3960 ;; This is before version 2.00 - convert entry to new format
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3961 ;; This is just to keep old users happy
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3962 (setq entry (cons (string-to-char (car entry))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3963 (cons (concat (car entry) ":")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3964 (cdr entry)))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3965 (setq typekeychar (nth 0 entry)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3966 typekey (char-to-string typekeychar)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3967 prefix (nth 1 entry)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3968 fmt (nth 2 entry)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3969 regexp (nth 3 entry)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3970 wordlist (nth 4 entry))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3971 (if (stringp wordlist)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3972 ;; This is before version 2.04 - convert to new format
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3973 (setq wordlist (nthcdr 4 entry)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3974 (if typekey
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3975 (add-to-list 'reftex-typekey-list typekey))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3976 (if (and typekey prefix)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3977 (add-to-list 'reftex-typekey-to-prefix-alist (cons typekey prefix)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3978 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3979 ((string-match "\\`\\\\" env-or-mac)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3980 ;; It's a macro
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3981 (add-to-list 'reftex-label-mac-list env-or-mac))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3982 (t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3983 (or (string= env-or-mac "any")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3984 (string= env-or-mac "")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3985 (add-to-list 'reftex-label-env-list env-or-mac))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3986 (and fmt
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3987 (not (assoc typekey reftex-typekey-to-format-alist))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3988 (setq reftex-typekey-to-format-alist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3989 (cons (cons typekey fmt)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3990 reftex-typekey-to-format-alist)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3991 (and (not (string= env-or-mac "any"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3992 (not (string= env-or-mac ""))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3993 (not (assoc env-or-mac reftex-env-or-mac-alist))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3994 (setq reftex-env-or-mac-alist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3995 (cons (list env-or-mac typekey regexp)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3996 reftex-env-or-mac-alist)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3997 (while (and wordlist (stringp (car wordlist)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3998 (or (assoc (car wordlist) reftex-words-to-typekey-alist)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
3999 (setq reftex-words-to-typekey-alist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4000 (cons (cons (downcase (car wordlist)) typekey)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4001 reftex-words-to-typekey-alist)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4002 (setq wordlist (cdr wordlist)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4003 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4004 ((string= "" env-or-mac) nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4005 ((assoc typekey qh-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4006 (setcdr (assoc typekey qh-list)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4007 (concat (cdr (assoc typekey qh-list)) " " env-or-mac)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4008 (t
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4009 (setq qh-list (cons (cons typekey env-or-mac) qh-list))))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4010
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4011 (setq qh-list (nreverse qh-list))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4012 (setq reftex-typekey-to-prefix-alist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4013 (nreverse reftex-typekey-to-prefix-alist))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4014 (setq reftex-type-query-prompt
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4015 (concat "Label type: "
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4016 (mapconcat '(lambda(x)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4017 (format "[%s]" (car x)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4018 qh-list " ")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4019 " (?=Help)"))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4020 (setq reftex-type-query-help
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4021 (concat "SELECT A LABEL TYPE:\n--------------------\n"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4022 (mapconcat '(lambda(x)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4023 (format " [%s] %s"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4024 (car x) (cdr x)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4025 qh-list "\n")))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4026
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4027 ;;; Keybindings --------------------------------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4028
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4029 (define-key reftex-mode-map "\C-c-" 'reftex-item)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4030 (define-key reftex-mode-map "\C-c=" 'reftex-toc)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4031 (define-key reftex-mode-map "\C-c(" 'reftex-label)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4032 (define-key reftex-mode-map "\C-c)" 'reftex-reference)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4033 (define-key reftex-mode-map "\C-c[" 'reftex-citation)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4034 (define-key reftex-mode-map "\C-c&" 'reftex-view-crossref)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4035
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4036 ;; If the user requests so, she can have a few more bindings:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4037 (cond
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4038 (reftex-extra-bindings
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4039 (define-key reftex-mode-map "\C-ct" 'reftex-toc)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4040 (define-key reftex-mode-map "\C-cl" 'reftex-label)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4041 (define-key reftex-mode-map "\C-cr" 'reftex-reference)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4042 (define-key reftex-mode-map "\C-cc" 'reftex-citation)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4043 (define-key reftex-mode-map "\C-cv" 'reftex-view-crossref)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4044 (define-key reftex-mode-map "\C-cg" 'reftex-grep-document)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4045 (define-key reftex-mode-map "\C-cs" 'reftex-search-document)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4046
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4047 ;;; Menus --------------------------------------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4048
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4049 ;; Define a menu for the menu bar if Emacs is running under X
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4050
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4051 (require 'easymenu)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4052
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4053 (easy-menu-define
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4054 reftex-mode-menu reftex-mode-map
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4055 "Menu used in RefTeX mode"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4056 '("Ref"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4057 ["Table of Contents" reftex-toc t]
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4058 "----"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4059 ["\\label" reftex-label t]
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4060 ["\\ref" reftex-reference t]
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4061 ["\\cite" reftex-citation t]
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4062 ["View crossref" reftex-view-crossref t]
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4063 "----"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4064 ("Search and Replace"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4065 ["Search whole document" reftex-search-document t]
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4066 ["Replace in document" reftex-query-replace-document t]
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4067 ["Grep on document" reftex-grep-document t]
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4068 "----"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4069 ["Find duplicate labels" reftex-find-duplicate-labels t]
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4070 ["Change label and refs" reftex-change-label t]
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4071 "----"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4072 ["Create TAGS file" reftex-create-tags-file t])
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4073 "----"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4074 ["Parse document" reftex-parse-document t]
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4075 ["Reset RefTeX Mode" reftex-reset-mode t]
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4076 ["Customize RefTeX" reftex-customize t]))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4077
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4078 ;;; Run Hook ------------------------------------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4079
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4080 (run-hooks 'reftex-load-hook)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4081
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4082 ;;; That's it! ----------------------------------------------------------------
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4083
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4084 ; Make sure tabels are compiled
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4085 (message "updating internal tables...")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4086 (reftex-compute-ref-cite-tables)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4087 (setq reftex-tables-dirty nil)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4088
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4089 (provide 'reftex)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4090
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4091 ;;;============================================================================
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4092
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents:
diff changeset
4093 ;;; reftex.el end here