Mercurial > emacs
annotate lisp/textmodes/reftex-toc.el @ 46780:5094a0226bac
Correction regarding --enable-static and libjpeg.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 01 Aug 2002 17:06:08 +0000 |
parents | 060f433ebf11 |
children | 904fd28be439 |
rev | line source |
---|---|
38422
7a94f1c588c4
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37998
diff
changeset
|
1 ;;; reftex-toc.el --- RefTeX's table of contents mode |
27192
f70a80cecdd3
New version number.
Carsten Dominik <dominik@science.uva.nl>
parents:
27035
diff
changeset
|
2 ;; Copyright (c) 1997, 1998, 1999, 2000 Free Software Foundation, Inc. |
27035 | 3 |
46612
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
41785
diff
changeset
|
4 ;; Author: Carsten Dominik <dominik@science.uva.nl> |
46683
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
5 ;; Version: 4.18 |
27035 | 6 |
7 ;; This file is part of GNU Emacs. | |
8 | |
9 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
11 ;; the Free Software Foundation; either version 2, or (at your option) | |
12 ;; any later version. | |
13 | |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
22 ;; Boston, MA 02111-1307, USA. | |
25280 | 23 |
38422
7a94f1c588c4
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37998
diff
changeset
|
24 ;;; Commentary: |
7a94f1c588c4
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37998
diff
changeset
|
25 |
7a94f1c588c4
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37998
diff
changeset
|
26 ;;; Code: |
7a94f1c588c4
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37998
diff
changeset
|
27 |
26910
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
28 (eval-when-compile (require 'cl)) |
25280 | 29 (provide 'reftex-toc) |
30 (require 'reftex) | |
31 ;;; | |
32 | |
33 (defvar reftex-toc-map (make-sparse-keymap) | |
34 "Keymap used for *toc* buffer.") | |
35 | |
36 (defvar reftex-toc-menu) | |
37 | |
38 (defun reftex-toc-mode () | |
39 "Major mode for managing Table of Contents for LaTeX files. | |
40 This buffer was created with RefTeX. | |
41 Press `?' for a summary of important key bindings. | |
42 | |
43 Here are all local bindings. | |
44 | |
45 \\{reftex-toc-map}" | |
46 (interactive) | |
47 (kill-all-local-variables) | |
48 (setq major-mode 'reftex-toc-mode | |
49 mode-name "TOC") | |
50 (use-local-map reftex-toc-map) | |
51 (set (make-local-variable 'revert-buffer-function) 'reftex-toc-revert) | |
52 (set (make-local-variable 'reftex-toc-include-labels-indicator) "") | |
26910
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
53 (set (make-local-variable 'reftex-toc-max-level-indicator) |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
54 (if (= reftex-toc-max-level 100) |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
55 "ALL" |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
56 (int-to-string reftex-toc-max-level))) |
25280 | 57 (setq mode-line-format |
58 (list "---- " 'mode-line-buffer-identification | |
59 " " 'global-mode-string " (" mode-name ")" | |
60 " L<" 'reftex-toc-include-labels-indicator ">" | |
61 " I<" 'reftex-toc-include-index-indicator ">" | |
26910
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
62 " T<" 'reftex-toc-max-level-indicator ">" |
25280 | 63 " -%-")) |
64 (setq truncate-lines t) | |
46683
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
65 (when (featurep 'xemacs) |
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
66 ;; XEmacs needs the call to make-local-hook |
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
67 (make-local-hook 'post-command-hook) |
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
68 (make-local-hook 'pre-command-hook)) |
25280 | 69 (make-local-variable 'reftex-last-follow-point) |
70 (add-hook 'post-command-hook 'reftex-toc-post-command-hook nil t) | |
71 (add-hook 'pre-command-hook 'reftex-toc-pre-command-hook nil t) | |
72 (easy-menu-add reftex-toc-menu reftex-toc-map) | |
73 (run-hooks 'reftex-toc-mode-hook)) | |
74 | |
75 (defvar reftex-last-toc-file nil | |
76 "Stores the file name from which `reftex-toc' was called. For redo command.") | |
77 | |
78 (defvar reftex-last-window-height nil) | |
46612
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
41785
diff
changeset
|
79 (defvar reftex-last-window-width nil) |
25280 | 80 (defvar reftex-toc-include-labels-indicator nil) |
81 (defvar reftex-toc-include-index-indicator nil) | |
26910
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
82 (defvar reftex-toc-max-level-indicator nil) |
25280 | 83 |
84 (defvar reftex-toc-return-marker (make-marker) | |
85 "Marker which makes it possible to return from toc to old position.") | |
86 | |
87 (defconst reftex-toc-help | |
88 " AVAILABLE KEYS IN TOC BUFFER | |
89 ============================ | |
90 n / p next-line / previous-line | |
91 SPC Show the corresponding location of the LaTeX document. | |
92 TAB Goto the location and keep the *toc* window. | |
93 RET Goto the location and hide the *toc* window (also on mouse-2). | |
94 C-c > Display Index. With prefix arg, restrict index to current section. | |
95 q / k Hide/Kill *toc* buffer, return to position of reftex-toc command. | |
96 l i c F Toggle display of [l]abels, [i]ndex, [c]ontext, [F]ile borders. | |
26910
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
97 t Change maximum toc depth (e.g. `3 t' hides levels greater than 3). |
25280 | 98 f / g Toggle follow mode on and off / Refresh *toc* buffer. |
99 r / C-u r Reparse the LaTeX document / Reparse entire LaTeX document. | |
100 . In other window, show position from where `reftex-toc' was called. | |
37998
706af946b1e7
* reftex-ref.el (reftex-select-label-help): Added "z" key
Carsten Dominik <dominik@science.uva.nl>
parents:
34402
diff
changeset
|
101 x Switch to TOC of external document (with LaTeX package `xr'). |
706af946b1e7
* reftex-ref.el (reftex-select-label-help): Added "z" key
Carsten Dominik <dominik@science.uva.nl>
parents:
34402
diff
changeset
|
102 z Jump to a specific section (e.g. '3 z' goes to section 3") |
25280 | 103 |
104 (defun reftex-toc (&optional rebuild) | |
105 "Show the table of contents for the current document. | |
106 When called with a raw C-u prefix, rescan the document first." | |
107 | |
108 (interactive) | |
109 | |
110 (if (or (not (string= reftex-last-toc-master (reftex-TeX-master-file))) | |
111 current-prefix-arg) | |
112 (reftex-erase-buffer "*toc*")) | |
113 | |
114 (setq reftex-last-toc-file (buffer-file-name)) | |
115 (setq reftex-last-toc-master (reftex-TeX-master-file)) | |
116 | |
117 (set-marker reftex-toc-return-marker (point)) | |
118 | |
119 ;; If follow mode is active, arrange to delay it one command | |
120 (if reftex-toc-follow-mode | |
121 (setq reftex-toc-follow-mode 1)) | |
122 | |
123 (and reftex-toc-include-index-entries | |
124 (reftex-ensure-index-support)) | |
125 (or reftex-support-index | |
126 (setq reftex-toc-include-index-entries nil)) | |
127 | |
128 ;; Ensure access to scanning info and rescan buffer if prefix are is '(4) | |
129 (reftex-access-scan-info current-prefix-arg) | |
130 | |
131 (let* ((this-buf (current-buffer)) | |
132 (docstruct-symbol reftex-docstruct-symbol) | |
133 (xr-data (assq 'xr (symbol-value reftex-docstruct-symbol))) | |
134 (xr-alist (cons (cons "" (buffer-file-name)) (nth 1 xr-data))) | |
46612
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
41785
diff
changeset
|
135 (here-I-am (if rebuild |
25280 | 136 (get 'reftex-toc :reftex-data) |
137 (car (reftex-where-am-I)))) | |
138 offset) | |
139 | |
140 (if (get-buffer-window "*toc*") | |
141 (select-window (get-buffer-window "*toc*")) | |
142 (when (or (not reftex-toc-keep-other-windows) | |
143 (< (window-height) (* 2 window-min-height))) | |
144 (delete-other-windows)) | |
46612
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
41785
diff
changeset
|
145 |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
41785
diff
changeset
|
146 (setq reftex-last-window-width (window-width) |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
41785
diff
changeset
|
147 reftex-last-window-height (window-height)) ; remember |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
41785
diff
changeset
|
148 (if reftex-toc-split-windows-horizontally |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
41785
diff
changeset
|
149 (split-window-horizontally |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
41785
diff
changeset
|
150 (floor (* (frame-width) reftex-toc-split-windows-horizontally-fraction))) |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
41785
diff
changeset
|
151 (split-window)) |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
41785
diff
changeset
|
152 |
25280 | 153 (let ((default-major-mode 'reftex-toc-mode)) |
154 (switch-to-buffer "*toc*"))) | |
155 | |
156 (or (eq major-mode 'reftex-toc-mode) (reftex-toc-mode)) | |
157 (set (make-local-variable 'reftex-docstruct-symbol) docstruct-symbol) | |
158 (setq reftex-toc-include-labels-indicator | |
159 (if (eq reftex-toc-include-labels t) | |
160 "ALL" | |
161 reftex-toc-include-labels)) | |
162 (setq reftex-toc-include-index-indicator | |
163 (if (eq reftex-toc-include-index-entries t) | |
164 "ALL" | |
165 reftex-toc-include-index-entries)) | |
166 | |
167 (cond | |
168 ((= (buffer-size) 0) | |
169 ;; buffer is empty - fill it with the table of contents | |
170 (message "Building *toc* buffer...") | |
171 | |
172 (setq buffer-read-only nil) | |
173 (insert (format | |
174 "TABLE-OF-CONTENTS on %s | |
175 SPC=view TAB=goto RET=goto+hide [q]uit [r]escan [l]abels [f]ollow [x]r [?]Help | |
176 ------------------------------------------------------------------------------ | |
177 " (abbreviate-file-name reftex-last-toc-master))) | |
178 | |
179 (if (reftex-use-fonts) | |
180 (put-text-property 1 (point) 'face reftex-toc-header-face)) | |
181 (put-text-property 1 (point) 'intangible t) | |
182 (put-text-property 1 2 'xr-alist xr-alist) | |
183 | |
184 (setq offset | |
185 (reftex-insert-docstruct | |
186 this-buf | |
187 t ; include toc | |
188 reftex-toc-include-labels | |
189 reftex-toc-include-index-entries | |
190 reftex-toc-include-file-boundaries | |
191 reftex-toc-include-context | |
192 nil ; counter | |
193 nil ; commented | |
194 here-I-am | |
195 "" ; xr-prefix | |
196 t ; a toc buffer | |
197 )) | |
198 | |
199 (run-hooks 'reftex-display-copied-context-hook) | |
200 (message "Building *toc* buffer...done.") | |
201 (setq buffer-read-only t)) | |
202 (t | |
203 ;; Only compute the offset | |
204 (setq offset | |
205 (or (reftex-get-offset this-buf here-I-am | |
206 (if reftex-toc-include-labels " " nil) | |
207 t | |
208 reftex-toc-include-index-entries | |
209 reftex-toc-include-file-boundaries) | |
210 (reftex-last-assoc-before-elt | |
211 'toc here-I-am | |
212 (symbol-value reftex-docstruct-symbol)))) | |
213 (put 'reftex-toc :reftex-line 3) | |
214 (goto-line 3) | |
215 (beginning-of-line))) | |
216 | |
217 ;; Find the correct starting point | |
218 (reftex-find-start-point (point) offset (get 'reftex-toc :reftex-line)) | |
219 (setq reftex-last-follow-point (point)))) | |
220 | |
221 (defun reftex-toc-pre-command-hook () | |
222 ;; used as pre command hook in *toc* buffer | |
223 (reftex-unhighlight 0) | |
224 (reftex-unhighlight 1)) | |
225 | |
226 (defun reftex-toc-post-command-hook () | |
227 ;; used in the post-command-hook for the *toc* buffer | |
228 (when (get-text-property (point) :data) | |
229 (put 'reftex-toc :reftex-data (get-text-property (point) :data)) | |
230 (and (> (point) 1) | |
231 (not (get-text-property (point) 'intangible)) | |
232 (memq reftex-highlight-selection '(cursor both)) | |
233 (reftex-highlight 1 | |
234 (or (previous-single-property-change (1+ (point)) :data) | |
235 (point-min)) | |
236 (or (next-single-property-change (point) :data) | |
237 (point-max))))) | |
238 (if (integerp reftex-toc-follow-mode) | |
239 ;; remove delayed action | |
240 (setq reftex-toc-follow-mode t) | |
241 (and reftex-toc-follow-mode | |
242 (not (equal reftex-last-follow-point (point))) | |
243 ;; show context in other window | |
244 (setq reftex-last-follow-point (point)) | |
245 (condition-case nil | |
246 (reftex-toc-visit-location nil (not reftex-revisit-to-follow)) | |
247 (error t))))) | |
248 | |
249 (defun reftex-re-enlarge () | |
250 ;; Enlarge windiw to a remembered size | |
46612
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
41785
diff
changeset
|
251 (if reftex-toc-split-windows-horizontally |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
41785
diff
changeset
|
252 (enlarge-window-horizontally |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
41785
diff
changeset
|
253 (max 0 (- (or reftex-last-window-width (window-width)) |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
41785
diff
changeset
|
254 (window-width)))) |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
41785
diff
changeset
|
255 (enlarge-window |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
41785
diff
changeset
|
256 (max 0 (- (or reftex-last-window-height (window-height)) |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
41785
diff
changeset
|
257 (window-height)))))) |
25280 | 258 |
259 (defun reftex-toc-show-help () | |
260 "Show a summary of special key bindings." | |
261 (interactive) | |
262 (with-output-to-temp-buffer "*RefTeX Help*" | |
263 (princ reftex-toc-help)) | |
264 (reftex-enlarge-to-fit "*RefTeX Help*" t) | |
265 ;; If follow mode is active, arrange to delay it one command | |
266 (if reftex-toc-follow-mode | |
267 (setq reftex-toc-follow-mode 1))) | |
268 | |
269 (defun reftex-toc-next (&optional arg) | |
270 "Move to next selectable item." | |
271 (interactive "p") | |
272 (setq reftex-callback-fwd t) | |
273 (or (eobp) (forward-char 1)) | |
274 (goto-char (or (next-single-property-change (point) :data) | |
275 (point)))) | |
276 (defun reftex-toc-previous (&optional arg) | |
277 "Move to previous selectable item." | |
278 (interactive "p") | |
279 (setq reftex-callback-fwd nil) | |
280 (goto-char (or (previous-single-property-change (point) :data) | |
281 (point)))) | |
282 (defun reftex-toc-next-heading (&optional arg) | |
283 "Move to next table of contentes line." | |
284 (interactive "p") | |
285 (end-of-line) | |
286 (re-search-forward "^ " nil t arg) | |
287 (beginning-of-line)) | |
288 (defun reftex-toc-previous-heading (&optional arg) | |
289 "Move to previous table of contentes line." | |
290 (interactive "p") | |
291 (re-search-backward "^ " nil t arg)) | |
292 (defun reftex-toc-toggle-follow () | |
293 "Toggle follow (other window follows with context)." | |
294 (interactive) | |
295 (setq reftex-last-follow-point -1) | |
296 (setq reftex-toc-follow-mode (not reftex-toc-follow-mode))) | |
297 (defun reftex-toc-toggle-file-boundary () | |
298 "Toggle inclusion of file boundaries in *toc* buffer." | |
299 (interactive) | |
300 (setq reftex-toc-include-file-boundaries | |
301 (not reftex-toc-include-file-boundaries)) | |
302 (reftex-toc-revert)) | |
303 (defun reftex-toc-toggle-labels (arg) | |
304 "Toggle inclusion of labels in *toc* buffer. | |
305 With prefix ARG, prompt for a label type and include only labels of | |
306 that specific type." | |
307 (interactive "P") | |
308 (setq reftex-toc-include-labels | |
309 (if arg (reftex-query-label-type) | |
310 (not reftex-toc-include-labels))) | |
311 (reftex-toc-revert)) | |
312 (defun reftex-toc-toggle-index (arg) | |
313 "Toggle inclusion of index in *toc* buffer. | |
314 With prefix arg, prompt for an index tag and include only entries of that | |
315 specific index." | |
316 (interactive "P") | |
317 (setq reftex-toc-include-index-entries | |
318 (if arg (reftex-index-select-tag) | |
319 (not reftex-toc-include-index-entries))) | |
320 (reftex-toc-revert)) | |
321 (defun reftex-toc-toggle-context () | |
322 "Toggle inclusion of label context in *toc* buffer. | |
323 Label context is only displayed when the labels are there as well." | |
324 (interactive) | |
325 (setq reftex-toc-include-context (not reftex-toc-include-context)) | |
326 (reftex-toc-revert)) | |
26910
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
327 (defun reftex-toc-max-level (arg) |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
328 "Set the maximum level of toc lines in this buffer to value of prefix ARG. |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
329 When no prefix is given, set the max level to a large number, so that all |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
330 levels are shown. For eaxample, to set the level to 3, type `3 m'." |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
331 (interactive "P") |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
332 (setq reftex-toc-max-level (if arg |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
333 (prefix-numeric-value arg) |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
334 100)) |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
335 (setq reftex-toc-max-level-indicator |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
336 (if arg (int-to-string reftex-toc-max-level) "ALL")) |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
337 (reftex-toc-revert)) |
25280 | 338 (defun reftex-toc-view-line () |
339 "View document location in other window." | |
340 (interactive) | |
341 (reftex-toc-visit-location)) | |
342 (defun reftex-toc-goto-line-and-hide () | |
343 "Go to document location in other window. Hide the *toc* window." | |
344 (interactive) | |
345 (reftex-toc-visit-location 'hide)) | |
346 (defun reftex-toc-goto-line () | |
347 "Go to document location in other window. *toc* window stays." | |
348 (interactive) | |
349 (reftex-toc-visit-location t)) | |
350 (defun reftex-toc-mouse-goto-line-and-hide (ev) | |
351 "Go to document location in other window. Hide the *toc* window." | |
352 (interactive "e") | |
353 (mouse-set-point ev) | |
354 (reftex-toc-visit-location 'hide)) | |
355 (defun reftex-toc-show-calling-point () | |
356 "Show point where reftex-toc was called from." | |
357 (interactive) | |
358 (let ((this-window (selected-window))) | |
359 (unwind-protect | |
360 (progn | |
361 (switch-to-buffer-other-window | |
362 (marker-buffer reftex-toc-return-marker)) | |
363 (goto-char (marker-position reftex-toc-return-marker)) | |
364 (recenter '(4))) | |
365 (select-window this-window)))) | |
366 (defun reftex-toc-quit () | |
367 "Hide the *toc* window and do not move point." | |
368 (interactive) | |
369 (or (one-window-p) (delete-window)) | |
370 (switch-to-buffer (marker-buffer reftex-toc-return-marker)) | |
371 (reftex-re-enlarge) | |
372 (goto-char (or (marker-position reftex-toc-return-marker) (point)))) | |
373 (defun reftex-toc-quit-and-kill () | |
374 "Kill the *toc* buffer." | |
375 (interactive) | |
376 (kill-buffer "*toc*") | |
377 (or (one-window-p) (delete-window)) | |
378 (switch-to-buffer (marker-buffer reftex-toc-return-marker)) | |
379 (reftex-re-enlarge) | |
380 (goto-char (marker-position reftex-toc-return-marker))) | |
381 (defun reftex-toc-display-index (&optional arg) | |
382 "Display the index buffer for the current document. | |
383 This works just like `reftex-display-index' from a LaTeX buffer. | |
384 With prefix arg 1, restrict index to the section at point." | |
385 (interactive "P") | |
386 (let ((data (get-text-property (point) :data)) | |
387 (docstruct (symbol-value reftex-docstruct-symbol)) | |
388 bor eor restr) | |
389 (when (equal arg 2) | |
390 (setq bor (reftex-last-assoc-before-elt 'toc data docstruct) | |
391 eor (assoc 'toc (cdr (memq bor docstruct))) | |
392 restr (list (nth 6 bor) bor eor))) | |
393 (reftex-toc-goto-line) | |
394 (reftex-display-index (if restr nil arg) restr))) | |
395 (defun reftex-toc-rescan (&rest ignore) | |
396 "Regenerate the *toc* buffer by reparsing file of section at point." | |
397 (interactive) | |
398 (if (and reftex-enable-partial-scans | |
399 (null current-prefix-arg)) | |
400 (let* ((data (get-text-property (point) :data)) | |
401 (what (car data)) | |
402 (file (cond ((eq what 'toc) (nth 3 data)) | |
403 ((memq what '(eof bof file-error)) (nth 1 data)) | |
404 ((stringp what) (nth 3 data)) | |
405 ((eq what 'index) (nth 3 data)))) | |
406 (line (+ (count-lines (point-min) (point)) (if (bolp) 1 0)))) | |
407 (if (not file) | |
408 (error "Don't know which file to rescan. Try `C-u r'") | |
409 (put 'reftex-toc :reftex-line line) | |
410 (switch-to-buffer-other-window | |
411 (reftex-get-file-buffer-force file)) | |
412 (setq current-prefix-arg '(4)) | |
413 (reftex-toc t))) | |
414 (reftex-toc-Rescan)) | |
415 (reftex-kill-temporary-buffers)) | |
416 (defun reftex-toc-Rescan (&rest ignore) | |
417 "Regenerate the *toc* buffer by reparsing the entire document." | |
418 (interactive) | |
419 (switch-to-buffer-other-window | |
420 (reftex-get-file-buffer-force reftex-last-toc-file)) | |
421 (setq current-prefix-arg '(16)) | |
422 (reftex-toc t)) | |
423 (defun reftex-toc-revert (&rest ignore) | |
424 "Regenerate the *toc* from the internal lists." | |
425 (interactive) | |
426 (switch-to-buffer-other-window | |
427 (reftex-get-file-buffer-force reftex-last-toc-file)) | |
428 (reftex-erase-buffer "*toc*") | |
429 (setq current-prefix-arg nil) | |
430 (reftex-toc t)) | |
431 (defun reftex-toc-external (&rest ignore) | |
432 "Switch to table of contents of an external document." | |
433 (interactive) | |
434 (let* ((old-buf (current-buffer)) | |
435 (xr-alist (get-text-property 1 'xr-alist)) | |
436 (xr-index (reftex-select-external-document | |
437 xr-alist 0))) | |
438 (switch-to-buffer-other-window (or (reftex-get-file-buffer-force | |
439 (cdr (nth xr-index xr-alist))) | |
440 (error "Cannot switch document"))) | |
441 (reftex-toc) | |
442 (if (equal old-buf (current-buffer)) | |
443 (message "") | |
444 (message "Switched document")))) | |
445 | |
37998
706af946b1e7
* reftex-ref.el (reftex-select-label-help): Added "z" key
Carsten Dominik <dominik@science.uva.nl>
parents:
34402
diff
changeset
|
446 (defun reftex-toc-jump (arg) |
706af946b1e7
* reftex-ref.el (reftex-select-label-help): Added "z" key
Carsten Dominik <dominik@science.uva.nl>
parents:
34402
diff
changeset
|
447 "Jump to a specific section. E.g. '3 z' jumps to section 3. |
706af946b1e7
* reftex-ref.el (reftex-select-label-help): Added "z" key
Carsten Dominik <dominik@science.uva.nl>
parents:
34402
diff
changeset
|
448 Useful for large TOC's." |
706af946b1e7
* reftex-ref.el (reftex-select-label-help): Added "z" key
Carsten Dominik <dominik@science.uva.nl>
parents:
34402
diff
changeset
|
449 (interactive "P") |
706af946b1e7
* reftex-ref.el (reftex-select-label-help): Added "z" key
Carsten Dominik <dominik@science.uva.nl>
parents:
34402
diff
changeset
|
450 (goto-char (point-min)) |
706af946b1e7
* reftex-ref.el (reftex-select-label-help): Added "z" key
Carsten Dominik <dominik@science.uva.nl>
parents:
34402
diff
changeset
|
451 (re-search-forward |
706af946b1e7
* reftex-ref.el (reftex-select-label-help): Added "z" key
Carsten Dominik <dominik@science.uva.nl>
parents:
34402
diff
changeset
|
452 (concat "^ *" (number-to-string (if (numberp arg) arg 1)) " ") |
706af946b1e7
* reftex-ref.el (reftex-select-label-help): Added "z" key
Carsten Dominik <dominik@science.uva.nl>
parents:
34402
diff
changeset
|
453 nil t) |
706af946b1e7
* reftex-ref.el (reftex-select-label-help): Added "z" key
Carsten Dominik <dominik@science.uva.nl>
parents:
34402
diff
changeset
|
454 (beginning-of-line)) |
706af946b1e7
* reftex-ref.el (reftex-select-label-help): Added "z" key
Carsten Dominik <dominik@science.uva.nl>
parents:
34402
diff
changeset
|
455 |
25280 | 456 (defun reftex-toc-visit-location (&optional final no-revisit) |
457 ;; Visit the tex file corresponding to the toc entry on the current line. | |
458 ;; If FINAL is t, stay there | |
459 ;; If FINAL is 'hide, hide the *toc* window. | |
460 ;; Otherwise, move cursor back into *toc* window. | |
461 ;; NO-REVISIT means don't visit files, just use live biffers. | |
462 ;; This function is pretty clever about finding back a section heading, | |
463 ;; even if the buffer is not live, or things like outline, x-symbol etc. | |
464 ;; have been active. | |
465 | |
466 (let* ((toc (get-text-property (point) :data)) | |
467 (toc-window (selected-window)) | |
468 show-window show-buffer match) | |
469 | |
470 (unless toc (error "Don't know which toc line to visit")) | |
471 | |
472 (cond | |
473 | |
474 ((eq (car toc) 'toc) | |
475 ;; a toc entry | |
476 (setq match (reftex-toc-find-section toc no-revisit))) | |
477 | |
478 ((eq (car toc) 'index) | |
479 ;; an index entry | |
480 (setq match (reftex-index-show-entry toc no-revisit))) | |
481 | |
482 ((memq (car toc) '(bof eof)) | |
483 ;; A file entry | |
484 (setq match | |
485 (let ((where (car toc)) | |
486 (file (nth 1 toc))) | |
487 (if (or (not no-revisit) (reftex-get-buffer-visiting file)) | |
488 (progn | |
489 (switch-to-buffer-other-window | |
490 (reftex-get-file-buffer-force file nil)) | |
491 (goto-char (if (eq where 'bof) (point-min) (point-max)))) | |
492 (message reftex-no-follow-message) nil)))) | |
493 | |
494 ((stringp (car toc)) | |
495 ;; a label | |
496 (setq match (reftex-show-label-location toc reftex-callback-fwd | |
497 no-revisit t)))) | |
498 | |
499 (setq show-window (selected-window) | |
500 show-buffer (current-buffer)) | |
501 | |
502 (unless match | |
503 (select-window toc-window) | |
504 (error "Cannot find location")) | |
505 | |
506 (select-window toc-window) | |
507 | |
508 ;; use the `final' parameter to decide what to do next | |
509 (cond | |
510 ((eq final t) | |
511 (reftex-unhighlight 0) | |
512 (select-window show-window)) | |
513 ((eq final 'hide) | |
514 (reftex-unhighlight 0) | |
515 (or (one-window-p) (delete-window)) | |
516 (switch-to-buffer show-buffer) | |
517 (reftex-re-enlarge)) | |
518 (t nil)))) | |
519 | |
520 (defun reftex-toc-find-section (toc &optional no-revisit) | |
521 (let* ((file (nth 3 toc)) | |
522 (marker (nth 4 toc)) | |
523 (level (nth 5 toc)) | |
524 (literal (nth 7 toc)) | |
525 (emergency-point (nth 8 toc)) | |
526 (match | |
527 (cond | |
528 ((and (markerp marker) (marker-buffer marker)) | |
529 ;; Buffer is still live and we have the marker. Should be easy. | |
530 (switch-to-buffer-other-window (marker-buffer marker)) | |
531 (goto-char (marker-position marker)) | |
532 (or (looking-at (regexp-quote literal)) | |
533 (looking-at (reftex-make-regexp-allow-for-ctrl-m literal)) | |
534 (looking-at (reftex-make-desperate-section-regexp literal)) | |
535 (looking-at (concat "\\\\" | |
536 (regexp-quote | |
537 (car | |
538 (rassq level | |
539 reftex-section-levels-all))) | |
26910
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
540 "[[{]?")))) |
25280 | 541 ((or (not no-revisit) |
542 (reftex-get-buffer-visiting file)) | |
543 ;; Marker is lost. Use the backup method. | |
544 (switch-to-buffer-other-window | |
545 (reftex-get-file-buffer-force file nil)) | |
546 (goto-char (or emergency-point (point-min))) | |
547 (or (looking-at (regexp-quote literal)) | |
548 (let ((len (length literal))) | |
549 (or (reftex-nearest-match (regexp-quote literal) len) | |
550 (reftex-nearest-match | |
551 (reftex-make-regexp-allow-for-ctrl-m literal) len) | |
552 (reftex-nearest-match | |
553 (reftex-make-desperate-section-regexp literal) len))))) | |
554 (t (message reftex-no-follow-message) nil)))) | |
555 (when match | |
556 (goto-char (match-beginning 0)) | |
557 (if (not (= (point) (point-max))) (recenter 1)) | |
558 (reftex-highlight 0 (match-beginning 0) (match-end 0) (current-buffer))) | |
559 match)) | |
560 | |
561 (defun reftex-make-desperate-section-regexp (old) | |
562 ;; Return a regexp which will still match a section statement even if | |
563 ;; x-symbol or isotex or the like have been at work in the mean time. | |
564 (let* ((n (1+ (string-match "[[{]" old))) | |
565 (new (regexp-quote (substring old 0 (1+ (string-match "[[{]" old))))) | |
566 (old (substring old n))) | |
567 (while (string-match | |
568 "\\([\r\n]\\)\\|\\(\\`\\|[ \t\n\r]\\)\\([a-zA-Z0-9]+\\)\\([ \t\n\r]\\|}\\'\\)" | |
569 old) | |
570 (if (match-beginning 1) | |
571 (setq new (concat new "[^\n\r]*[\n\r]")) | |
572 (setq new (concat new "[^\n\r]*" (match-string 3 old)))) | |
573 (setq old (substring old (match-end 0)))) | |
574 new)) | |
575 | |
576 ;; Table of Contents map | |
577 (define-key reftex-toc-map (if (featurep 'xemacs) [(button2)] [(mouse-2)]) | |
578 'reftex-toc-mouse-goto-line-and-hide) | |
579 | |
580 (substitute-key-definition | |
581 'next-line 'reftex-toc-next reftex-toc-map global-map) | |
582 (substitute-key-definition | |
583 'previous-line 'reftex-toc-previous reftex-toc-map global-map) | |
584 | |
585 (loop for x in | |
586 '(("n" . reftex-toc-next) | |
587 ("p" . reftex-toc-previous) | |
588 ("?" . reftex-toc-show-help) | |
589 (" " . reftex-toc-view-line) | |
590 ("\C-m" . reftex-toc-goto-line-and-hide) | |
591 ("\C-i" . reftex-toc-goto-line) | |
592 ("\C-c>". reftex-toc-display-index) | |
593 ("r" . reftex-toc-rescan) | |
594 ("R" . reftex-toc-Rescan) | |
595 ("g" . revert-buffer) | |
596 ("q" . reftex-toc-quit) | |
597 ("k" . reftex-toc-quit-and-kill) | |
598 ("f" . reftex-toc-toggle-follow) | |
599 ("F" . reftex-toc-toggle-file-boundary) | |
600 ("i" . reftex-toc-toggle-index) | |
601 ("l" . reftex-toc-toggle-labels) | |
26910
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
602 ("t" . reftex-toc-max-level) |
25280 | 603 ("c" . reftex-toc-toggle-context) |
604 ("%" . reftex-toc-toggle-commented) | |
605 ("x" . reftex-toc-external) | |
37998
706af946b1e7
* reftex-ref.el (reftex-select-label-help): Added "z" key
Carsten Dominik <dominik@science.uva.nl>
parents:
34402
diff
changeset
|
606 ("z" . reftex-toc-jump) |
25280 | 607 ("." . reftex-toc-show-calling-point) |
608 ("\C-c\C-n" . reftex-toc-next-heading) | |
609 ("\C-c\C-p" . reftex-toc-previous-heading)) | |
610 do (define-key reftex-toc-map (car x) (cdr x))) | |
611 | |
612 (loop for key across "0123456789" do | |
613 (define-key reftex-toc-map (vector (list key)) 'digit-argument)) | |
614 (define-key reftex-toc-map "-" 'negative-argument) | |
615 | |
616 (easy-menu-define | |
617 reftex-toc-menu reftex-toc-map | |
618 "Menu for Table of Contents buffer" | |
619 '("TOC" | |
620 ["Show Location" reftex-toc-view-line t] | |
621 ["Go To Location" reftex-toc-goto-line t] | |
622 ["Exit & Go To Location" reftex-toc-goto-line-and-hide t] | |
623 ["Index" reftex-toc-display-index t] | |
624 ["Quit" reftex-toc-quit t] | |
625 "--" | |
626 ["External Document TOC " reftex-toc-external t] | |
627 "--" | |
628 ("Update" | |
34402
5eec8d1d09f0
Update to RefTeX 4.15, see ChangeLog for details
Carsten Dominik <dominik@science.uva.nl>
parents:
34211
diff
changeset
|
629 ["Rebuilt *toc* Buffer" revert-buffer t] |
25280 | 630 ["Rescan One File" reftex-toc-rescan reftex-enable-partial-scans] |
631 ["Rescan Entire Document" reftex-toc-Rescan t]) | |
632 ("Options" | |
633 "TOC Items" | |
634 ["File Boundaries" reftex-toc-toggle-file-boundary :style toggle | |
635 :selected reftex-toc-include-file-boundaries] | |
636 ["Labels" reftex-toc-toggle-labels :style toggle | |
637 :selected reftex-toc-include-labels] | |
638 ["Index Entries" reftex-toc-toggle-index :style toggle | |
639 :selected reftex-toc-include-index-entries] | |
640 ["Context" reftex-toc-toggle-context :style toggle | |
641 :selected reftex-toc-include-context] | |
642 "--" | |
643 ["Follow Mode" reftex-toc-toggle-follow :style toggle | |
644 :selected reftex-toc-follow-mode]) | |
645 "--" | |
646 ["Help" reftex-toc-show-help t])) | |
647 | |
648 | |
649 ;;; reftex-toc.el ends here |