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