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