diff options
| author | Richard M. Stallman | 1998-02-03 06:26:34 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1998-02-03 06:26:34 +0000 |
| commit | 2faef4099610e9d040798506566c416d20d1bef2 (patch) | |
| tree | 552db5967d5d1fc22b74f86772cade5b78d2781b | |
| parent | 0fdb64d4ab3e23df82472a0b5aa6e869db1fd582 (diff) | |
| download | emacs-2faef4099610e9d040798506566c416d20d1bef2.tar.gz emacs-2faef4099610e9d040798506566c416d20d1bef2.zip | |
(reftex-toc): Fixed bug with split-window. Using
split-window instead of split-window-vertically.
(reftex-reset-mode): Removed obsolete buffer from kill list.
(reftex-make-and-insert-label-list, reftex-do-citation): Delete
other windows before displaying selection.
(reftex-cite-format-builtin): Fixed bug in Chicago format.
(reftex-enlarge-to-fit): New function.
(reftex-nicify-text): Cut context-string at \item,\\. Changed
match sequence for efficiency reasons.
(reftex-parse-from-file): Include files can be ignored with
`reftex-no-include-regexps'.
(reftex-no-include-regexps): New option.
(reftex-do-parse): Initialize appendix flag.
(reftex-parse-from-file): Interprete appendix.
(reftex-section-info): Use changed version of reftex-section-number.
(reftex-where-am-I): Interprete appendix match.
(reftex-init-section-numbers): New arg: appendix.
(reftex-section-number): Treat appendix enumeration.
(reftex-toc-external): Improved message.
(reftex-compute-ref-cite-tables): Regular expression extended for appendix.
(reftex-toc-rescan): Renamed from reftex-toc-redo.
(reftex-toc-Rescan): Renamed from reftex-toc-Redo.
(reftex-toc-revert): New function.
(reftex-select-external-document): Completion on label prefixes.
(reftex-find-file-on-path): Added an extra call to
expand-file-name for the directory.
(reftex-locate-bibliography-files): Added expand-file-name call.
(reftex-guess-label-type): New function.
(reftex-word-before-point): Function removed.
(reftex-reference): Uses reftex-guess-label-type. Changed meaning
of `~' in reference format. Magic words are regular expressions.
(reftex-compute-ref-cite-tables): Convert magic words to regexps.
(reftex-select-label-maps): Default bindings for TAB, up, down, RET.
(reftex-select-read-string): Now uses completion.
(reftex-make-and-insert-label-list): Prepare for completion.
(reftex-where-am-I): Fixed bug with input files.
(reftex-save-all-document-buffers): New command.
(reftex-select-next-heading): New function.
(reftex-select-previous-heading): New function.
(reftex-select-read-string): New function.
(reftex-offer-label-menu): Handle string value from reftex-select-item.
(reftex-reference): Fixed bug (missing save-excursion).
(reftex-toc-map): Added binding for ?n and ?p.
(reftex-do-citation): Changed to use reftex-default-bibliography.
(reftex-default-bibliography): New option.
(reftex-find-tex-file): Check for file-name-absolute-p first.
(reftex-format-label-function,reftex-format-ref-function,
reftex-format-cite-function): New hooks
(reftex-info): New function.
(reftex-compute-ref-cite-tables): Removed interactive form.
(reftex-where-am-I): Removed interactive form
(reftex-format-names): Removed interactive form
(reftex-vref-is-default): New customization variable
(reftex-mode-menu): Capitalize citation options
(reftex-last-cnt): Variable removed.
(reftex-last-data,reftex-last-line): New variables.
(reftex-select-toggle-varioref): New function.
(reftex-offer-label-menu): Changed mode-line-format for varioref.
(reftex-select-label-help): Help string updated.
(reftex-do-parse): Fixed bug with empty xr list.
(reftex-view-crossref): Prefix argument interpretation changed.
(reftex-get-offset): New function.
(reftex-label): Remove selection buffer to force update.
(reftex-access-scan-info): Remove selection buffers.
(reftex-select-external-document): Fixed bug with highest index.
(reftex-label-index-list, reftex-found-list): Variables removed.
(reftex-offer-label-menu, reftex-make-and-insert-label-list)
(reftex-select-item, reftex-citation, reftex-select-label-callback)
(reftex-bibtex-selection-callback,reftex-select-callback): Changed
to put the scan data directly into the text property :data,
instead of doing this indirectly with an index-list.
(reftex-make-selection-buffer-name): New function.
(reftex-tie-multifile-symbols): Store master-index-as-property.
(reftex-kill-buffer): New function.
(reftex-erase-buffer): New function.
(reftex-erase-all-selection-buffers): New function.
(reftex-mode-menu): Button "Restore from file" no longer sensitive
to existence of the file. This had caused problems for LateX
style files. Quoted `:style' and `:selected' for compatibility.
(reftex-access-parse-file): `Restore' action now throws an
exception when the file is not found.
(reftex-create-customize-menu): New function.
(reftex-label): Fixed bug which made naked labels in \footnotes.
(reftex-select-label-map, reftex-select-bib-map): New keymaps for
the RefTeX Select buffer.
(reftex-select-next, reftex-select-previous, reftex-select-scroll-down)
(reftex-select-scroll-up, reftex-select-quit)
(reftex-select-toggle-follow, reftex-select-callback)
(reftex-select-accept, reftex-select-help)
(reftex-select-recursive-edit, reftex-select-search-forward)
(reftex-select-search-backward, reftex-select-search)
(reftex-select-scroll-other-window)
(reftex-select-scroll-other-window-down):
New commands for use in the two new keymaps.
(reftex-select-item): Now uses the appropriate keymaps.
(reftex-toc-map): New keymap (a keymap for the toc buffer.
(reftex-toc): Now uses reftex-toc-map.
(reftex-fontify-select-label-buffer): New function
(reftex-select-font-lock-fontify-region): New function.
(reftex-make-and-insert-label-list): Refontification now uses
`reftex-select-font-lock-fontify-region'.
(reftex-show-entry): Refontification generalized.
(reftex-select-search-minibuffer-map): New constant.
(reftex-parse-from-file): Look for \begin{thebibliography}
(reftex-do-citation): Check also for thebibliography
(reftex-bibtex-selection-callback): Handle bibitem.
(reftex-view-crossref): Handle bibitem.
(reftex-extract-bib-entries-from-thebibliography): New function.
(reftex-format-bibitem): New function.
(reftex-parse-bibitem): New function.
(reftex-make-desparate-section-regexp): Changed name to
reftex-make-desperate-section-regexp.
(reftex-do-parse, reftex-locate-bibliography-files)
(reftex-string-to-label, reftex-select-external-document)
(reftex-find-duplicate-labels, reftex-format-bib-entry)
(reftex-do-citation, reftex-insert-bib-matches)
(reftex-select-search-minibuffer-map, reftex-access-search-path)
(reftex-compute-ref-cite-tables, reftex-recursive-directory-list):
All lambda expressions now quoted with `function'.
(reftex-view-crossref,reftex-mouse-view-crossref): Fixed bug with
multiple calls.
(reftex-get-buffer-visiting): Error message changed.
(reftex-select-external-document, reftex-query-label-type)
(reftex-do-citation, reftex-select-help):
Use `reftex-enlarge-to-fit' now.
(reftex-pop-to-bibtex-entry): No longer beep on failure, to make
it work better with follow mode.
| -rw-r--r-- | lisp/textmodes/reftex.el | 2827 |
1 files changed, 1554 insertions, 1273 deletions
diff --git a/lisp/textmodes/reftex.el b/lisp/textmodes/reftex.el index 7a7de9d0325..7668381c311 100644 --- a/lisp/textmodes/reftex.el +++ b/lisp/textmodes/reftex.el | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | ;; reftex.el --- Minor mode for doing \label, \ref and \cite in LaTeX | 1 | ;; reftex.el --- Minor mode for doing \label, \ref and \cite in LaTeX |
| 2 | ;; Copyright (c) 1997 Free Software Foundation, Inc. | 2 | ;; Copyright (c) 1997, 1998 Free Software Foundation, Inc. |
| 3 | 3 | ||
| 4 | ;; Author: Carsten Dominik <dominik@strw.LeidenUniv.nl> | 4 | ;; Author: Carsten Dominik <dominik@strw.LeidenUniv.nl> |
| 5 | ;; Keywords: tex | 5 | ;; Keywords: tex |
| @@ -32,6 +32,7 @@ | |||
| 32 | ;; efficient database lookup. A table of contents buffer provides easy | 32 | ;; efficient database lookup. A table of contents buffer provides easy |
| 33 | ;; access to any part of a document. | 33 | ;; access to any part of a document. |
| 34 | ;; | 34 | ;; |
| 35 | ;; | ||
| 35 | ;; To turn RefTeX Minor Mode on and off in a particular buffer, use | 36 | ;; To turn RefTeX Minor Mode on and off in a particular buffer, use |
| 36 | ;; `M-x reftex-mode'. | 37 | ;; `M-x reftex-mode'. |
| 37 | ;; | 38 | ;; |
| @@ -41,560 +42,89 @@ | |||
| 41 | ;; (add-hook 'LaTeX-mode-hook 'turn-on-reftex) ; with AUCTeX LaTeX mode | 42 | ;; (add-hook 'LaTeX-mode-hook 'turn-on-reftex) ; with AUCTeX LaTeX mode |
| 42 | ;; (add-hook 'latex-mode-hook 'turn-on-reftex) ; with Emacs latex mode | 43 | ;; (add-hook 'latex-mode-hook 'turn-on-reftex) ; with Emacs latex mode |
| 43 | ;; | 44 | ;; |
| 44 | ;; For default key bindings, see further down in this documentation. | ||
| 45 | ;; | ||
| 46 | ;;--------------------------------------------------------------------------- | ||
| 47 | ;; | 45 | ;; |
| 48 | ;; CONTENTS | 46 | ;; DOCUMENTATION |
| 49 | ;; -------- | 47 | ;; ------------- |
| 50 | ;; | 48 | ;; |
| 51 | ;; Overview............................ All you need to know to get started. | 49 | ;; There is an extensive texinfo document describing RefTeX in detail. |
| 52 | ;; | 50 | ;; When you are getting reftex.el with the Emacs distribution, the |
| 53 | ;; Configuration....................... How to configure RefTeX. | 51 | ;; info files should already be installed. To view this |
| 54 | ;; Configuration Examples........... Tutorial examples. | 52 | ;; documentation, use `M-x reftex-info RET'. |
| 55 | ;; Hooks............................ Available hooks. | ||
| 56 | ;; Configuration Variables.......... Complete listing. | ||
| 57 | ;; Key Bindings........................ A list of default bindings. | ||
| 58 | ;; Multifile Documents................. Documents spread over many files. | ||
| 59 | ;; References to Other Documents....... RefTeX and the LaTeX package `xr'. | ||
| 60 | ;; Optimizations for Large Documents... How to improve speed and memory use. | ||
| 61 | ;; Related Packages.................... Other Emacs packages. | ||
| 62 | ;; Known Bugs and Work-Arounds......... First aid. | ||
| 63 | ;; Author.............................. Who wrote RefTeX and who helped. | ||
| 64 | ;;--------------------------------------------------------------------------- | ||
| 65 | ;; | 53 | ;; |
| 66 | ;; OVERVIEW | 54 | ;; The documentation is also available at |
| 67 | ;; ======== | ||
| 68 | ;; | 55 | ;; |
| 69 | ;; 1. USING \label AND \ref. Labels and references are one of the strong | 56 | ;; http://www.strw.leidenuniv.nl/~dominik/Tools/ |
| 70 | ;; points of LaTeX. But, in documents with hundreds of equations, | ||
| 71 | ;; figures, tables etc. it becomes quickly impossible to find good label | ||
| 72 | ;; names and to actually remember them. Then, also completion of labels | ||
| 73 | ;; is not enough. One actually needs to see the context of the label | ||
| 74 | ;; definition to find the right one. | ||
| 75 | ;; | 57 | ;; |
| 76 | ;; - RefTeX distinguishes labels for different environments. It always | 58 | ;;--------------------------------------------------------------------------- |
| 59 | ;; | ||
| 60 | ;; RefTeX in a Nutshell | ||
| 61 | ;; ==================== | ||
| 62 | ;; | ||
| 63 | ;; 1. Labels and References | ||
| 64 | ;; RefTeX distinguishes labels for different environments. It always | ||
| 77 | ;; knows if a certain label references a figure, table etc.. You can | 65 | ;; knows if a certain label references a figure, table etc.. You can |
| 78 | ;; configure RefTeX to recognize any additional labeled environments | 66 | ;; configure RefTeX to recognize any additional labeled environments |
| 79 | ;; you have defined yourself. | 67 | ;; you have defined yourself (variable REFTEX-LABEL-ALIST). |
| 80 | ;; | 68 | ;; - Creating Labels |
| 81 | ;; - RefTeX defines automatically unique labels. Type `C-c (' | 69 | ;; Type `C-c (' (`reftex-label') to insert a label at point. |
| 82 | ;; (`reftex-label') to insert a label at point. RefTeX will either | 70 | ;; RefTeX will either |
| 83 | ;; - derive a label from context (default for section labels) | 71 | ;; - derive a label from context (default for section labels) |
| 84 | ;; - insert a simple label consisting of a prefix and a number | 72 | ;; |
| 85 | ;; (default for equations,enumerate items, and footnotes) or | 73 | ;; - insert a simple label consisting of a prefix and a number |
| 86 | ;; - prompt for a label string (figures and tables). | 74 | ;; (default for equations, enumerate items, and footnotes) |
| 87 | ;; Which labels are created how can be controlled with the variable | 75 | ;; or |
| 88 | ;; `reftex-insert-label-flags'. | 76 | ;; |
| 89 | ;; | 77 | ;; - prompt for a label string (figures and tables). |
| 90 | ;; - Referencing labels is a snap and I promise you'll love it. In | 78 | ;; |
| 91 | ;; order to make a reference, type `C-c )' (`reftex-reference'). This | 79 | ;; Which labels are created how is configurable (variable |
| 92 | ;; shows an outline of the document with all labels of a certain type | 80 | ;; REFTEX-INSERT-LABEL-FLAGS). |
| 93 | ;; (figure, equation,...) and context of the label definition. | 81 | ;; |
| 94 | ;; Selecting one of the labels inserts a \ref macro into the original | 82 | ;; - Referencing Labels |
| 95 | ;; buffer. Online help during the selection is available with `?'. | 83 | ;; Referencing labels is a snap and I promise you'll love it. |
| 96 | ;; | 84 | ;; In order to make a reference, type `C-c )' |
| 97 | ;; 2. CITATIONS. After typing `C-c [' (`reftex-citation'), RefTeX will let | 85 | ;; (`reftex-reference'). This shows an outline of the document |
| 98 | ;; you specify a regexp to search in current BibTeX database files (as | 86 | ;; with all labels of a certain type (figure, equation,...) and |
| 99 | ;; specified in the \bibliography command) and pull out a formatted list | 87 | ;; context of the label definition. Selecting one of the labels |
| 100 | ;; of matches for you to choose from. The list is *formatted* and | 88 | ;; inserts a `\ref' macro into the original buffer. Online help |
| 101 | ;; sorted, thus much easier to read than the raw database entries. The | 89 | ;; during the selection is available with `?'. |
| 102 | ;; text inserted into the buffer is by default just `\cite{KEY}', but | 90 | ;; |
| 103 | ;; can also contain author names and the year in a configurable way. | 91 | ;; 2. Citations |
| 104 | ;; See documentation of the variable `reftex-cite-format'. | 92 | ;; After typing `C-c [' (`reftex-citation'), RefTeX will let you |
| 105 | ;; | 93 | ;; specify a regular expression to search in current BibTeX database |
| 106 | ;; 3. TABLE OF CONTENTS. Typing `C-c =' (`reftex-toc') will show a table | 94 | ;; files (as specified in the `\bibliography' command) and pull out a |
| 107 | ;; of contents of the document. From that buffer, you can jump quickly | 95 | ;; formatted list of matches for you to choose from. The list is |
| 108 | ;; to every part of your document. This is similar to imenu, only it | 96 | ;; *formatted* and sorted, thus much easier to read than the raw |
| 109 | ;; works for entire multifile documents and uses the keyboard rather | 97 | ;; database entries. The text inserted into the buffer is by default |
| 110 | ;; than the mouse. The initial version of this function was contributed | 98 | ;; just `\cite{KEY}', but can also contain author names and the year |
| 111 | ;; by Stephen Eglen. | 99 | ;; in a configurable way (variable REFTEX-CITE-FORMAT). |
| 100 | ;; | ||
| 101 | ;; 3. Viewing Cross References | ||
| 102 | ;; With point on or anywhere before a `\ref' or `\cite' macro, press | ||
| 103 | ;; `C-c &' (`reftex-view-crossref'). This will display the | ||
| 104 | ;; corresponding label definition or BibTeX database entry in another | ||
| 105 | ;; window. | ||
| 106 | ;; | ||
| 107 | ;; 4. Table of Contents | ||
| 108 | ;; Typing `C-c =' (`reftex-toc') will show a table of contents of the | ||
| 109 | ;; document. From that buffer, you can jump quickly to every part of | ||
| 110 | ;; your document. | ||
| 111 | ;; | ||
| 112 | ;; 5. Multifile Documents | ||
| 113 | ;; Multifile Domuments are fully supported. RefTeX will provide cross | ||
| 114 | ;; referencing information from all files which are part of the | ||
| 115 | ;; document. You may also use it to reference labels in external | ||
| 116 | ;; documents (in cooperation with the LaTeX package `xr'). | ||
| 117 | ;; | ||
| 118 | ;; 6. Document Parsing | ||
| 119 | ;; RefTeX needs to parse the document in order to find labels and | ||
| 120 | ;; other information. It will do it automatically once, when you | ||
| 121 | ;; start working with a document. Re-parsing should not be necessary | ||
| 122 | ;; too often since RefTeX updates its lists internally when you make | ||
| 123 | ;; a new label with `reftex-label'. To enforce reparsing, call any | ||
| 124 | ;; of the commands described above with a raw `C-u' prefix, or press | ||
| 125 | ;; the `r' key in the label selection buffer or the table of contents | ||
| 126 | ;; buffer. | ||
| 112 | ;; | 127 | ;; |
| 113 | ;; 4. MULTIFILE DOCUMENTS are fully supported by RefTeX. Such documents | ||
| 114 | ;; consist of a master file and many other files being included via | ||
| 115 | ;; \input or \include. RefTeX will provide cross referencing | ||
| 116 | ;; information from all files which are part of the document. See | ||
| 117 | ;; `RefTeX and Multifile Documents' further down in the documentation | ||
| 118 | ;; for more information on this topic. | ||
| 119 | ;; | ||
| 120 | ;; 5. DOCUMENT PARSING. RefTeX needs to parse the document in order to | ||
| 121 | ;; find labels and other information. It will do it automatically once, | ||
| 122 | ;; when you start working with a document. Re-parsing should not be | ||
| 123 | ;; necessary too often since RefTeX updates its lists internally when | ||
| 124 | ;; you make a new label with `reftex-label'. To enforce reparsing, | ||
| 125 | ;; call any of the functions `reftex-citation', `reftex-label', | ||
| 126 | ;; `reftex-reference', `reftex-toc' with a raw C-u prefix, or press the | ||
| 127 | ;; `r' key in the label menu and table of contents buffer. | ||
| 128 | ;;--------------------------------------------------------------------------- | ||
| 129 | ;; | ||
| 130 | ;; CONFIGURATION | ||
| 131 | ;; ============= | ||
| 132 | ;; | ||
| 133 | ;; RefTeX needs to be configured if you use labels to mark environments | ||
| 134 | ;; defined by yourself (e.g. with `\newenvironment') or in packages not | ||
| 135 | ;; included in the standard LaTeX distribution. RefTeX's default settings | ||
| 136 | ;; make it recognize practically all labeled environments and macros | ||
| 137 | ;; discussed in `The LaTeX Companion' by Goossens, Mittelbach & Samarin, | ||
| 138 | ;; Addison-Wesley 1994. These are: | ||
| 139 | ;; | ||
| 140 | ;; - figure, figure*, table, table*, equation, eqnarray, enumerate, | ||
| 141 | ;; the \footnote macro (this is the LaTeX core stuff) | ||
| 142 | ;; - align, gather, multline, flalign, alignat, xalignat, xxalignat, | ||
| 143 | ;; subequations (from AMS-LaTeX's amsmath.sty package) | ||
| 144 | ;; - the \endnote macro (from endnotes.sty) | ||
| 145 | ;; - Beqnarray (fancybox.sty) | ||
| 146 | ;; - floatingfig (floatfig.sty) | ||
| 147 | ;; - longtable (longtable.sty) | ||
| 148 | ;; - figwindow, tabwindow (picinpar.sty) | ||
| 149 | ;; - sidewaysfigure, sidewaystable (rotating.sty) | ||
| 150 | ;; - subfigure, subfigure*, the \subfigure macro (subfigure.sty) | ||
| 151 | ;; - supertabular (supertab.sty) | ||
| 152 | ;; - wrapfigure (wrapfig.sty) | ||
| 153 | ;; | ||
| 154 | ;; If you want to use any other labeled environments or macros, you need | ||
| 155 | ;; to configure RefTeX. | ||
| 156 | ;; | ||
| 157 | ;; Per Abrahamsens custom.el package provides a simple way to do | ||
| 158 | ;; configuration. To try it out, use `M-x reftex-customize'. | ||
| 159 | ;; | ||
| 160 | ;; CONFIGURATION EXAMPLES | ||
| 161 | ;; ---------------------- | ||
| 162 | ;; | ||
| 163 | ;; Suppose you are working with AMS-LaTeX amsmath package (with its math | ||
| 164 | ;; environments like `align', `multline' etc.). RefTeX is preconfigured to | ||
| 165 | ;; recognize these - so there is nothing you have to do. | ||
| 166 | ;; | ||
| 167 | ;; Suppose you are also using `\newtheorem' in LaTeX in order to define two | ||
| 168 | ;; new environments `theorem' and `axiom' | ||
| 169 | ;; | ||
| 170 | ;; \newtheorem{axiom}{Axiom} | ||
| 171 | ;; \newtheorem{theorem}{Theorem} | ||
| 172 | ;; | ||
| 173 | ;; to be used like this: | ||
| 174 | ;; | ||
| 175 | ;; \begin{axiom} | ||
| 176 | ;; \label{ax:first} | ||
| 177 | ;; .... | ||
| 178 | ;; \end{axiom} | ||
| 179 | ;; | ||
| 180 | ;; So we need to tell RefTeX that `theorem' and `axiom' are new labeled | ||
| 181 | ;; environments which define their own label categories. Here is how: | ||
| 182 | ;; | ||
| 183 | ;; (setq reftex-label-alist | ||
| 184 | ;; '(("axiom" ?a "ax:" "~\\ref{%s}" nil ("Axiom" "Ax.")) | ||
| 185 | ;; ("theorem" ?h "thr:" "~\\ref{%s}" t ("Theorem" "Theor." "Th.")))) | ||
| 186 | ;; | ||
| 187 | ;; The type indicator characters ?a and ?h are used for prompts when RefTeX | ||
| 188 | ;; queries for a label type. Note that `h' was chosen for `theorem' since | ||
| 189 | ;; `t' is already taken by `table'. Note that also `s', `f', `e', `i', `n' | ||
| 190 | ;; are already used for standard environments. | ||
| 191 | ;; The automatic labels for Axioms and Theorems will look like "ax:23" or | ||
| 192 | ;; "thr:24". | ||
| 193 | ;; The "\ref{%s}" is a format string indicating how to insert references to | ||
| 194 | ;; these labels. | ||
| 195 | ;; The next item indicates how to grab context of the label definition. | ||
| 196 | ;; - t means to get it from a default location (from the beginning of a | ||
| 197 | ;; \macro or after the \begin statement). t is *not* a good choice for | ||
| 198 | ;; eqnarray and similar environments. | ||
| 199 | ;; - nil means to use the text right after the label definition. | ||
| 200 | ;; - For more complex ways of getting context, see the docstring of | ||
| 201 | ;; `reftex-label-alist'. | ||
| 202 | ;; The strings at the end of each entry are used to guess the correct label | ||
| 203 | ;; type from the word before point when creating a reference. E.g. if you | ||
| 204 | ;; write: "As we have shown in Theorem" and then press `C-c )', RefTeX will | ||
| 205 | ;; know that you are looking for a theorem label and restrict the menu to | ||
| 206 | ;; only these labels without even asking. | ||
| 207 | ;; | ||
| 208 | ;; Depending on how you would like the label insertion and selection for | ||
| 209 | ;; the new environments to work, you might want to add the letters "a" and | ||
| 210 | ;; "h" to some of the flags in the following variables: | ||
| 211 | ;; | ||
| 212 | ;; reftex-insert-label-flags reftex-label-menu-flags | ||
| 213 | ;; | ||
| 214 | ;; Suppose you want to make figures not directly with the figure | ||
| 215 | ;; environment, but with a macro like | ||
| 216 | ;; | ||
| 217 | ;; \newcommand{\myfig}[5][tbp]{% | ||
| 218 | ;; \begin{figure}[#1] | ||
| 219 | ;; \epsimp[#5]{#2} | ||
| 220 | ;; \caption{#3} | ||
| 221 | ;; \label{#4} | ||
| 222 | ;; \end{figure}} | ||
| 223 | ;; | ||
| 224 | ;; which would be called like | ||
| 225 | ;; | ||
| 226 | ;; \myfig[htp]{filename}{caption text}{label}{1} | ||
| 227 | ;; | ||
| 228 | ;; Now we also need to tell RefTeX that the 4th argument of the \myfig | ||
| 229 | ;; macro is a figure label, and where to find the context. | ||
| 230 | ;; | ||
| 231 | ;; (setq reftex-label-alist | ||
| 232 | ;; '(("axiom" ?a "ax:" "~\\ref{%s}" nil ("Axiom" "Ax.")) | ||
| 233 | ;; ("theorem" ?h "thr:" "~\\ref{%s}" t ("Theorem" "Theor." "Th.")) | ||
| 234 | ;; ("\\myfig[]{}{}{*}{}" ?f nil nil 3))) | ||
| 235 | ;; | ||
| 236 | ;; The empty pairs of brackets indicate the different arguments of the | ||
| 237 | ;; \myfig macro. The `*' marks the label argument. `?f' indicates that | ||
| 238 | ;; this is a figure label which will be listed together with labels from | ||
| 239 | ;; normal figure environments. The nil entries for prefix and reference | ||
| 240 | ;; format mean to use the defaults for figure labels. The `3' for the | ||
| 241 | ;; context method means to grab the 3rd macro argument - the caption. | ||
| 242 | ;; | ||
| 243 | ;; As a side effect of this configuration, `reftex-label' will now insert | ||
| 244 | ;; the required naked label (without the \label macro) when point is | ||
| 245 | ;; directly after the opening parenthesis of a \myfig macro argument. | ||
| 246 | ;; | ||
| 247 | ;; ----- | ||
| 248 | ;; | ||
| 249 | ;; If you are writing in a language different from English you might want | ||
| 250 | ;; to add magic words for that language. Here is a German example: | ||
| 251 | ;; | ||
| 252 | ;; (setq reftex-label-alist | ||
| 253 | ;; '((nil ?s nil nil nil ("Kapitel" "Kap." "Abschnitt" "Teil")) | ||
| 254 | ;; (nil ?e nil nil nil ("Gleichung" "Gl.")) | ||
| 255 | ;; (nil ?t nil nil nil ("Tabelle")) | ||
| 256 | ;; (nil ?f nil nil nil ("Figur" "Abbildung" "Abb.")) | ||
| 257 | ;; (nil ?n nil nil nil ("Anmerkung" "Anm.")) | ||
| 258 | ;; (nil ?i nil nil nil ("Punkt")))) | ||
| 259 | ;; | ||
| 260 | ;; Using nil as first item in each entry makes sure that this entry does | ||
| 261 | ;; not replace the original entry for that label type, but just adds magic | ||
| 262 | ;; words. | ||
| 263 | ;; | ||
| 264 | ;; ----- | ||
| 265 | ;; | ||
| 266 | ;; Normally, RefTeX inserts equation references with parenthesis like | ||
| 267 | ;; "~(\ref{KEY})". If you want to change this to square brackets, use | ||
| 268 | ;; | ||
| 269 | ;; (setq reftex-label-alist '((nil ?e nil "~[\\ref{%s}]" nil nil))) | ||
| 270 | ;; | ||
| 271 | ;; In order to use the AMS-LaTeX \eqref macro instead, either of the | ||
| 272 | ;; following lines does the job. | ||
| 273 | ;; | ||
| 274 | ;; (setq reftex-label-alist '((nil ?e nil "~\\eqref{%s}" nil nil))) | ||
| 275 | ;; (setq reftex-label-alist '(AMSTeX)) | ||
| 276 | ;; | ||
| 277 | ;; ---- | ||
| 278 | ;; | ||
| 279 | ;; By default, citations are inserted simply as \cite{KEY}. You can have | ||
| 280 | ;; more complex citation commands with many available packages, most | ||
| 281 | ;; notably the harvard and natbib packages. RefTeX can be configured to | ||
| 282 | ;; support these and other styles by setting the variable | ||
| 283 | ;; `reftex-cite-format'. E.g., for the natbib package you would use | ||
| 284 | ;; | ||
| 285 | ;; (setq reftex-cite-format 'natbib) | ||
| 286 | ;; | ||
| 287 | ;; This can also be done as a file variable. For the full list of builtin | ||
| 288 | ;; options, try `M-x customize-variable RET reftex-cite-format RET'. | ||
| 289 | ;; | ||
| 290 | ;; HOOKS | ||
| 291 | ;; ----- | ||
| 292 | ;; - Loading reftex.el runs the hook `reftex-load-hook'. | ||
| 293 | ;; - Turning on reftex-mode runs `reftex-mode-hook'. | ||
| 294 | ;; - Files visited literally are processed with | ||
| 295 | ;; `reftex-initialize-temporary-buffers' if that is a list of functions. | ||
| 296 | ;; | ||
| 297 | ;; CONFIGURATION VARIABLES | ||
| 298 | ;; ----------------------- | ||
| 299 | ;; | ||
| 300 | ;; The best way to learn about all configuration variables is via the | ||
| 301 | ;; browser interface of the custom library. For reference, I am giving | ||
| 302 | ;; here a complete list. | ||
| 303 | ;; | ||
| 304 | ;; ;; Defining label environments | ||
| 305 | ;; reftex-default-label-alist-entries | ||
| 306 | ;; reftex-label-alist | ||
| 307 | ;; reftex-section-levels | ||
| 308 | ;; reftex-default-context-regexps | ||
| 309 | ;; reftex-use-text-after-label-as-context | ||
| 310 | ;; ;; Label insertion | ||
| 311 | ;; reftex-insert-label-flags | ||
| 312 | ;; reftex-derive-label-parameters | ||
| 313 | ;; reftex-label-illegal-re | ||
| 314 | ;; reftex-abbrev-parameters | ||
| 315 | ;; ;; Label referencing | ||
| 316 | ;; reftex-label-menu-flags | ||
| 317 | ;; reftex-level-indent | ||
| 318 | ;; reftex-refontify-context | ||
| 319 | ;; reftex-guess-label-type | ||
| 320 | ;; ;; BibteX citation configuration | ||
| 321 | ;; reftex-bibpath-environment-variables | ||
| 322 | ;; reftex-bibfile-ignore-list | ||
| 323 | ;; reftex-sort-bibtex-matches | ||
| 324 | ;; reftex-cite-format | ||
| 325 | ;; reftex-comment-citations | ||
| 326 | ;; reftex-cite-comment-format | ||
| 327 | ;; reftex-cite-punctuation | ||
| 328 | ;; ;; Table of contents configuration | ||
| 329 | ;; reftex-toc-follow-mode | ||
| 330 | ;; ;; Fine-tuning the parser | ||
| 331 | ;; reftex-keep-temporary-buffers | ||
| 332 | ;; reftex-initialize-temporary-buffers | ||
| 333 | ;; reftex-enable-partial-scans | ||
| 334 | ;; reftex-save-parse-info | ||
| 335 | ;; ;; Miscellaneous configurations | ||
| 336 | ;; reftex-extra-bindings | ||
| 337 | ;; reftex-plug-into-AUCTeX | ||
| 338 | ;; reftex-use-fonts | ||
| 339 | ;; reftex-auto-show-entry | ||
| 340 | ;; reftex-load-hook | ||
| 341 | ;; reftex-mode-hook | ||
| 342 | ;;------------------------------------------------------------------------- | ||
| 343 | ;; | ||
| 344 | ;; KEY BINDINGS | ||
| 345 | ;; ============ | ||
| 346 | ;; | ||
| 347 | ;; All RefTeX commands can be reached from its menu, the `Ref' menu on the | ||
| 348 | ;; menu bar. More frequently used commands have key bindings: | ||
| 349 | ;; | ||
| 350 | ;; C-c = reftex-toc | ||
| 351 | ;; C-c ( reftex-label | ||
| 352 | ;; C-c ) reftex-reference | ||
| 353 | ;; C-c [ reftex-citation | ||
| 354 | ;; C-c & reftex-view-crossref | ||
| 355 | ;; | ||
| 356 | ;; These keys are chosen to avoid interfering with AUCTeX's settings. | ||
| 357 | ;; Personally, I also bind some functions in the C-c LETTER map for | ||
| 358 | ;; easier access: | ||
| 359 | ;; | ||
| 360 | ;; C-c t reftex-toc | ||
| 361 | ;; C-c l reftex-label | ||
| 362 | ;; C-c r reftex-reference | ||
| 363 | ;; C-c c reftex-citation | ||
| 364 | ;; C-c v reftex-view-crossref | ||
| 365 | ;; C-c s reftex-search-document | ||
| 366 | ;; C-c g reftex-grep-document | ||
| 367 | ;; | ||
| 368 | ;; If you want to copy those as well, set in your .emacs file: | ||
| 369 | ;; | ||
| 370 | ;; (setq reftex-extra-bindings t) | ||
| 371 | ;; | ||
| 372 | ;; It is possible to bind the function for viewing cross references to a | ||
| 373 | ;; mouse event. Something like the following will do the trick: | ||
| 374 | ;; | ||
| 375 | ;; (add-hook 'reftex-load-hook | ||
| 376 | ;; '(lambda () | ||
| 377 | ;; (define-key reftex-mode-map [(shift mouse-2)] | ||
| 378 | ;; 'reftex-mouse-view-crossref))) | ||
| 379 | ;;------------------------------------------------------------------------- | ||
| 380 | ;; | ||
| 381 | ;; REFTEX AND MULTIFILE DOCUMENTS | ||
| 382 | ;; ============================== | ||
| 383 | ;; | ||
| 384 | ;; The following is relevant when using RefTeX for multi-file documents: | ||
| 385 | ;; | ||
| 386 | ;; o RefTeX has full support for multifile documents. You can edit parts | ||
| 387 | ;; of several (multifile) documents at the same time without conflicts. | ||
| 388 | ;; RefTeX provides functions to run `grep', `search' and `query-replace' | ||
| 389 | ;; on all files which are part of a multifile document. | ||
| 390 | ;; | ||
| 391 | ;; o All files belonging to a multifile document should have a File | ||
| 392 | ;; Variable (`TeX-master' for AUCTeX or `tex-main-file' for the standard | ||
| 393 | ;; Emacs LaTeX mode) set to the name of the master file. See the | ||
| 394 | ;; documentation of your (La)TeX mode and the Emacs documentation on | ||
| 395 | ;; file variables: [Emacs/Customization/Variables/File Variables]. | ||
| 396 | ;; | ||
| 397 | ;; o The context of a label definition must be found in the same file as | ||
| 398 | ;; the label itself in order to be processed correctly by RefTeX. The | ||
| 399 | ;; only exception is that section labels referring to a section statement | ||
| 400 | ;; outside the current file can still use that section title as context. | ||
| 401 | ;;------------------------------------------------------------------------- | ||
| 402 | ;; | ||
| 403 | ;; REFERENCES TO OTHER DOCUMENTS | ||
| 404 | ;; ============================= | ||
| 405 | ;; | ||
| 406 | ;; RefTeX supports the LaTeX package `xr', which makes it possible to | ||
| 407 | ;; reference labels defined in another document. See the documentation on | ||
| 408 | ;; `xr' for details. | ||
| 409 | ;; When the document is set up to work with `xr', you can use the `x' key | ||
| 410 | ;; in the reference label menu to switch to the label menu of an external | ||
| 411 | ;; document and select any labels from there. In the *toc* buffer, the | ||
| 412 | ;; `x' key can be used to switch to the table of contents of an external | ||
| 413 | ;; document. | ||
| 414 | ;; | ||
| 415 | ;; For this kind of inter-document cross references, saving of parsing | ||
| 416 | ;; information can mean a large speed-up. | ||
| 417 | ;; | ||
| 418 | ;; (setq reftex-save-parse-info t) | ||
| 419 | ;; | ||
| 420 | ;;------------------------------------------------------------------------- | ||
| 421 | ;; | ||
| 422 | ;; OPTIMIZATIONS FOR LARGE DOCUMENTS | ||
| 423 | ;; ================================= | ||
| 424 | ;; | ||
| 425 | ;; The default settings of RefTeX ensure a safe ride for beginners and | ||
| 426 | ;; casual users. However, when using RefTeX for a large project and/or on | ||
| 427 | ;; a small computer, there are ways to improve speed or memory usage. | ||
| 428 | ;; | ||
| 429 | ;; o RefTeX will load other parts of a multifile document as well as BibTeX | ||
| 430 | ;; database files for lookup purposes. These buffers are kept, so that | ||
| 431 | ;; subsequent use of the same files is fast. If you can't afford keeping | ||
| 432 | ;; these buffers around, and if you can live with a speed penalty, try | ||
| 433 | ;; | ||
| 434 | ;; (setq reftex-keep-temporary-buffers nil) | ||
| 435 | ;; | ||
| 436 | ;; o The `C-u' prefix on the major RefTeX commands `reftex-label', | ||
| 437 | ;; `reftex-reference', `reftex-citation' and `reftex-toc' initiates | ||
| 438 | ;; re-parsing of the entire document in order to update the parsing | ||
| 439 | ;; information. For a large document this can be unnecessary, in | ||
| 440 | ;; particular if only one file has changed. RefTeX can be configured to | ||
| 441 | ;; do partial scans instead of full ones. `C-u' re-parsing then does | ||
| 442 | ;; apply only to the current buffer and files included from it. | ||
| 443 | ;; Likewise, the `r' key in both the label menu and the table-of-contents | ||
| 444 | ;; buffer will only prompt scanning of the file in which the label or | ||
| 445 | ;; section macro near the cursor was defined. Re-parsing of the entire | ||
| 446 | ;; document is still available by using `C-u C-u' as a prefix, or the | ||
| 447 | ;; capital `R' key in the menus. To use this feature, try | ||
| 448 | ;; | ||
| 449 | ;; (setq reftex-enable-partial-scans t) | ||
| 450 | ;; | ||
| 451 | ;; o Even with partial scans enabled, RefTeX still has to make one full | ||
| 452 | ;; scan, when you start working with a document. To avoid this, parsing | ||
| 453 | ;; information can stored in a file. The file `MASTER.rel' is used for | ||
| 454 | ;; storing information about a document with master file `MASTER.tex'. | ||
| 455 | ;; It is written each time RefTeX parses (part of) the document, and | ||
| 456 | ;; restored when you begin working with a document in a new editing | ||
| 457 | ;; session. To use this feature, put into .emacs: | ||
| 458 | ;; | ||
| 459 | ;; (setq reftex-save-parse-info t) | ||
| 460 | ;;---------------------------------------------------------------------------- | ||
| 461 | ;; | ||
| 462 | ;; RELATED PACKAGES | ||
| 463 | ;; ================ | ||
| 464 | ;; | ||
| 465 | ;; AUCTeX | ||
| 466 | ;; ------ | ||
| 467 | ;; If you are writing TeX or LaTeX documents with Emacs, you should have | ||
| 468 | ;; a look at AUCTeX, the definitive package to work with TeX and LaTeX. | ||
| 469 | ;; Information on AUCTeX can be found here: | ||
| 470 | ;; | ||
| 471 | ;; http://www.sunsite.auc.dk/auctex/ | ||
| 472 | ;; | ||
| 473 | ;; Instead of using the RefTeX functions described above directly, you can | ||
| 474 | ;; also use them indirectly, through AUCTeX (version 9.8a or later). | ||
| 475 | ;; RefTeX provides several interface functions which can be used as | ||
| 476 | ;; replacement for corresponding AUCTeX functions dealing with labels and | ||
| 477 | ;; citations. In this way you can work normally with AUCTeX and use RefTeX | ||
| 478 | ;; internals to create and complete labels and citation keys. | ||
| 479 | ;; | ||
| 480 | ;; `reftex-label' can be used as the `LaTeX-label-function' which does | ||
| 481 | ;; label insertion when new environments are created with `C-c C-e'. | ||
| 482 | ;; | ||
| 483 | ;; `reftex-arg-label', `reftex-arg-ref' and `reftex-arg-cite' can replace | ||
| 484 | ;; the corresponding `TeX-arg-...' functions. E.g. when you insert a label | ||
| 485 | ;; macro with `C-c RET label RET', RefTeX will be transparently used to | ||
| 486 | ;; create the label. | ||
| 487 | ;; | ||
| 488 | ;; In order to plug all 4 functions into AUCTeX, use: | ||
| 489 | ;; | ||
| 490 | ;; (setq reftex-plug-into-AUCTeX t) | ||
| 491 | ;; | ||
| 492 | ;; You may also choose to plug in only some of these functions. See the | ||
| 493 | ;; docstring of `reftex-plug-into-AUCTeX'. | ||
| 494 | ;; | ||
| 495 | ;; AUCTeX can support RefTeX via style files. A style file may contain | ||
| 496 | ;; calls to `reftex-add-to-label-alist' which defines additions to | ||
| 497 | ;; `reftex-label-alist'. The argument taken by this function must have the | ||
| 498 | ;; same format as `reftex-label-alist'. The `amsmath.el' style file of | ||
| 499 | ;; AUCTeX (>9.7p) for example contains the following: | ||
| 500 | ;; | ||
| 501 | ;; (TeX-add-style-hook "amsmath" | ||
| 502 | ;; (function | ||
| 503 | ;; (lambda () | ||
| 504 | ;; (if (featurep 'reftex) | ||
| 505 | ;; (reftex-add-to-label-alist '(AMSTeX)))))) | ||
| 506 | ;; | ||
| 507 | ;; while a package `myprop' defining a proposition environment with | ||
| 508 | ;; \newtheorem might use | ||
| 509 | ;; | ||
| 510 | ;; (TeX-add-style-hook "myprop" | ||
| 511 | ;; (function | ||
| 512 | ;; (lambda () | ||
| 513 | ;; (if (featurep 'reftex) | ||
| 514 | ;; (reftex-add-to-label-alist | ||
| 515 | ;; '(("proposition" ?p "prop:" "~\\ref{%s}" t | ||
| 516 | ;; ("Proposition" "Prop.")))))))) | ||
| 517 | ;; | ||
| 518 | ;; Bib-cite.el | ||
| 519 | ;; ----------- | ||
| 520 | ;; Once you have written a document with labels, refs and citations, it can | ||
| 521 | ;; be nice to read such a file like a hypertext document. RefTeX has some | ||
| 522 | ;; support for that (`reftex-view-crossref', `reftex-search-document'). A | ||
| 523 | ;; more elegant interface with mouse support and links into Hyperbole is | ||
| 524 | ;; provided (among other things) by Peter S. Galbraith's `bib-cite.el'. | ||
| 525 | ;; There is some overlap in the functionalities of Bib-cite and RefTeX. | ||
| 526 | ;; Bib-cite.el comes bundled with AUCTeX. You can also get the latest | ||
| 527 | ;; version from | ||
| 528 | ;; | ||
| 529 | ;; ftp://ftp.phys.ocean.dal.ca/users/rhogee/elisp/bib-cite.el | ||
| 530 | ;;--------------------------------------------------------------------------- | ||
| 531 | ;; | ||
| 532 | ;; KNOWN BUGS AND WORK-AROUNDS | ||
| 533 | ;; =========================== | ||
| 534 | ;; | ||
| 535 | ;; o \input, \include, \bibliography and \section (etc.) statements have | ||
| 536 | ;; to be first on a line (except for white space). | ||
| 537 | ;; | ||
| 538 | ;; o RefTeX sees also labels in regions commented out and will refuse to | ||
| 539 | ;; make duplicates of such a label. This is considered to be a feature. | ||
| 540 | ;; | ||
| 541 | ;; o When using partial scans (`reftex-enable-partial-scans'), the section | ||
| 542 | ;; numbers in the table of contents may eventually become wrong. A full | ||
| 543 | ;; scan will fix this. | ||
| 544 | ;; | ||
| 545 | ;; o RefTeX keeps only a global copy of the configuration variables. | ||
| 546 | ;; Also, any additions from style files go into a global variable. | ||
| 547 | ;; Practically, this should not be a problem. Theoretically, it could | ||
| 548 | ;; give conflicts if two documents used environments with identical | ||
| 549 | ;; names, but different associated label types. | ||
| 550 | ;; | ||
| 551 | ;; o When using packages which make the buffer representation of a file | ||
| 552 | ;; different from its disk representation (e.g. x-symbol, isotex, | ||
| 553 | ;; iso-cvt) you may find that RefTeX's parsing information sometimes | ||
| 554 | ;; reflects the disk state of a file. This happens only in *unvisited* | ||
| 555 | ;; parts of a multifile document, because RefTeX visits these files | ||
| 556 | ;; literally for speed reasons. Then both short context and section | ||
| 557 | ;; headings may look different from what you usually see on your screen. | ||
| 558 | ;; In rare cases `reftex-toc' may have problems to jump to an affected | ||
| 559 | ;; section heading. There are three possible ways to deal with this: | ||
| 560 | ;; | ||
| 561 | ;; - (setq reftex-keep-temporary-buffers t) | ||
| 562 | ;; This implies that RefTeX will load all parts of a multifile | ||
| 563 | ;; document into Emacs (i.e. there will be no temporary buffers). | ||
| 564 | ;; - (setq reftex-initialize-temporary-buffers t) | ||
| 565 | ;; This means full initialization of temporary buffers. It involves | ||
| 566 | ;; a penalty when the same file is used for lookup often. | ||
| 567 | ;; - Set `reftex-initialize-temporary-buffers' to a list of hook | ||
| 568 | ;; functions doing a minimal initialization. | ||
| 569 | ;; | ||
| 570 | ;; You might also want to check the variable `reftex-refontify-context'. | ||
| 571 | ;; | ||
| 572 | ;; o Some nasty :-# packages use an additional argument to a \begin macro | ||
| 573 | ;; to specify a label. E.g. Lamport's "pf.sty" uses both | ||
| 574 | ;; | ||
| 575 | ;; \step{LABEL}{CLAIM} and \begin{step+}{LABEL} | ||
| 576 | ;; CLAIM | ||
| 577 | ;; \end{step+} | ||
| 578 | ;; | ||
| 579 | ;; We need to trick RefTeX into swallowing this: | ||
| 580 | ;; | ||
| 581 | ;; ;; Configuration for Lamport's pf.sty | ||
| 582 | ;; (setq reftex-label-alist | ||
| 583 | ;; '(("\\step{*}{}" ?p "st:" "~\\stepref{%s}" 2 ("Step" "St.")) | ||
| 584 | ;; ("\\begin{step+}{*}" ?p "st:" "~\\stepref{%s}" 1000))) | ||
| 585 | ;; | ||
| 586 | ;; The first line is just a normal configuration for a macro. For the | ||
| 587 | ;; `step+' environment we actually tell RefTeX to look for the *macro* | ||
| 588 | ;; "\begin{step+}" and interprete the *first* argument (which in reality | ||
| 589 | ;; is a second argument to the macro \begin) as a label of type ?p. | ||
| 590 | ;; Argument count for this macro starts only after the {step+}, also | ||
| 591 | ;; when specifying how to get context. | ||
| 592 | ;; | ||
| 593 | ;; o In XEmacs 19.15, the overlay library has a bug. RefTeX does not | ||
| 594 | ;; suffer from it, but since it loads the library, other packages like | ||
| 595 | ;; GNUS will switch from extents to overlays and hit the bug. Upgrade | ||
| 596 | ;; to XEmacs 20, or fix the overlay library (in line 180 of overlay.el, | ||
| 597 | ;; change `(list before after)' to `(cons before after)'). | ||
| 598 | ;;--------------------------------------------------------------------------- | 128 | ;;--------------------------------------------------------------------------- |
| 599 | ;; | 129 | ;; |
| 600 | ;; AUTHOR | 130 | ;; AUTHOR |
| @@ -609,32 +139,26 @@ | |||
| 609 | ;; http://www.strw.leidenuniv.nl/~dominik/Tools/ | 139 | ;; http://www.strw.leidenuniv.nl/~dominik/Tools/ |
| 610 | ;; ftp://strw.leidenuniv.nl/pub/dominik/ | 140 | ;; ftp://strw.leidenuniv.nl/pub/dominik/ |
| 611 | ;; | 141 | ;; |
| 142 | ;; The version at this site is compatible with Emacs 19 - the version | ||
| 143 | ;; distributed with Emacs 20 is not. | ||
| 144 | ;; | ||
| 612 | ;; THANKS TO: | 145 | ;; THANKS TO: |
| 613 | ;; --------- | 146 | ;; --------- |
| 614 | ;; At least the following people have invested time to test and bug-fix | 147 | ;; Thanks to the people on the Net who have used RefTeX and helped |
| 615 | ;; reftex.el. Some have send patches for fixes or new features, or came | 148 | ;; developing it with their reports. In particular thanks to |
| 616 | ;; up with useful ideas. | ||
| 617 | ;; | 149 | ;; |
| 618 | ;; Stephen Eglen <stephene@cogs.susx.ac.uk> | 150 | ;; F. Burstall, Alastair Burt, Soren Dayton, Stephen Eglen, |
| 619 | ;; F.E. Burstall <F.E.Burstall@maths.bath.ac.uk> | 151 | ;; Karl Eichwalder, Peter Galbraith, Dieter Kraft, Adrian Lanz, |
| 620 | ;; Karl Eichwalder <ke@ke.Central.DE> | 152 | ;; Rory Molinari, Laurent Mugnier, Sudeep Kumar Palat, Daniel Polani, |
| 621 | ;; Laurent Mugnier <mugnier@onera.fr> | 153 | ;; Robin Socha, Richard Stanton, Allan Strand, Jan Vroonhof, |
| 622 | ;; Rory Molinari <molinari@yunt.math.lsa.umich.edu> | 154 | ;; Christoph Wedler. |
| 623 | ;; Soren Dayton <csdayton@cs.uchicago.edu> | ||
| 624 | ;; Daniel Polani <polani@Informatik.Uni-Mainz.DE> | ||
| 625 | ;; Allan Strand <astrand@trillium.NMSU.Edu> | ||
| 626 | ;; Adrian Lanz <lanz@waho.ethz.ch> | ||
| 627 | ;; Jan Vroonhof <vroonhof@math.ethz.ch> | ||
| 628 | ;; Alastair Burt <alastair.burt@dfki.de> | ||
| 629 | ;; Dieter Kraft <dkraft@acm.org> | ||
| 630 | ;; Robin S. Socha <r.socha@franck.pc.uni-koeln.de> | ||
| 631 | ;; | 155 | ;; |
| 632 | ;; The view crossref feature was inspired by the similar function in | 156 | ;; The view crossref feature was inspired by the similar function in |
| 633 | ;; Peter S. Galbraith's bib-cite.el. | 157 | ;; Peter Galbraith's bib-cite.el. |
| 634 | ;; | 158 | ;; |
| 635 | ;; Finally thanks to Uwe Bolick <bolick@physik.tu-berlin.de> who first | 159 | ;; Finally thanks to Uwe Bolick who first got me (some years ago) into |
| 636 | ;; got me (some years ago) into supporting LaTeX labels and references | 160 | ;; supporting LaTeX labels and references with an Editor (which was |
| 637 | ;; with an Editor (which was MicroEmacs at the time). | 161 | ;; MicroEmacs at the time). |
| 638 | ;; | 162 | ;; |
| 639 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 163 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 640 | ;; | 164 | ;; |
| @@ -687,7 +211,7 @@ | |||
| 687 | ("subequations" ?e nil nil t))) | 211 | ("subequations" ?e nil nil t))) |
| 688 | 212 | ||
| 689 | (endnotes "The \\endnote macro" | 213 | (endnotes "The \\endnote macro" |
| 690 | (("\\endnote[]{}" ?n nil nil 2 ("Endnote")))) | 214 | (("\\endnote[]{}" ?n nil nil 2 (regexp "Endnotes?")))) |
| 691 | 215 | ||
| 692 | (fancybox "The Beqnarray environment" | 216 | (fancybox "The Beqnarray environment" |
| 693 | (("Beqnarray" ?e nil nil eqnarray-like))) | 217 | (("Beqnarray" ?e nil nil eqnarray-like))) |
| @@ -720,28 +244,30 @@ | |||
| 720 | ;; The LaTeX core stuff | 244 | ;; The LaTeX core stuff |
| 721 | (LaTeX "LaTeX default environments" | 245 | (LaTeX "LaTeX default environments" |
| 722 | (("section" ?s "sec:" "~\\ref{%s}" (nil . t) | 246 | (("section" ?s "sec:" "~\\ref{%s}" (nil . t) |
| 723 | ("Part" "Chapter" "Chap." "Section" "Sec." "Sect." "Paragraph" "Par." | 247 | (regexp "Parts?" "Chapters?" "Chap\\." "Sections?" "Sect?\\." |
| 724 | "\\S" "Teil" "Kapitel" "Kap." "Abschnitt" )) | 248 | "Paragraphs?" "Par\\." |
| 249 | "\\\\S" "\247" "Teile?" "Kapitel" "Kap\\." "Abschnitte?" | ||
| 250 | "Appendi\\(x\\|ces\\)" "App\\." "Anh\"?ange?" "Anh\\.")) | ||
| 725 | 251 | ||
| 726 | ("enumerate" ?i "item:" "~\\ref{%s}" item | 252 | ("enumerate" ?i "item:" "~\\ref{%s}" item |
| 727 | ("Item" "Punkt")) | 253 | (regexp "Items?" "Punkte?")) |
| 728 | 254 | ||
| 729 | ("equation" ?e "eq:" "~(\\ref{%s})" t | 255 | ("equation" ?e "eq:" "~(\\ref{%s})" t |
| 730 | ("Equation" "Eq." "Eqn." "Gleichung" "Gl.")) | 256 | (regexp "Equations?" "Eqs?\\." "Eqn\\." "Gleichung\\(en\\)?" "Gl\\.")) |
| 731 | ("eqnarray" ?e "eq:" nil eqnarray-like) | 257 | ("eqnarray" ?e "eq:" nil eqnarray-like) |
| 732 | 258 | ||
| 733 | ("figure" ?f "fig:" "~\\ref{%s}" caption | 259 | ("figure" ?f "fig:" "~\\ref{%s}" caption |
| 734 | ("Figure" "Fig." "Abbildung" "Abb.")) | 260 | (regexp "Figure[sn]?" "Figs?\\." "Abbildung\\(en\\)?" "Abb\\.")) |
| 735 | ("figure*" ?f nil nil caption) | 261 | ("figure*" ?f nil nil caption) |
| 736 | 262 | ||
| 737 | ("table" ?t "tab:" "~\\ref{%s}" caption | 263 | ("table" ?t "tab:" "~\\ref{%s}" caption |
| 738 | ("Table" "Tab." "Tabelle")) | 264 | (regexp "Tables?" "Tab\\." "Tabellen?")) |
| 739 | ("table*" ?t nil nil caption) | 265 | ("table*" ?t nil nil caption) |
| 740 | 266 | ||
| 741 | ("\\footnote[]{}" ?n "note:" "~\\ref{%s}" 2 | 267 | ("\\footnote[]{}" ?n "note:" "~\\ref{%s}" 2 |
| 742 | ("Footnote" "Note")) | 268 | (regexp "Footnotes?" "Notes?")) |
| 743 | 269 | ||
| 744 | ("any" ?\ " " "\\ref{%s}" nil))) | 270 | ("any" ?\ " " "~\\ref{%s}" nil))) |
| 745 | 271 | ||
| 746 | ) | 272 | ) |
| 747 | "The default label environment descriptions. | 273 | "The default label environment descriptions. |
| @@ -778,7 +304,7 @@ distribution. Mixed-case symbols are convenience aliases.") | |||
| 778 | (?P . "\\shortcite{%l}") | 304 | (?P . "\\shortcite{%l}") |
| 779 | (?a . "\\citeA{%l}") | 305 | (?a . "\\citeA{%l}") |
| 780 | (?A . "\\shortciteA{%l}") | 306 | (?A . "\\shortciteA{%l}") |
| 781 | (?y . "\\citeyear{key}"))) | 307 | (?y . "\\citeyear{%l}"))) |
| 782 | (astron "The Astron package" | 308 | (astron "The Astron package" |
| 783 | ((?\C-m . "\\cite{%l}") | 309 | ((?\C-m . "\\cite{%l}") |
| 784 | (?p . "\\cite{%l}" ) | 310 | (?p . "\\cite{%l}" ) |
| @@ -822,12 +348,36 @@ The following conventions are valid for all alist entries: | |||
| 822 | (customize 'reftex)) | 348 | (customize 'reftex)) |
| 823 | (t (error "Custom.el not available")))) | 349 | (t (error "Custom.el not available")))) |
| 824 | 350 | ||
| 351 | (defun reftex-create-customize-menu () | ||
| 352 | "Create a full customization menu for RefTeX." | ||
| 353 | (interactive) | ||
| 354 | (if (fboundp 'customize-menu-create) | ||
| 355 | (progn | ||
| 356 | (easy-menu-change | ||
| 357 | '("Ref") "Customize" | ||
| 358 | `(["Browse RefTeX group" reftex-customize t] | ||
| 359 | "---" | ||
| 360 | ,(customize-menu-create 'reftex) | ||
| 361 | ["Set" Custom-set t] | ||
| 362 | ["Save" Custom-save t] | ||
| 363 | ["Reset to Current" Custom-reset-current t] | ||
| 364 | ["Reset to Saved" Custom-reset-saved t] | ||
| 365 | ["Reset to Standard Settings" Custom-reset-standard t])) | ||
| 366 | (message "\"Ref\"-menu now contains full customization menu")) | ||
| 367 | (error "Cannot expand menu (outdated version of cus-edit.el)"))) | ||
| 368 | |||
| 825 | (defun reftex-show-commentary () | 369 | (defun reftex-show-commentary () |
| 826 | "Use the finder to view the file documentation from `reftex.el'." | 370 | "Use the finder to view the file documentation from `reftex.el'." |
| 827 | (interactive) | 371 | (interactive) |
| 828 | (require 'finder) | 372 | (require 'finder) |
| 829 | (finder-commentary "reftex.el")) | 373 | (finder-commentary "reftex.el")) |
| 830 | 374 | ||
| 375 | (defun reftex-info () | ||
| 376 | "Read documentation for RefTeX in the info system." | ||
| 377 | (interactive) | ||
| 378 | (require 'info) | ||
| 379 | (Info-goto-node "(reftex)")) | ||
| 380 | |||
| 831 | ;; Support for \label and \ref -------------------------------------- | 381 | ;; Support for \label and \ref -------------------------------------- |
| 832 | 382 | ||
| 833 | (defgroup reftex-label-support nil | 383 | (defgroup reftex-label-support nil |
| @@ -925,8 +475,8 @@ one of its arguments. The elements of each list entry are: | |||
| 925 | 475 | ||
| 926 | 3. Format string for reference insert in buffer. `%s' will be replaced by | 476 | 3. Format string for reference insert in buffer. `%s' will be replaced by |
| 927 | the label. | 477 | the label. |
| 928 | When the format starts with `~', whitespace before point will be removed | 478 | When the format starts with `~', the `~' will only be inserted if |
| 929 | so that the reference cannot be separated from the word before it. | 479 | there is not already a whitespace before point. |
| 930 | 480 | ||
| 931 | 4. Indication on how to find the short context. | 481 | 4. Indication on how to find the short context. |
| 932 | - If nil, use the text following the \\label{...} macro. | 482 | - If nil, use the text following the \\label{...} macro. |
| @@ -935,7 +485,7 @@ one of its arguments. The elements of each list entry are: | |||
| 935 | - text following the \\begin{...} statement of environments. | 485 | - text following the \\begin{...} statement of environments. |
| 936 | (not a good choice for environments like eqnarray or enumerate, | 486 | (not a good choice for environments like eqnarray or enumerate, |
| 937 | where one has several labels in a single environment). | 487 | where one has several labels in a single environment). |
| 938 | - text after the macro name (stearting with the first arg) for macros. | 488 | - text after the macro name (starting with the first arg) for macros. |
| 939 | - If an integer, use the nth argument of the macro. As a special case, | 489 | - If an integer, use the nth argument of the macro. As a special case, |
| 940 | 1000 means to get text after the last macro argument. | 490 | 1000 means to get text after the last macro argument. |
| 941 | - If a string, use as regexp to search *backward* from the label. Context | 491 | - If a string, use as regexp to search *backward* from the label. Context |
| @@ -972,6 +522,9 @@ one of its arguments. The elements of each list entry are: | |||
| 972 | If the word before point is equal to one of these words when calling | 522 | If the word before point is equal to one of these words when calling |
| 973 | `reftex-reference', the label list offered will be automatically | 523 | `reftex-reference', the label list offered will be automatically |
| 974 | restricted to labels of the correct type. | 524 | restricted to labels of the correct type. |
| 525 | If the first element of this wordlist is the symbol `regexp', the | ||
| 526 | strings are interpreted as regular expressions. RefTeX will add | ||
| 527 | a \"\\\\W\" to the beginning and other stuff to the end of the regexp. | ||
| 975 | 528 | ||
| 976 | If the type indicator characters of two or more entries are the same, RefTeX | 529 | If the type indicator characters of two or more entries are the same, RefTeX |
| 977 | will use | 530 | will use |
| @@ -979,9 +532,9 @@ will use | |||
| 979 | - the magic words of all involved entries. | 532 | - the magic words of all involved entries. |
| 980 | 533 | ||
| 981 | Any list entry may also be a symbol. If that has an association in | 534 | Any list entry may also be a symbol. If that has an association in |
| 982 | `reftex-label-alist-builtin', the cdr of that association is spliced into the | 535 | `reftex-label-alist-builtin', the cddr of that association is spliced into the |
| 983 | list. However, builtin defaults should normally be set here but with the | 536 | list. However, builtin defaults should normally be set with the variable |
| 984 | variable `reftex-default-label-alist-entries." | 537 | `reftex-default-label-alist-entries." |
| 985 | :group 'reftex-defining-label-environments | 538 | :group 'reftex-defining-label-environments |
| 986 | :set 'reftex-set-dirty | 539 | :set 'reftex-set-dirty |
| 987 | :type | 540 | :type |
| @@ -1011,14 +564,14 @@ variable `reftex-default-label-alist-entries." | |||
| 1011 | (choice | 564 | (choice |
| 1012 | :tag " Derive label context" | 565 | :tag " Derive label context" |
| 1013 | ,@reftex-tmp))) | 566 | ,@reftex-tmp))) |
| 1014 | (repeat :tag "List of Magic Words" (string))) | 567 | (repeat :tag "List of Magic Words" (string))) |
| 1015 | (choice | 568 | (choice |
| 1016 | :tag "Package" | 569 | :tag "Package" |
| 1017 | :value AMSTeX | 570 | :value AMSTeX |
| 1018 | ,@(mapcar | 571 | ,@(mapcar |
| 1019 | (function | 572 | (function |
| 1020 | (lambda (x) | 573 | (lambda (x) |
| 1021 | (list 'const ':tag (concat (symbol-name (nth 0 x))); ": " (nth 1 x)) | 574 | (list 'const ':tag (concat (symbol-name (nth 0 x))) |
| 1022 | (nth 0 x)))) | 575 | (nth 0 x)))) |
| 1023 | reftex-label-alist-builtin))))) | 576 | reftex-label-alist-builtin))))) |
| 1024 | 577 | ||
| @@ -1101,11 +654,14 @@ DERIVE PROMPT ACTION | |||
| 1101 | t t Derive a label from context and prompt for confirmation. | 654 | t t Derive a label from context and prompt for confirmation. |
| 1102 | 655 | ||
| 1103 | Each flag may be set to t, nil, or a string of label type letters | 656 | Each flag may be set to t, nil, or a string of label type letters |
| 1104 | indicating the label types for which it should be true. | 657 | indicating the label types for which it should be true. The strings work |
| 658 | like character classes. | ||
| 1105 | Thus, the combination may be set differently for each label type. The | 659 | Thus, the combination may be set differently for each label type. The |
| 1106 | default settings \"s\" and \"sft\" mean: Derive section labels from headings | 660 | default settings \"s\" and \"sft\" mean: Derive section labels from headings |
| 1107 | (with confirmation). Prompt for figure and table labels. Use simple labels | 661 | (with confirmation). Prompt for figure and table labels. Use simple labels |
| 1108 | without confirmation for everything else." | 662 | without confirmation for everything else. |
| 663 | The available label types are: s (section), f (figure), t (table), i (item), | ||
| 664 | e (equation), n (footnote), plus any definitions in `reftex-label-alist'." | ||
| 1109 | :group 'reftex-making-and-inserting-labels | 665 | :group 'reftex-making-and-inserting-labels |
| 1110 | :type '(list (choice :tag "Derive label from context" | 666 | :type '(list (choice :tag "Derive label from context" |
| 1111 | (const :tag "always" t) | 667 | (const :tag "always" t) |
| @@ -1164,6 +720,15 @@ AFTER Character class after abbrev point in word." | |||
| 1164 | (string :tag "cut before char class " "^saeiou") | 720 | (string :tag "cut before char class " "^saeiou") |
| 1165 | (string :tag "cut after char class " "aeiou"))) | 721 | (string :tag "cut after char class " "aeiou"))) |
| 1166 | 722 | ||
| 723 | (defcustom reftex-format-label-function nil | ||
| 724 | "Function which produces the string to insert as a label definition. | ||
| 725 | Normally should be nil, unless you want to do something fancy. | ||
| 726 | The function will be called with two arguments, the LABEL and the DEFAULT | ||
| 727 | FORMAT, which usually is `\label{%s}'. The function should return the | ||
| 728 | string to insert into the buffer." | ||
| 729 | :group 'reftex-making-and-inserting-labels | ||
| 730 | :type 'function) | ||
| 731 | |||
| 1167 | ;; Label referencing | 732 | ;; Label referencing |
| 1168 | 733 | ||
| 1169 | (defgroup reftex-referencing-labels nil | 734 | (defgroup reftex-referencing-labels nil |
| @@ -1194,6 +759,8 @@ indicating the label types for which it should be true. These strings work | |||
| 1194 | like character classes in regular expressions. Thus, setting one of the | 759 | like character classes in regular expressions. Thus, setting one of the |
| 1195 | flags to \"sf\" makes the flag true for section and figure labels, nil | 760 | flags to \"sf\" makes the flag true for section and figure labels, nil |
| 1196 | for everything else. Setting it to \"^ft\" makes it the other way round. | 761 | for everything else. Setting it to \"^ft\" makes it the other way round. |
| 762 | The available label types are: s (section), f (figure), t (table), i (item), | ||
| 763 | e (equation), n (footnote), plus any definitions in `reftex-label-alist'. | ||
| 1197 | 764 | ||
| 1198 | Most options can also be switched from the label menu itself - so if you | 765 | Most options can also be switched from the label menu itself - so if you |
| 1199 | decide here to not have a table of contents in the label menu, you can still | 766 | decide here to not have a table of contents in the label menu, you can still |
| @@ -1210,6 +777,16 @@ get one interactively during selection from the label menu." | |||
| 1210 | (choice :tag "Searches match in toc lines " ,@reftex-tmp) | 777 | (choice :tag "Searches match in toc lines " ,@reftex-tmp) |
| 1211 | (choice :tag "Show begin/end of included files" ,@reftex-tmp))) | 778 | (choice :tag "Show begin/end of included files" ,@reftex-tmp))) |
| 1212 | 779 | ||
| 780 | (defcustom reftex-vref-is-default nil | ||
| 781 | "*Non-nil means, the varioref macro \\vref is used as default. | ||
| 782 | In the selection buffer, the `v' key toggles the reference macro between | ||
| 783 | `\\ref' and `\\vref'. The value of this variable determines the default | ||
| 784 | which is active when entering the selection process. | ||
| 785 | Instead of nil or t, this may also be a string of type letters indicating | ||
| 786 | the label types for which it should be true." | ||
| 787 | :group 'reftex-referencing-labels | ||
| 788 | :type `(choice :tag "\\vref is default macro" ,@reftex-tmp)) | ||
| 789 | |||
| 1213 | (defcustom reftex-level-indent 2 | 790 | (defcustom reftex-level-indent 2 |
| 1214 | "*Number of spaces to be used for indentation per section level." | 791 | "*Number of spaces to be used for indentation per section level." |
| 1215 | :group 'reftex-referencing-labels | 792 | :group 'reftex-referencing-labels |
| @@ -1217,13 +794,13 @@ get one interactively during selection from the label menu." | |||
| 1217 | 794 | ||
| 1218 | (defcustom reftex-refontify-context 1 | 795 | (defcustom reftex-refontify-context 1 |
| 1219 | "*Non-nil means, re-fontify the context in the label menu with font-lock. | 796 | "*Non-nil means, re-fontify the context in the label menu with font-lock. |
| 1220 | This slightly slows down the creation of the label menu. It is only necessay | 797 | This slightly slows down the creation of the label menu. It is only necessary |
| 1221 | when you definitely want the context fontified. | 798 | when you definitely want the context fontified. |
| 1222 | 799 | ||
| 1223 | This option may have 3 different values: | 800 | This option may have 3 different values: |
| 1224 | nil Never refontify. | 801 | nil Never refontify. |
| 1225 | t Always refontify. | 802 | t Always refontify. |
| 1226 | 1 Refontify when absolutly necessary, e.g. when with the x-symbol package. | 803 | 1 Refontify when absolutely necessary, e.g. when with the x-symbol package. |
| 1227 | The option is ignored when `reftex-use-fonts' is nil." | 804 | The option is ignored when `reftex-use-fonts' is nil." |
| 1228 | :group 'reftex-referencing-labels | 805 | :group 'reftex-referencing-labels |
| 1229 | :type '(choice | 806 | :type '(choice |
| @@ -1240,6 +817,16 @@ a label type. If you set this variable to nil, RefTeX will always prompt." | |||
| 1240 | :group 'reftex-referencing-labels | 817 | :group 'reftex-referencing-labels |
| 1241 | :type '(boolean)) | 818 | :type '(boolean)) |
| 1242 | 819 | ||
| 820 | (defcustom reftex-format-ref-function nil | ||
| 821 | "Function which produces the string to insert as a reference. | ||
| 822 | Normally should be nil, because the format to insert a reference can | ||
| 823 | already be specified in `reftex-label-alist'. | ||
| 824 | The function will be called with two arguments, the LABEL and the DEFAULT | ||
| 825 | FORMAT, which normally is `~\ref{%s}'. The function should return the | ||
| 826 | string to insert into the buffer." | ||
| 827 | :group 'reftex-referencing-labels | ||
| 828 | :type 'function) | ||
| 829 | |||
| 1243 | ;; BibteX citation configuration ---------------------------------------- | 830 | ;; BibteX citation configuration ---------------------------------------- |
| 1244 | 831 | ||
| 1245 | (defgroup reftex-citation-support nil | 832 | (defgroup reftex-citation-support nil |
| @@ -1262,6 +849,15 @@ like, which are ignored by RefTeX anyway." | |||
| 1262 | :set 'reftex-set-dirty | 849 | :set 'reftex-set-dirty |
| 1263 | :type '(repeat (string :tag "File name"))) | 850 | :type '(repeat (string :tag "File name"))) |
| 1264 | 851 | ||
| 852 | (defcustom reftex-default-bibliography nil | ||
| 853 | "*List of BibTeX database file which should be used if none are specified. | ||
| 854 | When `reftex-citation' is called from a document which has neither a | ||
| 855 | `\bibliography{..}' statement nor a `thebibliography' environment, | ||
| 856 | RefTeX will scan these files instead. Intended for using | ||
| 857 | `reftex-citation' in non-LaTeX files." | ||
| 858 | :group 'reftex-citation-support | ||
| 859 | :type '(repeat (file))) | ||
| 860 | |||
| 1265 | (defcustom reftex-sort-bibtex-matches 'reverse-year | 861 | (defcustom reftex-sort-bibtex-matches 'reverse-year |
| 1266 | "*Sorting of the entries found in BibTeX databases by reftex-citation. | 862 | "*Sorting of the entries found in BibTeX databases by reftex-citation. |
| 1267 | Possible values: | 863 | Possible values: |
| @@ -1299,6 +895,10 @@ It is also possible to access all other BibTeX database fields: | |||
| 1299 | 895 | ||
| 1300 | Usually, only %l is needed. Try, however, (setq reftex-comment-citations t). | 896 | Usually, only %l is needed. Try, however, (setq reftex-comment-citations t). |
| 1301 | 897 | ||
| 898 | Beware that all this only works when using BibTeX database files. When | ||
| 899 | citations are made from the \\bibitems in an explicit thebibliography | ||
| 900 | environment, only %l is available. | ||
| 901 | |||
| 1302 | If `reftex-cite-format' is an alist of characters and strings, the user | 902 | If `reftex-cite-format' is an alist of characters and strings, the user |
| 1303 | will be prompted for a character to select one of the possible format | 903 | will be prompted for a character to select one of the possible format |
| 1304 | strings. | 904 | strings. |
| @@ -1344,13 +944,22 @@ The comment is formatted according to `reftex-cite-comment-format'." | |||
| 1344 | This is a list of 3 strings. | 944 | This is a list of 3 strings. |
| 1345 | 1. normal names separator, like \", \" in Jones, Brown and Miller | 945 | 1. normal names separator, like \", \" in Jones, Brown and Miller |
| 1346 | 2. final names separator, like \" and \" in Jones, Brown and Miller | 946 | 2. final names separator, like \" and \" in Jones, Brown and Miller |
| 1347 | 3. The \"et al\" string, like \" {...}\" in Jones {\\it et al.}" | 947 | 3. The \"et al\" string, like \" {\\it et al.}\" in Jones {\\it et al.}" |
| 1348 | :group 'reftex-citation-support | 948 | :group 'reftex-citation-support |
| 1349 | :type '(list | 949 | :type '(list |
| 1350 | (string :tag "Separator for names ") | 950 | (string :tag "Separator for names ") |
| 1351 | (string :tag "Separator for last name in list") | 951 | (string :tag "Separator for last name in list") |
| 1352 | (string :tag "string used as et al. "))) | 952 | (string :tag "string used as et al. "))) |
| 1353 | 953 | ||
| 954 | (defcustom reftex-format-cite-function nil | ||
| 955 | "Function which produces the string to insert as a citation. | ||
| 956 | Normally should be nil, because the format to insert a reference can | ||
| 957 | already be specified in `reftex-cite-format'. | ||
| 958 | The function will be called with two arguments, the CITATION KEY and the | ||
| 959 | DEFAULT FORMAT, which is taken from `reftex-cite-format'. The function | ||
| 960 | should return the string to insert into the buffer." | ||
| 961 | :group 'reftex-citation-support | ||
| 962 | :type 'function) | ||
| 1354 | ;; Table of contents configuration -------------------------------------- | 963 | ;; Table of contents configuration -------------------------------------- |
| 1355 | 964 | ||
| 1356 | (defgroup reftex-table-of-contents-browser nil | 965 | (defgroup reftex-table-of-contents-browser nil |
| @@ -1409,6 +1018,13 @@ do a minimal initialization." | |||
| 1409 | (repeat :tag "Hook functions" :value (nil) | 1018 | (repeat :tag "Hook functions" :value (nil) |
| 1410 | (function-item)))) | 1019 | (function-item)))) |
| 1411 | 1020 | ||
| 1021 | (defcustom reftex-no-include-regexps '("\\.pstex_t\\'") ; default for x-symbol | ||
| 1022 | "*List of regular expressions to exclude certain input files from parsing. | ||
| 1023 | If the name of a file included via \\include or \\input is matched by any | ||
| 1024 | of the regular expressions in this list, that file is not parsed by RefTeX." | ||
| 1025 | :group 'reftex-optimizations-for-large-documents | ||
| 1026 | :type '(repeat (regexp))) | ||
| 1027 | |||
| 1412 | (defcustom reftex-enable-partial-scans nil | 1028 | (defcustom reftex-enable-partial-scans nil |
| 1413 | "*Non-nil means, re-parse only 1 file when asked to re-parse. | 1029 | "*Non-nil means, re-parse only 1 file when asked to re-parse. |
| 1414 | Re-parsing is normally requested with a `C-u' prefix to many RefTeX commands, | 1030 | Re-parsing is normally requested with a `C-u' prefix to many RefTeX commands, |
| @@ -1420,6 +1036,14 @@ in menus." | |||
| 1420 | :group 'reftex-optimizations-for-large-documents | 1036 | :group 'reftex-optimizations-for-large-documents |
| 1421 | :type 'boolean) | 1037 | :type 'boolean) |
| 1422 | 1038 | ||
| 1039 | (defcustom reftex-allow-automatic-rescan t | ||
| 1040 | "*Non-nil means, RefTeX may rescan the document when this seems necessary. | ||
| 1041 | Currently this applies only to rescanning after label insertion, when | ||
| 1042 | the new label cannot be inserted correctly into the internal label | ||
| 1043 | list." | ||
| 1044 | :group 'reftex-optimizations-for-large-documents | ||
| 1045 | :type 'boolean) | ||
| 1046 | |||
| 1423 | (defcustom reftex-save-parse-info nil | 1047 | (defcustom reftex-save-parse-info nil |
| 1424 | "*Non-nil means, save information gathered with parsing in a file. | 1048 | "*Non-nil means, save information gathered with parsing in a file. |
| 1425 | The file MASTER.rel in the same directory as MASTER.tex is used to save the | 1049 | The file MASTER.rel in the same directory as MASTER.tex is used to save the |
| @@ -1431,6 +1055,27 @@ information. When this variable is t, | |||
| 1431 | :group 'reftex-optimizations-for-large-documents | 1055 | :group 'reftex-optimizations-for-large-documents |
| 1432 | :type 'boolean) | 1056 | :type 'boolean) |
| 1433 | 1057 | ||
| 1058 | (defcustom reftex-use-multiple-selection-buffers nil | ||
| 1059 | "*Non-nil means use a separate selection buffer for each label type. | ||
| 1060 | These buffers are kept from one selection to the next and need not to be | ||
| 1061 | created for each use - so the menu generally comes up faster. The | ||
| 1062 | selection buffers will be erased (and therefore updated) automatically | ||
| 1063 | when new labels in its category are added. See the variable | ||
| 1064 | `reftex-auto-update-selection-buffers'." | ||
| 1065 | :group 'reftex-optimizations-for-large-documents | ||
| 1066 | :type 'boolean) | ||
| 1067 | |||
| 1068 | (defcustom reftex-auto-update-selection-buffers t | ||
| 1069 | "*Non-nil means, selection buffers will be updated automatically. | ||
| 1070 | When a new label is defined with `reftex-label', all selection buffers | ||
| 1071 | associated with that label category are emptied, in order to force an | ||
| 1072 | update upon next use. When nil, the buffers are left alone and have to be | ||
| 1073 | updated by hand, with the `g' key from the label selection process. | ||
| 1074 | The value of this variable will only have any effect when | ||
| 1075 | `reftex-use-multiple-selection-buffers' is non-nil." | ||
| 1076 | :group 'reftex-optimizations-for-large-documents | ||
| 1077 | :type 'boolean) | ||
| 1078 | |||
| 1434 | ;; Miscellaneous configurations ----------------------------------------- | 1079 | ;; Miscellaneous configurations ----------------------------------------- |
| 1435 | 1080 | ||
| 1436 | (defgroup reftex-miscellaneous-configurations nil | 1081 | (defgroup reftex-miscellaneous-configurations nil |
| @@ -1493,6 +1138,12 @@ context to a temporary buffer (value 'copy)." | |||
| 1493 | (const :tag "Unhide section permanently" t) | 1138 | (const :tag "Unhide section permanently" t) |
| 1494 | (const :tag "Copy context to show" copy))) | 1139 | (const :tag "Copy context to show" copy))) |
| 1495 | 1140 | ||
| 1141 | (defcustom reftex-revisit-to-follow t | ||
| 1142 | "*Non-nil means, follow-mode will revisit files if necessary. | ||
| 1143 | When nil, follow-mode will be suspended for stuff in unvisited files." | ||
| 1144 | :group 'reftex-miscellaneous-configurations | ||
| 1145 | :type '(boolean)) | ||
| 1146 | |||
| 1496 | (defcustom reftex-load-hook nil | 1147 | (defcustom reftex-load-hook nil |
| 1497 | "Hook which is being run when loading reftex.el." | 1148 | "Hook which is being run when loading reftex.el." |
| 1498 | :group 'reftex-miscellaneous-configurations | 1149 | :group 'reftex-miscellaneous-configurations |
| @@ -1510,7 +1161,7 @@ context to a temporary buffer (value 'copy)." | |||
| 1510 | ;;; Define the formal stuff for a minor mode named RefTeX. | 1161 | ;;; Define the formal stuff for a minor mode named RefTeX. |
| 1511 | ;;; | 1162 | ;;; |
| 1512 | 1163 | ||
| 1513 | ;; This file corresponds to RefTeX version 3.7 | 1164 | ;; This file corresponds to RefTeX version 3.17 |
| 1514 | 1165 | ||
| 1515 | (defvar reftex-mode nil | 1166 | (defvar reftex-mode nil |
| 1516 | "Determines if RefTeX minor mode is active.") | 1167 | "Determines if RefTeX minor mode is active.") |
| @@ -1579,6 +1230,8 @@ on the menu bar. | |||
| 1579 | (defvar LaTeX-label-function) | 1230 | (defvar LaTeX-label-function) |
| 1580 | (defvar tex-main-file) | 1231 | (defvar tex-main-file) |
| 1581 | (defvar outline-minor-mode) | 1232 | (defvar outline-minor-mode) |
| 1233 | (defvar font-lock-fontify-region-function) | ||
| 1234 | (defvar font-lock-syntactic-keywords) | ||
| 1582 | 1235 | ||
| 1583 | ;;; =========================================================================== | 1236 | ;;; =========================================================================== |
| 1584 | ;;; | 1237 | ;;; |
| @@ -1611,7 +1264,7 @@ This function is intended for AUCTeX macro support." | |||
| 1611 | (TeX-argument-insert (or key "") optional optional))) | 1264 | (TeX-argument-insert (or key "") optional optional))) |
| 1612 | 1265 | ||
| 1613 | (defun reftex-plug-into-AUCTeX () | 1266 | (defun reftex-plug-into-AUCTeX () |
| 1614 | ;; Replace AucTeX functions with RefTeX functions. | 1267 | ;; Replace AUCTeX functions with RefTeX functions. |
| 1615 | ;; Which functions are replaced is controlled by the variable | 1268 | ;; Which functions are replaced is controlled by the variable |
| 1616 | ;; `reftex-plug-into-AUCTeX'. | 1269 | ;; `reftex-plug-into-AUCTeX'. |
| 1617 | (let ((flags | 1270 | (let ((flags |
| @@ -1711,6 +1364,7 @@ mode reset is done on the next occasion." | |||
| 1711 | symlist (cdr symlist) | 1364 | symlist (cdr symlist) |
| 1712 | symname (symbol-name symbol)) | 1365 | symname (symbol-name symbol)) |
| 1713 | (set symbol (intern (concat symname "-" (int-to-string index)))) | 1366 | (set symbol (intern (concat symname "-" (int-to-string index)))) |
| 1367 | (put (symbol-value symbol) ':master-index index) | ||
| 1714 | ;; Initialize if new symbols. | 1368 | ;; Initialize if new symbols. |
| 1715 | (if newflag (set (symbol-value symbol) nil))) | 1369 | (if newflag (set (symbol-value symbol) nil))) |
| 1716 | 1370 | ||
| @@ -1731,7 +1385,6 @@ mode reset is done on the next occasion." | |||
| 1731 | ;; When AUCTeX is loaded, we will use it's more sophisticated method. | 1385 | ;; When AUCTeX is loaded, we will use it's more sophisticated method. |
| 1732 | ;; We also support the default TeX and LaTeX modes by checking for a | 1386 | ;; We also support the default TeX and LaTeX modes by checking for a |
| 1733 | ;; variable tex-main-file. | 1387 | ;; variable tex-main-file. |
| 1734 | |||
| 1735 | (let | 1388 | (let |
| 1736 | ((master | 1389 | ((master |
| 1737 | (cond | 1390 | (cond |
| @@ -1773,7 +1426,8 @@ mode reset is done on the next occasion." | |||
| 1773 | (setq master (concat master ".tex"))) | 1426 | (setq master (concat master ".tex"))) |
| 1774 | (t | 1427 | (t |
| 1775 | ;; Something is wrong here. Throw an exception. | 1428 | ;; Something is wrong here. Throw an exception. |
| 1776 | (error "No such master file %s" master))) | 1429 | (buffer-file-name))) |
| 1430 | ; (error "No such master file %s" master))) | ||
| 1777 | (expand-file-name master))) | 1431 | (expand-file-name master))) |
| 1778 | 1432 | ||
| 1779 | (defun reftex-parse-one () | 1433 | (defun reftex-parse-one () |
| @@ -1891,16 +1545,30 @@ This works also without an active TAGS table." | |||
| 1891 | (concat "\\\\\\(label\\|[a-z]*ref\\){" (regexp-quote from) "}") | 1545 | (concat "\\\\\\(label\\|[a-z]*ref\\){" (regexp-quote from) "}") |
| 1892 | (format "\\\\\\1{%s}" to)))) | 1546 | (format "\\\\\\1{%s}" to)))) |
| 1893 | 1547 | ||
| 1548 | (defun reftex-save-all-document-buffers () | ||
| 1549 | "Save all documents associated with the current document. | ||
| 1550 | The function is useful after a global action like replacing or renumbering | ||
| 1551 | labels." | ||
| 1552 | (interactive) | ||
| 1553 | (let ((files (reftex-all-document-files)) | ||
| 1554 | file buffer) | ||
| 1555 | (save-excursion | ||
| 1556 | (while (setq file (pop files)) | ||
| 1557 | (setq buffer (reftex-get-buffer-visiting file)) | ||
| 1558 | (when buffer | ||
| 1559 | (set-buffer buffer) | ||
| 1560 | (save-buffer)))))) | ||
| 1561 | |||
| 1894 | ;;; =========================================================================== | 1562 | ;;; =========================================================================== |
| 1895 | ;;; | 1563 | ;;; |
| 1896 | ;;; Functions to create and reference automatic labels. | 1564 | ;;; Functions to create and reference automatic labels. |
| 1897 | 1565 | ||
| 1898 | ;; The following constants are derived from `reftex-label-alist'. | 1566 | ;; The following constants are derived from `reftex-label-alist'. |
| 1899 | 1567 | ||
| 1900 | ;; Prompt used for label type querys directed to the user. | 1568 | ;; Prompt used for label type queries directed to the user. |
| 1901 | (defconst reftex-type-query-prompt nil) | 1569 | (defconst reftex-type-query-prompt nil) |
| 1902 | 1570 | ||
| 1903 | ;; Help string for label type querys. | 1571 | ;; Help string for label type queries. |
| 1904 | (defconst reftex-type-query-help nil) | 1572 | (defconst reftex-type-query-help nil) |
| 1905 | 1573 | ||
| 1906 | ;; Alist relating label type to reference format. | 1574 | ;; Alist relating label type to reference format. |
| @@ -1944,9 +1612,7 @@ This works also without an active TAGS table." | |||
| 1944 | (defvar reftex-active-toc nil) | 1612 | (defvar reftex-active-toc nil) |
| 1945 | (defvar reftex-tex-path nil) | 1613 | (defvar reftex-tex-path nil) |
| 1946 | (defvar reftex-bib-path nil) | 1614 | (defvar reftex-bib-path nil) |
| 1947 | 1615 | (defvar reftex-prefix) | |
| 1948 | ;; Internal list with index numbers of labels in the selection menu | ||
| 1949 | (defvar reftex-label-index-list) | ||
| 1950 | 1616 | ||
| 1951 | ;; List of buffers created temporarily for lookup, which should be killed. | 1617 | ;; List of buffers created temporarily for lookup, which should be killed. |
| 1952 | (defvar reftex-buffers-to-kill nil) | 1618 | (defvar reftex-buffers-to-kill nil) |
| @@ -1966,6 +1632,7 @@ This works also without an active TAGS table." | |||
| 1966 | (defun reftex-access-scan-info (&optional rescan file) | 1632 | (defun reftex-access-scan-info (&optional rescan file) |
| 1967 | ;; Access the scanning info. When the multifile symbols are not yet tied, | 1633 | ;; Access the scanning info. When the multifile symbols are not yet tied, |
| 1968 | ;; tie them. When they are empty or RESCAN is non-nil, scan the document. | 1634 | ;; tie them. When they are empty or RESCAN is non-nil, scan the document. |
| 1635 | ;; When FILE is non-nil, parse only from that file. | ||
| 1969 | 1636 | ||
| 1970 | ;; Reset the mode if we had changes to important variables. | 1637 | ;; Reset the mode if we had changes to important variables. |
| 1971 | (when (or reftex-tables-dirty | 1638 | (when (or reftex-tables-dirty |
| @@ -1979,6 +1646,12 @@ This works also without an active TAGS table." | |||
| 1979 | (if (eq reftex-docstruct-symbol nil) | 1646 | (if (eq reftex-docstruct-symbol nil) |
| 1980 | ;; Symbols are not yet tied: Tie them. | 1647 | ;; Symbols are not yet tied: Tie them. |
| 1981 | (reftex-tie-multifile-symbols)) | 1648 | (reftex-tie-multifile-symbols)) |
| 1649 | |||
| 1650 | (when (or (null (symbol-value reftex-docstruct-symbol)) | ||
| 1651 | (member rescan '(t 1 (4) (16)))) | ||
| 1652 | ;; The docstruct will change: Remove selection buffers. | ||
| 1653 | (save-excursion | ||
| 1654 | (reftex-erase-all-selection-buffers))) | ||
| 1982 | 1655 | ||
| 1983 | (if (and (null (symbol-value reftex-docstruct-symbol)) | 1656 | (if (and (null (symbol-value reftex-docstruct-symbol)) |
| 1984 | reftex-save-parse-info) | 1657 | reftex-save-parse-info) |
| @@ -1992,11 +1665,7 @@ This works also without an active TAGS table." | |||
| 1992 | (reftex-do-parse rescan file)))) | 1665 | (reftex-do-parse rescan file)))) |
| 1993 | 1666 | ||
| 1994 | (defun reftex-do-parse (rescan &optional file) | 1667 | (defun reftex-do-parse (rescan &optional file) |
| 1995 | ;; Access the scanning info. When the multifile symbols are not yet tied, | 1668 | ;; Do a rescan. When allowed, do only a partial scan from FILE. |
| 1996 | ;; tie them. When they are have to be created, do a buffer scan to | ||
| 1997 | ;; fill them. | ||
| 1998 | |||
| 1999 | ;; If RESCAN is non-nil, enforce document scanning | ||
| 2000 | 1669 | ||
| 2001 | ;; Normalize the rescan argument | 1670 | ;; Normalize the rescan argument |
| 2002 | (setq rescan (cond ((eq rescan t) t) | 1671 | (setq rescan (cond ((eq rescan t) t) |
| @@ -2015,8 +1684,7 @@ This works also without an active TAGS table." | |||
| 2015 | (master (reftex-TeX-master-file)) | 1684 | (master (reftex-TeX-master-file)) |
| 2016 | (master-dir (file-name-as-directory (file-name-directory master))) | 1685 | (master-dir (file-name-as-directory (file-name-directory master))) |
| 2017 | (file (or file (buffer-file-name))) | 1686 | (file (or file (buffer-file-name))) |
| 2018 | from-file | 1687 | from-file appendix docstruct tmp) |
| 2019 | docstruct tmp) | ||
| 2020 | 1688 | ||
| 2021 | ;; Make sure replacement is really an option here | 1689 | ;; Make sure replacement is really an option here |
| 2022 | (when (and (eq rescan t) | 1690 | (when (and (eq rescan t) |
| @@ -2035,10 +1703,12 @@ This works also without an active TAGS table." | |||
| 2035 | (t (error "horrible!!")))) | 1703 | (t (error "horrible!!")))) |
| 2036 | 1704 | ||
| 2037 | ;; Find active toc entry and initialize section-numbers | 1705 | ;; Find active toc entry and initialize section-numbers |
| 2038 | (setq reftex-active-toc | 1706 | (setq reftex-active-toc (reftex-last-assoc-before-elt |
| 2039 | (reftex-last-assoc-before-elt | 1707 | 'toc (list 'bof from-file) old-list) |
| 2040 | 'toc (list 'bof from-file) old-list)) | 1708 | appendix (reftex-last-assoc-before-elt |
| 2041 | (reftex-init-section-numbers reftex-active-toc) | 1709 | 'appendix (list 'bof from-file) old-list)) |
| 1710 | |||
| 1711 | (reftex-init-section-numbers reftex-active-toc appendix) | ||
| 2042 | 1712 | ||
| 2043 | (if (eq rescan 1) | 1713 | (if (eq rescan 1) |
| 2044 | (message "Scanning entire document...") | 1714 | (message "Scanning entire document...") |
| @@ -2074,24 +1744,28 @@ This works also without an active TAGS table." | |||
| 2074 | (setcdr entry (cons is-multi nil))) | 1744 | (setcdr entry (cons is-multi nil))) |
| 2075 | (unless (assq 'xr docstruct) | 1745 | (unless (assq 'xr docstruct) |
| 2076 | (let* ((allxr (reftex-all-assq 'xr-doc docstruct)) | 1746 | (let* ((allxr (reftex-all-assq 'xr-doc docstruct)) |
| 2077 | (alist (mapcar | 1747 | (alist (mapcar |
| 2078 | '(lambda (x) | 1748 | (function |
| 1749 | (lambda (x) | ||
| 2079 | (if (setq tmp (reftex-find-tex-file (nth 2 x) | 1750 | (if (setq tmp (reftex-find-tex-file (nth 2 x) |
| 2080 | master-dir)) | 1751 | master-dir)) |
| 2081 | (cons (nth 1 x) tmp) | 1752 | (cons (nth 1 x) tmp) |
| 2082 | (message "Can't find external document %s" | 1753 | (message "Can't find external document %s" |
| 2083 | (nth 2 x)) | 1754 | (nth 2 x)) |
| 2084 | nil)) | 1755 | nil))) |
| 2085 | allxr)) | 1756 | allxr)) |
| 2086 | (alist (delete nil alist)) | 1757 | (alist (delete nil alist)) |
| 2087 | (allprefix (delete nil (mapcar 'car alist))) | 1758 | (allprefix (delete nil (mapcar 'car alist))) |
| 2088 | (regexp (concat "\\`\\(" (mapconcat 'identity allprefix "\\|") | 1759 | (regexp (if allprefix |
| 2089 | "\\)"))) | 1760 | (concat "\\`\\(" |
| 1761 | (mapconcat 'identity allprefix "\\|") | ||
| 1762 | "\\)") | ||
| 1763 | "\\\\\\\\\\\\"))) ; this will never match | ||
| 2090 | (push (list 'xr alist regexp) docstruct))) | 1764 | (push (list 'xr alist regexp) docstruct))) |
| 2091 | 1765 | ||
| 2092 | (set reftex-docstruct-symbol docstruct) | 1766 | (set reftex-docstruct-symbol docstruct) |
| 2093 | 1767 | ||
| 2094 | ;; Save the parsing informtion into a file? | 1768 | ;; Save the parsing information into a file? |
| 2095 | (if reftex-save-parse-info | 1769 | (if reftex-save-parse-info |
| 2096 | (reftex-access-parse-file 'write)))) | 1770 | (reftex-access-parse-file 'write)))) |
| 2097 | 1771 | ||
| @@ -2106,7 +1780,7 @@ This works also without an active TAGS table." | |||
| 2106 | ;; Scan the buffer for labels and save them in a list. | 1780 | ;; Scan the buffer for labels and save them in a list. |
| 2107 | (let ((regexp reftex-everything-regexp) | 1781 | (let ((regexp reftex-everything-regexp) |
| 2108 | (bound 0) | 1782 | (bound 0) |
| 2109 | file-found tmp | 1783 | file-found tmp include-file |
| 2110 | (level 1) | 1784 | (level 1) |
| 2111 | (highest-level 100) | 1785 | (highest-level 100) |
| 2112 | toc-entry next-buf) | 1786 | toc-entry next-buf) |
| @@ -2163,16 +1837,30 @@ This works also without an active TAGS table." | |||
| 2163 | 1837 | ||
| 2164 | ((match-end 7) | 1838 | ((match-end 7) |
| 2165 | ;; It's an include or input | 1839 | ;; It's an include or input |
| 2166 | (setq docstruct | 1840 | (setq include-file (reftex-match-string 7)) |
| 2167 | (reftex-parse-from-file | 1841 | (if (delq nil (mapcar |
| 2168 | (reftex-match-string 7) | 1842 | (lambda (x) (string-match x include-file)) |
| 2169 | docstruct master-dir))) | 1843 | reftex-no-include-regexps)) |
| 2170 | 1844 | (progn | |
| 2171 | ((match-end 8) | 1845 | ;; Ignore the file |
| 1846 | (push (list 'bof include-file) docstruct) | ||
| 1847 | (push (list 'eof include-file) docstruct)) | ||
| 1848 | ;; Parse it | ||
| 1849 | (setq docstruct | ||
| 1850 | (reftex-parse-from-file | ||
| 1851 | include-file | ||
| 1852 | docstruct master-dir)))) | ||
| 1853 | |||
| 1854 | ((match-end 9) | ||
| 1855 | ;; Appendix starts here | ||
| 1856 | (reftex-init-section-numbers nil t) | ||
| 1857 | (push (cons 'appendix t) docstruct)) | ||
| 1858 | |||
| 1859 | ((match-end 10) | ||
| 2172 | ;; A macro with label | 1860 | ;; A macro with label |
| 2173 | (save-excursion | 1861 | (save-excursion |
| 2174 | (let* ((mac (reftex-match-string 8)) | 1862 | (let* ((mac (reftex-match-string 10)) |
| 2175 | (label (progn (goto-char (match-end 8)) | 1863 | (label (progn (goto-char (match-end 10)) |
| 2176 | (save-match-data | 1864 | (save-match-data |
| 2177 | (reftex-no-props | 1865 | (reftex-no-props |
| 2178 | (reftex-nth-arg-wrapper | 1866 | (reftex-nth-arg-wrapper |
| @@ -2189,10 +1877,15 @@ This works also without an active TAGS table." | |||
| 2189 | (when (setq tmp (reftex-locate-bibliography-files master-dir)) | 1877 | (when (setq tmp (reftex-locate-bibliography-files master-dir)) |
| 2190 | (push (cons 'bib tmp) docstruct)) | 1878 | (push (cons 'bib tmp) docstruct)) |
| 2191 | 1879 | ||
| 1880 | (goto-char 1) | ||
| 1881 | (when (re-search-forward | ||
| 1882 | "\\(\\`\\|[\n\r]\\)[ \t]*\\\\begin{thebibliography}" nil t) | ||
| 1883 | (push (cons 'thebib file) docstruct)) | ||
| 1884 | |||
| 2192 | ;; Find external document specifications | 1885 | ;; Find external document specifications |
| 2193 | (goto-char 1) | 1886 | (goto-char 1) |
| 2194 | (while (re-search-forward "[\n\r][ \t]*\\\\externaldocument\\(\\[\\([^]]*\\)\\]\\)?{\\([^}]+\\)}" nil t) | 1887 | (while (re-search-forward "[\n\r][ \t]*\\\\externaldocument\\(\\[\\([^]]*\\)\\]\\)?{\\([^}]+\\)}" nil t) |
| 2195 | (push (list 'xr-doc (reftex-match-string 2) | 1888 | (push (list 'xr-doc (reftex-match-string 2) |
| 2196 | (reftex-match-string 3)) | 1889 | (reftex-match-string 3)) |
| 2197 | docstruct)) | 1890 | docstruct)) |
| 2198 | 1891 | ||
| @@ -2206,14 +1899,14 @@ This works also without an active TAGS table." | |||
| 2206 | docstruct)) | 1899 | docstruct)) |
| 2207 | 1900 | ||
| 2208 | (defun reftex-locate-bibliography-files (master-dir) | 1901 | (defun reftex-locate-bibliography-files (master-dir) |
| 2209 | ;; Scan buffer for bibliography macro and return file list. | 1902 | ;; Scan buffer for bibliography macro and return file list. |
| 2210 | (let (file-list) | 1903 | (let (file-list) |
| 2211 | (save-excursion | 1904 | (save-excursion |
| 2212 | (goto-char (point-min)) | 1905 | (goto-char (point-min)) |
| 2213 | (if (re-search-forward | 1906 | (if (re-search-forward |
| 2214 | "\\(\\`\\|[\n\r]\\)[ \t]*\\\\bibliography{[ \t]*\\([^}]+\\)" nil t) | 1907 | "\\(\\`\\|[\n\r]\\)[ \t]*\\\\bibliography{[ \t]*\\([^}]+\\)" nil t) |
| 2215 | (setq file-list | 1908 | (setq file-list |
| 2216 | (mapcar '(lambda (x) (concat x ".bib")) | 1909 | (mapcar (function (lambda (x) (concat x ".bib"))) |
| 2217 | (reftex-delete-list | 1910 | (reftex-delete-list |
| 2218 | reftex-bibfile-ignore-list | 1911 | reftex-bibfile-ignore-list |
| 2219 | (split-string | 1912 | (split-string |
| @@ -2222,7 +1915,8 @@ This works also without an active TAGS table." | |||
| 2222 | (delete nil | 1915 | (delete nil |
| 2223 | (mapcar | 1916 | (mapcar |
| 2224 | (function | 1917 | (function |
| 2225 | (lambda (file) (reftex-find-bib-file file master-dir))) | 1918 | (lambda (file) |
| 1919 | (reftex-find-bib-file file master-dir))) | ||
| 2226 | file-list))))) | 1920 | file-list))))) |
| 2227 | 1921 | ||
| 2228 | (defun reftex-last-assoc-before-elt (key elt list) | 1922 | (defun reftex-last-assoc-before-elt (key elt list) |
| @@ -2289,13 +1983,13 @@ This works also without an active TAGS table." | |||
| 2289 | (if (file-exists-p file) | 1983 | (if (file-exists-p file) |
| 2290 | ;; load the file and return t for success | 1984 | ;; load the file and return t for success |
| 2291 | (progn (load-file file) t) | 1985 | (progn (load-file file) t) |
| 2292 | ;; return nil for failure | 1986 | ;; throw an exception |
| 2293 | nil)) | 1987 | (error "No restore file %s" file))) |
| 2294 | ((eq action 'read) | 1988 | ((eq action 'read) |
| 2295 | (if (file-exists-p file) | 1989 | (if (file-exists-p file) |
| 2296 | ;; load the file and return t for success | 1990 | ;; load the file and return t for success |
| 2297 | (progn (load-file file) t) | 1991 | (progn (load-file file) t) |
| 2298 | ;; return nil for failure | 1992 | ;; return nil for failure, but no exception |
| 2299 | nil)) | 1993 | nil)) |
| 2300 | (t | 1994 | (t |
| 2301 | (save-excursion | 1995 | (save-excursion |
| @@ -2339,7 +2033,9 @@ This works also without an active TAGS table." | |||
| 2339 | If ENVIRONMENT is given, don't bother to find out yourself. | 2033 | If ENVIRONMENT is given, don't bother to find out yourself. |
| 2340 | If NO-INSERT is non-nil, do not insert label into buffer. | 2034 | If NO-INSERT is non-nil, do not insert label into buffer. |
| 2341 | With prefix arg, force to rescan document first. | 2035 | With prefix arg, force to rescan document first. |
| 2342 | The label is also inserted into the label list. | 2036 | When you are prompted to enter or confirm a label, and you reply with |
| 2037 | just the prefix or an empty string, no label at all will be inserted. | ||
| 2038 | A new label is also recorded into the label list. | ||
| 2343 | This function is controlled by the settings of reftex-insert-label-flags." | 2039 | This function is controlled by the settings of reftex-insert-label-flags." |
| 2344 | 2040 | ||
| 2345 | (interactive) | 2041 | (interactive) |
| @@ -2355,104 +2051,126 @@ This function is controlled by the settings of reftex-insert-label-flags." | |||
| 2355 | (error "Can't figure out what kind of label should be inserted")) | 2051 | (error "Can't figure out what kind of label should be inserted")) |
| 2356 | 2052 | ||
| 2357 | ;; Ok, go ahead. | 2053 | ;; Ok, go ahead. |
| 2358 | (let* ((entry (assoc environment reftex-env-or-mac-alist)) | 2054 | (catch 'exit |
| 2359 | (typekey (nth 1 entry)) | 2055 | (let* ((entry (assoc environment reftex-env-or-mac-alist)) |
| 2360 | (format (nth 3 entry)) | 2056 | (typekey (nth 1 entry)) |
| 2361 | label prefix valid default force-prompt) | 2057 | (format (nth 3 entry)) |
| 2362 | (when (and (eq (string-to-char environment) ?\\) | 2058 | label prefix valid default force-prompt rescan-is-useful) |
| 2363 | (nth 4 entry) | 2059 | (when (and (eq (string-to-char environment) ?\\) |
| 2364 | (memq (preceding-char) '(?\[ ?\{))) | 2060 | (nth 5 entry) |
| 2365 | (setq format "%s")) | 2061 | (memq (preceding-char) '(?\[ ?\{))) |
| 2366 | 2062 | (setq format "%s")) | |
| 2367 | (setq prefix (or (cdr (assoc typekey reftex-typekey-to-prefix-alist)) | 2063 | |
| 2368 | (concat typekey "-"))) | 2064 | (setq prefix (or (cdr (assoc typekey reftex-typekey-to-prefix-alist)) |
| 2369 | ;; Replace any escapes in the prefix | 2065 | (concat typekey "-"))) |
| 2370 | (setq prefix (reftex-replace-prefix-escapes prefix)) | 2066 | ;; Replace any escapes in the prefix |
| 2371 | 2067 | (setq prefix (reftex-replace-prefix-escapes prefix)) | |
| 2372 | ;; Make a default label. | 2068 | |
| 2373 | (cond | 2069 | ;; Make a default label. |
| 2374 | 2070 | (cond | |
| 2375 | ((reftex-typekey-check typekey (nth 0 reftex-insert-label-flags)) | ||
| 2376 | ;; Derive a label from context. | ||
| 2377 | (setq reftex-active-toc (reftex-last-assoc-before-elt | ||
| 2378 | 'toc (car (reftex-where-am-I)) | ||
| 2379 | (symbol-value reftex-docstruct-symbol))) | ||
| 2380 | (setq default (reftex-no-props | ||
| 2381 | (nth 2 (reftex-label-info " " nil nil t)))) | ||
| 2382 | ;; Catch the cases where the is actually no context available. | ||
| 2383 | (if (or (string-match "NO MATCH FOR CONTEXT REGEXP" default) | ||
| 2384 | (string-match "ILLEGAL VALUE OF PARSE" default) | ||
| 2385 | (string-match "SECTION HEADING NOT FOUND" default) | ||
| 2386 | (string-match "HOOK ERROR" default) | ||
| 2387 | (string-match "^[ \t]*$" default)) | ||
| 2388 | (setq default prefix | ||
| 2389 | force-prompt t) ; need to prompt | ||
| 2390 | (setq default (concat prefix (reftex-string-to-label default))) | ||
| 2391 | |||
| 2392 | ;; Make it unique. | ||
| 2393 | (setq default (reftex-uniquify-label default nil "-")))) | ||
| 2394 | |||
| 2395 | ((reftex-typekey-check typekey (nth 1 reftex-insert-label-flags)) ; prompt | ||
| 2396 | ;; Minimal default: the user will be prompted. | ||
| 2397 | (setq default prefix)) | ||
| 2398 | |||
| 2399 | (t | ||
| 2400 | ;; Make an automatic label. | ||
| 2401 | (setq default (reftex-uniquify-label prefix t)))) | ||
| 2402 | |||
| 2403 | ;; Should we ask the user? | ||
| 2404 | (if (or (reftex-typekey-check typekey | ||
| 2405 | (nth 1 reftex-insert-label-flags)) ; prompt | ||
| 2406 | force-prompt) | ||
| 2407 | |||
| 2408 | (while (not valid) | ||
| 2409 | ;; iterate until we get a legal label | ||
| 2410 | 2071 | ||
| 2411 | (setq label (read-string | 2072 | ((reftex-typekey-check typekey (nth 0 reftex-insert-label-flags)) |
| 2412 | (if (string= format "%s") "Naked Label: " "Label: ") | 2073 | ;; Derive a label from context. |
| 2413 | default)) | 2074 | (setq reftex-active-toc (reftex-last-assoc-before-elt |
| 2075 | 'toc (car (reftex-where-am-I)) | ||
| 2076 | (symbol-value reftex-docstruct-symbol))) | ||
| 2077 | (setq default (reftex-no-props | ||
| 2078 | (nth 2 (reftex-label-info " " nil nil t)))) | ||
| 2079 | ;; Catch the cases where the is actually no context available. | ||
| 2080 | (if (or (string-match "NO MATCH FOR CONTEXT REGEXP" default) | ||
| 2081 | (string-match "ILLEGAL VALUE OF PARSE" default) | ||
| 2082 | (string-match "SECTION HEADING NOT FOUND" default) | ||
| 2083 | (string-match "HOOK ERROR" default) | ||
| 2084 | (string-match "^[ \t]*$" default)) | ||
| 2085 | (setq default prefix | ||
| 2086 | force-prompt t) ; need to prompt | ||
| 2087 | (setq default (concat prefix (reftex-string-to-label default))) | ||
| 2088 | |||
| 2089 | ;; Make it unique. | ||
| 2090 | (setq default (reftex-uniquify-label default nil "-")))) | ||
| 2091 | |||
| 2092 | ((reftex-typekey-check typekey (nth 1 reftex-insert-label-flags)) | ||
| 2093 | ;; Minimal default: the user will be prompted. | ||
| 2094 | (setq default prefix)) | ||
| 2414 | 2095 | ||
| 2415 | ;; Lets make sure that this is a legal label | 2096 | (t |
| 2416 | (cond | 2097 | ;; Make an automatic label. |
| 2098 | (setq default (reftex-uniquify-label prefix t)))) | ||
| 2099 | |||
| 2100 | ;; Should we ask the user? | ||
| 2101 | (if (or (reftex-typekey-check typekey | ||
| 2102 | (nth 1 reftex-insert-label-flags)) ; prompt | ||
| 2103 | force-prompt) | ||
| 2104 | |||
| 2105 | (while (not valid) | ||
| 2106 | ;; iterate until we get a legal label | ||
| 2107 | |||
| 2108 | (setq label (read-string | ||
| 2109 | (if (string= format "%s") "Naked Label: " "Label: ") | ||
| 2110 | default)) | ||
| 2111 | |||
| 2112 | ;; Lets make sure that this is a legal label | ||
| 2113 | (cond | ||
| 2114 | |||
| 2115 | ((string-match (concat "\\`\\(" (regexp-quote prefix) | ||
| 2116 | "\\)?[ \t]*\\'") | ||
| 2117 | label) | ||
| 2118 | ;; No label at all, please | ||
| 2119 | (message "No label inserted.") | ||
| 2120 | (throw 'exit nil)) | ||
| 2121 | |||
| 2122 | ;; Test if label contains strange characters | ||
| 2123 | ((string-match reftex-label-illegal-re label) | ||
| 2124 | (message "Label \"%s\" contains illegal characters" label) | ||
| 2125 | (ding) | ||
| 2126 | (sit-for 2)) | ||
| 2127 | |||
| 2128 | ;; Look it up in the label list | ||
| 2129 | ((setq entry (assoc label | ||
| 2130 | (symbol-value reftex-docstruct-symbol))) | ||
| 2131 | (ding) | ||
| 2132 | (if (y-or-n-p | ||
| 2133 | (format "Label '%s' exists. Use anyway? " label)) | ||
| 2134 | (setq valid t))) | ||
| 2135 | |||
| 2136 | ;; Label is ok | ||
| 2137 | (t | ||
| 2138 | (setq valid t)))) | ||
| 2139 | (setq label default)) | ||
| 2140 | |||
| 2141 | ;; Insert the label into the label list | ||
| 2142 | (let* ((here-I-am-info (reftex-where-am-I)) | ||
| 2143 | (here-I-am (car here-I-am-info)) | ||
| 2144 | (note (if (cdr here-I-am-info) | ||
| 2145 | "" | ||
| 2146 | "POSITION UNCERTAIN. RESCAN TO FIX.")) | ||
| 2147 | (file (buffer-file-name)) | ||
| 2148 | (text nil) | ||
| 2149 | (tail (memq here-I-am (symbol-value reftex-docstruct-symbol)))) | ||
| 2150 | |||
| 2151 | (or (cdr here-I-am-info) (setq rescan-is-useful t)) | ||
| 2152 | |||
| 2153 | (if tail | ||
| 2154 | (setcdr tail (cons (list label typekey text file note) | ||
| 2155 | (cdr tail))))) | ||
| 2156 | |||
| 2157 | ;; Insert the label into the buffer | ||
| 2158 | (unless no-insert | ||
| 2159 | (insert | ||
| 2160 | (if reftex-format-label-function | ||
| 2161 | (funcall reftex-format-label-function label format) | ||
| 2162 | (format format label)))) | ||
| 2417 | 2163 | ||
| 2418 | ;; Test if label contains strange characters | 2164 | ;; Delete the corresponding selection buffers to force update on next use. |
| 2419 | ((string-match reftex-label-illegal-re label) | 2165 | (when reftex-auto-update-selection-buffers |
| 2420 | (message "Label \"%s\" contains illegal characters" label) | 2166 | (reftex-erase-buffer (reftex-make-selection-buffer-name typekey)) |
| 2421 | (ding) | 2167 | (reftex-erase-buffer (reftex-make-selection-buffer-name " "))) |
| 2422 | (sit-for 2)) | ||
| 2423 | 2168 | ||
| 2424 | ;; Look it up in the label list | 2169 | (when (and rescan-is-useful reftex-allow-automatic-rescan) |
| 2425 | ((setq entry (assoc label | 2170 | (reftex-parse-one)) |
| 2426 | (symbol-value reftex-docstruct-symbol))) | ||
| 2427 | (message "Label \"%s\" exists in file %s" label (nth 3 entry)) | ||
| 2428 | (ding) | ||
| 2429 | (sit-for 2)) | ||
| 2430 | 2171 | ||
| 2431 | ;; Label is ok | 2172 | ;; return value of the function is the label |
| 2432 | (t | 2173 | label))) |
| 2433 | (setq valid t)))) | ||
| 2434 | (setq label default)) | ||
| 2435 | |||
| 2436 | ;; Insert the label into the label list | ||
| 2437 | (let* ((here-I-am-info (reftex-where-am-I)) | ||
| 2438 | (here-I-am (car here-I-am-info)) | ||
| 2439 | (note (if (cdr here-I-am-info) | ||
| 2440 | "" | ||
| 2441 | "POSITION UNCERTAIN. RESCAN TO FIX.")) | ||
| 2442 | (file (buffer-file-name)) | ||
| 2443 | (text nil) | ||
| 2444 | (tail (memq here-I-am (symbol-value reftex-docstruct-symbol)))) | ||
| 2445 | |||
| 2446 | (if tail | ||
| 2447 | (setcdr tail (cons (list label typekey text file note) | ||
| 2448 | (cdr tail))))) | ||
| 2449 | |||
| 2450 | ;; Insert the label into the buffer | ||
| 2451 | (unless no-insert | ||
| 2452 | (insert (format format label))) | ||
| 2453 | |||
| 2454 | ;; return value of the function is the label | ||
| 2455 | label)) | ||
| 2456 | 2174 | ||
| 2457 | (defun reftex-string-to-label (string) | 2175 | (defun reftex-string-to-label (string) |
| 2458 | ;; Convert a string (a sentence) to a label. | 2176 | ;; Convert a string (a sentence) to a label. |
| @@ -2482,7 +2200,7 @@ This function is controlled by the settings of reftex-insert-label-flags." | |||
| 2482 | (setcdr (nthcdr (1- (nth 0 reftex-derive-label-parameters)) words) nil)) | 2200 | (setcdr (nthcdr (1- (nth 0 reftex-derive-label-parameters)) words) nil)) |
| 2483 | 2201 | ||
| 2484 | ;; First, try to use all words | 2202 | ;; First, try to use all words |
| 2485 | (setq string (mapconcat '(lambda(w) w) words | 2203 | (setq string (mapconcat 'identity words |
| 2486 | (nth 4 reftex-derive-label-parameters))) | 2204 | (nth 4 reftex-derive-label-parameters))) |
| 2487 | 2205 | ||
| 2488 | ;; Abbreviate words if enforced by user settings or string length | 2206 | ;; Abbreviate words if enforced by user settings or string length |
| @@ -2491,11 +2209,12 @@ This function is controlled by the settings of reftex-insert-label-flags." | |||
| 2491 | (> (length string) (nth 1 reftex-derive-label-parameters)))) | 2209 | (> (length string) (nth 1 reftex-derive-label-parameters)))) |
| 2492 | (setq words | 2210 | (setq words |
| 2493 | (mapcar | 2211 | (mapcar |
| 2494 | '(lambda (w) (if (string-match reftex-abbrev-regexp w) | 2212 | (function |
| 2495 | (match-string 1 w) | 2213 | (lambda (w) (if (string-match reftex-abbrev-regexp w) |
| 2496 | w)) | 2214 | (match-string 1 w) |
| 2215 | w))) | ||
| 2497 | words) | 2216 | words) |
| 2498 | string (mapconcat '(lambda(w) w) words | 2217 | string (mapconcat 'identity words |
| 2499 | (nth 4 reftex-derive-label-parameters)))) | 2218 | (nth 4 reftex-derive-label-parameters)))) |
| 2500 | 2219 | ||
| 2501 | ;; Shorten if still to long | 2220 | ;; Shorten if still to long |
| @@ -2584,21 +2303,26 @@ This function is controlled by the settings of reftex-insert-label-flags." | |||
| 2584 | "Select: [n]ext [p]revious [r]escan [ ]context e[x]tern [q]uit RET [?]HELP+more") | 2303 | "Select: [n]ext [p]revious [r]escan [ ]context e[x]tern [q]uit RET [?]HELP+more") |
| 2585 | 2304 | ||
| 2586 | (defconst reftex-select-label-help | 2305 | (defconst reftex-select-label-help |
| 2587 | " AVAILABLE KEYS IN REFERENCE LABEL MENU | 2306 | " n / p Go to next/previous label (Cursor motion works as well) |
| 2588 | -------------------------------------- | 2307 | C-c C-n/p Go to next/previous section heading. |
| 2589 | n / p Go to next/previous label (Cursor motion works as well) | 2308 | b / l Jump back to previous selection / Reuse last referenced label |
| 2590 | C-s / C-r Search forward/backward. Use repeated C-s/C-r as in isearch. | 2309 | C-s / C-r Search forward/backward. Use repeated C-s/C-r as in isearch. |
| 2591 | r / s Reparse document / Switch label type | 2310 | g / s Update menu / Switch label type |
| 2311 | r / R Reparse document / Reparse entire document | ||
| 2592 | x Switch to label menu of external document (with LaTeX package `xr') | 2312 | x Switch to label menu of external document (with LaTeX package `xr') |
| 2593 | t i c # % Toggle: [i]ncl. file borders, [t]able of contents, [c]ontext | 2313 | t i c # % Toggle: [i]ncl. file borders, [t]able of contents, [c]ontext |
| 2594 | [#] label counters, [%] labels in comments | 2314 | [#] label counters, [%] labels in comments |
| 2595 | SPC Show full context for current label in other window | 2315 | SPC / f Show full context in other window / Toggle follow mode |
| 2596 | f Toggle follow mode: other window will follow context | 2316 | v / e Toggle \\ref <-> \\vref / Recursive Edit into other window |
| 2597 | l / q Reuse last referenced label / Quit without accepting label | 2317 | TAB Enter a label with completion |
| 2598 | e Recursive Edit into other window | 2318 | q / RET Quit without accepting label / Accept current label") |
| 2599 | RET Accept current label") | 2319 | |
| 2320 | (defvar reftex-select-label-map nil | ||
| 2321 | "Keymap used for *RefTeX Select* buffer, when selecting a label. | ||
| 2322 | This keymap can be used to configure the label selection process which is | ||
| 2323 | started with the command \\[reftex-reference].") | ||
| 2600 | 2324 | ||
| 2601 | (defun reftex-reference (&optional type no-insert) | 2325 | (defun reftex-reference (&optional type no-insert cut) |
| 2602 | "Make a LaTeX reference. Look only for labels of a certain TYPE. | 2326 | "Make a LaTeX reference. Look only for labels of a certain TYPE. |
| 2603 | With prefix arg, force to rescan buffer for labels. This should only be | 2327 | With prefix arg, force to rescan buffer for labels. This should only be |
| 2604 | necessary if you have recently entered labels yourself without using | 2328 | necessary if you have recently entered labels yourself without using |
| @@ -2619,41 +2343,69 @@ When called with 2 C-u prefix args, disable magic word recognition." | |||
| 2619 | (unless type | 2343 | (unless type |
| 2620 | ;; guess type from context | 2344 | ;; guess type from context |
| 2621 | (if (and reftex-guess-label-type | 2345 | (if (and reftex-guess-label-type |
| 2622 | (setq type (assoc (downcase (reftex-word-before-point)) | 2346 | (setq type (reftex-guess-label-type))) |
| 2623 | reftex-words-to-typekey-alist))) | 2347 | (setq cut (cdr type) |
| 2624 | (setq type (cdr type)) | 2348 | type (car type)) |
| 2625 | (setq type (reftex-query-label-type)))) | 2349 | (setq type (reftex-query-label-type)))) |
| 2626 | 2350 | ||
| 2627 | (let (label pair | 2351 | (let* ((varioref (if (reftex-typekey-check |
| 2628 | (form (or (cdr (assoc type reftex-typekey-to-format-alist)) | 2352 | type reftex-vref-is-default) |
| 2629 | "\\ref{%s}"))) | 2353 | "\\vref" "\\ref")) |
| 2354 | (form "\\ref{%s}") | ||
| 2355 | label pair) | ||
| 2630 | 2356 | ||
| 2631 | ;; Have the user select a label | 2357 | ;; Have the user select a label |
| 2632 | (setq pair (reftex-offer-label-menu type)) | 2358 | (setq pair (save-excursion |
| 2633 | (setq label (car pair)) | 2359 | (reftex-offer-label-menu type))) |
| 2360 | (setq label (car pair) | ||
| 2361 | type (cdr pair) | ||
| 2362 | form (or (cdr (assoc type reftex-typekey-to-format-alist)) | ||
| 2363 | form)) | ||
| 2634 | 2364 | ||
| 2635 | (if (and label | 2365 | (if (and label |
| 2636 | (not no-insert)) | 2366 | (not no-insert)) |
| 2637 | (progn | 2367 | (progn |
| 2638 | ;; do we need to remove spaces? | 2368 | (if cut (backward-delete-char cut)) |
| 2639 | (if (string= "~" (substring form 0 1)) | 2369 | |
| 2640 | (while (or (= (preceding-char) ?\ ) | 2370 | ;; remove ~ if we do already have a space |
| 2641 | (= (preceding-char) ?\C-i)) | 2371 | (when (and (= ?~ (string-to-char form)) |
| 2642 | (backward-delete-char 1))) | 2372 | (= ?\ (preceding-char))) |
| 2373 | (setq form (substring form 1))) | ||
| 2374 | ;; do we need to switch from \ref to \vref? | ||
| 2375 | (when (string= varioref "\\vref") | ||
| 2376 | (while (string-match "\\\\ref{" form) | ||
| 2377 | (setq form (replace-match "\\vref{" t t form)))) | ||
| 2643 | ;; ok, insert the reference | 2378 | ;; ok, insert the reference |
| 2644 | (insert (format form label label)) | 2379 | (insert |
| 2380 | (if reftex-format-ref-function | ||
| 2381 | (funcall reftex-format-ref-function label form) | ||
| 2382 | (format form label label))) | ||
| 2645 | (message "")) | 2383 | (message "")) |
| 2646 | (message "Quit")) | 2384 | (message "Quit")) |
| 2647 | ;; return the label | 2385 | ;; return the label |
| 2648 | label)) | 2386 | label)) |
| 2649 | 2387 | ||
| 2388 | (defun reftex-guess-label-type () | ||
| 2389 | (let ((words reftex-words-to-typekey-alist) | ||
| 2390 | (case-fold-search t) | ||
| 2391 | (bound (max (point-min) (- (point) 35))) | ||
| 2392 | matched cell) | ||
| 2393 | (save-excursion | ||
| 2394 | (while (and (setq cell (pop words)) | ||
| 2395 | (not (setq matched | ||
| 2396 | (re-search-backward (car cell) bound t)))))) | ||
| 2397 | (if matched | ||
| 2398 | (cons (cdr cell) (- (match-end 0) (match-end 1))) | ||
| 2399 | nil))) | ||
| 2400 | |||
| 2650 | (defun reftex-offer-label-menu (typekey) | 2401 | (defun reftex-offer-label-menu (typekey) |
| 2651 | ;; Offer a menu with the appropriate labels. Return (label . file). | 2402 | ;; Offer a menu with the appropriate labels. Return (label . typekey). |
| 2652 | (let* ((buf (current-buffer)) | 2403 | (let* ((buf (current-buffer)) |
| 2653 | (xr-data (assq 'xr (symbol-value reftex-docstruct-symbol))) | 2404 | (xr-data (assq 'xr (symbol-value reftex-docstruct-symbol))) |
| 2654 | (xr-alist (cons (cons "" (buffer-file-name)) (nth 1 xr-data))) | 2405 | (xr-alist (cons (cons "" (buffer-file-name)) (nth 1 xr-data))) |
| 2655 | (xr-index 0) | 2406 | (xr-index 0) |
| 2656 | (here-I-am (car (reftex-where-am-I))) | 2407 | (here-I-am (car (reftex-where-am-I))) |
| 2408 | (here-I-am1 here-I-am) | ||
| 2657 | (toc (reftex-typekey-check typekey reftex-label-menu-flags 0)) | 2409 | (toc (reftex-typekey-check typekey reftex-label-menu-flags 0)) |
| 2658 | (files (reftex-typekey-check typekey reftex-label-menu-flags 7)) | 2410 | (files (reftex-typekey-check typekey reftex-label-menu-flags 7)) |
| 2659 | (context (not (reftex-typekey-check | 2411 | (context (not (reftex-typekey-check |
| @@ -2666,7 +2418,8 @@ When called with 2 C-u prefix args, disable magic word recognition." | |||
| 2666 | (match-everywhere (reftex-typekey-check | 2418 | (match-everywhere (reftex-typekey-check |
| 2667 | typekey reftex-label-menu-flags 6)) | 2419 | typekey reftex-label-menu-flags 6)) |
| 2668 | (prefix "") | 2420 | (prefix "") |
| 2669 | offset rtn key cnt last-cnt entry) | 2421 | selection-buffers |
| 2422 | offset rtn key data last-data entry) | ||
| 2670 | 2423 | ||
| 2671 | (setq entry (cons nil nil)) | 2424 | (setq entry (cons nil nil)) |
| 2672 | 2425 | ||
| @@ -2675,63 +2428,79 @@ When called with 2 C-u prefix args, disable magic word recognition." | |||
| 2675 | (catch 'exit | 2428 | (catch 'exit |
| 2676 | (while t | 2429 | (while t |
| 2677 | (save-window-excursion | 2430 | (save-window-excursion |
| 2431 | (delete-other-windows) | ||
| 2678 | (setq reftex-call-back-to-this-buffer buf) | 2432 | (setq reftex-call-back-to-this-buffer buf) |
| 2679 | (switch-to-buffer-other-window "*RefTeX Select*") | 2433 | (if reftex-use-multiple-selection-buffers |
| 2680 | (erase-buffer) | 2434 | (switch-to-buffer-other-window |
| 2435 | (save-excursion | ||
| 2436 | (set-buffer buf) | ||
| 2437 | (reftex-make-selection-buffer-name typekey))) | ||
| 2438 | (switch-to-buffer-other-window "*RefTeX Select*") | ||
| 2439 | (erase-buffer)) | ||
| 2440 | (add-to-list 'selection-buffers (current-buffer)) | ||
| 2681 | (setq truncate-lines t) | 2441 | (setq truncate-lines t) |
| 2682 | (setq mode-line-format | 2442 | (setq mode-line-format |
| 2683 | (list "---- " 'mode-line-buffer-identification | 2443 | (list "---- " 'mode-line-buffer-identification |
| 2444 | " " 'varioref | ||
| 2684 | " " (abbreviate-file-name | 2445 | " " (abbreviate-file-name |
| 2685 | (buffer-file-name buf)) | 2446 | (buffer-file-name buf)) |
| 2686 | " -%-")) | 2447 | " -%-")) |
| 2687 | 2448 | (cond | |
| 2688 | (setq reftex-label-index-list | 2449 | ((= 0 (buffer-size)) |
| 2689 | (reftex-make-and-insert-label-list | 2450 | (setq offset (reftex-make-and-insert-label-list |
| 2690 | typekey buf toc files context counter commented | 2451 | typekey buf toc files context counter commented |
| 2691 | here-I-am prefix)) | 2452 | (or here-I-am offset) prefix))) |
| 2453 | (here-I-am | ||
| 2454 | (setq offset (reftex-get-offset buf here-I-am typekey))) | ||
| 2455 | (t (setq offset t))) | ||
| 2456 | (setq offset (or offset t)) | ||
| 2457 | |||
| 2692 | (setq here-I-am nil) ; turn off determination of offset | 2458 | (setq here-I-am nil) ; turn off determination of offset |
| 2693 | ;; use only when searched | ||
| 2694 | (setq offset (or (car reftex-label-index-list) offset)) | ||
| 2695 | ;; only this is the true list | ||
| 2696 | (pop reftex-label-index-list) | ||
| 2697 | (setq rtn | 2459 | (setq rtn |
| 2698 | (reftex-select-item | 2460 | (reftex-select-item |
| 2699 | reftex-select-label-prompt | 2461 | reftex-select-label-prompt |
| 2700 | "^>" | ||
| 2701 | 2 | ||
| 2702 | reftex-select-label-help | 2462 | reftex-select-label-help |
| 2703 | '(?r ?R ?g ?c ?t ?s ?# ?i ?l ?% ?x) | 2463 | reftex-select-label-map |
| 2704 | offset | 2464 | offset |
| 2705 | 'reftex-select-label-callback follow | 2465 | 'reftex-select-label-callback follow |
| 2706 | match-everywhere)) | 2466 | match-everywhere)) |
| 2707 | (setq key (car rtn) | 2467 | (setq key (car rtn) |
| 2708 | cnt (nth 1 rtn) | 2468 | data (nth 1 rtn) |
| 2709 | last-cnt (nth 2 rtn) | 2469 | last-data (nth 2 rtn) |
| 2710 | offset (1+ (or cnt last-cnt 0))) | 2470 | offset t) |
| 2711 | (unless key (throw 'exit nil)) | 2471 | (unless key (throw 'exit nil)) |
| 2712 | (cond | 2472 | (cond |
| 2473 | ((eq key ?g) | ||
| 2474 | ;; update buffer | ||
| 2475 | (erase-buffer)) | ||
| 2713 | ((or (eq key ?r) | 2476 | ((or (eq key ?r) |
| 2714 | (eq key ?R) | 2477 | (eq key ?R)) |
| 2715 | (eq key ?g)) | ||
| 2716 | ;; rescan buffer | 2478 | ;; rescan buffer |
| 2717 | (reftex-parse-document buf (or cnt last-cnt) key)) | 2479 | (erase-buffer) |
| 2480 | (reftex-parse-document buf last-data key)) | ||
| 2718 | ((eq key ?c) | 2481 | ((eq key ?c) |
| 2719 | ;; toggle context mode | 2482 | ;; toggle context mode |
| 2483 | (erase-buffer) | ||
| 2720 | (setq context (not context))) | 2484 | (setq context (not context))) |
| 2721 | ((eq key ?s) | 2485 | ((eq key ?s) |
| 2722 | ;; switch type | 2486 | ;; switch type |
| 2487 | (setq here-I-am here-I-am1) | ||
| 2723 | (setq typekey (reftex-query-label-type))) | 2488 | (setq typekey (reftex-query-label-type))) |
| 2724 | ((eq key ?t) | 2489 | ((eq key ?t) |
| 2725 | ;; toggle tabel of contents display | 2490 | ;; toggle table of contents display |
| 2491 | (erase-buffer) | ||
| 2726 | (setq toc (not toc))) | 2492 | (setq toc (not toc))) |
| 2727 | ((eq key ?i) | 2493 | ((eq key ?i) |
| 2728 | ;; toggle display of included file borders | 2494 | ;; toggle display of included file borders |
| 2495 | (erase-buffer) | ||
| 2729 | (setq files (not files))) | 2496 | (setq files (not files))) |
| 2730 | ((eq key ?#) | 2497 | ((eq key ?#) |
| 2731 | ;; toggle counter display | 2498 | ;; toggle counter display |
| 2499 | (erase-buffer) | ||
| 2732 | (setq counter (not counter))) | 2500 | (setq counter (not counter))) |
| 2733 | ((eq key ?%) | 2501 | ((eq key ?%) |
| 2734 | ;; toggle display of commented labels | 2502 | ;; toggle display of commented labels |
| 2503 | (erase-buffer) | ||
| 2735 | (setq commented (not commented))) | 2504 | (setq commented (not commented))) |
| 2736 | ((eq key ?l) | 2505 | ((eq key ?l) |
| 2737 | ;; reuse the last referenced label again | 2506 | ;; reuse the last referenced label again |
| @@ -2744,53 +2513,98 @@ When called with 2 C-u prefix args, disable magic word recognition." | |||
| 2744 | (setq buf (or (reftex-get-file-buffer-force | 2513 | (setq buf (or (reftex-get-file-buffer-force |
| 2745 | (cdr (nth xr-index xr-alist))) | 2514 | (cdr (nth xr-index xr-alist))) |
| 2746 | (error "Cannot switch document")) | 2515 | (error "Cannot switch document")) |
| 2747 | prefix (or (car (nth xr-index xr-alist)) "") | 2516 | prefix (or (car (nth xr-index xr-alist)) "")) |
| 2748 | offset nil)) | 2517 | (set-buffer buf) |
| 2518 | (reftex-access-scan-info)) | ||
| 2519 | ((stringp key) | ||
| 2520 | (setq entry | ||
| 2521 | (or (assoc key (symbol-value reftex-docstruct-symbol)) | ||
| 2522 | (list key typekey))) | ||
| 2523 | (throw 'exit t)) | ||
| 2749 | (t | 2524 | (t |
| 2750 | (set-buffer buf) | 2525 | (set-buffer buf) |
| 2751 | (if cnt | 2526 | (if data |
| 2752 | (progn | 2527 | (progn |
| 2753 | (setq entry (nth (nth cnt reftex-label-index-list) | 2528 | (setq entry data) |
| 2754 | (symbol-value reftex-docstruct-symbol))) | ||
| 2755 | (setq reftex-last-used-reference entry)) | 2529 | (setq reftex-last-used-reference entry)) |
| 2756 | (setq entry nil)) | 2530 | (setq entry nil)) |
| 2757 | (throw 'exit t)))))) | 2531 | (throw 'exit t)))))) |
| 2758 | (kill-buffer "*RefTeX Select*") | 2532 | (mapcar (function (lambda (buf) |
| 2759 | (and (get-buffer "*RefTeX Context Copy*") | 2533 | (and (buffer-live-p buf) |
| 2760 | (kill-buffer "*RefTeX Context Copy*")) | 2534 | (bury-buffer buf)))) |
| 2535 | selection-buffers) | ||
| 2536 | (reftex-kill-buffer "*RefTeX Context Copy*") | ||
| 2761 | (reftex-kill-temporary-buffers)) | 2537 | (reftex-kill-temporary-buffers)) |
| 2762 | (cons (if (nth 0 entry) (concat prefix (nth 0 entry)) nil) | 2538 | (cons (if (nth 0 entry) (concat prefix (nth 0 entry)) nil) |
| 2763 | (nth 3 entry)))) | 2539 | (nth 1 entry)))) |
| 2764 | 2540 | ||
| 2765 | (defun reftex-select-external-document (xr-alist xr-index) | 2541 | (defun reftex-select-external-document (xr-alist xr-index) |
| 2766 | ;; Return index of an external document. | 2542 | ;; Return index of an external document. |
| 2767 | (cond | 2543 | (let* ((len (length xr-alist)) (highest (1- (+ ?0 len))) |
| 2768 | ((= (length xr-alist) 1) | 2544 | (prompt (format "[%c-%c] Select SPC/DEL: Scroll TAB: Read prefix with completion" ?0 highest)) |
| 2769 | (message "No external douments available") | 2545 | key prefix) |
| 2770 | (ding) 0) | 2546 | (cond |
| 2771 | ((= (length xr-alist) 2) | 2547 | ((= len 1) |
| 2772 | (- 1 xr-index)) | 2548 | (message "No external documents available") |
| 2773 | (t | 2549 | (ding) 0) |
| 2774 | (save-window-excursion | 2550 | ((= len 2) |
| 2775 | (let* ((fmt " [%c] %-5s %s\n") (n (1- ?0)) key) | 2551 | (- 1 xr-index)) |
| 2776 | (with-output-to-temp-buffer "*RefTeX Select*" | 2552 | (t |
| 2777 | (princ | 2553 | (save-excursion |
| 2778 | (concat "Select a document by pressing a number key:\n KEY PREFIX DOCUMENT\n----------------------\n" | 2554 | (save-window-excursion |
| 2779 | (mapconcat '(lambda (x) | 2555 | (let* ((length (apply 'max (mapcar |
| 2780 | (format fmt (incf n) (or (car x) "") | 2556 | (lambda(x) (length (car x))) xr-alist))) |
| 2781 | (abbreviate-file-name (cdr x)))) | 2557 | (fmt (format " [%%c] %%-%ds %%s\n" length)) |
| 2782 | xr-alist "")))) | 2558 | (n (1- ?0))) |
| 2783 | (setq key (read-char)) | 2559 | (with-output-to-temp-buffer "*RefTeX Select*" |
| 2784 | (if (< (- key ?1) (length xr-alist)) | 2560 | (princ "SELECT EXTERNAL DOCUMENT\n------------------------\n") |
| 2785 | (- key ?0) | 2561 | (princ |
| 2786 | (error "Illegal document selection [%c]" key))))))) | 2562 | (mapconcat |
| 2787 | 2563 | (function | |
| 2564 | (lambda (x) | ||
| 2565 | (format fmt (incf n) (or (car x) "") | ||
| 2566 | (abbreviate-file-name (cdr x))))) | ||
| 2567 | xr-alist "")))) | ||
| 2568 | (reftex-enlarge-to-fit "*RefTeX Select*") | ||
| 2569 | (select-window (get-buffer-window "*RefTeX Select*")) | ||
| 2570 | (setq truncate-lines t) | ||
| 2571 | (catch 'exit | ||
| 2572 | (while t | ||
| 2573 | (princ prompt) | ||
| 2574 | (setq key (read-char-exclusive)) | ||
| 2575 | (cond | ||
| 2576 | ((= key ?\C-?) (condition-case nil (scroll-down) (error nil))) | ||
| 2577 | ((= key ?\ ) (condition-case nil (scroll-up) (error nil))) | ||
| 2578 | ((and (>= key ?0) (<= key highest)) | ||
| 2579 | (throw 'exit (- key ?0))) | ||
| 2580 | ((= key ?\C-i) | ||
| 2581 | (setq prefix (completing-read "Prefix: " xr-alist nil t)) | ||
| 2582 | (throw 'exit (- len (length (memq (assoc prefix xr-alist) | ||
| 2583 | xr-alist))))) | ||
| 2584 | (t (error "Illegal document selection [%c]" key))))))))))) | ||
| 2585 | |||
| 2586 | (defun reftex-make-selection-buffer-name (type &optional index) | ||
| 2587 | ;; Make unique name for a selection buffer. | ||
| 2588 | (format "*RefTeX[%s][%d]*" | ||
| 2589 | type (or index (get reftex-docstruct-symbol ':master-index) 0))) | ||
| 2590 | |||
| 2591 | (defun reftex-get-offset (buf here-am-I typekey) | ||
| 2592 | ;; Find the correct offset data, like make-and-insert would, but faster. | ||
| 2593 | (save-excursion | ||
| 2594 | (set-buffer buf) | ||
| 2595 | (reftex-access-scan-info) | ||
| 2596 | (let* ((rest (memq here-am-I (symbol-value reftex-docstruct-symbol))) | ||
| 2597 | entry) | ||
| 2598 | (while (and (setq entry (pop rest)) | ||
| 2599 | (not (and (stringp (car entry)) | ||
| 2600 | (equal typekey (nth 1 entry)))))) | ||
| 2601 | entry))) | ||
| 2602 | |||
| 2788 | (defun reftex-make-and-insert-label-list | 2603 | (defun reftex-make-and-insert-label-list |
| 2789 | (typekey0 buf toc files context counter show-commented here-I-am xr-prefix) | 2604 | (typekey0 buf toc files context counter show-commented here-I-am xr-prefix) |
| 2790 | ;; Insert a menu of all labels in buffer BUF into current buffer. | 2605 | ;; Insert a menu of all labels in buffer BUF into current buffer. |
| 2791 | ;; Return the list of labels, with the index of HERE-I-AM as extra car. | 2606 | ;; Return the data property of the entry corresponding to HERE-I-AM. |
| 2792 | (let* ((font (reftex-use-fonts)) | 2607 | (let* ((font (reftex-use-fonts)) |
| 2793 | (refont (reftex-refontify)) | ||
| 2794 | (cnt 0) | 2608 | (cnt 0) |
| 2795 | (index -1) | 2609 | (index -1) |
| 2796 | (toc-indent " ") | 2610 | (toc-indent " ") |
| @@ -2801,7 +2615,9 @@ When called with 2 C-u prefix args, disable magic word recognition." | |||
| 2801 | (concat ". " | 2615 | (concat ". " |
| 2802 | (if toc (make-string (* 7 reftex-level-indent) ?\ ) ""))) | 2616 | (if toc (make-string (* 7 reftex-level-indent) ?\ ) ""))) |
| 2803 | all cell text label typekey note comment master-dir-re | 2617 | all cell text label typekey note comment master-dir-re |
| 2804 | index-list offset docstruct-symbol from from1 to) | 2618 | offset from to docstruct-symbol) |
| 2619 | |||
| 2620 | (message "Creating Selection Buffer...") | ||
| 2805 | 2621 | ||
| 2806 | ;; Pop to buffer buf to get the correct buffer-local variables | 2622 | ;; Pop to buffer buf to get the correct buffer-local variables |
| 2807 | (save-excursion | 2623 | (save-excursion |
| @@ -2811,41 +2627,36 @@ When called with 2 C-u prefix args, disable magic word recognition." | |||
| 2811 | (reftex-access-scan-info) | 2627 | (reftex-access-scan-info) |
| 2812 | 2628 | ||
| 2813 | (setq docstruct-symbol reftex-docstruct-symbol | 2629 | (setq docstruct-symbol reftex-docstruct-symbol |
| 2814 | all (symbol-value reftex-docstruct-symbol) | 2630 | all (symbol-value reftex-docstruct-symbol) |
| 2815 | reftex-active-toc nil | 2631 | reftex-active-toc nil |
| 2816 | master-dir-re | 2632 | master-dir-re |
| 2817 | (concat "\\`" (regexp-quote | 2633 | (concat "\\`" (regexp-quote |
| 2818 | (file-name-directory (reftex-TeX-master-file)))))) | 2634 | (file-name-directory (reftex-TeX-master-file)))))) |
| 2819 | 2635 | ||
| 2820 | (when refont | 2636 | (set (make-local-variable 'reftex-docstruct-symbol) docstruct-symbol) |
| 2821 | ;; Calculate font-lock-defaults as in LaTeX mode. | 2637 | (set (make-local-variable 'reftex-prefix) |
| 2822 | (make-local-variable 'font-lock-defaults) | 2638 | (cdr (assoc typekey0 reftex-typekey-to-prefix-alist))) |
| 2823 | (setq font-lock-defaults nil) | 2639 | (if (equal reftex-prefix " ") (setq reftex-prefix nil)) |
| 2824 | (let ((major-mode 'latex-mode)) | ||
| 2825 | (font-lock-set-defaults)) | ||
| 2826 | ;; The following is only needed for XEmacs, but does not hurt Emacs. | ||
| 2827 | (setq font-lock-mode nil)) | ||
| 2828 | 2640 | ||
| 2829 | ;; Walk the docstruct and insert the appropriate stuff | 2641 | ;; Walk the docstruct and insert the appropriate stuff |
| 2830 | |||
| 2831 | (while (setq cell (pop all)) | 2642 | (while (setq cell (pop all)) |
| 2832 | 2643 | ||
| 2833 | (incf index) | 2644 | (incf index) |
| 2834 | (setq from (point)) | 2645 | (setq from (point)) |
| 2835 | 2646 | ||
| 2836 | (if (eq cell here-I-am) (setq offset (1+ cnt))) | 2647 | (if (eq cell here-I-am) (setq offset 'attention)) |
| 2837 | 2648 | ||
| 2838 | (cond | 2649 | (cond |
| 2839 | 2650 | ||
| 2840 | ((memq (car cell) '(bib label-numbers master-dir is-multi | 2651 | ((memq (car cell) '(bib thebib label-numbers appendix |
| 2841 | xr xr-doc))) | 2652 | master-dir is-multi xr xr-doc))) |
| 2842 | ;; These are currently ignored | 2653 | ;; These are currently ignored |
| 2843 | 2654 | ||
| 2844 | ((memq (car cell) '(bof eof file-error)) | 2655 | ((memq (car cell) '(bof eof file-error)) |
| 2845 | ;; Beginning or end of a file | 2656 | ;; Beginning or end of a file |
| 2846 | (when files | 2657 | (when files |
| 2847 | (insert | 2658 | (insert |
| 2848 | " " (if (string-match master-dir-re (nth 1 cell)) | 2659 | " File " (if (string-match master-dir-re (nth 1 cell)) |
| 2849 | (substring (nth 1 cell) (match-end 0)) | 2660 | (substring (nth 1 cell) (match-end 0)) |
| 2850 | (nth 1 cell)) | 2661 | (nth 1 cell)) |
| 2851 | (cond ((eq (car cell) 'bof) " starts here\n") | 2662 | (cond ((eq (car cell) 'bof) " starts here\n") |
| @@ -2865,9 +2676,7 @@ When called with 2 C-u prefix args, disable magic word recognition." | |||
| 2865 | ;; a label | 2676 | ;; a label |
| 2866 | (when (null (nth 2 cell)) | 2677 | (when (null (nth 2 cell)) |
| 2867 | ;; No context yet. Quick update. | 2678 | ;; No context yet. Quick update. |
| 2868 | (setq cell (reftex-label-info-update cell)) | 2679 | (setcdr cell (cdr (reftex-label-info-update cell)))) |
| 2869 | (setcar (nthcdr index (symbol-value docstruct-symbol)) | ||
| 2870 | cell)) | ||
| 2871 | 2680 | ||
| 2872 | (setq label (car cell) | 2681 | (setq label (car cell) |
| 2873 | typekey (nth 1 cell) | 2682 | typekey (nth 1 cell) |
| @@ -2880,7 +2689,7 @@ When called with 2 C-u prefix args, disable magic word recognition." | |||
| 2880 | 2689 | ||
| 2881 | ;; Yes we want this one | 2690 | ;; Yes we want this one |
| 2882 | (incf cnt) | 2691 | (incf cnt) |
| 2883 | (push index index-list) | 2692 | (if (eq offset 'attention) (setq offset cell)) |
| 2884 | 2693 | ||
| 2885 | (setq label (concat xr-prefix label)) | 2694 | (setq label (concat xr-prefix label)) |
| 2886 | (when comment (setq label (concat "% " label))) | 2695 | (when comment (setq label (concat "% " label))) |
| @@ -2899,19 +2708,16 @@ When called with 2 C-u prefix args, disable magic word recognition." | |||
| 2899 | (setq to (point)) | 2708 | (setq to (point)) |
| 2900 | 2709 | ||
| 2901 | (when context | 2710 | (when context |
| 2902 | (setq from1 to) | ||
| 2903 | (insert context-indent text "\n") | 2711 | (insert context-indent text "\n") |
| 2904 | (setq to (point)) | 2712 | (setq to (point))) |
| 2905 | (when refont | 2713 | (put-text-property from to ':data cell) |
| 2906 | (font-lock-fontify-region from1 to) | ||
| 2907 | (goto-char to))) | ||
| 2908 | (put-text-property from to 'cnt (1- cnt)) | ||
| 2909 | (goto-char to))))) | 2714 | (goto-char to))))) |
| 2910 | 2715 | ||
| 2911 | ;; Return the index list | 2716 | (when (reftex-refontify) |
| 2912 | (cons offset (nreverse index-list)))) | 2717 | (reftex-fontify-select-label-buffer)) |
| 2718 | offset)) | ||
| 2913 | 2719 | ||
| 2914 | (defun reftex-parse-document (&optional buffer cnt key) | 2720 | (defun reftex-parse-document (&optional buffer data key) |
| 2915 | "Rescan the document." | 2721 | "Rescan the document." |
| 2916 | (interactive) | 2722 | (interactive) |
| 2917 | (save-window-excursion | 2723 | (save-window-excursion |
| @@ -2921,10 +2727,7 @@ When called with 2 C-u prefix args, disable magic word recognition." | |||
| 2921 | (error "No such buffer %s" (buffer-name buffer)) | 2727 | (error "No such buffer %s" (buffer-name buffer)) |
| 2922 | (set-buffer buffer))) | 2728 | (set-buffer buffer))) |
| 2923 | (let ((arg (if (eq key ?R) '(16) '(4))) | 2729 | (let ((arg (if (eq key ?R) '(16) '(4))) |
| 2924 | (file (if cnt | 2730 | (file (nth 3 data))) |
| 2925 | (nth 3 | ||
| 2926 | (nth (nth cnt reftex-label-index-list) | ||
| 2927 | (symbol-value reftex-docstruct-symbol)))))) | ||
| 2928 | (reftex-access-scan-info arg file))))) | 2731 | (reftex-access-scan-info arg file))))) |
| 2929 | 2732 | ||
| 2930 | (defun reftex-query-label-type () | 2733 | (defun reftex-query-label-type () |
| @@ -2935,6 +2738,7 @@ When called with 2 C-u prefix args, disable magic word recognition." | |||
| 2935 | (save-window-excursion | 2738 | (save-window-excursion |
| 2936 | (with-output-to-temp-buffer "*RefTeX Help*" | 2739 | (with-output-to-temp-buffer "*RefTeX Help*" |
| 2937 | (princ reftex-type-query-help)) | 2740 | (princ reftex-type-query-help)) |
| 2741 | (reftex-enlarge-to-fit "*RefTeX Help*") | ||
| 2938 | (setq key (read-char)) | 2742 | (setq key (read-char)) |
| 2939 | (kill-buffer "*RefTeX Help*"))) | 2743 | (kill-buffer "*RefTeX Help*"))) |
| 2940 | (unless (member (char-to-string key) reftex-typekey-list) | 2744 | (unless (member (char-to-string key) reftex-typekey-list) |
| @@ -2951,8 +2755,7 @@ When called with 2 C-u prefix args, disable magic word recognition." | |||
| 2951 | (macro (reftex-match-string 3)) | 2755 | (macro (reftex-match-string 3)) |
| 2952 | (star (= ?* (char-after (match-end 3)))) | 2756 | (star (= ?* (char-after (match-end 3)))) |
| 2953 | (level (cdr (assoc macro reftex-section-levels))) | 2757 | (level (cdr (assoc macro reftex-section-levels))) |
| 2954 | (section-number (reftex-section-number | 2758 | (section-number (reftex-section-number level star)) |
| 2955 | reftex-section-numbers level star)) | ||
| 2956 | (text1 (save-match-data (save-excursion (reftex-context-substring)))) | 2759 | (text1 (save-match-data (save-excursion (reftex-context-substring)))) |
| 2957 | (literal (buffer-substring-no-properties | 2760 | (literal (buffer-substring-no-properties |
| 2958 | (1- (match-beginning 3)) | 2761 | (1- (match-beginning 3)) |
| @@ -3088,7 +2891,6 @@ When called with 2 C-u prefix args, disable magic word recognition." | |||
| 3088 | ;; Return the docstruct entry above point. Actually returns a cons | 2891 | ;; Return the docstruct entry above point. Actually returns a cons |
| 3089 | ;; cell in which the cdr is a flag indicating if the information is | 2892 | ;; cell in which the cdr is a flag indicating if the information is |
| 3090 | ;; exact (t) or approximate (nil). | 2893 | ;; exact (t) or approximate (nil). |
| 3091 | (interactive) | ||
| 3092 | 2894 | ||
| 3093 | (let ((docstruct (symbol-value reftex-docstruct-symbol)) | 2895 | (let ((docstruct (symbol-value reftex-docstruct-symbol)) |
| 3094 | (cnt 0) rtn | 2896 | (cnt 0) rtn |
| @@ -3140,16 +2942,16 @@ When called with 2 C-u prefix args, disable magic word recognition." | |||
| 3140 | (car | 2942 | (car |
| 3141 | (member (list 'eof (reftex-find-tex-file | 2943 | (member (list 'eof (reftex-find-tex-file |
| 3142 | (reftex-match-string 7) | 2944 | (reftex-match-string 7) |
| 3143 | (cons | 2945 | (cdr (assq 'master-dir docstruct)))) |
| 3144 | (cdr (assq 'master-dir docstruct)) | ||
| 3145 | reftex-tex-path))) | ||
| 3146 | docstruct))) | 2946 | docstruct))) |
| 3147 | ((match-end 8) | 2947 | ((match-end 9) |
| 2948 | (assq 'appendix (symbol-value reftex-docstruct-symbol))) | ||
| 2949 | ((match-end 10) | ||
| 3148 | (save-excursion | 2950 | (save-excursion |
| 3149 | (goto-char (match-end 8)) | 2951 | (goto-char (match-end 10)) |
| 3150 | (assoc (reftex-no-props | 2952 | (assoc (reftex-no-props |
| 3151 | (reftex-nth-arg-wrapper | 2953 | (reftex-nth-arg-wrapper |
| 3152 | (reftex-match-string 8))) | 2954 | (reftex-match-string 10))) |
| 3153 | (symbol-value reftex-docstruct-symbol)))) | 2955 | (symbol-value reftex-docstruct-symbol)))) |
| 3154 | (t | 2956 | (t |
| 3155 | (error "This should not happen (reftex-where-am-I)")))))) | 2957 | (error "This should not happen (reftex-where-am-I)")))))) |
| @@ -3271,82 +3073,88 @@ When called with 2 C-u prefix args, disable magic word recognition." | |||
| 3271 | ;; no list - just grab 100 characters | 3073 | ;; no list - just grab 100 characters |
| 3272 | (buffer-substring-no-properties (point) (min (reftex-fp 150) (point-max)))))) | 3074 | (buffer-substring-no-properties (point) (min (reftex-fp 150) (point-max)))))) |
| 3273 | 3075 | ||
| 3274 | (defun reftex-init-section-numbers (&optional toc-entry) | 3076 | (defun reftex-init-section-numbers (&optional toc-entry appendix) |
| 3275 | ;; Initialize the section numbers with zeros or with what is found | 3077 | ;; Initialize the section numbers with zeros or with what is found |
| 3276 | ;; in the toc entry. | 3078 | ;; in the toc entry. |
| 3277 | (let* ((level (or (nth 5 toc-entry) -1)) | 3079 | (let* ((level (or (nth 5 toc-entry) -1)) |
| 3278 | (numbers (nreverse (split-string (or (nth 6 toc-entry) "") "\\."))) | 3080 | (numbers (nreverse (split-string (or (nth 6 toc-entry) "") "\\."))) |
| 3279 | (depth (1- (length reftex-section-numbers))) | 3081 | (depth (1- (length reftex-section-numbers))) |
| 3280 | (i depth)) | 3082 | (i depth) number-string) |
| 3281 | (while (>= i 0) | 3083 | (while (>= i 0) |
| 3282 | (if (> i level) | 3084 | (if (> i level) |
| 3283 | (aset reftex-section-numbers i 0) | 3085 | (aset reftex-section-numbers i 0) |
| 3284 | (aset reftex-section-numbers i (string-to-int (or (car numbers) "0"))) | 3086 | (setq number-string (or (car numbers) "0")) |
| 3087 | (if (string-match "\\`[A-Z]\\'" number-string) | ||
| 3088 | (aset reftex-section-numbers i | ||
| 3089 | (- (string-to-char number-string) ?A -1)) | ||
| 3090 | (aset reftex-section-numbers i (string-to-int number-string))) | ||
| 3285 | (pop numbers)) | 3091 | (pop numbers)) |
| 3286 | (decf i)))) | 3092 | (decf i))) |
| 3093 | (put 'reftex-section-numbers 'appendix appendix)) | ||
| 3287 | 3094 | ||
| 3288 | (defun reftex-section-number (section-numbers &optional level star) | 3095 | (defun reftex-section-number (&optional level star) |
| 3289 | ;; Return a string with the current section number. | 3096 | ;; Return a string with the current section number. |
| 3290 | ;; When LEVEL is non-nil, increase section numbers on that level. | 3097 | ;; When LEVEL is non-nil, increase section numbers on that level. |
| 3291 | (let* ((depth (1- (length section-numbers))) idx n (string "")) | 3098 | (let* ((depth (1- (length reftex-section-numbers))) idx n (string "") |
| 3099 | (appendix (get 'reftex-section-numbers 'appendix))) | ||
| 3292 | (when level | 3100 | (when level |
| 3293 | (when (and (> level -1) (not star)) | 3101 | (when (and (> level -1) (not star)) |
| 3294 | (aset section-numbers level (1+ (aref section-numbers level)))) | 3102 | (aset reftex-section-numbers |
| 3103 | level (1+ (aref reftex-section-numbers level)))) | ||
| 3295 | (setq idx (1+ level)) | 3104 | (setq idx (1+ level)) |
| 3296 | (while (<= idx depth) | 3105 | (while (<= idx depth) |
| 3297 | (aset section-numbers idx 0) | 3106 | (aset reftex-section-numbers idx 0) |
| 3298 | (incf idx))) | 3107 | (incf idx))) |
| 3299 | (setq idx 0) | 3108 | (setq idx 0) |
| 3300 | (while (<= idx depth) | 3109 | (while (<= idx depth) |
| 3301 | (setq n (aref section-numbers idx)) | 3110 | (setq n (aref reftex-section-numbers idx)) |
| 3302 | (setq string (concat string (if (not (string= string "")) "." "") | 3111 | (setq string (concat string (if (not (string= string "")) "." "") |
| 3303 | (int-to-string n))) | 3112 | (int-to-string n))) |
| 3304 | (incf idx)) | 3113 | (incf idx)) |
| 3305 | (save-match-data | 3114 | (save-match-data |
| 3306 | (if (string-match "\\`\\(0\\.\\)+" string) | 3115 | (if (string-match "\\`\\([@0]\\.\\)+" string) |
| 3307 | (setq string (replace-match "" nil nil string))) | 3116 | (setq string (replace-match "" nil nil string))) |
| 3308 | (if (string-match "\\(\\.0\\)+\\'" string) | 3117 | (if (string-match "\\(\\.0\\)+\\'" string) |
| 3309 | (setq string (replace-match "" nil nil string)))) | 3118 | (setq string (replace-match "" nil nil string))) |
| 3119 | (if (and appendix | ||
| 3120 | (string-match "\\`[0-9]+" string)) | ||
| 3121 | (setq string (concat (char-to-string (1- (+ ?A (string-to-int (match-string 0 string))))) (substring string (match-end 0)))))) | ||
| 3122 | |||
| 3310 | (if star | 3123 | (if star |
| 3311 | (concat (make-string (1- (length string)) ?\ ) "*") | 3124 | (concat (make-string (1- (length string)) ?\ ) "*") |
| 3312 | string))) | 3125 | string))) |
| 3313 | 3126 | ||
| 3314 | ;; A variable to remember the index of the last label context shown | 3127 | (defun reftex-select-label-callback (data forward no-revisit) |
| 3315 | (defvar reftex-last-cnt 0) | ||
| 3316 | |||
| 3317 | (defun reftex-select-label-callback (cnt) | ||
| 3318 | ;; Callback function called from the label selection in order to | 3128 | ;; Callback function called from the label selection in order to |
| 3319 | ;; show context in another window | 3129 | ;; show context in another window |
| 3320 | (let* ((this-window (selected-window)) | 3130 | (let* ((this-window (selected-window)) |
| 3321 | index entry label file buffer re) | 3131 | label file buffer re found) |
| 3322 | ;; pop to original buffer in order to get correct variables | 3132 | ;; pop to original buffer in order to get correct variables |
| 3323 | (catch 'exit | 3133 | (catch 'exit |
| 3324 | (save-excursion | 3134 | (setq label (nth 0 data) |
| 3325 | (set-buffer reftex-call-back-to-this-buffer) | 3135 | file (nth 3 data)) |
| 3326 | (setq index (nth (or cnt 1) reftex-label-index-list) | ||
| 3327 | entry (nth index (symbol-value reftex-docstruct-symbol)) | ||
| 3328 | label (nth 0 entry) | ||
| 3329 | file (nth 3 entry))) | ||
| 3330 | 3136 | ||
| 3331 | ;; goto the file in another window | 3137 | ;; goto the file in another window |
| 3332 | (setq buffer (reftex-get-file-buffer-force | 3138 | (setq buffer |
| 3333 | file (not reftex-keep-temporary-buffers))) | 3139 | (if no-revisit |
| 3140 | (get-file-buffer file) | ||
| 3141 | (reftex-get-file-buffer-force | ||
| 3142 | file (not reftex-keep-temporary-buffers)))) | ||
| 3334 | (if buffer | 3143 | (if buffer |
| 3335 | ;; good - the file is available | 3144 | ;; good - the file is available |
| 3336 | (switch-to-buffer-other-window buffer) | 3145 | (switch-to-buffer-other-window buffer) |
| 3337 | ;; we have got a problem here. The file does not exist. | 3146 | ;; we have got a problem here. The file does not exist. |
| 3338 | ;; Let' get out of here.. | 3147 | ;; Let' get out of here.. |
| 3339 | (ding) | 3148 | ;; (ding) |
| 3340 | (throw 'exit nil)) | 3149 | (throw 'exit nil)) |
| 3341 | 3150 | ||
| 3342 | |||
| 3343 | ;; search for that label | 3151 | ;; search for that label |
| 3344 | (setq re (format reftex-find-label-regexp-format (regexp-quote label))) | 3152 | (setq re (format reftex-find-label-regexp-format (regexp-quote label))) |
| 3345 | (unless (and (integerp cnt) | 3153 | (setq found |
| 3346 | (integerp reftex-last-cnt) | 3154 | (if forward |
| 3347 | (if (> cnt reftex-last-cnt) | 3155 | (re-search-forward re nil t) |
| 3348 | (re-search-forward re nil t) | 3156 | (re-search-backward re nil t))) |
| 3349 | (re-search-backward re nil t))) | 3157 | (unless found |
| 3350 | (goto-char (point-min)) | 3158 | (goto-char (point-min)) |
| 3351 | (unless (re-search-forward re nil t) | 3159 | (unless (re-search-forward re nil t) |
| 3352 | ;; Ooops. Must be in a macro with distributed args. | 3160 | ;; Ooops. Must be in a macro with distributed args. |
| @@ -3398,21 +3206,24 @@ When called with 2 C-u prefix args, disable magic word recognition." | |||
| 3398 | (cnt 0) | 3206 | (cnt 0) |
| 3399 | (dlist | 3207 | (dlist |
| 3400 | (mapcar | 3208 | (mapcar |
| 3401 | '(lambda(x) | 3209 | (function |
| 3402 | (let (x1) | 3210 | (lambda (x) |
| 3403 | (cond | 3211 | (let (x1) |
| 3404 | ((memq (car x) | 3212 | (cond |
| 3405 | '(toc bof eof bib label-numbers xr xr-doc | 3213 | ((memq (car x) |
| 3406 | master-dir file-error is-multi)) | 3214 | '(toc bof eof bib thebib label-numbers xr xr-doc |
| 3407 | nil) | 3215 | master-dir file-error appendix is-multi)) |
| 3408 | (t | 3216 | nil) |
| 3409 | (setq x1 (reftex-all-assoc-string | 3217 | (t |
| 3410 | (car x) (symbol-value reftex-docstruct-symbol))) | 3218 | (setq x1 (reftex-all-assoc-string |
| 3411 | (if (< 1 (length x1)) | 3219 | (car x) (symbol-value reftex-docstruct-symbol))) |
| 3412 | (append (list (car x)) | 3220 | (if (< 1 (length x1)) |
| 3413 | (mapcar '(lambda(x) | 3221 | (append (list (car x)) |
| 3414 | (abbreviate-file-name (nth 3 x))) x1)) | 3222 | (mapcar (function |
| 3415 | (list nil)))))) | 3223 | (lambda(x) |
| 3224 | (abbreviate-file-name (nth 3 x)))) | ||
| 3225 | x1)) | ||
| 3226 | (list nil))))))) | ||
| 3416 | (reftex-uniquify (symbol-value reftex-docstruct-symbol))))) | 3227 | (reftex-uniquify (symbol-value reftex-docstruct-symbol))))) |
| 3417 | 3228 | ||
| 3418 | (setq dlist (reftex-uniquify dlist)) | 3229 | (setq dlist (reftex-uniquify dlist)) |
| @@ -3428,14 +3239,15 @@ When called with 2 C-u prefix args, disable magic word recognition." | |||
| 3428 | (insert " LABEL FILE\n") | 3239 | (insert " LABEL FILE\n") |
| 3429 | (insert " -------------------------------------------------------------\n") | 3240 | (insert " -------------------------------------------------------------\n") |
| 3430 | (use-local-map (make-sparse-keymap)) | 3241 | (use-local-map (make-sparse-keymap)) |
| 3431 | (local-set-key [?q] '(lambda () (interactive) | 3242 | (local-set-key [?q] (function |
| 3432 | (kill-buffer (current-buffer)) (delete-window))) | 3243 | (lambda () (interactive) |
| 3244 | (kill-buffer (current-buffer)) (delete-window)))) | ||
| 3433 | (local-set-key [?r] 'reftex-change-label) | 3245 | (local-set-key [?r] 'reftex-change-label) |
| 3434 | (while dlist | 3246 | (while dlist |
| 3435 | (when (and (car (car dlist)) | 3247 | (when (and (car (car dlist)) |
| 3436 | (cdr (car dlist))) | 3248 | (cdr (car dlist))) |
| 3437 | (incf cnt) | 3249 | (incf cnt) |
| 3438 | (insert (mapconcat '(lambda(x) x) (car dlist) "\n ") "\n")) | 3250 | (insert (mapconcat 'identity (car dlist) "\n ") "\n")) |
| 3439 | (pop dlist)) | 3251 | (pop dlist)) |
| 3440 | (goto-char (point-min)) | 3252 | (goto-char (point-min)) |
| 3441 | (when (= cnt 0) | 3253 | (when (= cnt 0) |
| @@ -3508,24 +3320,27 @@ When called with 2 C-u prefix args, disable magic word recognition." | |||
| 3508 | (reftex-highlight 0 (1+ (- (point) beg-hlt)) | 3320 | (reftex-highlight 0 (1+ (- (point) beg-hlt)) |
| 3509 | (1+ (- (point) end-hlt))) | 3321 | (1+ (- (point) end-hlt))) |
| 3510 | (when (reftex-refontify) | 3322 | (when (reftex-refontify) |
| 3511 | (make-local-variable 'font-lock-defaults) | 3323 | (set (make-local-variable 'font-lock-defaults) nil) |
| 3512 | (setq font-lock-defaults nil) | ||
| 3513 | (let ((major-mode 'latex-mode)) | 3324 | (let ((major-mode 'latex-mode)) |
| 3514 | (font-lock-set-defaults) | 3325 | (font-lock-mode 1))) |
| 3515 | (font-lock-fontify-buffer))) | ||
| 3516 | (setq buffer-read-only t))) | 3326 | (setq buffer-read-only t))) |
| 3517 | )))) | 3327 | )))) |
| 3518 | 3328 | ||
| 3519 | (defun reftex-nicify-text (text) | 3329 | (defun reftex-nicify-text (text) |
| 3520 | ;; Make TEXT nice for inclusion as context into label menu | 3330 | ;; Make TEXT nice for inclusion as context into label menu |
| 3521 | (while (string-match "[\n\r\t]\\|[ \t][ \t]+" text) ; remove extra whitespace | 3331 | ;; remove line breaks and extra white space |
| 3332 | (while (string-match "[\n\r\t]\\|[ \t][ \t]+" text) | ||
| 3522 | (setq text (replace-match " " nil t text))) | 3333 | (setq text (replace-match " " nil t text))) |
| 3523 | (if (string-match "\\\\end{.*" text) ; nothing beyond \end{ | 3334 | ;; cut before the next `\end{' or `\item' or `\\' |
| 3335 | (if (string-match "\\(\\\\end{\\|\\\\item\\|\\\\\\\\\\).*" text) | ||
| 3524 | (setq text (replace-match "" nil t text))) | 3336 | (setq text (replace-match "" nil t text))) |
| 3525 | (if (string-match "\\\\label{[^}]*}" text) ; kill the label | 3337 | ;; kill the embedded label |
| 3338 | (if (string-match "\\\\label{[^}]*}" text) | ||
| 3526 | (setq text (replace-match "" nil t text))) | 3339 | (setq text (replace-match "" nil t text))) |
| 3527 | (if (string-match "\\`[ }]+" text) ; leading whitespace, `}' | 3340 | ;; remove leading garbage |
| 3341 | (if (string-match "\\`[ }]+" text) | ||
| 3528 | (setq text (replace-match "" nil t text))) | 3342 | (setq text (replace-match "" nil t text))) |
| 3343 | ;; limit length | ||
| 3529 | (cond | 3344 | (cond |
| 3530 | ((> (length text) 100) (substring text 0 100)) | 3345 | ((> (length text) 100) (substring text 0 100)) |
| 3531 | ((= (length text) 0) " ") | 3346 | ((= (length text) 0) " ") |
| @@ -3544,6 +3359,9 @@ When called with 2 C-u prefix args, disable magic word recognition." | |||
| 3544 | 3359 | ||
| 3545 | ;; We keep at most one *toc* buffer - it is easy to make them | 3360 | ;; We keep at most one *toc* buffer - it is easy to make them |
| 3546 | 3361 | ||
| 3362 | (defvar reftex-toc-map (make-sparse-keymap) | ||
| 3363 | "Keymap used for *toc* buffer.") | ||
| 3364 | |||
| 3547 | (defvar reftex-last-toc-master nil | 3365 | (defvar reftex-last-toc-master nil |
| 3548 | "Stores the name of the tex file that `reftex-toc' was last run on.") | 3366 | "Stores the name of the tex file that `reftex-toc' was last run on.") |
| 3549 | 3367 | ||
| @@ -3558,12 +3376,13 @@ When called with 2 C-u prefix args, disable magic word recognition." | |||
| 3558 | (defconst reftex-toc-help | 3376 | (defconst reftex-toc-help |
| 3559 | " AVAILABLE KEYS IN TOC BUFFER | 3377 | " AVAILABLE KEYS IN TOC BUFFER |
| 3560 | ============================ | 3378 | ============================ |
| 3379 | n / p next-line / previous-line | ||
| 3561 | SPC Show the corresponding section of the LaTeX document. | 3380 | SPC Show the corresponding section of the LaTeX document. |
| 3562 | TAB Goto the section. | 3381 | TAB Goto the section. |
| 3563 | RET Goto the section and hide the *toc* buffer (also on mouse-2). | 3382 | RET Goto the section and hide the *toc* buffer (also on mouse-2). |
| 3564 | q / Q Hide/Kill *toc* buffer, return to position of last reftex-toc command. | 3383 | q / Q Hide/Kill *toc* buffer, return to position of last reftex-toc command. |
| 3565 | f Toggle follow mode on and off. | 3384 | f / g Toggle follow mode on and off / Refresh *toc* buffer. |
| 3566 | r / g Reparse the LaTeX document. | 3385 | r / R Reparse the LaTeX document / Reparse entire LaTeX document. |
| 3567 | x Switch to TOC of external document (with LaTeX package `xr').") | 3386 | x Switch to TOC of external document (with LaTeX package `xr').") |
| 3568 | 3387 | ||
| 3569 | (defun reftex-toc () | 3388 | (defun reftex-toc () |
| @@ -3596,34 +3415,24 @@ When called with a raw C-u prefix, rescan the document first." | |||
| 3596 | 3415 | ||
| 3597 | (if (get-buffer-window "*toc*") | 3416 | (if (get-buffer-window "*toc*") |
| 3598 | (select-window (get-buffer-window "*toc*")) | 3417 | (select-window (get-buffer-window "*toc*")) |
| 3418 | (when (< (window-height) (* 2 window-min-height)) | ||
| 3419 | (delete-other-windows)) | ||
| 3599 | (setq reftex-last-window-height (window-height)) ; remember | 3420 | (setq reftex-last-window-height (window-height)) ; remember |
| 3600 | (split-window-vertically) | 3421 | (split-window) |
| 3601 | (switch-to-buffer (get-buffer-create "*toc*"))) | 3422 | (switch-to-buffer (get-buffer-create "*toc*"))) |
| 3602 | 3423 | ||
| 3603 | (cond | 3424 | (cond |
| 3604 | ;; buffer is empty - fill it with the table of contents | 3425 | ;; buffer is empty - fill it with the table of contents |
| 3605 | ((= (buffer-size) 0) | 3426 | ((= (buffer-size) 0) |
| 3606 | 3427 | (message "Building *toc* buffer...") | |
| 3607 | (local-set-key "?" 'reftex-toc-show-help) | ||
| 3608 | (local-set-key " " 'reftex-toc-view-line) | ||
| 3609 | (local-set-key "\C-m" 'reftex-toc-goto-line-and-hide) | ||
| 3610 | (local-set-key "\C-i" 'reftex-toc-goto-line) | ||
| 3611 | (local-set-key "r" 'reftex-toc-redo) | ||
| 3612 | (local-set-key "R" 'reftex-toc-Redo) | ||
| 3613 | (local-set-key "g" 'revert-buffer) | ||
| 3614 | (local-set-key "q" 'reftex-toc-quit) | ||
| 3615 | (local-set-key "Q" 'reftex-toc-quit-and-kill) | ||
| 3616 | (local-set-key "f" 'reftex-toc-toggle-follow) | ||
| 3617 | (local-set-key "x" 'reftex-toc-external) | ||
| 3618 | (local-set-key [(mouse-2)] 'reftex-toc-mouse-goto-line-and-hide); Emacs | ||
| 3619 | (local-set-key [(button2)] 'reftex-toc-mouse-goto-line-and-hide); XEmacs | ||
| 3620 | (make-local-variable 'revert-buffer-function) | 3428 | (make-local-variable 'revert-buffer-function) |
| 3621 | (setq revert-buffer-function 'reftex-toc-redo) | 3429 | (setq revert-buffer-function 'reftex-toc-revert) |
| 3622 | (setq truncate-lines t) | 3430 | (setq truncate-lines t) |
| 3623 | (make-local-hook 'post-command-hook) | 3431 | (make-local-hook 'post-command-hook) |
| 3624 | (make-local-hook 'pre-command-hook) | 3432 | (make-local-hook 'pre-command-hook) |
| 3625 | (setq post-command-hook '(reftex-toc-post-command-hook)) | 3433 | (setq post-command-hook '(reftex-toc-post-command-hook)) |
| 3626 | (setq pre-command-hook '(reftex-toc-pre-command-hook)) | 3434 | (setq pre-command-hook '(reftex-toc-pre-command-hook)) |
| 3435 | (use-local-map reftex-toc-map) | ||
| 3627 | 3436 | ||
| 3628 | (insert (format | 3437 | (insert (format |
| 3629 | "TABLE-OF-CONTENTS on %s | 3438 | "TABLE-OF-CONTENTS on %s |
| @@ -3647,6 +3456,7 @@ SPC=view TAB=goto RET=goto+hide [q]uit [r]escan [f]ollow-mode e[x]tern [?]Help | |||
| 3647 | 3456 | ||
| 3648 | (backward-delete-char 1) | 3457 | (backward-delete-char 1) |
| 3649 | 3458 | ||
| 3459 | (message "Building *toc* buffer...done.") | ||
| 3650 | (setq buffer-read-only t)) | 3460 | (setq buffer-read-only t)) |
| 3651 | (t | 3461 | (t |
| 3652 | (goto-line 3) | 3462 | (goto-line 3) |
| @@ -3685,8 +3495,8 @@ SPC=view TAB=goto RET=goto+hide [q]uit [r]escan [f]ollow-mode e[x]tern [?]Help | |||
| 3685 | (reftex-toc-follow-mode | 3495 | (reftex-toc-follow-mode |
| 3686 | ;; show context in other window | 3496 | ;; show context in other window |
| 3687 | (condition-case nil | 3497 | (condition-case nil |
| 3688 | (reftex-toc-visit-line) | 3498 | (reftex-toc-visit-line nil (not reftex-revisit-to-follow)) |
| 3689 | (error (ding) t))))) | 3499 | (error t))))) |
| 3690 | 3500 | ||
| 3691 | (defun reftex-empty-toc-buffer () | 3501 | (defun reftex-empty-toc-buffer () |
| 3692 | (if (get-buffer "*toc*") | 3502 | (if (get-buffer "*toc*") |
| @@ -3745,8 +3555,8 @@ SPC=view TAB=goto RET=goto+hide [q]uit [r]escan [f]ollow-mode e[x]tern [?]Help | |||
| 3745 | (switch-to-buffer (marker-buffer reftex-toc-return-marker)) | 3555 | (switch-to-buffer (marker-buffer reftex-toc-return-marker)) |
| 3746 | (reftex-re-enlarge) | 3556 | (reftex-re-enlarge) |
| 3747 | (goto-char (marker-position reftex-toc-return-marker))) | 3557 | (goto-char (marker-position reftex-toc-return-marker))) |
| 3748 | (defun reftex-toc-redo (&rest ignore) | 3558 | (defun reftex-toc-rescan (&rest ignore) |
| 3749 | "Regenerate the *toc* buffer by reparsing file of last reftex-toc command." | 3559 | "Regenerate the *toc* buffer by reparsing file of section at point." |
| 3750 | (interactive) | 3560 | (interactive) |
| 3751 | (if reftex-enable-partial-scans | 3561 | (if reftex-enable-partial-scans |
| 3752 | (let ((file (nth 3 (get-text-property (point) 'toc)))) | 3562 | (let ((file (nth 3 (get-text-property (point) 'toc)))) |
| @@ -3756,27 +3566,39 @@ SPC=view TAB=goto RET=goto+hide [q]uit [r]escan [f]ollow-mode e[x]tern [?]Help | |||
| 3756 | (reftex-get-file-buffer-force file)) | 3566 | (reftex-get-file-buffer-force file)) |
| 3757 | (setq current-prefix-arg '(4)) | 3567 | (setq current-prefix-arg '(4)) |
| 3758 | (reftex-toc))) | 3568 | (reftex-toc))) |
| 3759 | (reftex-toc-Redo)) | 3569 | (reftex-toc-Rescan)) |
| 3760 | (reftex-kill-temporary-buffers)) | 3570 | (reftex-kill-temporary-buffers)) |
| 3761 | (defun reftex-toc-Redo (&rest ignore) | 3571 | (defun reftex-toc-Rescan (&rest ignore) |
| 3762 | "Regenerate the *toc* buffer by reparsing the entire document." | 3572 | "Regenerate the *toc* buffer by reparsing the entire document." |
| 3763 | (interactive) | 3573 | (interactive) |
| 3764 | (switch-to-buffer-other-window | 3574 | (switch-to-buffer-other-window |
| 3765 | (reftex-get-file-buffer-force reftex-last-toc-file)) | 3575 | (reftex-get-file-buffer-force reftex-last-toc-file)) |
| 3766 | (setq current-prefix-arg '(16)) | 3576 | (setq current-prefix-arg '(16)) |
| 3767 | (reftex-toc)) | 3577 | (reftex-toc)) |
| 3578 | (defun reftex-toc-revert (&rest ignore) | ||
| 3579 | "Regenerate the *toc* from the internal lists." | ||
| 3580 | (interactive) | ||
| 3581 | (switch-to-buffer-other-window | ||
| 3582 | (reftex-get-file-buffer-force reftex-last-toc-file)) | ||
| 3583 | (reftex-empty-toc-buffer) | ||
| 3584 | (setq current-prefix-arg nil) | ||
| 3585 | (reftex-toc)) | ||
| 3768 | (defun reftex-toc-external (&rest ignore) | 3586 | (defun reftex-toc-external (&rest ignore) |
| 3769 | "Switch to table of contents of an external document." | 3587 | "Switch to table of contents of an external document." |
| 3770 | (interactive) | 3588 | (interactive) |
| 3771 | (let* ((xr-alist (get-text-property 1 'xr-alist)) | 3589 | (let* ((old-buf (current-buffer)) |
| 3590 | (xr-alist (get-text-property 1 'xr-alist)) | ||
| 3772 | (xr-index (reftex-select-external-document | 3591 | (xr-index (reftex-select-external-document |
| 3773 | xr-alist 0))) | 3592 | xr-alist 0))) |
| 3774 | (switch-to-buffer-other-window (or (reftex-get-file-buffer-force | 3593 | (switch-to-buffer-other-window (or (reftex-get-file-buffer-force |
| 3775 | (cdr (nth xr-index xr-alist))) | 3594 | (cdr (nth xr-index xr-alist))) |
| 3776 | (error "Cannot switch document"))) | 3595 | (error "Cannot switch document"))) |
| 3777 | (reftex-toc))) | 3596 | (reftex-toc) |
| 3597 | (if (equal old-buf (current-buffer)) | ||
| 3598 | (message "") | ||
| 3599 | (message "Switched document")))) | ||
| 3778 | 3600 | ||
| 3779 | (defun reftex-toc-visit-line (&optional final) | 3601 | (defun reftex-toc-visit-line (&optional final no-revisit) |
| 3780 | ;; Visit the tex file corresponding to the toc entry on the current line. | 3602 | ;; Visit the tex file corresponding to the toc entry on the current line. |
| 3781 | ;; If FINAL is t, stay there | 3603 | ;; If FINAL is t, stay there |
| 3782 | ;; If FINAL is 'hide, hide the *toc* window. | 3604 | ;; If FINAL is 'hide, hide the *toc* window. |
| @@ -3804,12 +3626,13 @@ SPC=view TAB=goto RET=goto+hide [q]uit [r]escan [f]ollow-mode e[x]tern [?]Help | |||
| 3804 | (goto-char (marker-position marker)) | 3626 | (goto-char (marker-position marker)) |
| 3805 | (or (looking-at (regexp-quote literal)) | 3627 | (or (looking-at (regexp-quote literal)) |
| 3806 | (looking-at (reftex-make-regexp-allow-for-ctrl-m literal)) | 3628 | (looking-at (reftex-make-regexp-allow-for-ctrl-m literal)) |
| 3807 | (looking-at (reftex-make-desparate-section-regexp literal)) | 3629 | (looking-at (reftex-make-desperate-section-regexp literal)) |
| 3808 | (looking-at (concat "\\\\" | 3630 | (looking-at (concat "\\\\" |
| 3809 | (regexp-quote | 3631 | (regexp-quote |
| 3810 | (car (rassq level reftex-section-levels))) | 3632 | (car (rassq level reftex-section-levels))) |
| 3811 | "[[{]")))) | 3633 | "[[{]")))) |
| 3812 | (t | 3634 | ((or (not no-revisit) |
| 3635 | (get-file-buffer file)) | ||
| 3813 | ;; Marker is lost. Use the backup method. | 3636 | ;; Marker is lost. Use the backup method. |
| 3814 | (switch-to-buffer-other-window | 3637 | (switch-to-buffer-other-window |
| 3815 | (reftex-get-file-buffer-force file nil)) | 3638 | (reftex-get-file-buffer-force file nil)) |
| @@ -3821,7 +3644,7 @@ SPC=view TAB=goto RET=goto+hide [q]uit [r]escan [f]ollow-mode e[x]tern [?]Help | |||
| 3821 | (reftex-nearest-match | 3644 | (reftex-nearest-match |
| 3822 | (reftex-make-regexp-allow-for-ctrl-m literal) pos) | 3645 | (reftex-make-regexp-allow-for-ctrl-m literal) pos) |
| 3823 | (reftex-nearest-match | 3646 | (reftex-nearest-match |
| 3824 | (reftex-make-desparate-section-regexp literal) pos))))) | 3647 | (reftex-make-desperate-section-regexp literal) pos))))) |
| 3825 | )) | 3648 | )) |
| 3826 | 3649 | ||
| 3827 | (setq show-window (selected-window) | 3650 | (setq show-window (selected-window) |
| @@ -3856,7 +3679,6 @@ SPC=view TAB=goto RET=goto+hide [q]uit [r]escan [f]ollow-mode e[x]tern [?]Help | |||
| 3856 | ;; Variables and constants | 3679 | ;; Variables and constants |
| 3857 | 3680 | ||
| 3858 | ;; Define variable to silence compiler warnings | 3681 | ;; Define variable to silence compiler warnings |
| 3859 | (defvar reftex-found-list) | ||
| 3860 | (defvar reftex-cite-format-builtin) | 3682 | (defvar reftex-cite-format-builtin) |
| 3861 | 3683 | ||
| 3862 | ;; The history list of regular expressions used for citations | 3684 | ;; The history list of regular expressions used for citations |
| @@ -3867,17 +3689,21 @@ SPC=view TAB=goto RET=goto+hide [q]uit [r]escan [f]ollow-mode e[x]tern [?]Help | |||
| 3867 | "Select: [n]ext [p]revious [r]estrict [ ]full_entry [q]uit RET [?]Help+more") | 3689 | "Select: [n]ext [p]revious [r]estrict [ ]full_entry [q]uit RET [?]Help+more") |
| 3868 | 3690 | ||
| 3869 | (defconst reftex-citation-help | 3691 | (defconst reftex-citation-help |
| 3870 | "AVAILABLE KEYS IN MAKE CITATION MENU | 3692 | " n / p Go to next/previous entry (Cursor motion works as well). |
| 3871 | --------------------------------------- | ||
| 3872 | n / p Go to next/previous entry (Cursor motion works as well). | ||
| 3873 | C-s / C-r Search forward/backward. Use repeated C-s/C-r as in isearch. | 3693 | C-s / C-r Search forward/backward. Use repeated C-s/C-r as in isearch. |
| 3874 | g / r Start over with new regexp / Restrict with additional regexp. | 3694 | g / r Start over with new regexp / Refine with additional regexp. |
| 3875 | SPC Show full database entry in other window. | 3695 | SPC Show full database entry in other window. |
| 3876 | f Toggle follow mode: Other window will follow with full db entry. | 3696 | f Toggle follow mode: Other window will follow with full db entry. |
| 3877 | q Quit without inserting \\cite macro into buffer. | 3697 | q Quit without inserting \\cite macro into buffer. |
| 3878 | e Recursive edit into other window. | 3698 | e Recursive edit into other window. |
| 3699 | TAB Enter citation key with completion. | ||
| 3879 | RET / a Accept current entry / Accept all entries.") | 3700 | RET / a Accept current entry / Accept all entries.") |
| 3880 | 3701 | ||
| 3702 | (defvar reftex-select-bib-map nil | ||
| 3703 | "Keymap used for *RefTeX Select* buffer, when selecting a BibTeX entry. | ||
| 3704 | This keymap can be used to configure the BibTeX selection process which is | ||
| 3705 | started with the command \\[reftex-citation].") | ||
| 3706 | |||
| 3881 | ;; Find bibtex files | 3707 | ;; Find bibtex files |
| 3882 | 3708 | ||
| 3883 | (defun reftex-get-bibfile-list () | 3709 | (defun reftex-get-bibfile-list () |
| @@ -3900,26 +3726,30 @@ SPC=view TAB=goto RET=goto+hide [q]uit [r]escan [f]ollow-mode e[x]tern [?]Help | |||
| 3900 | (symbol-value reftex-docstruct-symbol)))) | 3726 | (symbol-value reftex-docstruct-symbol)))) |
| 3901 | ;; Anywhere in the entire document | 3727 | ;; Anywhere in the entire document |
| 3902 | (cdr (assq 'bib (symbol-value reftex-docstruct-symbol))) | 3728 | (cdr (assq 'bib (symbol-value reftex-docstruct-symbol))) |
| 3903 | (error "\\bibliography statment missing or .bib files not found."))) | 3729 | (error "\\bibliography statement missing or .bib files not found."))) |
| 3904 | 3730 | ||
| 3905 | (defun reftex-find-tex-file (file master-dir &optional die) | 3731 | (defun reftex-find-tex-file (file master-dir &optional die) |
| 3906 | ;; Find FILE in MASTER-DIR or on reftex-tex-path. | 3732 | ;; Find FILE in MASTER-DIR or on reftex-tex-path. |
| 3907 | ;; FILE may be given without the .tex extension. | 3733 | ;; FILE may be given without the .tex extension. |
| 3908 | (reftex-access-search-path "tex") | 3734 | (cond |
| 3909 | (let* ((path (cons master-dir reftex-tex-path)) | 3735 | ((file-name-absolute-p file) |
| 3910 | file1) | 3736 | (if (file-exists-p file) file nil)) |
| 3911 | (setq file1 | 3737 | (t |
| 3912 | (or (reftex-find-file-on-path (concat file ".tex") path) | 3738 | (reftex-access-search-path "tex") |
| 3913 | (reftex-find-file-on-path file path))) | 3739 | (let* ((path (cons master-dir reftex-tex-path)) |
| 3914 | (unless file1 | 3740 | file1) |
| 3915 | (reftex-access-search-path "tex" t file) | ||
| 3916 | (setq path (cons master-dir reftex-tex-path)) | ||
| 3917 | (setq file1 | 3741 | (setq file1 |
| 3918 | (or (reftex-find-file-on-path (concat file ".tex") path) | 3742 | (or (reftex-find-file-on-path (concat file ".tex") path) |
| 3919 | (reftex-find-file-on-path file path)))) | 3743 | (reftex-find-file-on-path file path))) |
| 3920 | (cond (file1 file1) | 3744 | (unless file1 |
| 3921 | (die (error "No such file: %s" file) nil) | 3745 | (reftex-access-search-path "tex" t file) |
| 3922 | (t (message "No such file: %s (ignored)" file) nil)))) | 3746 | (setq path (cons master-dir reftex-tex-path)) |
| 3747 | (setq file1 | ||
| 3748 | (or (reftex-find-file-on-path (concat file ".tex") path) | ||
| 3749 | (reftex-find-file-on-path file path)))) | ||
| 3750 | (cond (file1 file1) | ||
| 3751 | (die (error "No such file: %s" file) nil) | ||
| 3752 | (t (message "No such file: %s (ignored)" file) nil)))))) | ||
| 3923 | 3753 | ||
| 3924 | (defun reftex-find-bib-file (file master-dir &optional die) | 3754 | (defun reftex-find-bib-file (file master-dir &optional die) |
| 3925 | ;; Find FILE in MASTER-DIR or on reftex-bib-path | 3755 | ;; Find FILE in MASTER-DIR or on reftex-bib-path |
| @@ -3937,13 +3767,19 @@ SPC=view TAB=goto RET=goto+hide [q]uit [r]escan [f]ollow-mode e[x]tern [?]Help | |||
| 3937 | ;; Find a certain reference in any of the BibTeX files. | 3767 | ;; Find a certain reference in any of the BibTeX files. |
| 3938 | 3768 | ||
| 3939 | (defun reftex-pop-to-bibtex-entry (key file-list | 3769 | (defun reftex-pop-to-bibtex-entry (key file-list |
| 3940 | &optional mark-to-kill highlight) | 3770 | &optional mark-to-kill highlight item) |
| 3941 | ;; Find BibTeX KEY in any file in FILE-LIST in another window. | 3771 | ;; Find BibTeX KEY in any file in FILE-LIST in another window. |
| 3942 | ;; If mark-to-kill is non-nil, mark new buffer to kill." | 3772 | ;; If MARK-TO-KILL is non-nil, mark new buffer to kill. |
| 3943 | 3773 | ;; If HIGHLIGHT is non-nil, highlight the match. | |
| 3944 | (let* ((re (concat "@[a-zA-Z]+[ \t\n\r]*[{(][ \t\n\r]*" (regexp-quote key) "[ \t\n\r,]")) | 3774 | ;; If ITEM in non-nil, search for bibitem instead of database entry. |
| 3775 | |||
| 3776 | (let* ((re | ||
| 3777 | (if item | ||
| 3778 | (concat "\\\\bibitem\\(\\[[^]]*\\]\\)?{" (regexp-quote key) "}") | ||
| 3779 | (concat "@[a-zA-Z]+[ \t\n\r]*[{(][ \t\n\r]*" (regexp-quote key)))) | ||
| 3945 | (window-conf (current-window-configuration)) | 3780 | (window-conf (current-window-configuration)) |
| 3946 | file buf) | 3781 | file buf) |
| 3782 | |||
| 3947 | (catch 'exit | 3783 | (catch 'exit |
| 3948 | (switch-to-buffer-other-window (current-buffer)) | 3784 | (switch-to-buffer-other-window (current-buffer)) |
| 3949 | (while file-list | 3785 | (while file-list |
| @@ -3961,8 +3797,9 @@ SPC=view TAB=goto RET=goto+hide [q]uit [r]escan [f]ollow-mode e[x]tern [?]Help | |||
| 3961 | (reftex-highlight 0 (match-beginning 0) (match-end 0))) | 3797 | (reftex-highlight 0 (match-beginning 0) (match-end 0))) |
| 3962 | (throw 'exit (selected-window)))) | 3798 | (throw 'exit (selected-window)))) |
| 3963 | (set-window-configuration window-conf) | 3799 | (set-window-configuration window-conf) |
| 3964 | (beep) | 3800 | (if item |
| 3965 | (message "No BibTeX entry with citation key %s" key)))) | 3801 | (message "No \\bibitem with citation key %s" key) |
| 3802 | (message "No BibTeX entry with citation key %s" key))))) | ||
| 3966 | 3803 | ||
| 3967 | ;; Parse bibtex buffers | 3804 | ;; Parse bibtex buffers |
| 3968 | 3805 | ||
| @@ -3981,7 +3818,7 @@ SPC=view TAB=goto RET=goto+hide [q]uit [r]escan [f]ollow-mode e[x]tern [?]Help | |||
| 3981 | "[ \t]*&&[ \t]*")) | 3818 | "[ \t]*&&[ \t]*")) |
| 3982 | 3819 | ||
| 3983 | (setq first-re (car re-list) ; We'll use the first re to find things, | 3820 | (setq first-re (car re-list) ; We'll use the first re to find things, |
| 3984 | rest-re (cdr re-list)) ; the other to narrow down. | 3821 | rest-re (cdr re-list)) ; the others to narrow down. |
| 3985 | (if (string-match "\\`[ \t]*\\'" first-re) | 3822 | (if (string-match "\\`[ \t]*\\'" first-re) |
| 3986 | (error "Empty regular expression")) | 3823 | (error "Empty regular expression")) |
| 3987 | 3824 | ||
| @@ -4105,10 +3942,75 @@ SPC=view TAB=goto RET=goto+hide [q]uit [r]escan [f]ollow-mode e[x]tern [?]Help | |||
| 4105 | (reftex-parse-bibtex-entry nil start (point))) | 3942 | (reftex-parse-bibtex-entry nil start (point))) |
| 4106 | nil))))) | 3943 | nil))))) |
| 4107 | 3944 | ||
| 3945 | ;; Parse the thebibliography environment | ||
| 3946 | (defun reftex-extract-bib-entries-from-thebibliography (file) | ||
| 3947 | ;; Extract bib-entries from the \begin{thebibliography} environment. | ||
| 3948 | ;; Parsing is not as good as for the BibTeX database stuff. | ||
| 3949 | ;; The environment should be located in file FILE. | ||
| 3950 | |||
| 3951 | (let* (start end buf entries re re-list) | ||
| 3952 | (unless file | ||
| 3953 | (error "Need file name to find thebibliography environment")) | ||
| 3954 | (setq buf (reftex-get-file-buffer-force | ||
| 3955 | file (not reftex-keep-temporary-buffers))) | ||
| 3956 | (unless buf | ||
| 3957 | (error "No such file %s" file)) | ||
| 3958 | (message "Scanning thebibliography environment in %s" file) | ||
| 3959 | |||
| 3960 | (save-excursion | ||
| 3961 | (set-buffer buf) | ||
| 3962 | (save-restriction | ||
| 3963 | (widen) | ||
| 3964 | (goto-char (point-min)) | ||
| 3965 | (if (re-search-forward | ||
| 3966 | "\\(\\`\\|[\n\r]\\)[ \t]*\\\\begin{thebibliography}" nil t) | ||
| 3967 | (progn | ||
| 3968 | (beginning-of-line 2) | ||
| 3969 | (setq start (point)))) | ||
| 3970 | (if (re-search-forward | ||
| 3971 | "\\(\\`\\|[\n\r]\\)[ \t]*\\\\end{thebibliography}" nil t) | ||
| 3972 | (progn | ||
| 3973 | (beginning-of-line 1) | ||
| 3974 | (setq end (point)))) | ||
| 3975 | (when (and start (point)) | ||
| 3976 | (setq entries | ||
| 3977 | (mapcar 'reftex-parse-bibitem | ||
| 3978 | (delete "" | ||
| 3979 | (split-string | ||
| 3980 | (buffer-substring-no-properties start end) | ||
| 3981 | "[ \t\n\r]*\\\\bibitem\\(\\[[^]]*]\\)*"))))))) | ||
| 3982 | (unless entries | ||
| 3983 | (error "No bibitems found")) | ||
| 3984 | |||
| 3985 | (setq re-list (split-string | ||
| 3986 | (read-string "RegExp [ && RegExp...]: " | ||
| 3987 | nil 'reftex-cite-regexp-hist) | ||
| 3988 | "[ \t]*&&[ \t]*")) | ||
| 3989 | (if (string-match "\\`[ \t]*\\'" (car re-list)) | ||
| 3990 | (error "Empty regular expression")) | ||
| 3991 | |||
| 3992 | (while (and (setq re (pop re-list)) entries) | ||
| 3993 | (setq entries | ||
| 3994 | (delete nil (mapcar | ||
| 3995 | (function | ||
| 3996 | (lambda (x) | ||
| 3997 | (if (string-match re (cdr (assoc "&entry" x))) | ||
| 3998 | x nil))) | ||
| 3999 | entries)))) | ||
| 4000 | |||
| 4001 | (setq entries | ||
| 4002 | (mapcar | ||
| 4003 | (function | ||
| 4004 | (lambda (x) | ||
| 4005 | (cons (cons "&formatted" (reftex-format-bibitem x)) x))) | ||
| 4006 | entries)) | ||
| 4007 | |||
| 4008 | entries)) | ||
| 4009 | |||
| 4108 | ;; Parse and format individual entries | 4010 | ;; Parse and format individual entries |
| 4109 | 4011 | ||
| 4110 | (defun reftex-get-bib-names (field entry) | 4012 | (defun reftex-get-bib-names (field entry) |
| 4111 | ;; Return a list with the author or editor anmes in ENTRY | 4013 | ;; Return a list with the author or editor names in ENTRY |
| 4112 | (let ((names (reftex-get-bib-field field entry))) | 4014 | (let ((names (reftex-get-bib-field field entry))) |
| 4113 | (if (equal "" names) | 4015 | (if (equal "" names) |
| 4114 | (setq names (reftex-get-bib-field "editor" entry))) | 4016 | (setq names (reftex-get-bib-field "editor" entry))) |
| @@ -4160,7 +4062,7 @@ SPC=view TAB=goto RET=goto+hide [q]uit [r]escan [f]ollow-mode e[x]tern [?]Help | |||
| 4160 | (setq start (point)) | 4062 | (setq start (point)) |
| 4161 | (re-search-forward "[ \t\n\r,}]" nil 1))) | 4063 | (re-search-forward "[ \t\n\r,}]" nil 1))) |
| 4162 | (setq field (buffer-substring-no-properties start (1- (point)))) | 4064 | (setq field (buffer-substring-no-properties start (1- (point)))) |
| 4163 | ;; remove extra whitesp | 4065 | ;; remove extra whitespace |
| 4164 | (while (string-match "[\n\t\r]\\|[ \t][ \t]+" field) | 4066 | (while (string-match "[\n\t\r]\\|[ \t][ \t]+" field) |
| 4165 | (setq field (replace-match " " nil t field))) | 4067 | (setq field (replace-match " " nil t field))) |
| 4166 | ;; remove leading garbage | 4068 | ;; remove leading garbage |
| @@ -4181,7 +4083,7 @@ SPC=view TAB=goto RET=goto+hide [q]uit [r]escan [f]ollow-mode e[x]tern [?]Help | |||
| 4181 | ;; Format a BibTeX ENTRY so that it is nice to look at | 4083 | ;; Format a BibTeX ENTRY so that it is nice to look at |
| 4182 | (let* | 4084 | (let* |
| 4183 | ((auth-list (reftex-get-bib-names "author" entry)) | 4085 | ((auth-list (reftex-get-bib-names "author" entry)) |
| 4184 | (authors (mapconcat '(lambda (x) x) auth-list ", ")) | 4086 | (authors (mapconcat 'identity auth-list ", ")) |
| 4185 | (year (reftex-get-bib-field "year" entry)) | 4087 | (year (reftex-get-bib-field "year" entry)) |
| 4186 | (title (reftex-get-bib-field "title" entry)) | 4088 | (title (reftex-get-bib-field "title" entry)) |
| 4187 | (type (reftex-get-bib-field "&type" entry)) | 4089 | (type (reftex-get-bib-field "&type" entry)) |
| @@ -4216,6 +4118,40 @@ SPC=view TAB=goto RET=goto+hide [q]uit [r]escan [f]ollow-mode e[x]tern [?]Help | |||
| 4216 | extra)) | 4118 | extra)) |
| 4217 | (concat key "\n " authors " " year " " extra "\n " title "\n\n"))) | 4119 | (concat key "\n " authors " " year " " extra "\n " title "\n\n"))) |
| 4218 | 4120 | ||
| 4121 | (defun reftex-parse-bibitem (item) | ||
| 4122 | ;; Parse a \bibitem entry | ||
| 4123 | (let ((key "") (text "")) | ||
| 4124 | (when (string-match "\\`{\\([^}]+\\)}\\([\001-\255]*\\)" item) | ||
| 4125 | (setq key (match-string 1 item) | ||
| 4126 | text (match-string 2 item))) | ||
| 4127 | ;; Clean up the text a little bit | ||
| 4128 | (while (string-match "[\n\r\t]\\|[ \t][ \t]+" text) | ||
| 4129 | (setq text (replace-match " " nil t text))) | ||
| 4130 | (if (string-match "\\`[ \t]+" text) | ||
| 4131 | (setq text (replace-match "" nil t text))) | ||
| 4132 | (list | ||
| 4133 | (cons "&key" key) | ||
| 4134 | (cons "&text" text) | ||
| 4135 | (cons "&entry" (concat key " " text))))) | ||
| 4136 | |||
| 4137 | (defun reftex-format-bibitem (item) | ||
| 4138 | ;; Format a \bibitem entry so that it is (relatively) nice to look at. | ||
| 4139 | (let ((text (reftex-get-bib-field "&text" item)) | ||
| 4140 | (key (reftex-get-bib-field "&key" item)) | ||
| 4141 | (lines nil)) | ||
| 4142 | |||
| 4143 | ;; Wrap the text into several lines. | ||
| 4144 | (while (and (> (length text) 70) | ||
| 4145 | (string-match " " (substring text 60))) | ||
| 4146 | (push (substring text 0 (+ 60 (match-beginning 0))) lines) | ||
| 4147 | (setq text (substring text (+ 61 (match-beginning 0))))) | ||
| 4148 | (push text lines) | ||
| 4149 | (setq text (mapconcat 'identity (nreverse lines) "\n ")) | ||
| 4150 | |||
| 4151 | (when (reftex-use-fonts) | ||
| 4152 | (put-text-property 0 (length text) 'face 'font-lock-comment-face text)) | ||
| 4153 | (concat key "\n " text "\n\n"))) | ||
| 4154 | |||
| 4219 | ;; Make a citation | 4155 | ;; Make a citation |
| 4220 | 4156 | ||
| 4221 | (defun reftex-citation (&optional no-insert) | 4157 | (defun reftex-citation (&optional no-insert) |
| @@ -4291,17 +4227,30 @@ bibliography statement (e.g. if it was changed)." | |||
| 4291 | (if (> (car x) 31) " " "") | 4227 | (if (> (car x) 31) " " "") |
| 4292 | (cdr x)))) | 4228 | (cdr x)))) |
| 4293 | format "\n"))) | 4229 | format "\n"))) |
| 4230 | (reftex-enlarge-to-fit "*RefTeX Select*") | ||
| 4294 | (setq key (read-char)) | 4231 | (setq key (read-char)) |
| 4295 | (if (assq key format) | 4232 | (if (assq key format) |
| 4296 | (setq format (cdr (assq key format))) | 4233 | (setq format (cdr (assq key format))) |
| 4297 | (error "No citation format associated with key `%c'" key))))) | 4234 | (error "No citation format associated with key `%c'" key))))) |
| 4298 | 4235 | ||
| 4299 | (let* (entry cnt rtn ins-string re-list re | 4236 | (let* (entry data rtn ins-string re-list re found-list found-list-r) |
| 4300 | ;; scan bibtex files | 4237 | |
| 4301 | (reftex-found-list (reftex-extract-bib-entries | 4238 | ;; Scan bibtex files |
| 4302 | (reftex-get-bibfile-list))) | 4239 | (setq found-list |
| 4303 | (found-list-r nil)) | 4240 | (cond |
| 4304 | (unless reftex-found-list | 4241 | ((assq 'bib (symbol-value reftex-docstruct-symbol)) |
| 4242 | ;; using BibTeX database files. | ||
| 4243 | (reftex-extract-bib-entries (reftex-get-bibfile-list))) | ||
| 4244 | ((assq 'thebib (symbol-value reftex-docstruct-symbol)) | ||
| 4245 | ;; using thebibliography environment. | ||
| 4246 | (reftex-extract-bib-entries-from-thebibliography | ||
| 4247 | (cdr (assq 'thebib (symbol-value reftex-docstruct-symbol))))) | ||
| 4248 | (reftex-default-bibliography | ||
| 4249 | (message "Using default bibliography") | ||
| 4250 | (reftex-extract-bib-entries reftex-default-bibliography)) | ||
| 4251 | (t (error "Document does not have a bibliography")))) | ||
| 4252 | |||
| 4253 | (unless found-list | ||
| 4305 | (error "Sorry, no matches found")) | 4254 | (error "Sorry, no matches found")) |
| 4306 | 4255 | ||
| 4307 | ;; remember where we came from | 4256 | ;; remember where we came from |
| @@ -4309,9 +4258,10 @@ bibliography statement (e.g. if it was changed)." | |||
| 4309 | 4258 | ||
| 4310 | ;; offer selection | 4259 | ;; offer selection |
| 4311 | (save-window-excursion | 4260 | (save-window-excursion |
| 4261 | (delete-other-windows) | ||
| 4312 | (switch-to-buffer-other-window "*RefTeX Select*") | 4262 | (switch-to-buffer-other-window "*RefTeX Select*") |
| 4313 | (erase-buffer) | 4263 | (erase-buffer) |
| 4314 | (reftex-insert-bib-matches reftex-found-list) | 4264 | (reftex-insert-bib-matches found-list) |
| 4315 | (if (= 0 (buffer-size)) | 4265 | (if (= 0 (buffer-size)) |
| 4316 | (error "Sorry, no matches found")) | 4266 | (error "Sorry, no matches found")) |
| 4317 | (setq truncate-lines t) | 4267 | (setq truncate-lines t) |
| @@ -4321,24 +4271,22 @@ bibliography statement (e.g. if it was changed)." | |||
| 4321 | (setq rtn | 4271 | (setq rtn |
| 4322 | (reftex-select-item | 4272 | (reftex-select-item |
| 4323 | reftex-citation-prompt | 4273 | reftex-citation-prompt |
| 4324 | "^[^ \t\n\r]" | ||
| 4325 | 4 | ||
| 4326 | reftex-citation-help | 4274 | reftex-citation-help |
| 4327 | '(?r ?a ?g ?\C-m) | 4275 | reftex-select-bib-map |
| 4328 | nil | 4276 | nil |
| 4329 | 'reftex-bibtex-selection-callback nil)) | 4277 | 'reftex-bibtex-selection-callback nil)) |
| 4330 | (setq key (car rtn) | 4278 | (setq key (car rtn) |
| 4331 | cnt (nth 1 rtn)) | 4279 | data (nth 1 rtn)) |
| 4332 | (unless key (throw 'exit nil)) | 4280 | (unless key (throw 'exit nil)) |
| 4333 | (cond | 4281 | (cond |
| 4334 | ((eq key ?g) | 4282 | ((eq key ?g) |
| 4335 | (setq reftex-found-list | 4283 | (setq found-list |
| 4336 | (save-excursion | 4284 | (save-excursion |
| 4337 | (set-buffer reftex-call-back-to-this-buffer) | 4285 | (set-buffer reftex-call-back-to-this-buffer) |
| 4338 | (reftex-extract-bib-entries | 4286 | (reftex-extract-bib-entries |
| 4339 | (reftex-get-bibfile-list)))) | 4287 | (reftex-get-bibfile-list)))) |
| 4340 | (erase-buffer) | 4288 | (erase-buffer) |
| 4341 | (reftex-insert-bib-matches reftex-found-list) | 4289 | (reftex-insert-bib-matches found-list) |
| 4342 | (if (= 0 (buffer-size)) | 4290 | (if (= 0 (buffer-size)) |
| 4343 | (error "Sorry, no matches found")) | 4291 | (error "Sorry, no matches found")) |
| 4344 | (goto-char 1)) | 4292 | (goto-char 1)) |
| @@ -4356,27 +4304,31 @@ bibliography statement (e.g. if it was changed)." | |||
| 4356 | (setq found-list-r | 4304 | (setq found-list-r |
| 4357 | (delete "" | 4305 | (delete "" |
| 4358 | (mapcar | 4306 | (mapcar |
| 4359 | '(lambda (x) | 4307 | (function |
| 4360 | (if (string-match | 4308 | (lambda (x) |
| 4361 | re (cdr (assoc "&entry" x))) | 4309 | (if (string-match |
| 4362 | x | 4310 | re (cdr (assoc "&entry" x))) |
| 4363 | "")) | 4311 | x |
| 4364 | reftex-found-list)))) | 4312 | ""))) |
| 4313 | found-list)))) | ||
| 4365 | (if found-list-r | 4314 | (if found-list-r |
| 4366 | (setq reftex-found-list found-list-r) | 4315 | (setq found-list found-list-r) |
| 4367 | (ding)) | 4316 | (ding)) |
| 4368 | (erase-buffer) | 4317 | (erase-buffer) |
| 4369 | (reftex-insert-bib-matches reftex-found-list) | 4318 | (reftex-insert-bib-matches found-list) |
| 4370 | (goto-char 1)) | 4319 | (goto-char 1)) |
| 4371 | ((eq key ?a) | 4320 | ((eq key ?a) |
| 4372 | (setq entry 'all) | 4321 | (setq entry 'all) |
| 4373 | (throw 'exit t)) | 4322 | (throw 'exit t)) |
| 4374 | ((or (eq key ?\C-m) | 4323 | ((or (eq key ?\C-m) |
| 4375 | (eq key 'return)) | 4324 | (eq key 'return)) |
| 4376 | (if cnt | 4325 | (if data |
| 4377 | (setq entry (nth cnt reftex-found-list)) | 4326 | (setq entry data) |
| 4378 | (setq entry nil)) | 4327 | (setq entry nil)) |
| 4379 | (throw 'exit t)) | 4328 | (throw 'exit t)) |
| 4329 | ((stringp key) | ||
| 4330 | (setq entry (list (cons "&key" key))) | ||
| 4331 | (throw 'exit t)) | ||
| 4380 | (t | 4332 | (t |
| 4381 | (ding))))) | 4333 | (ding))))) |
| 4382 | (progn | 4334 | (progn |
| @@ -4384,10 +4336,20 @@ bibliography statement (e.g. if it was changed)." | |||
| 4384 | (if (eq entry 'all) | 4336 | (if (eq entry 'all) |
| 4385 | (setq ins-string | 4337 | (setq ins-string |
| 4386 | (mapconcat | 4338 | (mapconcat |
| 4387 | '(lambda (entry) | 4339 | (function |
| 4388 | (reftex-format-citation entry format)) | 4340 | (lambda (entry) |
| 4389 | reftex-found-list "\n")) | 4341 | (if reftex-format-cite-function |
| 4390 | (setq ins-string (reftex-format-citation entry format)))) | 4342 | (funcall reftex-format-cite-function |
| 4343 | (reftex-get-bib-field "&key" entry) | ||
| 4344 | format) | ||
| 4345 | (reftex-format-citation entry format)))) | ||
| 4346 | found-list "\n")) | ||
| 4347 | (setq ins-string | ||
| 4348 | (if reftex-format-cite-function | ||
| 4349 | (funcall reftex-format-cite-function | ||
| 4350 | (reftex-get-bib-field "&key" entry) | ||
| 4351 | format) | ||
| 4352 | (reftex-format-citation entry format))))) | ||
| 4391 | (setq ins-string "") | 4353 | (setq ins-string "") |
| 4392 | (message "Quit"))) | 4354 | (message "Quit"))) |
| 4393 | (kill-buffer "*RefTeX Select*") | 4355 | (kill-buffer "*RefTeX Select*") |
| @@ -4414,16 +4376,16 @@ bibliography statement (e.g. if it was changed)." | |||
| 4414 | 4376 | ||
| 4415 | (defun reftex-insert-bib-matches (list) | 4377 | (defun reftex-insert-bib-matches (list) |
| 4416 | ;; Insert the bib matches and number them correctly | 4378 | ;; Insert the bib matches and number them correctly |
| 4417 | (let ((cnt -1) tmp) | 4379 | (let (tmp) |
| 4418 | (mapcar '(lambda (x) | 4380 | (mapcar |
| 4419 | (setq tmp (cdr (assoc "&formatted" x))) | 4381 | (function |
| 4420 | (incf cnt) | 4382 | (lambda (x) |
| 4421 | (put-text-property 0 (length tmp) 'cnt cnt tmp) | 4383 | (setq tmp (cdr (assoc "&formatted" x))) |
| 4422 | (insert tmp)) | 4384 | (put-text-property 0 (length tmp) ':data x tmp) |
| 4423 | list))) | 4385 | (insert tmp))) |
| 4386 | list))) | ||
| 4424 | 4387 | ||
| 4425 | (defun reftex-format-names (namelist n) | 4388 | (defun reftex-format-names (namelist n) |
| 4426 | (interactive) | ||
| 4427 | (let (last (len (length namelist))) | 4389 | (let (last (len (length namelist))) |
| 4428 | (cond | 4390 | (cond |
| 4429 | ((= 1 len) (car namelist)) | 4391 | ((= 1 len) (car namelist)) |
| @@ -4444,7 +4406,7 @@ bibliography statement (e.g. if it was changed)." | |||
| 4444 | 4406 | ||
| 4445 | (if (and reftex-comment-citations | 4407 | (if (and reftex-comment-citations |
| 4446 | (string-match "%l" reftex-cite-comment-format)) | 4408 | (string-match "%l" reftex-cite-comment-format)) |
| 4447 | (error "reftex-cite-comment-format contains illeagal %%l")) | 4409 | (error "reftex-cite-comment-format contains illegal %%l")) |
| 4448 | 4410 | ||
| 4449 | (while (string-match | 4411 | (while (string-match |
| 4450 | "\\(\\`\\|[^%]\\)\\(\\(%\\([0-9]*\\)\\([a-zA-Z]\\)\\)[.,;: ]*\\)" | 4412 | "\\(\\`\\|[^%]\\)\\(\\(%\\([0-9]*\\)\\([a-zA-Z]\\)\\)[.,;: ]*\\)" |
| @@ -4499,18 +4461,36 @@ bibliography statement (e.g. if it was changed)." | |||
| 4499 | (setq format (replace-match "" t t format))) | 4461 | (setq format (replace-match "" t t format))) |
| 4500 | format) | 4462 | format) |
| 4501 | 4463 | ||
| 4502 | ;; This is slow and not recommended for follow mode | 4464 | (defun reftex-bibtex-selection-callback (data ignore no-revisit) |
| 4503 | (defun reftex-bibtex-selection-callback (cnt) | ||
| 4504 | ;; Callback function to be called from the BibTeX selection, in | 4465 | ;; Callback function to be called from the BibTeX selection, in |
| 4505 | ;; order to display context. This function is relatively slow and not | 4466 | ;; order to display context. This function is relatively slow and not |
| 4506 | ;; recommended for follow mode, just for individual lookups. | 4467 | ;; recommended for follow mode. It works OK for individual lookups. |
| 4507 | (let ((win (selected-window)) | 4468 | (let ((win (selected-window)) |
| 4508 | (key (reftex-get-bib-field "&key" (nth cnt reftex-found-list))) | 4469 | (key (reftex-get-bib-field "&key" data)) |
| 4509 | (bibfile-list (save-excursion | 4470 | bibfile-list item tmp) |
| 4510 | (set-buffer reftex-call-back-to-this-buffer) | 4471 | |
| 4511 | (reftex-get-bibfile-list)))) | 4472 | (catch 'exit |
| 4512 | (reftex-pop-to-bibtex-entry key bibfile-list | 4473 | (save-excursion |
| 4513 | (not reftex-keep-temporary-buffers) t) | 4474 | (set-buffer reftex-call-back-to-this-buffer) |
| 4475 | (cond | ||
| 4476 | ((assq 'bib (symbol-value reftex-docstruct-symbol)) | ||
| 4477 | (setq bibfile-list (reftex-get-bibfile-list))) | ||
| 4478 | ((setq tmp (assq 'thebib (symbol-value reftex-docstruct-symbol))) | ||
| 4479 | (setq bibfile-list (list (cdr tmp)) | ||
| 4480 | item t)) | ||
| 4481 | (reftex-default-bibliography | ||
| 4482 | (setq bibfile-list reftex-default-bibliography)) | ||
| 4483 | (t (ding) (throw 'exit)))) | ||
| 4484 | |||
| 4485 | (when no-revisit | ||
| 4486 | (setq bibfile-list | ||
| 4487 | (delq nil (mapcar (lambda (x) | ||
| 4488 | (if (get-file-buffer x) x nil)) | ||
| 4489 | bibfile-list)))) | ||
| 4490 | |||
| 4491 | (reftex-pop-to-bibtex-entry | ||
| 4492 | key bibfile-list (not reftex-keep-temporary-buffers) t item)) | ||
| 4493 | |||
| 4514 | (select-window win))) | 4494 | (select-window win))) |
| 4515 | 4495 | ||
| 4516 | ;;; =========================================================================== | 4496 | ;;; =========================================================================== |
| @@ -4520,6 +4500,9 @@ bibliography statement (e.g. if it was changed)." | |||
| 4520 | ;; Marker for return point from recursive edit | 4500 | ;; Marker for return point from recursive edit |
| 4521 | (defvar reftex-recursive-edit-marker (make-marker)) | 4501 | (defvar reftex-recursive-edit-marker (make-marker)) |
| 4522 | 4502 | ||
| 4503 | (defvar reftex-last-data nil) | ||
| 4504 | (defvar reftex-last-line nil) | ||
| 4505 | |||
| 4523 | (defun reftex-check-recursive-edit () | 4506 | (defun reftex-check-recursive-edit () |
| 4524 | ;; Check if we are already in a recursive edit. Abort with helpful | 4507 | ;; Check if we are already in a recursive edit. Abort with helpful |
| 4525 | ;; message if so. | 4508 | ;; message if so. |
| @@ -4528,197 +4511,281 @@ bibliography statement (e.g. if it was changed)." | |||
| 4528 | (substitute-command-keys | 4511 | (substitute-command-keys |
| 4529 | "In unfinished recursive edit. Finish (\\[exit-recursive-edit]) or abort (\\[abort-recursive-edit]).")))) | 4512 | "In unfinished recursive edit. Finish (\\[exit-recursive-edit]) or abort (\\[abort-recursive-edit]).")))) |
| 4530 | 4513 | ||
| 4531 | (defun reftex-select-item (prompt next-re size help-string | 4514 | (defun reftex-select-item (prompt help-string keymap |
| 4532 | event-list &optional offset | 4515 | &optional offset |
| 4533 | call-back cb-flag match-everywhere) | 4516 | call-back cb-flag match-everywhere) |
| 4534 | ;; Select an item. Show PROMPT to user, find next item with NEXT-RE | 4517 | ;; Select an item, using PROMPT. The function returns a key indicating |
| 4535 | ;; regular expression, return on any of the events listed in | 4518 | ;; an exit status, along with a data structure indicating which item was |
| 4536 | ;; EVENT-LIST. The function returns the event along with an integer | 4519 | ;; selected. |
| 4537 | ;; indicating which item was selected. When OFFSET is specified, | 4520 | ;; HELP-STRING contains help. KEYMAP is a keymap with the available |
| 4538 | ;; starts at that item in the list. When CALL-BACK is given, it is a | 4521 | ;; selection commands. |
| 4539 | ;; function which is called with the index of the element. | 4522 | ;; OFFSET can be a label list item which will be selected at start. |
| 4540 | 4523 | ;; When it is t, point will start out at the beginning of the buffer. | |
| 4541 | (let* (key key-sq b e ev cnt last-cnt cmd skip-callback | 4524 | ;; Any other value will cause restart where last selection left off. |
| 4542 | (search-str "") tmp search-start matched forward mini-map last-key | 4525 | ;; When CALL-BACK is given, it is a function which is called with the index |
| 4543 | (offset1 (or offset 1)) win1 win2) | 4526 | ;; of the element. |
| 4544 | 4527 | ;; CB-FLAG is the initial value of that flag. | |
| 4545 | ;; Set up a minibuffer keymap for the search stuff | 4528 | ;; When MATCH-EVERYWHERE is t, searches will also match in non-selectable |
| 4546 | (setq mini-map (copy-keymap minibuffer-local-map)) | 4529 | ;; places. |
| 4547 | (define-key mini-map "\C-s" | 4530 | |
| 4548 | '(lambda () (interactive) (setq forward t) (exit-minibuffer))) | 4531 | (let* (key-sq b e ev data last-data cmd skip-callback |
| 4549 | (define-key mini-map "\C-r" | 4532 | (orig-buffer (current-buffer)) |
| 4550 | '(lambda () (interactive) (setq forward nil) (exit-minibuffer))) | 4533 | (search-str "") last-cmd callback-fwd) |
| 4551 | (define-key mini-map "\C-m" 'exit-minibuffer) | ||
| 4552 | 4534 | ||
| 4553 | (setq ev | 4535 | (setq ev |
| 4554 | (catch 'exit | 4536 | (catch 'exit |
| 4555 | (save-window-excursion | 4537 | (save-window-excursion |
| 4556 | (setq truncate-lines t) | 4538 | (setq truncate-lines t) |
| 4557 | (goto-char 1) | ||
| 4558 | (unless (re-search-forward next-re nil t offset1) | ||
| 4559 | ;; in case the offset is illegal | ||
| 4560 | (setq offset1 1) | ||
| 4561 | (re-search-forward next-re nil t offset1)) | ||
| 4562 | (beginning-of-line 1) | ||
| 4563 | (while t | ||
| 4564 | (setq last-cnt (or cnt last-cnt)) | ||
| 4565 | (setq cnt (get-text-property (point) 'cnt)) | ||
| 4566 | (if (and cnt cb-flag call-back (not skip-callback)) | ||
| 4567 | (funcall call-back cnt)) | ||
| 4568 | (setq skip-callback nil) | ||
| 4569 | (if cnt | ||
| 4570 | (setq b (or (previous-single-property-change | ||
| 4571 | (1+ (point)) 'cnt) | ||
| 4572 | (point-min)) | ||
| 4573 | e (or (next-single-property-change | ||
| 4574 | (point) 'cnt) | ||
| 4575 | (point-max))) | ||
| 4576 | (setq b (point) e (point))) | ||
| 4577 | (reftex-highlight 1 b e) | ||
| 4578 | (if (or (not (pos-visible-in-window-p b)) | ||
| 4579 | (not (pos-visible-in-window-p e))) | ||
| 4580 | (recenter (/ (window-height) 2))) | ||
| 4581 | (setq key-sq (read-key-sequence prompt)) | ||
| 4582 | (setq last-key key) | ||
| 4583 | (setq key (car | ||
| 4584 | (cond | ||
| 4585 | ((fboundp 'event-to-character) ; XEmacs | ||
| 4586 | (mapcar 'event-to-character key-sq)) | ||
| 4587 | ((fboundp 'listify-key-sequence) ; Emacs | ||
| 4588 | (listify-key-sequence key-sq)) | ||
| 4589 | (t (error "Please report this problem to dominik@strw.leidenuniv.nl"))))) | ||
| 4590 | |||
| 4591 | (setq cmd (key-binding key-sq)) | ||
| 4592 | |||
| 4593 | (reftex-unhighlight 2) | ||
| 4594 | (reftex-unhighlight 0) | ||
| 4595 | 4539 | ||
| 4596 | (cond | 4540 | ;; Find a good starting point |
| 4597 | 4541 | (cond | |
| 4598 | ;; Single line motions | 4542 | (offset |
| 4599 | ((or (eq key ?n) | 4543 | (goto-char |
| 4600 | (eq key ?\C-i) | 4544 | (or (and (listp offset) |
| 4601 | (eq cmd 'next-line)) | 4545 | (text-property-any (point-min) (point-max) |
| 4602 | (or (eobp) (forward-char 1)) | 4546 | ':data offset)) |
| 4603 | (re-search-forward next-re nil t 1) | 4547 | (and (local-variable-p 'reftex-last-data (current-buffer)) |
| 4604 | (beginning-of-line 1)) | 4548 | (boundp 'reftex-last-data) |
| 4605 | ((or (eq key ?p) | 4549 | (listp reftex-last-data) |
| 4606 | (eq cmd 'previous-line)) | 4550 | (text-property-any (point-min) (point-max) |
| 4607 | (re-search-backward next-re nil t)) | 4551 | ':data reftex-last-data)) |
| 4608 | 4552 | (and (local-variable-p 'reftex-last-line (current-buffer)) | |
| 4609 | ;; Page motions | 4553 | (boundp 'reftex-last-line) |
| 4610 | ((eq cmd 'scroll-up) | 4554 | (integerp reftex-last-line) |
| 4611 | (while (and (pos-visible-in-window-p) | 4555 | (progn (goto-line reftex-last-line) (point))) |
| 4612 | (re-search-forward next-re nil t))) | 4556 | (point-min)))) |
| 4613 | (beginning-of-line 1) | 4557 | (t (goto-char (point-min)))) |
| 4614 | (recenter 1)) | 4558 | (beginning-of-line 1) |
| 4615 | ((eq cmd 'scroll-down) | ||
| 4616 | (while (and (pos-visible-in-window-p) | ||
| 4617 | (re-search-backward next-re nil t))) | ||
| 4618 | (recenter (- (window-height) size 2))) | ||
| 4619 | |||
| 4620 | ;; Begin and end of buffer | ||
| 4621 | ((eq cmd 'beginning-of-buffer) | ||
| 4622 | (goto-char (point-min)) | ||
| 4623 | (re-search-forward next-re nil t) | ||
| 4624 | (beginning-of-line 1)) | ||
| 4625 | ((eq cmd 'end-of-buffer) | ||
| 4626 | (goto-char (point-max)) | ||
| 4627 | (re-search-backward next-re nil t)) | ||
| 4628 | |||
| 4629 | ;; Exit | ||
| 4630 | ((eq key ?q) | ||
| 4631 | (throw 'exit nil)) | ||
| 4632 | ((eq key ?\C-g) | ||
| 4633 | (if (or (eq last-key ?\C-s) (eq last-key ?\C-r)) | ||
| 4634 | (ding) | ||
| 4635 | (bury-buffer) | ||
| 4636 | (error "Abort"))) | ||
| 4637 | ((or (eq key ?\C-m) | ||
| 4638 | (eq key 'return) | ||
| 4639 | (eq cmd 'newline)) | ||
| 4640 | (throw 'exit 'return)) | ||
| 4641 | ((memq key event-list) | ||
| 4642 | (throw 'exit key)) | ||
| 4643 | |||
| 4644 | ;; Callback | ||
| 4645 | ((or (eq key ?C) ; backward compatibility | ||
| 4646 | (eq key ?f)) | ||
| 4647 | (setq cb-flag (not cb-flag))) | ||
| 4648 | ((eq key ?\ ) | ||
| 4649 | (if cnt (funcall call-back cnt) (ding))) | ||
| 4650 | |||
| 4651 | ;; Help | ||
| 4652 | ((eq key ?\?) | ||
| 4653 | (with-output-to-temp-buffer "*RefTeX Help*" | ||
| 4654 | (princ help-string)) | ||
| 4655 | (setq win1 (selected-window) | ||
| 4656 | win2 (get-buffer-window "*RefTeX Help*" t)) | ||
| 4657 | (select-window win2) | ||
| 4658 | (unless (and (pos-visible-in-window-p 1) | ||
| 4659 | (pos-visible-in-window-p (point-max))) | ||
| 4660 | (enlarge-window (1+ (- (count-lines 1 (point-max)) | ||
| 4661 | (window-height))))) | ||
| 4662 | (select-window win1) | ||
| 4663 | (setq skip-callback t)) | ||
| 4664 | |||
| 4665 | ;; Searching | ||
| 4666 | ((or (setq forward (eq key ?\C-s)) (eq key ?\C-r)) | ||
| 4667 | (if (or (and (not (eq last-key ?\C-s)) | ||
| 4668 | (not (eq last-key ?\C-r))) | ||
| 4669 | (string= search-str "")) | ||
| 4670 | (setq tmp ; get a new string | ||
| 4671 | (read-from-minibuffer | ||
| 4672 | (if (string= search-str "") | ||
| 4673 | "Search: " | ||
| 4674 | (format "Search [%s]:" search-str)) | ||
| 4675 | nil mini-map) | ||
| 4676 | search-str (if (string= tmp "") | ||
| 4677 | search-str tmp))) | ||
| 4678 | (setq search-start (point)) | ||
| 4679 | (and (not (string= search-str "")) | ||
| 4680 | (progn | ||
| 4681 | (while | ||
| 4682 | (and (setq matched | ||
| 4683 | (if forward | ||
| 4684 | (search-forward search-str nil 1) | ||
| 4685 | (search-backward search-str nil 1))) | ||
| 4686 | (or (>= (save-excursion | ||
| 4687 | (goto-char (match-beginning 0)) | ||
| 4688 | (current-column)) | ||
| 4689 | (window-width)) | ||
| 4690 | (not (or (get-text-property (point) 'cnt) | ||
| 4691 | match-everywhere))))) | ||
| 4692 | (if matched | ||
| 4693 | (reftex-highlight 2 (match-beginning 0) | ||
| 4694 | (match-end 0)) | ||
| 4695 | (ding) | ||
| 4696 | (goto-char search-start))))) | ||
| 4697 | |||
| 4698 | ;; Recursive edit | ||
| 4699 | ((eq key ?e) | ||
| 4700 | (set-marker reftex-recursive-edit-marker (point)) | ||
| 4701 | (unwind-protect | ||
| 4702 | (progn | ||
| 4703 | (save-window-excursion | ||
| 4704 | (save-excursion | ||
| 4705 | (other-window 1) | ||
| 4706 | (message | ||
| 4707 | (substitute-command-keys | ||
| 4708 | "Recursive edit. Return to selection with \\[exit-recursive-edit]")) | ||
| 4709 | (recursive-edit))) | ||
| 4710 | (unless (equal (marker-buffer | ||
| 4711 | reftex-recursive-edit-marker) | ||
| 4712 | (current-buffer)) | ||
| 4713 | (error "Cannot continue RefTeX from this buffer.")) | ||
| 4714 | (goto-char reftex-recursive-edit-marker)) | ||
| 4715 | (set-marker reftex-recursive-edit-marker nil))) | ||
| 4716 | 4559 | ||
| 4717 | (t | 4560 | (unwind-protect |
| 4718 | (ding))))))) | 4561 | (progn |
| 4562 | (use-local-map keymap) | ||
| 4563 | (while t | ||
| 4564 | (setq data (get-text-property (point) ':data)) | ||
| 4565 | (setq last-data (or data last-data)) | ||
| 4566 | |||
| 4567 | (if (and data cb-flag call-back (not skip-callback)) | ||
| 4568 | (funcall call-back data callback-fwd | ||
| 4569 | (not reftex-revisit-to-follow))) | ||
| 4570 | (setq skip-callback nil) | ||
| 4571 | (if data | ||
| 4572 | (setq b (or (previous-single-property-change | ||
| 4573 | (1+ (point)) ':data) | ||
| 4574 | (point-min)) | ||
| 4575 | e (or (next-single-property-change | ||
| 4576 | (point) ':data) | ||
| 4577 | (point-max))) | ||
| 4578 | (setq b (point) e (point))) | ||
| 4579 | (reftex-highlight 1 b e) | ||
| 4580 | (if (or (not (pos-visible-in-window-p b)) | ||
| 4581 | (not (pos-visible-in-window-p e))) | ||
| 4582 | (recenter (/ (window-height) 2))) | ||
| 4583 | |||
| 4584 | (setq last-cmd cmd | ||
| 4585 | cmd nil) | ||
| 4586 | |||
| 4587 | (setq key-sq (read-key-sequence prompt)) | ||
| 4588 | (setq cmd (lookup-key keymap key-sq)) | ||
| 4589 | |||
| 4590 | (reftex-unhighlight 2) | ||
| 4591 | (reftex-unhighlight 1) | ||
| 4592 | (reftex-unhighlight 0) | ||
| 4593 | |||
| 4594 | (if cmd | ||
| 4595 | (condition-case nil | ||
| 4596 | (progn | ||
| 4597 | (command-execute cmd) | ||
| 4598 | ;FIXME: (run-hooks 'post-command-hook) | ||
| 4599 | ) | ||
| 4600 | (error (ding))) | ||
| 4601 | (ding)) | ||
| 4602 | |||
| 4603 | (unless (equal (current-buffer) orig-buffer) | ||
| 4604 | (error "Selection commands must return to *RefTeX Select* buffer.")))) | ||
| 4605 | (use-local-map nil))))) | ||
| 4606 | |||
| 4607 | (set (make-local-variable 'reftex-last-line) | ||
| 4608 | (+ (count-lines (point-min) (point)) (if (bolp) 1 0))) | ||
| 4609 | (set (make-local-variable 'reftex-last-data) last-data) | ||
| 4719 | (and (get-buffer "*RefTeX Help*") (kill-buffer "*RefTeX Help*")) | 4610 | (and (get-buffer "*RefTeX Help*") (kill-buffer "*RefTeX Help*")) |
| 4720 | (message "") | 4611 | (message "") |
| 4721 | (list ev cnt last-cnt))) | 4612 | (list ev data last-data))) |
| 4613 | |||
| 4614 | ;; The following variables are all bound dynamically in `reftex-select-item'. | ||
| 4615 | ;; The defvars are here only to silence the byte compiler. | ||
| 4616 | |||
| 4617 | (defvar last-cmd) | ||
| 4618 | (defvar found-list) | ||
| 4619 | (defvar cb-flag) | ||
| 4620 | (defvar data) | ||
| 4621 | (defvar call-back) | ||
| 4622 | (defvar help-string) | ||
| 4623 | (defvar skip-callback) | ||
| 4624 | (defvar search-str) | ||
| 4625 | (defvar match-everywhere) | ||
| 4626 | (defvar forward) | ||
| 4627 | (defvar keymap) | ||
| 4628 | (defvar callback-fwd) | ||
| 4629 | (defvar varioref) | ||
| 4630 | (defconst reftex-select-search-minibuffer-map | ||
| 4631 | (let ((map (copy-keymap minibuffer-local-map))) | ||
| 4632 | (define-key map "\C-s" | ||
| 4633 | (function (lambda() (interactive) (setq forward t) (exit-minibuffer)))) | ||
| 4634 | (define-key map "\C-r" | ||
| 4635 | (function (lambda() (interactive) (setq forward nil) (exit-minibuffer)))) | ||
| 4636 | (define-key map "\C-m" 'exit-minibuffer) | ||
| 4637 | map)) | ||
| 4638 | |||
| 4639 | ;; The selection commands | ||
| 4640 | |||
| 4641 | (defun reftex-select-next () | ||
| 4642 | (interactive) | ||
| 4643 | (setq callback-fwd t) | ||
| 4644 | (or (eobp) (forward-char 1)) | ||
| 4645 | (re-search-forward "^[^. \t\n\r]" nil t 1) | ||
| 4646 | (beginning-of-line 1)) | ||
| 4647 | (defun reftex-select-previous () | ||
| 4648 | (interactive) | ||
| 4649 | (setq callback-fwd nil) | ||
| 4650 | (re-search-backward "^[^. \t\n\r]" nil t)) | ||
| 4651 | (defun reftex-select-scroll-up () | ||
| 4652 | (interactive) | ||
| 4653 | (setq callback-fwd t) | ||
| 4654 | (while (and (pos-visible-in-window-p) | ||
| 4655 | (re-search-forward "^[^. \t\n\r]" nil t))) | ||
| 4656 | (beginning-of-line 1) | ||
| 4657 | (recenter 1)) | ||
| 4658 | (defun reftex-select-scroll-down () | ||
| 4659 | (interactive) | ||
| 4660 | (setq callback-fwd nil) | ||
| 4661 | (while (and (pos-visible-in-window-p) | ||
| 4662 | (re-search-backward "^[^. \t\n\r]" nil t))) | ||
| 4663 | (recenter (- (window-height) 4))) | ||
| 4664 | (defun reftex-select-next-heading () | ||
| 4665 | (interactive) | ||
| 4666 | (end-of-line) | ||
| 4667 | (re-search-forward "^ " nil t) | ||
| 4668 | (beginning-of-line)) | ||
| 4669 | (defun reftex-select-previous-heading () | ||
| 4670 | (interactive) | ||
| 4671 | (re-search-backward "^ " nil t)) | ||
| 4672 | (defun reftex-select-scroll-other-window () | ||
| 4673 | (interactive) | ||
| 4674 | (setq skip-callback t) | ||
| 4675 | (scroll-other-window)) | ||
| 4676 | (defun reftex-select-scroll-other-window-down () | ||
| 4677 | (interactive) | ||
| 4678 | (setq skip-callback t) | ||
| 4679 | (scroll-other-window-down nil)) | ||
| 4680 | (defun reftex-select-quit () | ||
| 4681 | (interactive) | ||
| 4682 | (throw 'exit nil)) | ||
| 4683 | (defun reftex-select-jump-to-previous () | ||
| 4684 | (interactive) | ||
| 4685 | (let (pos) | ||
| 4686 | (cond | ||
| 4687 | ((and (local-variable-p 'reftex-last-data (current-buffer)) | ||
| 4688 | reftex-last-data | ||
| 4689 | (setq pos (text-property-any (point-min) (point-max) | ||
| 4690 | ':data reftex-last-data))) | ||
| 4691 | (goto-char pos)) | ||
| 4692 | ((and (local-variable-p 'reftex-last-line (current-buffer)) | ||
| 4693 | (integerp reftex-last-line)) | ||
| 4694 | (goto-line reftex-last-line)) | ||
| 4695 | (t (ding))))) | ||
| 4696 | (defun reftex-select-toggle-follow () | ||
| 4697 | (interactive) | ||
| 4698 | (setq cb-flag (not cb-flag))) | ||
| 4699 | (defun reftex-select-toggle-varioref () | ||
| 4700 | (interactive) | ||
| 4701 | (if (string= varioref "\\ref") | ||
| 4702 | (setq varioref "\\vref") | ||
| 4703 | (setq varioref "\\ref")) | ||
| 4704 | (force-mode-line-update)) | ||
| 4705 | (defun reftex-select-callback () | ||
| 4706 | (interactive) | ||
| 4707 | (if data (funcall call-back data callback-fwd nil) (ding))) | ||
| 4708 | (defun reftex-select-accept () | ||
| 4709 | (interactive) | ||
| 4710 | (throw 'exit 'return)) | ||
| 4711 | (defun reftex-select-read-label () | ||
| 4712 | (interactive) | ||
| 4713 | (let ((label (completing-read | ||
| 4714 | "Label: " (symbol-value reftex-docstruct-symbol) | ||
| 4715 | nil nil reftex-prefix))) | ||
| 4716 | (unless (or (equal label "") (equal label reftex-prefix)) | ||
| 4717 | (throw 'exit label)))) | ||
| 4718 | (defun reftex-select-read-cite () | ||
| 4719 | (interactive) | ||
| 4720 | (let* ((list (mapcar (lambda (x) | ||
| 4721 | (cons (reftex-get-bib-field "&key" x) 1)) | ||
| 4722 | found-list)) | ||
| 4723 | (key (completing-read "Citation key: " list))) | ||
| 4724 | (unless (equal key "") | ||
| 4725 | (throw 'exit key)))) | ||
| 4726 | (defun reftex-select-help () | ||
| 4727 | (interactive) | ||
| 4728 | (with-output-to-temp-buffer "*RefTeX Help*" | ||
| 4729 | (princ help-string)) | ||
| 4730 | (reftex-enlarge-to-fit "*RefTeX Help*" t) | ||
| 4731 | (setq skip-callback t)) | ||
| 4732 | (defun reftex-select-recursive-edit () | ||
| 4733 | (interactive) | ||
| 4734 | (set-marker reftex-recursive-edit-marker (point)) | ||
| 4735 | (unwind-protect | ||
| 4736 | (progn | ||
| 4737 | (save-window-excursion | ||
| 4738 | (save-excursion | ||
| 4739 | (other-window 1) | ||
| 4740 | (message | ||
| 4741 | (substitute-command-keys | ||
| 4742 | "Recursive edit. Return to selection with \\[exit-recursive-edit]")) | ||
| 4743 | (recursive-edit))) | ||
| 4744 | (unless (equal (marker-buffer | ||
| 4745 | reftex-recursive-edit-marker) | ||
| 4746 | (current-buffer)) | ||
| 4747 | (error "Cannot continue RefTeX from this buffer.")) | ||
| 4748 | (goto-char reftex-recursive-edit-marker)) | ||
| 4749 | (set-marker reftex-recursive-edit-marker nil))) | ||
| 4750 | |||
| 4751 | (defun reftex-select-search-forward () | ||
| 4752 | (interactive) | ||
| 4753 | (reftex-select-search t)) | ||
| 4754 | (defun reftex-select-search-backward () | ||
| 4755 | (interactive) | ||
| 4756 | (reftex-select-search nil)) | ||
| 4757 | (defun reftex-select-search (forward) | ||
| 4758 | (let (tmp search-start matched) | ||
| 4759 | (if (or (and (not (eq last-cmd 'reftex-select-search-forward)) | ||
| 4760 | (not (eq last-cmd 'reftex-select-search-backward))) | ||
| 4761 | (string= search-str "")) | ||
| 4762 | (setq tmp ; get a new string | ||
| 4763 | (read-from-minibuffer | ||
| 4764 | (if (string= search-str "") | ||
| 4765 | "Search: " | ||
| 4766 | (format "Search [%s]:" search-str)) | ||
| 4767 | nil reftex-select-search-minibuffer-map) | ||
| 4768 | search-str (if (string= tmp "") | ||
| 4769 | search-str tmp))) | ||
| 4770 | (setq search-start (point)) | ||
| 4771 | (and (not (string= search-str "")) | ||
| 4772 | (progn | ||
| 4773 | (while | ||
| 4774 | (and (setq matched | ||
| 4775 | (if forward | ||
| 4776 | (search-forward search-str nil 1) | ||
| 4777 | (search-backward search-str nil 1))) | ||
| 4778 | (or (>= (save-excursion | ||
| 4779 | (goto-char (match-beginning 0)) | ||
| 4780 | (current-column)) | ||
| 4781 | (window-width)) | ||
| 4782 | (not (or (get-text-property (point) ':data) | ||
| 4783 | match-everywhere))))) | ||
| 4784 | (if matched | ||
| 4785 | (reftex-highlight 2 (match-beginning 0) | ||
| 4786 | (match-end 0)) | ||
| 4787 | (ding) | ||
| 4788 | (goto-char search-start)))))) | ||
| 4722 | 4789 | ||
| 4723 | ;;; =========================================================================== | 4790 | ;;; =========================================================================== |
| 4724 | ;;; | 4791 | ;;; |
| @@ -4727,14 +4794,19 @@ bibliography statement (e.g. if it was changed)." | |||
| 4727 | (defun reftex-view-crossref (&optional arg) | 4794 | (defun reftex-view-crossref (&optional arg) |
| 4728 | "View cross reference of \\ref or \\cite macro at point. | 4795 | "View cross reference of \\ref or \\cite macro at point. |
| 4729 | If the macro at point is a \\ref, show the corresponding label definition. | 4796 | If the macro at point is a \\ref, show the corresponding label definition. |
| 4730 | If it is a \\cite, show the BibTeX database entry. | 4797 | If it is a \\cite, show the BibTeX database entry or the \\bibitem. |
| 4731 | If there is no such macro at point, search forward to find one. | 4798 | If there is no such macro at point, search forward to find one. |
| 4732 | When you call this function several times in direct successtion, point will | 4799 | When you call this function several times in direct succession, point will |
| 4733 | move to view subsequent cross references further down in the buffer. | 4800 | move to view subsequent cross references further down in the buffer. |
| 4734 | To cope with the plethora of variations in packages, this function | 4801 | To cope with the plethora of variations in packages, this function |
| 4735 | assumes any macro either starting with ending in `ref' or `cite' to contain | 4802 | assumes any macro either starting with or ending in `ref' or `cite' to |
| 4736 | cross references. | 4803 | contain cross references. |
| 4737 | With argument, actually select the window showing the cross reference." | 4804 | When the LaTeX package `xr' is being used, this command will also view |
| 4805 | crossreferences in external documents. However, this works correctly only | ||
| 4806 | when the \\externaldocument macros are used with the optional label prefix | ||
| 4807 | argument. | ||
| 4808 | With one or two C-u prefixes, enforce rescanning of the document. | ||
| 4809 | With argument t or 1, select the window showing the cross reference." | ||
| 4738 | 4810 | ||
| 4739 | (interactive "P") | 4811 | (interactive "P") |
| 4740 | 4812 | ||
| @@ -4753,7 +4825,9 @@ With argument, actually select the window showing the cross reference." | |||
| 4753 | (setq macro (substring macro 1))) | 4825 | (setq macro (substring macro 1))) |
| 4754 | (setq macro nil)) | 4826 | (setq macro nil)) |
| 4755 | 4827 | ||
| 4756 | (if (and macro (eq last-command this-command)) | 4828 | (if (and macro |
| 4829 | (eq last-command this-command) | ||
| 4830 | (eq last-command 'reftex-view-crossref)) | ||
| 4757 | (if (string= macro "cite") | 4831 | (if (string= macro "cite") |
| 4758 | (progn | 4832 | (progn |
| 4759 | (skip-chars-forward "^},%") | 4833 | (skip-chars-forward "^},%") |
| @@ -4784,19 +4858,30 @@ With argument, actually select the window showing the cross reference." | |||
| 4784 | (error "No cross reference to display")) | 4858 | (error "No cross reference to display")) |
| 4785 | 4859 | ||
| 4786 | ;; Ensure access to scanning info | 4860 | ;; Ensure access to scanning info |
| 4787 | (reftex-access-scan-info) | 4861 | (reftex-access-scan-info current-prefix-arg) |
| 4788 | 4862 | ||
| 4789 | (cond | 4863 | (cond |
| 4790 | ((string= macro "cite") | 4864 | ((string= macro "cite") |
| 4791 | (setq cmd 'reftex-pop-to-bibtex-entry | 4865 | (cond |
| 4792 | args (list | 4866 | ((assq 'bib (symbol-value reftex-docstruct-symbol)) |
| 4793 | (reftex-this-word "^{},%\n\r") | 4867 | (setq cmd 'reftex-pop-to-bibtex-entry |
| 4794 | (reftex-get-bibfile-list) nil t))) | 4868 | args (list |
| 4869 | (reftex-this-word "^{},%\n\r") | ||
| 4870 | (reftex-get-bibfile-list) nil t))) | ||
| 4871 | ((assq 'thebib (symbol-value reftex-docstruct-symbol)) | ||
| 4872 | (setq cmd 'reftex-pop-to-bibtex-entry | ||
| 4873 | args (list | ||
| 4874 | (reftex-this-word "^{},%\n\r") | ||
| 4875 | (list (cdr (assq 'thebib | ||
| 4876 | (symbol-value reftex-docstruct-symbol)))) | ||
| 4877 | nil t t))) | ||
| 4878 | (t (error "Cannot display crossref\n")))) | ||
| 4795 | ((string= macro "ref") | 4879 | ((string= macro "ref") |
| 4796 | (let* ((label (reftex-this-word "^{}%\n\r")) | 4880 | (let* ((label (reftex-this-word "^{}%\n\r")) |
| 4797 | (xr-data (assoc 'xr (symbol-value reftex-docstruct-symbol))) | 4881 | (xr-data (assoc 'xr (symbol-value reftex-docstruct-symbol))) |
| 4798 | (xr-re (nth 2 xr-data)) | 4882 | (xr-re (nth 2 xr-data)) |
| 4799 | (entry (assoc label (symbol-value reftex-docstruct-symbol)))) | 4883 | (entry (assoc label (symbol-value reftex-docstruct-symbol)))) |
| 4884 | |||
| 4800 | (if (and (not entry) (string-match xr-re label)) | 4885 | (if (and (not entry) (string-match xr-re label)) |
| 4801 | ;; Label is defined in external document | 4886 | ;; Label is defined in external document |
| 4802 | (save-excursion | 4887 | (save-excursion |
| @@ -4820,7 +4905,8 @@ With argument, actually select the window showing the cross reference." | |||
| 4820 | (add-hook 'pre-command-hook 'reftex-highlight-shall-die) | 4905 | (add-hook 'pre-command-hook 'reftex-highlight-shall-die) |
| 4821 | (select-window my-window) | 4906 | (select-window my-window) |
| 4822 | (goto-char point) | 4907 | (goto-char point) |
| 4823 | (and arg (select-window pop-window)))) | 4908 | (when (or (equal arg t) (equal arg 1)) |
| 4909 | (select-window pop-window)))) | ||
| 4824 | 4910 | ||
| 4825 | (defun reftex-mouse-view-crossref (ev) | 4911 | (defun reftex-mouse-view-crossref (ev) |
| 4826 | "View cross reference of \\ref or \\cite macro where you click. | 4912 | "View cross reference of \\ref or \\cite macro where you click. |
| @@ -4830,7 +4916,6 @@ If there is no such macro at point, search forward to find one. | |||
| 4830 | With argument, actually select the window showing the cross reference." | 4916 | With argument, actually select the window showing the cross reference." |
| 4831 | (interactive "e") | 4917 | (interactive "e") |
| 4832 | (mouse-set-point ev) | 4918 | (mouse-set-point ev) |
| 4833 | (setq last-command 'self-insert-command) ;; make sure we do not move! | ||
| 4834 | (reftex-view-crossref current-prefix-arg)) | 4919 | (reftex-view-crossref current-prefix-arg)) |
| 4835 | 4920 | ||
| 4836 | ;;; =========================================================================== | 4921 | ;;; =========================================================================== |
| @@ -4932,17 +5017,6 @@ With argument, actually select the window showing the cross reference." | |||
| 4932 | (throw 'exit (cons env (point)))))) | 5017 | (throw 'exit (cons env (point)))))) |
| 4933 | (nreverse env-list))))) | 5018 | (nreverse env-list))))) |
| 4934 | 5019 | ||
| 4935 | (defun reftex-word-before-point () | ||
| 4936 | ;; Return the word before point. Word means here: | ||
| 4937 | ;; Consists of [a-zA-Z0-9.:] and ends at point or whitespace. | ||
| 4938 | (let ((pos (point))) | ||
| 4939 | (save-excursion | ||
| 4940 | (re-search-backward "[^ \t\n\r]" (point-min) 1) | ||
| 4941 | (setq pos (min (1+ (point)) (point-max))) | ||
| 4942 | (if (re-search-backward "[^a-zA-Z0-9\\\.:]" (point-min) 1) | ||
| 4943 | (forward-char 1)) | ||
| 4944 | (buffer-substring-no-properties (point) pos)))) | ||
| 4945 | |||
| 4946 | ;; ============================================================================ | 5020 | ;; ============================================================================ |
| 4947 | ;; | 5021 | ;; |
| 4948 | ;; Some generally useful functions | 5022 | ;; Some generally useful functions |
| @@ -4958,6 +5032,18 @@ With argument, actually select the window showing the cross reference." | |||
| 4958 | (when (match-beginning n) | 5032 | (when (match-beginning n) |
| 4959 | (buffer-substring-no-properties (match-beginning n) (match-end n)))) | 5033 | (buffer-substring-no-properties (match-beginning n) (match-end n)))) |
| 4960 | 5034 | ||
| 5035 | (defun reftex-kill-buffer (buffer) | ||
| 5036 | ;; Kill buffer if it exists. | ||
| 5037 | (and (setq buffer (get-buffer buffer)) | ||
| 5038 | (kill-buffer buffer))) | ||
| 5039 | |||
| 5040 | (defun reftex-erase-buffer (buffer) | ||
| 5041 | ;; Erase buffer if it exists. | ||
| 5042 | (and (setq buffer (get-buffer buffer)) | ||
| 5043 | (save-excursion | ||
| 5044 | (set-buffer buffer) | ||
| 5045 | (erase-buffer)))) | ||
| 5046 | |||
| 4961 | (defun reftex-this-word (&optional class) | 5047 | (defun reftex-this-word (&optional class) |
| 4962 | ;; Grab the word around point. | 5048 | ;; Grab the word around point. |
| 4963 | (setq class (or class "-a-zA-Z0-9:_/.*;|")) | 5049 | (setq class (or class "-a-zA-Z0-9:_/.*;|")) |
| @@ -5021,9 +5107,28 @@ With argument, actually select the window showing the cross reference." | |||
| 5021 | (pop alist)) | 5107 | (pop alist)) |
| 5022 | (nreverse out))) | 5108 | (nreverse out))) |
| 5023 | 5109 | ||
| 5110 | (defun reftex-enlarge-to-fit (buf2 &optional keep-current) | ||
| 5111 | ;; Enlarge other window displaying buffer without killing current window | ||
| 5112 | ;; If KEEP-CURRENT in non-nil, current buffer must remain visible. | ||
| 5113 | (let* ((win1 (selected-window)) | ||
| 5114 | (buf1 (current-buffer)) | ||
| 5115 | (win2 (get-buffer-window buf2))) | ||
| 5116 | (when win2 | ||
| 5117 | (select-window win2) | ||
| 5118 | (unless (and (pos-visible-in-window-p 1) | ||
| 5119 | (pos-visible-in-window-p (point-max))) | ||
| 5120 | (enlarge-window (1+ (- (count-lines 1 (point-max)) | ||
| 5121 | (window-height)))))) | ||
| 5122 | (cond | ||
| 5123 | ((window-live-p win1) (select-window win1)) | ||
| 5124 | (keep-current | ||
| 5125 | ;; we must have the old buffer! | ||
| 5126 | (switch-to-buffer-other-window buf1) | ||
| 5127 | (shrink-window (- (window-height) window-min-height)))))) | ||
| 5128 | |||
| 5024 | (defun reftex-access-search-path (which &optional recurse file) | 5129 | (defun reftex-access-search-path (which &optional recurse file) |
| 5025 | ;; Access path from environment variables. WHICH is either "tex" or "bib". | 5130 | ;; Access path from environment variables. WHICH is either "tex" or "bib". |
| 5026 | ;; When RECURSE is t, expand recursive paths, ending in double slash | 5131 | ;; When RECURSE is t, expand recursive paths, ending in double slash. |
| 5027 | ;; FILE is just for the message. | 5132 | ;; FILE is just for the message. |
| 5028 | (let* ((pathvar (intern (concat "reftex-" which "-path"))) | 5133 | (let* ((pathvar (intern (concat "reftex-" which "-path"))) |
| 5029 | (status (get pathvar 'status))) | 5134 | (status (get pathvar 'status))) |
| @@ -5034,7 +5139,7 @@ With argument, actually select the window showing the cross reference." | |||
| 5034 | (let ((env-vars (if (equal which "tex") (list "TEXINPUTS") | 5139 | (let ((env-vars (if (equal which "tex") (list "TEXINPUTS") |
| 5035 | reftex-bibpath-environment-variables))) | 5140 | reftex-bibpath-environment-variables))) |
| 5036 | (set pathvar (reftex-parse-colon-path | 5141 | (set pathvar (reftex-parse-colon-path |
| 5037 | (mapconcat '(lambda(x) (or (getenv x) "")) | 5142 | (mapconcat (function (lambda(x) (or (getenv x) ""))) |
| 5038 | env-vars path-separator)))) | 5143 | env-vars path-separator)))) |
| 5039 | (put pathvar 'status 'split)) | 5144 | (put pathvar 'status 'split)) |
| 5040 | ((and (eq 'split status) recurse) | 5145 | ((and (eq 'split status) recurse) |
| @@ -5054,7 +5159,7 @@ With argument, actually select the window showing the cross reference." | |||
| 5054 | (while (setq dir (pop thepath)) | 5159 | (while (setq dir (pop thepath)) |
| 5055 | (when (string= (substring dir -2) doubleslash) | 5160 | (when (string= (substring dir -2) doubleslash) |
| 5056 | (setq dir (substring dir 0 -1))) | 5161 | (setq dir (substring dir 0 -1))) |
| 5057 | (setq file1 (expand-file-name file dir)) | 5162 | (setq file1 (expand-file-name file (expand-file-name dir))) |
| 5058 | (if (file-exists-p file1) | 5163 | (if (file-exists-p file1) |
| 5059 | (throw 'exit file1))) | 5164 | (throw 'exit file1))) |
| 5060 | ;; No such file | 5165 | ;; No such file |
| @@ -5082,7 +5187,8 @@ With argument, actually select the window showing the cross reference." | |||
| 5082 | (while (setq dir (pop path)) | 5187 | (while (setq dir (pop path)) |
| 5083 | (setq dirs | 5188 | (setq dirs |
| 5084 | (delete nil | 5189 | (delete nil |
| 5085 | (mapcar (function | 5190 | (mapcar |
| 5191 | (function | ||
| 5086 | (lambda (x) | 5192 | (lambda (x) |
| 5087 | (if (and (file-directory-p x) | 5193 | (if (and (file-directory-p x) |
| 5088 | (not (string-match "/\\.+\\'" x))) | 5194 | (not (string-match "/\\.+\\'" x))) |
| @@ -5101,7 +5207,7 @@ With argument, actually select the window showing the cross reference." | |||
| 5101 | (setq string (replace-match "[\n\r]" nil t string))) | 5207 | (setq string (replace-match "[\n\r]" nil t string))) |
| 5102 | string)) | 5208 | string)) |
| 5103 | 5209 | ||
| 5104 | (defun reftex-make-desparate-section-regexp (old) | 5210 | (defun reftex-make-desperate-section-regexp (old) |
| 5105 | ;; Return a regexp which will still match a section statement even if | 5211 | ;; Return a regexp which will still match a section statement even if |
| 5106 | ;; x-symbol or isotex or the like have been at work in the mean time. | 5212 | ;; x-symbol or isotex or the like have been at work in the mean time. |
| 5107 | (let* ((n (1+ (string-match "[[{]" old))) | 5213 | (let* ((n (1+ (string-match "[[{]" old))) |
| @@ -5132,7 +5238,7 @@ With argument, actually select the window showing the cross reference." | |||
| 5132 | (get-file-buffer file))) | 5238 | (get-file-buffer file))) |
| 5133 | ((fboundp 'find-buffer-visiting) ; Emacs | 5239 | ((fboundp 'find-buffer-visiting) ; Emacs |
| 5134 | (find-buffer-visiting file)) | 5240 | (find-buffer-visiting file)) |
| 5135 | (t (error "Please report this problem to dominik@strw.leidenuniv.nl")))) | 5241 | (t (error "This should not happen (reftex-get-buffer-visiting)")))) |
| 5136 | 5242 | ||
| 5137 | (defun reftex-get-file-buffer-force (file &optional mark-to-kill) | 5243 | (defun reftex-get-file-buffer-force (file &optional mark-to-kill) |
| 5138 | ;; Return a buffer visiting file. Make one, if necessary. | 5244 | ;; Return a buffer visiting file. Make one, if necessary. |
| @@ -5223,6 +5329,39 @@ With argument, actually select the window showing the cross reference." | |||
| 5223 | (and (eq 1 reftex-refontify-context) | 5329 | (and (eq 1 reftex-refontify-context) |
| 5224 | (or (featurep 'x-symbol)))))) | 5330 | (or (featurep 'x-symbol)))))) |
| 5225 | 5331 | ||
| 5332 | (defun reftex-fontify-select-label-buffer () | ||
| 5333 | ;; Fontify the `*RefTeX Select*' buffer | ||
| 5334 | (cond | ||
| 5335 | ((fboundp 'font-lock-default-fontify-region) | ||
| 5336 | ;; Good: we have the indirection functions, and can support lazy-lock etc. | ||
| 5337 | (set (make-local-variable 'font-lock-fontify-region-function) | ||
| 5338 | 'reftex-select-font-lock-fontify-region) | ||
| 5339 | (let ((major-mode 'latex-mode)) | ||
| 5340 | (font-lock-mode 1))) | ||
| 5341 | ((fboundp 'font-lock-set-defaults-1) | ||
| 5342 | ;; Looks like the XEmacs font-lock stuff. | ||
| 5343 | ;; FIXME: this is still kind of a hack, but might go away with XEmacs 20.4 | ||
| 5344 | (set (make-local-variable 'font-lock-keywords) nil) | ||
| 5345 | (let ((major-mode 'latex-mode) | ||
| 5346 | (font-lock-defaults-computed nil)) | ||
| 5347 | (font-lock-set-defaults-1) | ||
| 5348 | (reftex-select-font-lock-fontify-region (point-min) (point-max)))) | ||
| 5349 | (t | ||
| 5350 | ;; Oops? | ||
| 5351 | (message "Sorry: cannot refontify RefTeX Select buffer.")))) | ||
| 5352 | |||
| 5353 | (defun reftex-select-font-lock-fontify-region (beg end &optional loudly) | ||
| 5354 | ;; Fontify a region, but only lines starting with a dot. | ||
| 5355 | (let ((func (if (fboundp 'font-lock-default-fontify-region) | ||
| 5356 | 'font-lock-default-fontify-region | ||
| 5357 | 'font-lock-fontify-region)) | ||
| 5358 | beg1 end1) | ||
| 5359 | (goto-char beg) | ||
| 5360 | (while (re-search-forward "^\\." end t) | ||
| 5361 | (setq beg1 (point) end1 (progn (skip-chars-forward "^\n") (point))) | ||
| 5362 | (funcall func beg1 end1 nil) | ||
| 5363 | (goto-char end1)))) | ||
| 5364 | |||
| 5226 | ;; Highlighting uses overlays. If this is for XEmacs, we need to load | 5365 | ;; Highlighting uses overlays. If this is for XEmacs, we need to load |
| 5227 | ;; the overlay library, available in version 19.15 | 5366 | ;; the overlay library, available in version 19.15 |
| 5228 | (and (not (fboundp 'make-overlay)) | 5367 | (and (not (fboundp 'make-overlay)) |
| @@ -5249,7 +5388,7 @@ With argument, actually select the window showing the cross reference." | |||
| 5249 | (move-overlay (aref reftex-highlight-overlays index) | 5388 | (move-overlay (aref reftex-highlight-overlays index) |
| 5250 | begin end (or buffer (current-buffer)))) | 5389 | begin end (or buffer (current-buffer)))) |
| 5251 | (defun reftex-unhighlight (index) | 5390 | (defun reftex-unhighlight (index) |
| 5252 | "Detatch overlay INDEX." | 5391 | "Detach overlay INDEX." |
| 5253 | (delete-overlay (aref reftex-highlight-overlays index))) | 5392 | (delete-overlay (aref reftex-highlight-overlays index))) |
| 5254 | 5393 | ||
| 5255 | (defun reftex-highlight-shall-die () | 5394 | (defun reftex-highlight-shall-die () |
| @@ -5280,12 +5419,14 @@ these variables." | |||
| 5280 | 5419 | ||
| 5281 | ;; Kill temporary buffers associated with RefTeX - just in case they | 5420 | ;; Kill temporary buffers associated with RefTeX - just in case they |
| 5282 | ;; were not cleaned up properly | 5421 | ;; were not cleaned up properly |
| 5283 | (let ((buffer-list '("*RefTeX Master*" "*RefTeX Help*" "*RefTeX Select*" | 5422 | (save-excursion |
| 5284 | "*Duplicate Labels*" "*toc*" "*RefTeX-scratch*")) | 5423 | (let ((buffer-list '("*RefTeX Help*" "*RefTeX Select*" |
| 5285 | buf) | 5424 | "*Duplicate Labels*" "*toc*" "*RefTeX-scratch*")) |
| 5286 | (while (setq buf (pop buffer-list)) | 5425 | buf) |
| 5287 | (if (get-buffer buf) | 5426 | (while (setq buf (pop buffer-list)) |
| 5288 | (kill-buffer buf)))) | 5427 | (if (get-buffer buf) |
| 5428 | (kill-buffer buf)))) | ||
| 5429 | (reftex-erase-all-selection-buffers)) | ||
| 5289 | 5430 | ||
| 5290 | ;; Make sure the current document will be rescanned soon. | 5431 | ;; Make sure the current document will be rescanned soon. |
| 5291 | (reftex-reset-scanning-information) | 5432 | (reftex-reset-scanning-information) |
| @@ -5311,10 +5452,19 @@ This enforces rescanning the buffer on next use." | |||
| 5311 | (not (null (symbol-value symbol)))) | 5452 | (not (null (symbol-value symbol)))) |
| 5312 | (set (symbol-value symbol) nil))))) | 5453 | (set (symbol-value symbol) nil))))) |
| 5313 | 5454 | ||
| 5455 | (defun reftex-erase-all-selection-buffers () | ||
| 5456 | ;; Remove all selection buffers associated with current document. | ||
| 5457 | (mapcar (function | ||
| 5458 | (lambda (type) | ||
| 5459 | (reftex-erase-buffer (reftex-make-selection-buffer-name type)))) | ||
| 5460 | reftex-typekey-list)) | ||
| 5461 | |||
| 5314 | (defun reftex-compute-ref-cite-tables () | 5462 | (defun reftex-compute-ref-cite-tables () |
| 5315 | ;; Update ref and cite tables | 5463 | ;; Update ref and cite tables |
| 5316 | 5464 | ||
| 5317 | (interactive) | 5465 | ;; Update AUCTeX style information |
| 5466 | (when (and (featurep 'tex-site) (fboundp 'TeX-update-style)) | ||
| 5467 | (condition-case nil (TeX-update-style) (error nil))) | ||
| 5318 | 5468 | ||
| 5319 | ;; Compile information in reftex-label-alist | 5469 | ;; Compile information in reftex-label-alist |
| 5320 | (let ((tmp (reftex-uniquify (reftex-splice-symbols-into-list | 5470 | (let ((tmp (reftex-uniquify (reftex-splice-symbols-into-list |
| @@ -5326,7 +5476,7 @@ This enforces rescanning the buffer on next use." | |||
| 5326 | '(nil))) | 5476 | '(nil))) |
| 5327 | entry env-or-mac typekeychar typekey prefix context word | 5477 | entry env-or-mac typekeychar typekey prefix context word |
| 5328 | fmt reffmt labelfmt wordlist qh-list macros-with-labels | 5478 | fmt reffmt labelfmt wordlist qh-list macros-with-labels |
| 5329 | nargs nlabel opt-args cell sum) | 5479 | nargs nlabel opt-args cell sum i words-are-re) |
| 5330 | 5480 | ||
| 5331 | (setq reftex-words-to-typekey-alist nil | 5481 | (setq reftex-words-to-typekey-alist nil |
| 5332 | reftex-typekey-list nil | 5482 | reftex-typekey-list nil |
| @@ -5388,13 +5538,13 @@ This enforces rescanning the buffer on next use." | |||
| 5388 | ((string= env-or-mac "")) | 5538 | ((string= env-or-mac "")) |
| 5389 | ((string= env-or-mac "section")) | 5539 | ((string= env-or-mac "section")) |
| 5390 | (t | 5540 | (t |
| 5391 | (add-to-list 'reftex-label-env-list env-or-mac) | 5541 | (add-to-list 'reftex-label-env-list env-or-mac))))) |
| 5392 | ;; Translate some special context cases | 5542 | ;; Translate some special context cases |
| 5393 | (when (assq context reftex-default-context-regexps) | 5543 | (when (assq context reftex-default-context-regexps) |
| 5394 | (setq context | 5544 | (setq context |
| 5395 | (format | 5545 | (format |
| 5396 | (cdr (assq context reftex-default-context-regexps)) | 5546 | (cdr (assq context reftex-default-context-regexps)) |
| 5397 | (regexp-quote env-or-mac)))))))) | 5547 | (regexp-quote env-or-mac)))) |
| 5398 | (and reffmt | 5548 | (and reffmt |
| 5399 | (not (assoc typekey reftex-typekey-to-format-alist)) | 5549 | (not (assoc typekey reftex-typekey-to-format-alist)) |
| 5400 | (push (cons typekey reffmt) reftex-typekey-to-format-alist)) | 5550 | (push (cons typekey reffmt) reftex-typekey-to-format-alist)) |
| @@ -5404,9 +5554,13 @@ This enforces rescanning the buffer on next use." | |||
| 5404 | (push (list env-or-mac typekey context labelfmt | 5554 | (push (list env-or-mac typekey context labelfmt |
| 5405 | nargs nlabel opt-args) | 5555 | nargs nlabel opt-args) |
| 5406 | reftex-env-or-mac-alist)) | 5556 | reftex-env-or-mac-alist)) |
| 5557 | (if (eq (car wordlist) 'regexp) | ||
| 5558 | (setq wordlist (cdr wordlist) | ||
| 5559 | words-are-re t) | ||
| 5560 | (setq words-are-re nil)) | ||
| 5407 | (while (and (setq word (pop wordlist)) | 5561 | (while (and (setq word (pop wordlist)) |
| 5408 | (stringp word)) | 5562 | (stringp word)) |
| 5409 | (setq word (downcase word)) | 5563 | (setq word (identity (if words-are-re word (regexp-quote word)))) |
| 5410 | (or (assoc word reftex-words-to-typekey-alist) | 5564 | (or (assoc word reftex-words-to-typekey-alist) |
| 5411 | (push (cons word typekey) reftex-words-to-typekey-alist))) | 5565 | (push (cons word typekey) reftex-words-to-typekey-alist))) |
| 5412 | (cond | 5566 | (cond |
| @@ -5416,32 +5570,52 @@ This enforces rescanning the buffer on next use." | |||
| 5416 | (t | 5570 | (t |
| 5417 | (push (list typekey env-or-mac) qh-list))))) | 5571 | (push (list typekey env-or-mac) qh-list))))) |
| 5418 | 5572 | ||
| 5419 | (setq qh-list (sort qh-list '(lambda (x1 x2) (string< (car x1) (car x2))))) | 5573 | (setq qh-list |
| 5574 | (sort qh-list (function | ||
| 5575 | (lambda (x1 x2) (string< (car x1) (car x2)))))) | ||
| 5420 | (setq reftex-typekey-to-prefix-alist | 5576 | (setq reftex-typekey-to-prefix-alist |
| 5421 | (nreverse reftex-typekey-to-prefix-alist)) | 5577 | (nreverse reftex-typekey-to-prefix-alist)) |
| 5422 | (setq reftex-type-query-prompt | 5578 | (setq reftex-type-query-prompt |
| 5423 | (concat "Label type: " | 5579 | (concat "Label type: " |
| 5424 | (mapconcat '(lambda(x) | 5580 | (mapconcat (function (lambda(x) (format "[%s]" (car x)))) |
| 5425 | (format "[%s]" (car x))) | ||
| 5426 | qh-list " ") | 5581 | qh-list " ") |
| 5427 | " (?=Help)")) | 5582 | " (?=Help)")) |
| 5428 | (setq reftex-type-query-help | 5583 | (setq reftex-type-query-help |
| 5429 | (concat "SELECT A LABEL TYPE:\n--------------------\n" | 5584 | (concat "SELECT A LABEL TYPE:\n--------------------\n" |
| 5430 | (mapconcat | 5585 | (mapconcat |
| 5431 | '(lambda(x) | 5586 | (function |
| 5432 | (setq sum 0) | 5587 | (lambda(x) |
| 5433 | (format " [%s] %s" | 5588 | (setq sum 0) |
| 5434 | (car x) | 5589 | (format " [%s] %s" |
| 5435 | (mapconcat | 5590 | (car x) |
| 5436 | '(lambda(x) | 5591 | (mapconcat |
| 5437 | (setq sum (+ sum (length x))) | 5592 | (lambda(x) |
| 5438 | (if (< sum 60) | 5593 | (setq sum (+ sum (length x))) |
| 5439 | x | 5594 | (if (< sum 60) |
| 5440 | (setq sum 0) | 5595 | x |
| 5441 | (concat "\n " x))) | 5596 | (setq sum 0) |
| 5442 | (cdr x) " "))) | 5597 | (concat "\n " x))) |
| 5598 | (cdr x) " ")))) | ||
| 5443 | qh-list "\n"))) | 5599 | qh-list "\n"))) |
| 5444 | 5600 | ||
| 5601 | ;; Convert magic words to regular expressions | ||
| 5602 | (setq reftex-words-to-typekey-alist | ||
| 5603 | (mapcar | ||
| 5604 | (lambda (x) | ||
| 5605 | (setq word (car x) | ||
| 5606 | typekey (cdr x) | ||
| 5607 | fmt (cdr (assoc typekey reftex-typekey-to-format-alist))) | ||
| 5608 | (setq word (concat "\\W\\(" word "[ \t\n\r]*\\)\\(")) | ||
| 5609 | (setq i 0) | ||
| 5610 | (while (and (< i 10) | ||
| 5611 | (< i (length fmt)) | ||
| 5612 | (not (member (aref fmt i) '(?%)))) | ||
| 5613 | (setq word (concat word "\\|" (regexp-quote | ||
| 5614 | (substring fmt 0 (1+ i))))) | ||
| 5615 | (incf i)) | ||
| 5616 | (cons (concat word "\\)\\=") typekey)) | ||
| 5617 | (nreverse reftex-words-to-typekey-alist))) | ||
| 5618 | |||
| 5445 | ;; Calculate the regular expressions | 5619 | ;; Calculate the regular expressions |
| 5446 | (let ((label-re "\\\\label{\\([^}]*\\)}") | 5620 | (let ((label-re "\\\\label{\\([^}]*\\)}") |
| 5447 | (include-re "\\(\\`\\|[\n\r]\\)[ \t]*\\\\\\(include\\|input\\)[{ \t]+\\([^} \t\n\r]+\\)") | 5621 | (include-re "\\(\\`\\|[\n\r]\\)[ \t]*\\\\\\(include\\|input\\)[{ \t]+\\([^} \t\n\r]+\\)") |
| @@ -5449,6 +5623,7 @@ This enforces rescanning the buffer on next use." | |||
| 5449 | (concat "\\(\\`\\|[\n\r]\\)[ \t]*\\\\\\(" | 5623 | (concat "\\(\\`\\|[\n\r]\\)[ \t]*\\\\\\(" |
| 5450 | (mapconcat 'car reftex-section-levels "\\|") | 5624 | (mapconcat 'car reftex-section-levels "\\|") |
| 5451 | "\\)\\*?\\(\\[[^]]*\\]\\)?{")) | 5625 | "\\)\\*?\\(\\[[^]]*\\]\\)?{")) |
| 5626 | (appendix-re "\\(\\`\\|[\n\r]\\)[ \t]*\\(\\\\appendix\\)") | ||
| 5452 | (macro-re | 5627 | (macro-re |
| 5453 | (if macros-with-labels | 5628 | (if macros-with-labels |
| 5454 | (concat "\\(" | 5629 | (concat "\\(" |
| @@ -5465,6 +5640,7 @@ This enforces rescanning the buffer on next use." | |||
| 5465 | (concat section-re "\\|" include-re) | 5640 | (concat section-re "\\|" include-re) |
| 5466 | reftex-everything-regexp | 5641 | reftex-everything-regexp |
| 5467 | (concat label-re "\\|" section-re "\\|" include-re | 5642 | (concat label-re "\\|" section-re "\\|" include-re |
| 5643 | "\\|" appendix-re | ||
| 5468 | (if macros-with-labels "\\|" "") macro-re) | 5644 | (if macros-with-labels "\\|" "") macro-re) |
| 5469 | reftex-find-label-regexp-format find-label-re-format | 5645 | reftex-find-label-regexp-format find-label-re-format |
| 5470 | reftex-find-label-regexp-format2 | 5646 | reftex-find-label-regexp-format2 |
| @@ -5489,6 +5665,87 @@ This enforces rescanning the buffer on next use." | |||
| 5489 | (define-key reftex-mode-map "\C-cg" 'reftex-grep-document) | 5665 | (define-key reftex-mode-map "\C-cg" 'reftex-grep-document) |
| 5490 | (define-key reftex-mode-map "\C-cs" 'reftex-search-document))) | 5666 | (define-key reftex-mode-map "\C-cs" 'reftex-search-document))) |
| 5491 | 5667 | ||
| 5668 | ;; Selection Keymaps | ||
| 5669 | (let ((map (make-sparse-keymap))) | ||
| 5670 | ; First, the common stuff | ||
| 5671 | (substitute-key-definition | ||
| 5672 | 'next-line 'reftex-select-next map global-map) | ||
| 5673 | (substitute-key-definition | ||
| 5674 | 'previous-line 'reftex-select-previous map global-map) | ||
| 5675 | (substitute-key-definition | ||
| 5676 | 'scroll-up 'reftex-select-scroll-up map global-map) | ||
| 5677 | (substitute-key-definition | ||
| 5678 | 'scroll-down 'reftex-select-scroll-down map global-map) | ||
| 5679 | (substitute-key-definition | ||
| 5680 | 'scroll-other-window 'reftex-select-scroll-other-window map global-map) | ||
| 5681 | (substitute-key-definition | ||
| 5682 | 'scroll-other-window-down 'reftex-select-scroll-other-window-down map global-map) | ||
| 5683 | (substitute-key-definition | ||
| 5684 | 'beginning-of-buffer 'beginning-of-buffer map global-map) | ||
| 5685 | (substitute-key-definition | ||
| 5686 | 'end-of-buffer 'end-of-buffer map global-map) | ||
| 5687 | (substitute-key-definition | ||
| 5688 | 'keyboard-quit 'keyboard-quit map global-map) | ||
| 5689 | (substitute-key-definition | ||
| 5690 | 'newline 'reftex-select-accept map global-map) | ||
| 5691 | (substitute-key-definition | ||
| 5692 | 'delete-other-windows 'delete-other-windows map global-map) | ||
| 5693 | (define-key map " " 'reftex-select-callback) | ||
| 5694 | (define-key map "n" 'reftex-select-next) | ||
| 5695 | (define-key map [(down)] 'reftex-select-next) | ||
| 5696 | (define-key map "p" 'reftex-select-previous) | ||
| 5697 | (define-key map [(up)] 'reftex-select-previous) | ||
| 5698 | (define-key map "f" 'reftex-select-toggle-follow) | ||
| 5699 | (define-key map "\C-m" 'reftex-select-accept) | ||
| 5700 | (define-key map [(return)] 'reftex-select-accept) | ||
| 5701 | (define-key map "\C-s" 'reftex-select-search-forward) | ||
| 5702 | (define-key map "\C-r" 'reftex-select-search-backward) | ||
| 5703 | (define-key map "e" 'reftex-select-recursive-edit) | ||
| 5704 | (define-key map "q" 'reftex-select-quit) | ||
| 5705 | (define-key map "?" 'reftex-select-help) | ||
| 5706 | |||
| 5707 | (setq reftex-select-label-map map) | ||
| 5708 | (setq reftex-select-bib-map (copy-keymap map)) | ||
| 5709 | |||
| 5710 | ;; Now the rest | ||
| 5711 | |||
| 5712 | (loop for key across "cgilrRstx#%" do | ||
| 5713 | (define-key reftex-select-label-map (vector (list key)) | ||
| 5714 | (list 'lambda '() '(interactive) (list 'throw '(quote exit) key)))) | ||
| 5715 | (define-key reftex-select-label-map "b" 'reftex-select-jump-to-previous) | ||
| 5716 | (define-key reftex-select-label-map "v" 'reftex-select-toggle-varioref) | ||
| 5717 | (define-key reftex-select-label-map [(tab)] 'reftex-select-read-label) | ||
| 5718 | (define-key reftex-select-label-map "\C-i" 'reftex-select-read-label) | ||
| 5719 | (define-key reftex-select-label-map "\C-c\C-n" 'reftex-select-next-heading) | ||
| 5720 | (define-key reftex-select-label-map "\C-c\C-p" 'reftex-select-previous-heading) | ||
| 5721 | |||
| 5722 | (loop for key across "grRa" do | ||
| 5723 | (define-key reftex-select-bib-map (vector (list key)) | ||
| 5724 | (list 'lambda '() '(interactive) (list 'throw '(quote exit) key)))) | ||
| 5725 | (define-key reftex-select-bib-map "\C-i" 'reftex-select-read-cite) | ||
| 5726 | (define-key reftex-select-bib-map [(tab)] 'reftex-select-read-cite)) | ||
| 5727 | |||
| 5728 | ;; Table of Contents map | ||
| 5729 | (let ((map reftex-toc-map)) | ||
| 5730 | (define-key map [(mouse-2)] 'reftex-toc-mouse-goto-line-and-hide); Emacs | ||
| 5731 | (define-key map [(button2)] 'reftex-toc-mouse-goto-line-and-hide); XEmacs | ||
| 5732 | (define-key map "n" 'next-line) | ||
| 5733 | (define-key map "p" 'previous-line) | ||
| 5734 | (define-key map "?" 'reftex-toc-show-help) | ||
| 5735 | (define-key map " " 'reftex-toc-view-line) | ||
| 5736 | (define-key map "\C-m" 'reftex-toc-goto-line-and-hide) | ||
| 5737 | (define-key map "\C-i" 'reftex-toc-goto-line) | ||
| 5738 | (define-key map "r" 'reftex-toc-rescan) | ||
| 5739 | (define-key map "R" 'reftex-toc-Rescan) | ||
| 5740 | (define-key map "g" 'revert-buffer) | ||
| 5741 | (define-key map "q" 'reftex-toc-quit) | ||
| 5742 | (define-key map "Q" 'reftex-toc-quit-and-kill) | ||
| 5743 | (define-key map "f" 'reftex-toc-toggle-follow) | ||
| 5744 | (define-key map "x" 'reftex-toc-external) | ||
| 5745 | (loop for key across "0123456789" do | ||
| 5746 | (define-key map (vector (list key)) 'digit-argument)) | ||
| 5747 | (define-key map "-" 'negative-argument)) | ||
| 5748 | |||
| 5492 | ;;; Menus -------------------------------------------------------------------- | 5749 | ;;; Menus -------------------------------------------------------------------- |
| 5493 | 5750 | ||
| 5494 | ;; Define a menu for the menu bar if Emacs is running under X | 5751 | ;; Define a menu for the menu bar if Emacs is running under X |
| @@ -5511,8 +5768,7 @@ This enforces rescanning the buffer on next use." | |||
| 5511 | ["Entire Document" reftex-parse-all (reftex-is-multi)] | 5768 | ["Entire Document" reftex-parse-all (reftex-is-multi)] |
| 5512 | ["Save to File" (reftex-access-parse-file 'write) | 5769 | ["Save to File" (reftex-access-parse-file 'write) |
| 5513 | (> (length (symbol-value reftex-docstruct-symbol)) 0)] | 5770 | (> (length (symbol-value reftex-docstruct-symbol)) 0)] |
| 5514 | ["Restore from File" (reftex-access-parse-file 'restore) | 5771 | ["Restore from File" (reftex-access-parse-file 'restore) t] |
| 5515 | (reftex-access-parse-file 'readable)] | ||
| 5516 | "----" | 5772 | "----" |
| 5517 | ["Enable Partial Scans" | 5773 | ["Enable Partial Scans" |
| 5518 | (setq reftex-enable-partial-scans (not reftex-enable-partial-scans)) | 5774 | (setq reftex-enable-partial-scans (not reftex-enable-partial-scans)) |
| @@ -5522,7 +5778,7 @@ This enforces rescanning the buffer on next use." | |||
| 5522 | :style toggle :selected reftex-save-parse-info] | 5778 | :style toggle :selected reftex-save-parse-info] |
| 5523 | "---" | 5779 | "---" |
| 5524 | ["Reset RefTeX Mode" reftex-reset-mode t]) | 5780 | ["Reset RefTeX Mode" reftex-reset-mode t]) |
| 5525 | ("Multifile" | 5781 | ("Global Actions" |
| 5526 | ["Search Whole Document" reftex-search-document t] | 5782 | ["Search Whole Document" reftex-search-document t] |
| 5527 | ["Replace in Document" reftex-query-replace-document t] | 5783 | ["Replace in Document" reftex-query-replace-document t] |
| 5528 | ["Grep on Document" reftex-grep-document t] | 5784 | ["Grep on Document" reftex-grep-document t] |
| @@ -5530,16 +5786,35 @@ This enforces rescanning the buffer on next use." | |||
| 5530 | ["Create TAGS File" reftex-create-tags-file t] | 5786 | ["Create TAGS File" reftex-create-tags-file t] |
| 5531 | "----" | 5787 | "----" |
| 5532 | ["Find Duplicate Labels" reftex-find-duplicate-labels t] | 5788 | ["Find Duplicate Labels" reftex-find-duplicate-labels t] |
| 5533 | ["Change Label and Refs" reftex-change-label t]) | 5789 | ["Change Label and Refs" reftex-change-label t] |
| 5790 | ;;;["Renumber Simple Labels" reftex-renumber-simple-labels t] | ||
| 5791 | "---" | ||
| 5792 | ["Save document" reftex-save-all-document-buffers t]) | ||
| 5793 | "---" | ||
| 5794 | ("Reference Options" | ||
| 5795 | "Varioref Setting" | ||
| 5796 | ["Use `\\vref' by Default" | ||
| 5797 | (setq reftex-vref-is-default (not reftex-vref-is-default)) | ||
| 5798 | :style toggle :selected reftex-vref-is-default] | ||
| 5799 | "---" | ||
| 5800 | "Selection Buffers" | ||
| 5801 | ["Use Multiple Buffers" | ||
| 5802 | (setq reftex-use-multiple-selection-buffers | ||
| 5803 | (not reftex-use-multiple-selection-buffers)) | ||
| 5804 | :style toggle :selected reftex-use-multiple-selection-buffers] | ||
| 5805 | ["Auto Update Buffers" | ||
| 5806 | (setq reftex-auto-update-selection-buffers | ||
| 5807 | (not reftex-auto-update-selection-buffers)) | ||
| 5808 | :style toggle :selected reftex-auto-update-selection-buffers]) | ||
| 5534 | ("Citation Options" | 5809 | ("Citation Options" |
| 5535 | "Citation Style" | 5810 | "Citation Style" |
| 5536 | ,@(mapcar | 5811 | ,@(mapcar |
| 5537 | (function | 5812 | (function |
| 5538 | (lambda (x) | 5813 | (lambda (x) |
| 5539 | (vector | 5814 | (vector |
| 5540 | (symbol-name (car x)) | 5815 | (capitalize (symbol-name (car x))) |
| 5541 | (list 'setq 'reftex-cite-format (list 'quote (car x))) | 5816 | (list 'setq 'reftex-cite-format (list 'quote (car x))) |
| 5542 | :style 'radio :selected | 5817 | ':style 'radio ':selected |
| 5543 | (list 'eq 'reftex-cite-format (list 'quote (car x)))))) | 5818 | (list 'eq 'reftex-cite-format (list 'quote (car x)))))) |
| 5544 | reftex-cite-format-builtin) | 5819 | reftex-cite-format-builtin) |
| 5545 | "----" | 5820 | "----" |
| @@ -5557,10 +5832,15 @@ This enforces rescanning the buffer on next use." | |||
| 5557 | :style radio :selected (eq reftex-sort-bibtex-matches 'reverse-year)] | 5832 | :style radio :selected (eq reftex-sort-bibtex-matches 'reverse-year)] |
| 5558 | ["Not" (setq reftex-sort-bibtex-matches nil) | 5833 | ["Not" (setq reftex-sort-bibtex-matches nil) |
| 5559 | :style radio :selected (eq reftex-sort-bibtex-matches nil)]) | 5834 | :style radio :selected (eq reftex-sort-bibtex-matches nil)]) |
| 5835 | ("Customize" | ||
| 5836 | ["Browse RefTeX group" reftex-customize t] | ||
| 5837 | "---" | ||
| 5838 | ["Build Full Customize Menu" reftex-create-customize-menu | ||
| 5839 | (fboundp 'customize-menu-create)]) | ||
| 5560 | "----" | 5840 | "----" |
| 5561 | ["Customize RefTeX" reftex-customize t] | 5841 | ("Documentation" |
| 5562 | "----" | 5842 | ["Info" reftex-info t] |
| 5563 | ["Show Documentation" reftex-show-commentary t])) | 5843 | ["Commentary" reftex-show-commentary t]))) |
| 5564 | 5844 | ||
| 5565 | ;;; Run Hook ------------------------------------------------------------------ | 5845 | ;;; Run Hook ------------------------------------------------------------------ |
| 5566 | 5846 | ||
| @@ -5570,7 +5850,7 @@ This enforces rescanning the buffer on next use." | |||
| 5570 | 5850 | ||
| 5571 | (provide 'reftex) | 5851 | (provide 'reftex) |
| 5572 | 5852 | ||
| 5573 | ; Make sure tabels are compiled | 5853 | ; Make sure tables are compiled |
| 5574 | (message "updating internal tables...") | 5854 | (message "updating internal tables...") |
| 5575 | (reftex-compute-ref-cite-tables) | 5855 | (reftex-compute-ref-cite-tables) |
| 5576 | (message "updating internal tables...done") | 5856 | (message "updating internal tables...done") |
| @@ -5579,3 +5859,4 @@ This enforces rescanning the buffer on next use." | |||
| 5579 | ;;;============================================================================ | 5859 | ;;;============================================================================ |
| 5580 | 5860 | ||
| 5581 | ;;; reftex.el ends here | 5861 | ;;; reftex.el ends here |
| 5862 | |||