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