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