Add 2010 to copyright years.
[bpt/emacs.git] / lisp / textmodes / reftex-toc.el
CommitLineData
3afbc435 1;;; reftex-toc.el --- RefTeX's table of contents mode
e6ce8c42
GM
2
3;; Copyright (C) 1997, 1998, 1999, 2000, 2003, 2004, 2005, 2006, 2007,
114f9c96 4;; 2008, 2009, 2010 Free Software Foundation, Inc.
3ba2590f 5
6fbeb429 6;; Author: Carsten Dominik <dominik@science.uva.nl>
ce545621 7;; Maintainer: auctex-devel@gnu.org
5d2a58e0 8;; Version: 4.31
3ba2590f
RS
9
10;; This file is part of GNU Emacs.
11
1fecc8fe 12;; GNU Emacs is free software: you can redistribute it and/or modify
3ba2590f 13;; it under the terms of the GNU General Public License as published by
1fecc8fe
GM
14;; the Free Software Foundation, either version 3 of the License, or
15;; (at your option) any later version.
3ba2590f
RS
16
17;; GNU Emacs is distributed in the hope that it will be useful,
18;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20;; GNU General Public License for more details.
21
22;; You should have received a copy of the GNU General Public License
1fecc8fe 23;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
1a9461d0 24
3afbc435
PJ
25;;; Commentary:
26
27;;; Code:
28
7c4d13cc 29(eval-when-compile (require 'cl))
1a9461d0
CD
30(provide 'reftex-toc)
31(require 'reftex)
32;;;
33
34(defvar reftex-toc-map (make-sparse-keymap)
35 "Keymap used for *toc* buffer.")
36
37(defvar reftex-toc-menu)
7b07114a
CD
38(defvar reftex-last-window-height nil)
39(defvar reftex-last-window-width nil)
85a387c4
JB
40(defvar reftex-toc-include-labels-indicator nil)
41(defvar reftex-toc-include-index-indicator nil)
42(defvar reftex-toc-max-level-indicator nil)
1a9461d0
CD
43
44(defun reftex-toc-mode ()
45 "Major mode for managing Table of Contents for LaTeX files.
46This buffer was created with RefTeX.
47Press `?' for a summary of important key bindings.
48
49Here are all local bindings.
50
51\\{reftex-toc-map}"
52 (interactive)
53 (kill-all-local-variables)
54 (setq major-mode 'reftex-toc-mode
3666daf6 55 mode-name "TOC")
1a9461d0 56 (use-local-map reftex-toc-map)
3666daf6 57 (set (make-local-variable 'transient-mark-mode) t)
0c86715d
DN
58 (when (featurep 'xemacs)
59 (set (make-local-variable 'zmacs-regions) t))
1a9461d0
CD
60 (set (make-local-variable 'revert-buffer-function) 'reftex-toc-revert)
61 (set (make-local-variable 'reftex-toc-include-labels-indicator) "")
7c4d13cc
CD
62 (set (make-local-variable 'reftex-toc-max-level-indicator)
63 (if (= reftex-toc-max-level 100)
3666daf6
CD
64 "ALL"
65 (int-to-string reftex-toc-max-level)))
1a9461d0 66 (setq mode-line-format
3666daf6
CD
67 (list "---- " 'mode-line-buffer-identification
68 " " 'global-mode-string " (" mode-name ")"
69 " L<" 'reftex-toc-include-labels-indicator ">"
70 " I<" 'reftex-toc-include-index-indicator ">"
71 " T<" 'reftex-toc-max-level-indicator ">"
72 " -%-"))
1a9461d0 73 (setq truncate-lines t)
7ac7387b
CD
74 (when (featurep 'xemacs)
75 ;; XEmacs needs the call to make-local-hook
76 (make-local-hook 'post-command-hook)
77 (make-local-hook 'pre-command-hook))
1a9461d0
CD
78 (make-local-variable 'reftex-last-follow-point)
79 (add-hook 'post-command-hook 'reftex-toc-post-command-hook nil t)
80 (add-hook 'pre-command-hook 'reftex-toc-pre-command-hook nil t)
81 (easy-menu-add reftex-toc-menu reftex-toc-map)
7b07114a 82 (run-hooks 'reftex-toc-mode-hook))
1a9461d0
CD
83
84(defvar reftex-last-toc-file nil
85 "Stores the file name from which `reftex-toc' was called. For redo command.")
86
1a9461d0
CD
87
88(defvar reftex-toc-return-marker (make-marker)
89 "Marker which makes it possible to return from toc to old position.")
90
91(defconst reftex-toc-help
92" AVAILABLE KEYS IN TOC BUFFER
93 ============================
94n / p next-line / previous-line
95SPC Show the corresponding location of the LaTeX document.
96TAB Goto the location and keep the *toc* window.
97RET Goto the location and hide the *toc* window (also on mouse-2).
3666daf6 98< / > Promote / Demote section, or all sections in region.
1a9461d0
CD
99C-c > Display Index. With prefix arg, restrict index to current section.
100q / k Hide/Kill *toc* buffer, return to position of reftex-toc command.
101l i c F Toggle display of [l]abels, [i]ndex, [c]ontext, [F]ile borders.
7c4d13cc 102t Change maximum toc depth (e.g. `3 t' hides levels greater than 3).
3666daf6
CD
103f / g Toggle follow mode / Refresh *toc* buffer.
104a / d Toggle auto recenter / Toggle dedicated frame
1a9461d0
CD
105r / C-u r Reparse the LaTeX document / Reparse entire LaTeX document.
106. In other window, show position from where `reftex-toc' was called.
3666daf6 107M-% Global search and replace to rename label at point.
70d797cd 108x Switch to TOC of external document (with LaTeX package `xr').
3666daf6 109z Jump to a specific section (e.g. '3 z' goes to section 3).")
1a9461d0 110
3666daf6 111(defun reftex-toc (&optional rebuild reuse)
1a9461d0
CD
112 "Show the table of contents for the current document.
113When called with a raw C-u prefix, rescan the document first."
114
3666daf6
CD
115;; The REUSE argument means, search all visible frames for a window
116;; displaying the toc window. If yes, reuse this window.
117
1a9461d0
CD
118 (interactive)
119
120 (if (or (not (string= reftex-last-toc-master (reftex-TeX-master-file)))
121 current-prefix-arg)
122 (reftex-erase-buffer "*toc*"))
123
124 (setq reftex-last-toc-file (buffer-file-name))
125 (setq reftex-last-toc-master (reftex-TeX-master-file))
126
127 (set-marker reftex-toc-return-marker (point))
128
129 ;; If follow mode is active, arrange to delay it one command
130 (if reftex-toc-follow-mode
131 (setq reftex-toc-follow-mode 1))
132
133 (and reftex-toc-include-index-entries
134 (reftex-ensure-index-support))
135 (or reftex-support-index
136 (setq reftex-toc-include-index-entries nil))
137
138 ;; Ensure access to scanning info and rescan buffer if prefix are is '(4)
139 (reftex-access-scan-info current-prefix-arg)
140
141 (let* ((this-buf (current-buffer))
3666daf6
CD
142 (docstruct-symbol reftex-docstruct-symbol)
143 (xr-data (assq 'xr (symbol-value reftex-docstruct-symbol)))
144 (xr-alist (cons (cons "" (buffer-file-name)) (nth 1 xr-data)))
145 (here-I-am (if (boundp 'reftex-rebuilding-toc)
146 (get 'reftex-toc :reftex-data)
147 (car (reftex-where-am-I))))
148 (unsplittable (if (fboundp 'frame-property)
149 (frame-property (selected-frame) 'unsplittable)
150 (frame-parameter (selected-frame) 'unsplittable)))
151 offset toc-window)
152
e6ce8c42 153 (if (setq toc-window (get-buffer-window
3666daf6
CD
154 "*toc*"
155 (if reuse 'visible)))
156 (select-window toc-window)
1a9461d0 157 (when (or (not reftex-toc-keep-other-windows)
3666daf6
CD
158 (< (window-height) (* 2 window-min-height)))
159 (delete-other-windows))
6fbeb429
CD
160
161 (setq reftex-last-window-width (window-width)
3666daf6
CD
162 reftex-last-window-height (window-height)) ; remember
163
164 (unless unsplittable
165 (if reftex-toc-split-windows-horizontally
166 (split-window-horizontally
167 (floor (* (window-width)
168 reftex-toc-split-windows-fraction)))
e6ce8c42 169 (split-window-vertically
3666daf6
CD
170 (floor (* (window-height)
171 reftex-toc-split-windows-fraction)))))
6fbeb429 172
d63eb0e7 173 (switch-to-buffer "*toc*"))
1a9461d0
CD
174
175 (or (eq major-mode 'reftex-toc-mode) (reftex-toc-mode))
176 (set (make-local-variable 'reftex-docstruct-symbol) docstruct-symbol)
177 (setq reftex-toc-include-labels-indicator
3666daf6
CD
178 (if (eq reftex-toc-include-labels t)
179 "ALL"
180 reftex-toc-include-labels))
1a9461d0 181 (setq reftex-toc-include-index-indicator
3666daf6
CD
182 (if (eq reftex-toc-include-index-entries t)
183 "ALL"
184 reftex-toc-include-index-entries))
1a9461d0
CD
185
186 (cond
187 ((= (buffer-size) 0)
188 ;; buffer is empty - fill it with the table of contents
189 (message "Building *toc* buffer...")
190
191 (setq buffer-read-only nil)
192 (insert (format
193"TABLE-OF-CONTENTS on %s
194SPC=view TAB=goto RET=goto+hide [q]uit [r]escan [l]abels [f]ollow [x]r [?]Help
195------------------------------------------------------------------------------
196" (abbreviate-file-name reftex-last-toc-master)))
197
198 (if (reftex-use-fonts)
4a9699d8
SM
199 (put-text-property (point-min) (point) 'face reftex-toc-header-face))
200 (put-text-property (point-min) (point) 'intangible t)
201 (put-text-property (point-min) (1+ (point-min)) 'xr-alist xr-alist)
1a9461d0
CD
202
203 (setq offset
3666daf6
CD
204 (reftex-insert-docstruct
205 this-buf
206 t ; include toc
207 reftex-toc-include-labels
208 reftex-toc-include-index-entries
209 reftex-toc-include-file-boundaries
210 reftex-toc-include-context
211 nil ; counter
212 nil ; commented
e6ce8c42 213 here-I-am
3666daf6
CD
214 "" ; xr-prefix
215 t ; a toc buffer
216 ))
e6ce8c42 217
1a9461d0
CD
218 (run-hooks 'reftex-display-copied-context-hook)
219 (message "Building *toc* buffer...done.")
220 (setq buffer-read-only t))
221 (t
222 ;; Only compute the offset
223 (setq offset
3666daf6
CD
224 (or (reftex-get-offset this-buf here-I-am
225 (if reftex-toc-include-labels " " nil)
226 t
227 reftex-toc-include-index-entries
228 reftex-toc-include-file-boundaries)
e6ce8c42 229 (reftex-last-assoc-before-elt
3666daf6
CD
230 'toc here-I-am
231 (symbol-value reftex-docstruct-symbol))))
1a9461d0 232 (put 'reftex-toc :reftex-line 3)
e6ce8c42
GM
233 (goto-char (point-min))
234 (forward-line 2)))
1a9461d0
CD
235
236 ;; Find the correct starting point
237 (reftex-find-start-point (point) offset (get 'reftex-toc :reftex-line))
238 (setq reftex-last-follow-point (point))))
239
3b919c9f
CD
240(defun reftex-toc-recenter (&optional arg)
241 "Display the TOC window and highlight line corresponding to current position."
242 (interactive "P")
3666daf6
CD
243 (let ((buf (current-buffer))
244 (frame (selected-frame)))
245 (reftex-toc arg t)
3b919c9f 246 (if (= (count-lines 1 (point)) 2)
3666daf6
CD
247 (let ((current-prefix-arg nil))
248 (select-window (get-buffer-window buf frame))
249 (reftex-toc nil t)))
3b919c9f 250 (and (> (point) 1)
3666daf6
CD
251 (not (get-text-property (point) 'intangible))
252 (memq reftex-highlight-selection '(cursor both))
253 (reftex-highlight 2
e6ce8c42 254 (or (previous-single-property-change
3666daf6
CD
255 (min (point-max) (1+ (point))) :data)
256 (point-min))
257 (or (next-single-property-change (point) :data)
258 (point-max))))
259 (select-window (get-buffer-window buf frame))))
3b919c9f 260
1a9461d0
CD
261(defun reftex-toc-pre-command-hook ()
262 ;; used as pre command hook in *toc* buffer
263 (reftex-unhighlight 0)
3b919c9f 264 )
1a9461d0
CD
265
266(defun reftex-toc-post-command-hook ()
267 ;; used in the post-command-hook for the *toc* buffer
268 (when (get-text-property (point) :data)
269 (put 'reftex-toc :reftex-data (get-text-property (point) :data))
270 (and (> (point) 1)
3666daf6
CD
271 (not (get-text-property (point) 'intangible))
272 (memq reftex-highlight-selection '(cursor both))
273 (reftex-highlight 2
274 (or (previous-single-property-change (1+ (point)) :data)
275 (point-min))
276 (or (next-single-property-change (point) :data)
277 (point-max)))))
1a9461d0
CD
278 (if (integerp reftex-toc-follow-mode)
279 ;; remove delayed action
280 (setq reftex-toc-follow-mode t)
3666daf6
CD
281 (and (not (reftex-toc-dframe-p))
282 reftex-toc-follow-mode
283 (not (equal reftex-last-follow-point (point)))
284 ;; show context in other window
285 (setq reftex-last-follow-point (point))
286 (condition-case nil
287 (reftex-toc-visit-location nil (not reftex-revisit-to-follow))
288 (error t)))))
1a9461d0
CD
289
290(defun reftex-re-enlarge ()
4a9699d8 291 ;; Enlarge window to a remembered size.
6fbeb429
CD
292 (if reftex-toc-split-windows-horizontally
293 (enlarge-window-horizontally
294 (max 0 (- (or reftex-last-window-width (window-width))
3666daf6 295 (window-width))))
6fbeb429
CD
296 (enlarge-window
297 (max 0 (- (or reftex-last-window-height (window-height))
3666daf6
CD
298 (window-height))))))
299
300(defun reftex-toc-dframe-p (&optional frame error)
e6ce8c42 301 ;; Check if FRAME is the dedicated TOC frame.
3666daf6
CD
302 ;; If yes, and ERROR is non-nil, throw an error.
303 (setq frame (or frame (selected-frame)))
e6ce8c42 304 (let ((res (equal
3666daf6
CD
305 (if (fboundp 'frame-property)
306 (frame-property frame 'name)
307 (frame-parameter frame 'name))
308 "RefTeX TOC Frame")))
309 (if (and res error)
52ebd91d 310 (error "This frame is view-only. Use `C-c =' to create toc window for commands"))
3666daf6 311 res))
1a9461d0
CD
312
313(defun reftex-toc-show-help ()
314 "Show a summary of special key bindings."
315 (interactive)
3666daf6 316 (reftex-toc-dframe-p nil 'error)
1a9461d0
CD
317 (with-output-to-temp-buffer "*RefTeX Help*"
318 (princ reftex-toc-help))
319 (reftex-enlarge-to-fit "*RefTeX Help*" t)
320 ;; If follow mode is active, arrange to delay it one command
321 (if reftex-toc-follow-mode
322 (setq reftex-toc-follow-mode 1)))
323
324(defun reftex-toc-next (&optional arg)
325 "Move to next selectable item."
326 (interactive "p")
a445370f 327 (when (featurep 'xemacs) (setq zmacs-region-stays t))
1a9461d0
CD
328 (setq reftex-callback-fwd t)
329 (or (eobp) (forward-char 1))
e6ce8c42 330 (goto-char (or (next-single-property-change (point) :data)
3666daf6 331 (point))))
1a9461d0
CD
332(defun reftex-toc-previous (&optional arg)
333 "Move to previous selectable item."
334 (interactive "p")
a445370f 335 (when (featurep 'xemacs) (setq zmacs-region-stays t))
1a9461d0
CD
336 (setq reftex-callback-fwd nil)
337 (goto-char (or (previous-single-property-change (point) :data)
3666daf6 338 (point))))
1a9461d0
CD
339(defun reftex-toc-next-heading (&optional arg)
340 "Move to next table of contentes line."
341 (interactive "p")
a445370f 342 (when (featurep 'xemacs) (setq zmacs-region-stays t))
1a9461d0
CD
343 (end-of-line)
344 (re-search-forward "^ " nil t arg)
345 (beginning-of-line))
346(defun reftex-toc-previous-heading (&optional arg)
347 "Move to previous table of contentes line."
348 (interactive "p")
a445370f 349 (when (featurep 'xemacs) (setq zmacs-region-stays t))
1a9461d0
CD
350 (re-search-backward "^ " nil t arg))
351(defun reftex-toc-toggle-follow ()
352 "Toggle follow (other window follows with context)."
353 (interactive)
354 (setq reftex-last-follow-point -1)
355 (setq reftex-toc-follow-mode (not reftex-toc-follow-mode)))
356(defun reftex-toc-toggle-file-boundary ()
357 "Toggle inclusion of file boundaries in *toc* buffer."
358 (interactive)
359 (setq reftex-toc-include-file-boundaries
3666daf6 360 (not reftex-toc-include-file-boundaries))
1a9461d0
CD
361 (reftex-toc-revert))
362(defun reftex-toc-toggle-labels (arg)
363 "Toggle inclusion of labels in *toc* buffer.
364With prefix ARG, prompt for a label type and include only labels of
365that specific type."
366 (interactive "P")
e6ce8c42 367 (setq reftex-toc-include-labels
3666daf6
CD
368 (if arg (reftex-query-label-type)
369 (not reftex-toc-include-labels)))
1a9461d0
CD
370 (reftex-toc-revert))
371(defun reftex-toc-toggle-index (arg)
372 "Toggle inclusion of index in *toc* buffer.
373With prefix arg, prompt for an index tag and include only entries of that
374specific index."
375 (interactive "P")
376 (setq reftex-toc-include-index-entries
3666daf6
CD
377 (if arg (reftex-index-select-tag)
378 (not reftex-toc-include-index-entries)))
1a9461d0
CD
379 (reftex-toc-revert))
380(defun reftex-toc-toggle-context ()
381 "Toggle inclusion of label context in *toc* buffer.
382Label context is only displayed when the labels are there as well."
383 (interactive)
384 (setq reftex-toc-include-context (not reftex-toc-include-context))
385 (reftex-toc-revert))
7c4d13cc
CD
386(defun reftex-toc-max-level (arg)
387 "Set the maximum level of toc lines in this buffer to value of prefix ARG.
388When no prefix is given, set the max level to a large number, so that all
389levels are shown. For eaxample, to set the level to 3, type `3 m'."
390 (interactive "P")
391 (setq reftex-toc-max-level (if arg
3666daf6
CD
392 (prefix-numeric-value arg)
393 100))
7c4d13cc 394 (setq reftex-toc-max-level-indicator
3666daf6 395 (if arg (int-to-string reftex-toc-max-level) "ALL"))
7c4d13cc 396 (reftex-toc-revert))
1a9461d0
CD
397(defun reftex-toc-view-line ()
398 "View document location in other window."
399 (interactive)
3666daf6 400 (reftex-toc-dframe-p nil 'error)
1a9461d0
CD
401 (reftex-toc-visit-location))
402(defun reftex-toc-goto-line-and-hide ()
403 "Go to document location in other window. Hide the *toc* window."
404 (interactive)
3666daf6 405 (reftex-toc-dframe-p nil 'error)
1a9461d0
CD
406 (reftex-toc-visit-location 'hide))
407(defun reftex-toc-goto-line ()
408 "Go to document location in other window. *toc* window stays."
409 (interactive)
3666daf6 410 (reftex-toc-dframe-p nil 'error)
1a9461d0
CD
411 (reftex-toc-visit-location t))
412(defun reftex-toc-mouse-goto-line-and-hide (ev)
413 "Go to document location in other window. Hide the *toc* window."
414 (interactive "e")
415 (mouse-set-point ev)
3666daf6 416 (reftex-toc-dframe-p nil 'error)
1a9461d0
CD
417 (reftex-toc-visit-location 'hide))
418(defun reftex-toc-show-calling-point ()
419 "Show point where reftex-toc was called from."
420 (interactive)
3666daf6 421 (reftex-toc-dframe-p nil 'error)
1a9461d0
CD
422 (let ((this-window (selected-window)))
423 (unwind-protect
3666daf6
CD
424 (progn
425 (switch-to-buffer-other-window
426 (marker-buffer reftex-toc-return-marker))
427 (goto-char (marker-position reftex-toc-return-marker))
428 (recenter '(4)))
1a9461d0
CD
429 (select-window this-window))))
430(defun reftex-toc-quit ()
3666daf6
CD
431 "Hide the *toc* window and do not move point.
432If the toc window is the only window on the dedicated TOC frame, the frame
433is destroyed."
1a9461d0 434 (interactive)
3666daf6
CD
435 (if (and (one-window-p)
436 (reftex-toc-dframe-p)
437 (> (length (frame-list)) 1))
438 (delete-frame)
439 (or (one-window-p) (delete-window))
440 (switch-to-buffer (marker-buffer reftex-toc-return-marker))
441 (reftex-re-enlarge)
442 (goto-char (or (marker-position reftex-toc-return-marker) (point)))))
1a9461d0
CD
443(defun reftex-toc-quit-and-kill ()
444 "Kill the *toc* buffer."
445 (interactive)
446 (kill-buffer "*toc*")
447 (or (one-window-p) (delete-window))
448 (switch-to-buffer (marker-buffer reftex-toc-return-marker))
449 (reftex-re-enlarge)
450 (goto-char (marker-position reftex-toc-return-marker)))
451(defun reftex-toc-display-index (&optional arg)
452 "Display the index buffer for the current document.
453This works just like `reftex-display-index' from a LaTeX buffer.
454With prefix arg 1, restrict index to the section at point."
455 (interactive "P")
3666daf6 456 (reftex-toc-dframe-p nil 'error)
1a9461d0 457 (let ((data (get-text-property (point) :data))
3666daf6
CD
458 (docstruct (symbol-value reftex-docstruct-symbol))
459 bor eor restr)
1a9461d0
CD
460 (when (equal arg 2)
461 (setq bor (reftex-last-assoc-before-elt 'toc data docstruct)
3666daf6
CD
462 eor (assoc 'toc (cdr (memq bor docstruct)))
463 restr (list (nth 6 bor) bor eor)))
1a9461d0
CD
464 (reftex-toc-goto-line)
465 (reftex-display-index (if restr nil arg) restr)))
3666daf6
CD
466
467;; Rescanning the document and rebuilding the TOC buffer.
1a9461d0
CD
468(defun reftex-toc-rescan (&rest ignore)
469 "Regenerate the *toc* buffer by reparsing file of section at point."
470 (interactive)
e6ce8c42 471 (if (and reftex-enable-partial-scans
3666daf6 472 (null current-prefix-arg))
1a9461d0 473 (let* ((data (get-text-property (point) :data))
3666daf6
CD
474 (what (car data))
475 (file (cond ((eq what 'toc) (nth 3 data))
476 ((memq what '(eof bof file-error)) (nth 1 data))
477 ((stringp what) (nth 3 data))
478 ((eq what 'index) (nth 3 data))))
479 (line (+ (count-lines (point-min) (point)) (if (bolp) 1 0))))
1a9461d0
CD
480 (if (not file)
481 (error "Don't know which file to rescan. Try `C-u r'")
3666daf6 482 (put 'reftex-toc :reftex-line line)
1a9461d0
CD
483 (switch-to-buffer-other-window
484 (reftex-get-file-buffer-force file))
3666daf6
CD
485 (setq current-prefix-arg '(4))
486 (let ((reftex-rebuilding-toc t))
487 (reftex-toc))))
1a9461d0
CD
488 (reftex-toc-Rescan))
489 (reftex-kill-temporary-buffers))
3666daf6 490
1a9461d0
CD
491(defun reftex-toc-Rescan (&rest ignore)
492 "Regenerate the *toc* buffer by reparsing the entire document."
493 (interactive)
3b919c9f
CD
494 (let* ((line (+ (count-lines (point-min) (point)) (if (bolp) 1 0))))
495 (put 'reftex-toc :reftex-line line))
1a9461d0
CD
496 (switch-to-buffer-other-window
497 (reftex-get-file-buffer-force reftex-last-toc-file))
498 (setq current-prefix-arg '(16))
3b919c9f
CD
499 (let ((reftex-rebuilding-toc t))
500 (reftex-toc)))
3666daf6 501
1a9461d0
CD
502(defun reftex-toc-revert (&rest ignore)
503 "Regenerate the *toc* from the internal lists."
504 (interactive)
e6ce8c42 505 (let ((unsplittable
3666daf6
CD
506 (if (fboundp 'frame-property)
507 (frame-property (selected-frame) 'unsplittable)
508 (frame-parameter (selected-frame) 'unsplittable)))
509 (reftex-rebuilding-toc t))
510 (if unsplittable
511 (switch-to-buffer
512 (reftex-get-file-buffer-force reftex-last-toc-file))
513 (switch-to-buffer-other-window
514 (reftex-get-file-buffer-force reftex-last-toc-file))))
1a9461d0
CD
515 (reftex-erase-buffer "*toc*")
516 (setq current-prefix-arg nil)
3666daf6
CD
517 (reftex-toc t))
518
1a9461d0
CD
519(defun reftex-toc-external (&rest ignore)
520 "Switch to table of contents of an external document."
521 (interactive)
3666daf6 522 (reftex-toc-dframe-p nil 'error)
1a9461d0 523 (let* ((old-buf (current-buffer))
3666daf6
CD
524 (xr-alist (get-text-property 1 'xr-alist))
525 (xr-index (reftex-select-external-document
526 xr-alist 0)))
1a9461d0 527 (switch-to-buffer-other-window (or (reftex-get-file-buffer-force
3666daf6
CD
528 (cdr (nth xr-index xr-alist)))
529 (error "Cannot switch document")))
1a9461d0
CD
530 (reftex-toc)
531 (if (equal old-buf (current-buffer))
3666daf6 532 (message "")
1a9461d0
CD
533 (message "Switched document"))))
534
70d797cd
CD
535(defun reftex-toc-jump (arg)
536 "Jump to a specific section. E.g. '3 z' jumps to section 3.
537Useful for large TOC's."
538 (interactive "P")
539 (goto-char (point-min))
540 (re-search-forward
541 (concat "^ *" (number-to-string (if (numberp arg) arg 1)) " ")
542 nil t)
543 (beginning-of-line))
544
3666daf6
CD
545;; Promotion/Demotion stuff
546
7b07114a
CD
547(defvar delta)
548(defvar mpos)
549(defvar pro-or-de)
550(defvar start-pos)
551(defvar start-line)
552(defvar mark-line)
553
3666daf6
CD
554(defun reftex-toc-demote (&optional arg)
555 "Demote section at point. If region is active, apply to all in region."
556 (interactive "p")
557 (reftex-toc-do-promote 1))
558(defun reftex-toc-promote (&optional arg)
559 "Promote section at point. If region is active, apply to all in region."
560 (interactive "p")
561 (reftex-toc-do-promote -1))
562(defun reftex-toc-do-promote (delta)
563 "Workhorse for reftex-toc-promote and reftex-to-demote.
564Changes the level of sections in the current region, or just the section at
565point."
566 ;; We should not do anything unless we are sure this is going to work for
567 ;; each section in the region. Therefore we first collect information and
568 ;; test.
569 (let* ((start-line (+ (count-lines (point-min) (point))
570 (if (bolp) 1 0)))
571 (mark-line (if (reftex-region-active-p)
572 (save-excursion (goto-char (mark))
573 (+ (count-lines (point-min) (point))
574 (if (bolp) 1 0)))))
575 (start-pos (point))
576 (pro-or-de (if (> delta 0) "de" "pro"))
577 beg end entries data sections nsec mpos msg)
578 (setq msg
579 (catch 'exit
580 (if (reftex-region-active-p)
581 ;; A region is dangerous, check if we have a brandnew scan,
582 ;; to make sure we are not missing any section statements.
583 (if (not (reftex-toc-check-docstruct))
584 (reftex-toc-load-all-files-for-promotion) ;; exits
585 (setq beg (min (point) (mark))
586 end (max (point) (mark))))
587 (setq beg (point) end (point)))
588 (goto-char beg)
589 (while (and (setq data (get-text-property (point) :data))
590 (<= (point) end))
591 (if (eq (car data) 'toc) (push (cons data (point)) entries))
592 (goto-char (or (next-single-property-change (point) :data)
593 (point-max))))
594 (setq entries (nreverse entries))
595 ;; Get the relevant section numbers, for an informative message
596 (goto-char start-pos)
597 (setq sections (reftex-toc-extract-section-number (car entries)))
598 (if (> (setq nsec (length entries)) 1)
e6ce8c42 599 (setq sections
3666daf6
CD
600 (concat sections "-"
601 (reftex-toc-extract-section-number
602 (nth (1- nsec) entries)))))
603 ;; Run through the list and prepare the changes.
604 (setq entries (mapcar 'reftex-toc-promote-prepare entries))
605 ;; Ask for permission
606 (if (or (not reftex-toc-confirm-promotion) ; never confirm
607 (and (integerp reftex-toc-confirm-promotion) ; confirm if many
608 (< nsec reftex-toc-confirm-promotion))
609 (yes-or-no-p ; ask
610 (format "%s %d toc-entr%s (section%s %s)? "
611 (if (< delta 0) "Promote" "Demote")
612 nsec
613 (if (= 1 nsec) "y" "ies")
614 (if (= 1 nsec) "" "s")
615 sections)))
616 nil ; we have permission, do nothing
617 (error "Abort")) ; abort, we don't have permission
618 ;; Do the changes
17d10974 619 (mapc 'reftex-toc-promote-action entries)
3666daf6
CD
620 ;; Rescan the document and rebuilt the toc buffer
621 (save-window-excursion
622 (reftex-toc-Rescan))
623 (reftex-toc-restore-region start-line mark-line)
e6ce8c42 624 (message "%d section%s %smoted"
3666daf6
CD
625 nsec (if (= 1 nsec) "" "s") pro-or-de)
626 nil))
274f1353 627 (if msg (progn (ding) (message "%s" msg)))))
3666daf6 628
3666daf6
CD
629
630(defun reftex-toc-restore-region (point-line &optional mark-line)
e6ce8c42
GM
631 (when mark-line
632 (goto-char (point-min))
633 (forward-line (1- mark-line))
634 (setq mpos (point)))
635 (when point-line
636 (goto-char (point-min))
637 (forward-line (1- point-line)))
3666daf6
CD
638 (if mark-line
639 (progn
640 (set-mark mpos)
a445370f 641 (if (featurep 'xemacs)
3666daf6
CD
642 (zmacs-activate-region)
643 (setq mark-active t
644 deactivate-mark nil)))))
645
7b07114a
CD
646(defvar name1)
647(defvar dummy)
648(defvar dummy2)
649
3666daf6
CD
650(defun reftex-toc-promote-prepare (x)
651 "Look at a toc entry and see if we could pro/demote it.
652Expects the level change DELTA to be dynamically scoped into this function.
653This function prepares everything for the changes, but does not do it.
654The return value is a list with information needed when doing the
655promotion/demotion later."
656 (let* ((data (car x))
657 (toc-point (cdr x))
658 (marker (nth 4 data))
659 (literal (nth 7 data))
660 (load nil)
661 (name nil)
662 ;; Here follows some paranoid code to make very sure we are not
663 ;; going to break anything
664 (name1 ; dummy
665 (if (and (markerp marker) (marker-buffer marker))
666 ;; Buffer is still live and we have the marker.
667 (progn
668 (save-excursion
669 ;; Goto the buffer and check of section is unchanged
670 (set-buffer (marker-buffer marker))
671 (goto-char (marker-position marker))
672 (if (looking-at (regexp-quote literal))
673 ;; OK, get the makro name
674 (progn
675 (beginning-of-line 1)
676 (if (looking-at reftex-section-regexp)
677 (setq name (reftex-match-string 2))
5a0c3f56 678 (error "Something is wrong! Contact maintainer!")))
3666daf6
CD
679 ;; Section has changed, request scan and loading
680 ;; We use a variable to delay until after the safe-exc.
681 ;; because otherwise we loose the region.
682 (setq load t)))
683 ;; Scan document and load all files, this exits command
684 (if load (reftex-toc-load-all-files-for-promotion))) ; exits
685 ;; We don't have a live marker: scan and load files.
686 (reftex-toc-load-all-files-for-promotion)))
687 (level (cdr (assoc name reftex-section-levels-all)))
688 (dummy (if (not (integerp level))
689 (progn
690 (goto-char toc-point)
691 (error "Cannot %smote special sections" pro-or-de))))
692 ;; Delta is dynamically scoped into here...
693 (newlevel (if (>= level 0) (+ delta level) (- level delta)))
694 (dummy2 (if (or (and (>= level 0) (= newlevel -1))
695 (and (< level 0) (= newlevel 0)))
696 (error "Cannot %smote \\%s" pro-or-de name)))
697 (newname (reftex-toc-newhead-from-alist newlevel name
698 reftex-section-levels-all)))
699 (if (and name newname)
700 (list data name newname toc-point)
701 (goto-char toc-point)
702 (error "Cannot %smote \\%s" pro-or-de name))))
703
704(defun reftex-toc-promote-action (x)
705 "Change the level of a toc entry.
706DELTA and PRO-OR-DE are assumed to be dynamically scoped into this function."
707 (let* ((data (car x))
708 (name (nth 1 x))
709 (newname (nth 2 x))
710 (marker (nth 4 data)))
9a529312 711 (with-current-buffer (marker-buffer marker)
3666daf6
CD
712 (goto-char (marker-position marker))
713 (if (looking-at (concat "\\([ \t]*\\\\\\)" (regexp-quote name)))
714 (replace-match (concat "\\1" newname))
715 (error "Fatal error during %smotion" pro-or-de)))))
716
717(defun reftex-toc-extract-section-number (entry)
718 "Get the numbering of a toc entry, for message purposes."
719 (if (string-match "\\s-*\\(\\S-+\\)" (nth 2 (car entry)))
720 (match-string 1 (nth 2 (car entry)))
721 "?"))
722
723(defun reftex-toc-newhead-from-alist (nlevel head alist)
724 "Get new heading with level NLEVEL from ALIST.
725If there are no such entries, return nil.
726If there are several different entries with same new level, choose
727the one with the smallest distance to the assocation of HEAD in the alist.
728This makes it possible for promotion to work several sets of headings,
729if these sets are sorted blocks in the alist."
730 (let* ((al alist)
731 (ass (assoc head al))
732 (pos (length (memq ass al)))
733 dist (mindist 1000) newhead)
734 (while al
735 (if (equal (cdar al) nlevel)
736 (progn
737 (setq dist (abs (- (length al) pos)))
738 (if (< dist mindist)
739 (setq newhead (car (car al))
740 mindist dist))))
741 (setq al (cdr al)))
742 newhead))
743
744(defun reftex-toc-check-docstruct ()
745 "Check if the current docstruct is fully up to date and all files visited."
746 ;; We do this by checking if all sections are on the right position
747 (let ((docstruct (symbol-value reftex-docstruct-symbol))
748 entry marker empoint)
749 (catch 'exit
750 (while (setq entry (pop docstruct))
751 (if (eq (car entry) 'toc)
752 (progn
753 (setq marker (nth 4 entry)
754 empoint (nth 8 entry))
755 (if (not (and (markerp marker)
756 (marker-buffer marker)
757 (= (marker-position marker) empoint)))
758 (throw 'exit nil)))))
759 t)))
760
761(defun reftex-toc-load-all-files-for-promotion ()
762 "Make sure all files of the document are being visited by buffers,
763and that the scanning info is absolutely up to date.
764We do this by rescanning with reftex-keep-temporary-buffers bound to t.
42187e99 765The variable PRO-OR-DE is assumed to be dynamically scoped into this function.
3666daf6
CD
766When finished, we exit with an error message."
767 (let ((reftex-keep-temporary-buffers t))
768 (reftex-toc-Rescan)
769 (reftex-toc-restore-region start-line mark-line)
770 (throw 'exit
42187e99 771 "TOC had to be updated first. Please check selection and repeat the command.")))
3666daf6
CD
772
773(defun reftex-toc-rename-label ()
774 "Rename the currently selected label in the *TOC* buffer.
775This launches a global search and replace in order to rename a label.
776Renaming a label is hardly ever necessary - the only exeption is after
777promotion/demotion in connection with a package like fancyref, where the
778label prefix determines the wording of a reference."
779 (interactive)
780 (let* ((toc (get-text-property (point) :data))
781 (label (car toc)) newlabel)
782 (if (not (stringp label))
5a0c3f56 783 (error "This is not a label entry"))
3666daf6
CD
784 (setq newlabel (read-string (format "Rename label \"%s\" to:" label)))
785 (if (assoc newlabel (symbol-value reftex-docstruct-symbol))
e6ce8c42 786 (if (not (y-or-n-p
3666daf6
CD
787 (format "Label '%s' exists. Use anyway? " label)))
788 (error "Abort")))
789 (save-excursion
790 (save-window-excursion
791 (reftex-toc-visit-location t)
792 (condition-case nil
793 (reftex-query-replace-document
794 (concat "{" (regexp-quote label) "}")
795 (format "{%s}" newlabel))
e6ce8c42 796 (error t))))
3666daf6
CD
797 (reftex-toc-rescan)))
798
799
1a9461d0
CD
800(defun reftex-toc-visit-location (&optional final no-revisit)
801 ;; Visit the tex file corresponding to the toc entry on the current line.
802 ;; If FINAL is t, stay there
803 ;; If FINAL is 'hide, hide the *toc* window.
804 ;; Otherwise, move cursor back into *toc* window.
4a9699d8 805 ;; NO-REVISIT means don't visit files, just use live buffers.
1a9461d0
CD
806 ;; This function is pretty clever about finding back a section heading,
807 ;; even if the buffer is not live, or things like outline, x-symbol etc.
808 ;; have been active.
809
810 (let* ((toc (get-text-property (point) :data))
811 (toc-window (selected-window))
812 show-window show-buffer match)
813
814 (unless toc (error "Don't know which toc line to visit"))
e6ce8c42 815
1a9461d0 816 (cond
e6ce8c42 817
1a9461d0
CD
818 ((eq (car toc) 'toc)
819 ;; a toc entry
820 (setq match (reftex-toc-find-section toc no-revisit)))
821
822 ((eq (car toc) 'index)
823 ;; an index entry
824 (setq match (reftex-index-show-entry toc no-revisit)))
825
826 ((memq (car toc) '(bof eof))
827 ;; A file entry
828 (setq match
3666daf6
CD
829 (let ((where (car toc))
830 (file (nth 1 toc)))
831 (if (or (not no-revisit) (reftex-get-buffer-visiting file))
832 (progn
e6ce8c42 833 (switch-to-buffer-other-window
3666daf6
CD
834 (reftex-get-file-buffer-force file nil))
835 (goto-char (if (eq where 'bof) (point-min) (point-max))))
274f1353 836 (message "%s" reftex-no-follow-message) nil))))
1a9461d0
CD
837
838 ((stringp (car toc))
839 ;; a label
840 (setq match (reftex-show-label-location toc reftex-callback-fwd
3666daf6 841 no-revisit t))))
1a9461d0
CD
842
843 (setq show-window (selected-window)
844 show-buffer (current-buffer))
845
846 (unless match
847 (select-window toc-window)
848 (error "Cannot find location"))
849
850 (select-window toc-window)
851
852 ;; use the `final' parameter to decide what to do next
853 (cond
854 ((eq final t)
855 (reftex-unhighlight 0)
856 (select-window show-window))
857 ((eq final 'hide)
858 (reftex-unhighlight 0)
859 (or (one-window-p) (delete-window))
4a9699d8
SM
860 ;; If `show-window' is still live, show-buffer is already visible
861 ;; so let's not make it visible in yet-another-window.
862 (if (window-live-p show-window)
3666daf6 863 (set-buffer show-buffer)
4a9699d8 864 (switch-to-buffer show-buffer))
1a9461d0
CD
865 (reftex-re-enlarge))
866 (t nil))))
867
868(defun reftex-toc-find-section (toc &optional no-revisit)
869 (let* ((file (nth 3 toc))
3666daf6
CD
870 (marker (nth 4 toc))
871 (level (nth 5 toc))
872 (literal (nth 7 toc))
873 (emergency-point (nth 8 toc))
874 (match
875 (cond
876 ((and (markerp marker) (marker-buffer marker))
877 ;; Buffer is still live and we have the marker. Should be easy.
878 (switch-to-buffer-other-window (marker-buffer marker))
f3c18bd0 879 (push-mark nil)
3666daf6
CD
880 (goto-char (marker-position marker))
881 (or (looking-at (regexp-quote literal))
882 (looking-at (reftex-make-regexp-allow-for-ctrl-m literal))
883 (looking-at (reftex-make-desperate-section-regexp literal))
884 (looking-at (concat "\\\\"
885 (regexp-quote
e6ce8c42
GM
886 (car
887 (rassq level
3666daf6
CD
888 reftex-section-levels-all)))
889 "[[{]?"))))
890 ((or (not no-revisit)
891 (reftex-get-buffer-visiting file))
892 ;; Marker is lost. Use the backup method.
893 (switch-to-buffer-other-window
894 (reftex-get-file-buffer-force file nil))
895 (goto-char (or emergency-point (point-min)))
896 (or (looking-at (regexp-quote literal))
897 (let ((len (length literal)))
898 (or (reftex-nearest-match (regexp-quote literal) len)
899 (reftex-nearest-match
900 (reftex-make-regexp-allow-for-ctrl-m literal) len)
901 (reftex-nearest-match
902 (reftex-make-desperate-section-regexp literal) len)))))
274f1353 903 (t (message "%s" reftex-no-follow-message) nil))))
1a9461d0
CD
904 (when match
905 (goto-char (match-beginning 0))
906 (if (not (= (point) (point-max))) (recenter 1))
907 (reftex-highlight 0 (match-beginning 0) (match-end 0) (current-buffer)))
908 match))
909
910(defun reftex-make-desperate-section-regexp (old)
911 ;; Return a regexp which will still match a section statement even if
912 ;; x-symbol or isotex or the like have been at work in the mean time.
913 (let* ((n (1+ (string-match "[[{]" old)))
914 (new (regexp-quote (substring old 0 (1+ (string-match "[[{]" old)))))
915 (old (substring old n)))
916 (while (string-match
917 "\\([\r\n]\\)\\|\\(\\`\\|[ \t\n\r]\\)\\([a-zA-Z0-9]+\\)\\([ \t\n\r]\\|}\\'\\)"
918 old)
919 (if (match-beginning 1)
920 (setq new (concat new "[^\n\r]*[\n\r]"))
921 (setq new (concat new "[^\n\r]*" (match-string 3 old))))
922 (setq old (substring old (match-end 0))))
923 new))
924
3666daf6 925;; Auto recentering of TOC window
3b919c9f
CD
926
927(defun reftex-recenter-toc-when-idle ()
928 (and (> (buffer-size) 5)
929 reftex-mode
930 (not (active-minibuffer-window))
931 (fboundp 'reftex-toc-mode)
3666daf6 932 (get-buffer-window "*toc*" 'visible)
3b919c9f 933 (string= reftex-last-toc-master (reftex-TeX-master-file))
3666daf6
CD
934 (let (current-prefix-arg)
935 (reftex-toc-recenter))))
3b919c9f
CD
936
937(defun reftex-toggle-auto-toc-recenter ()
938 "Toggle the automatic recentering of the toc window.
939When active, leaving point idle will make the toc window jump to the correct
940section."
941 (interactive)
942 (if reftex-toc-auto-recenter-timer
943 (progn
3666daf6
CD
944 (if (featurep 'xemacs)
945 (delete-itimer reftex-toc-auto-recenter-timer)
946 (cancel-timer reftex-toc-auto-recenter-timer))
947 (setq reftex-toc-auto-recenter-timer nil)
948 (message "Automatic recentering of toc windwo was turned off"))
3b919c9f 949 (setq reftex-toc-auto-recenter-timer
3666daf6
CD
950 (if (featurep 'xemacs)
951 (start-itimer "RefTeX Idle Timer for recenter"
952 'reftex-recenter-toc-when-idle
953 reftex-idle-time reftex-idle-time t)
954 (run-with-idle-timer
955 reftex-idle-time t 'reftex-recenter-toc-when-idle)))
3b919c9f
CD
956 (message "Automatic recentering of toc window was turned on")))
957
3666daf6
CD
958(defun reftex-toc-toggle-dedicated-frame ()
959 "Toggle the display of a separate frame for the TOC.
960This frame is not used by the `reftex-toc' commands, but it is useful to
961always show the current section in connection with the option
962`reftex-auto-recenter-toc'."
963 (interactive)
964 (catch 'exit
965 (let* ((frames (frame-list)) frame
966 (get-frame-prop-func (if (fboundp 'frame-property)
967 'frame-property
968 'frame-parameter)))
969 (while (setq frame (pop frames))
970 (if (equal (funcall get-frame-prop-func frame 'name)
971 "RefTeX TOC Frame")
972 (progn
973 (delete-frame frame)
974 (throw 'exit nil))))
975 (reftex-make-separate-toc-frame))))
976
977(defun reftex-make-separate-toc-frame ()
978 ;; Create a new fame showing only the toc buffer.
979 (let ((current-frame (selected-frame))
980 (current-window (selected-window))
981 (current-toc-window (get-buffer-window "*toc*" 'visible))
982 current-toc-frame)
983 (if (and current-toc-window
984 (not (equal (selected-frame) (window-frame current-toc-window))))
985 nil
986 (setq current-toc-frame
987 (make-frame
988 '((name . "RefTeX TOC Frame")
989 (height . 20) (width . 60)
990 (unsplittable . t)
991 (minibuffer . nil)
992 (default-toolbar-visible-p . nil)
993 (menubar-visible-p . nil)
994 (horizontal-scrollbar-visible-p . nil))))
995 (select-frame current-toc-frame)
996 (switch-to-buffer "*toc*")
997 (select-frame current-frame)
df17e41e
GM
998 (cond ((fboundp 'x-focus-frame)
999 (x-focus-frame current-frame))
1000 ((and (featurep 'xemacs) ; `focus-frame' is a nop in Emacs.
1001 (fboundp 'focus-frame))
1002 (focus-frame current-frame)))
3666daf6
CD
1003 (select-window current-window)
1004 (when (eq reftex-auto-recenter-toc 'frame)
1005 (unless reftex-toc-auto-recenter-timer
1006 (reftex-toggle-auto-toc-recenter))
1007 (add-hook 'delete-frame-hook 'reftex-toc-delete-frame-hook)))))
1008
1009(defun reftex-toc-delete-frame-hook (frame)
1010 (if (and reftex-toc-auto-recenter-timer
1011 (reftex-toc-dframe-p frame))
1012 (progn
1013 (reftex-toggle-auto-toc-recenter))))
3b919c9f 1014
1a9461d0
CD
1015;; Table of Contents map
1016(define-key reftex-toc-map (if (featurep 'xemacs) [(button2)] [(mouse-2)])
1017 'reftex-toc-mouse-goto-line-and-hide)
f620c6bd 1018(define-key reftex-toc-map [follow-link] 'mouse-face)
1a9461d0
CD
1019
1020(substitute-key-definition
1021 'next-line 'reftex-toc-next reftex-toc-map global-map)
1022(substitute-key-definition
1023 'previous-line 'reftex-toc-previous reftex-toc-map global-map)
1024
1025(loop for x in
3666daf6
CD
1026 '(("n" . reftex-toc-next)
1027 ("p" . reftex-toc-previous)
1028 ("?" . reftex-toc-show-help)
1029 (" " . reftex-toc-view-line)
1030 ("\C-m" . reftex-toc-goto-line-and-hide)
1031 ("\C-i" . reftex-toc-goto-line)
1032 ("\C-c>" . reftex-toc-display-index)
1033 ("r" . reftex-toc-rescan)
1034 ("R" . reftex-toc-Rescan)
1035 ("g" . revert-buffer)
1036 ("q" . reftex-toc-quit);
1037 ("k" . reftex-toc-quit-and-kill)
1038 ("f" . reftex-toc-toggle-follow);
1039 ("a" . reftex-toggle-auto-toc-recenter)
1040 ("d" . reftex-toc-toggle-dedicated-frame)
1041 ("F" . reftex-toc-toggle-file-boundary)
1042 ("i" . reftex-toc-toggle-index)
1043 ("l" . reftex-toc-toggle-labels)
1044 ("t" . reftex-toc-max-level)
1045 ("c" . reftex-toc-toggle-context)
1046; ("%" . reftex-toc-toggle-commented)
1047 ("\M-%" . reftex-toc-rename-label)
1048 ("x" . reftex-toc-external)
1049 ("z" . reftex-toc-jump)
1050 ("." . reftex-toc-show-calling-point)
1051 ("\C-c\C-n" . reftex-toc-next-heading)
1052 ("\C-c\C-p" . reftex-toc-previous-heading)
1053 (">" . reftex-toc-demote)
1054 ("<" . reftex-toc-promote))
1a9461d0
CD
1055 do (define-key reftex-toc-map (car x) (cdr x)))
1056
1057(loop for key across "0123456789" do
1058 (define-key reftex-toc-map (vector (list key)) 'digit-argument))
1059(define-key reftex-toc-map "-" 'negative-argument)
1060
e6ce8c42 1061(easy-menu-define
1a9461d0
CD
1062 reftex-toc-menu reftex-toc-map
1063 "Menu for Table of Contents buffer"
1064 '("TOC"
1065 ["Show Location" reftex-toc-view-line t]
1066 ["Go To Location" reftex-toc-goto-line t]
1067 ["Exit & Go To Location" reftex-toc-goto-line-and-hide t]
3666daf6 1068 ["Show Calling Point" reftex-toc-show-calling-point t]
1a9461d0
CD
1069 ["Quit" reftex-toc-quit t]
1070 "--"
3666daf6
CD
1071 ("Edit"
1072 ["Promote" reftex-toc-promote t]
1073 ["Demote" reftex-toc-demote t]
1074 ["Rename Label" reftex-toc-rename-label t])
1075 "--"
1076 ["Index" reftex-toc-display-index t]
1a9461d0
CD
1077 ["External Document TOC " reftex-toc-external t]
1078 "--"
1079 ("Update"
11b4a0d2 1080 ["Rebuilt *toc* Buffer" revert-buffer t]
1a9461d0
CD
1081 ["Rescan One File" reftex-toc-rescan reftex-enable-partial-scans]
1082 ["Rescan Entire Document" reftex-toc-Rescan t])
1083 ("Options"
1084 "TOC Items"
1085 ["File Boundaries" reftex-toc-toggle-file-boundary :style toggle
1086 :selected reftex-toc-include-file-boundaries]
1087 ["Labels" reftex-toc-toggle-labels :style toggle
1088 :selected reftex-toc-include-labels]
1089 ["Index Entries" reftex-toc-toggle-index :style toggle
1090 :selected reftex-toc-include-index-entries]
1091 ["Context" reftex-toc-toggle-context :style toggle
1092 :selected reftex-toc-include-context]
1093 "--"
e6ce8c42 1094 ["Follow Mode" reftex-toc-toggle-follow :style toggle
3666daf6
CD
1095 :selected reftex-toc-follow-mode]
1096 ["Auto Recenter" reftex-toggle-auto-toc-recenter :style toggle
1097 :selected reftex-toc-auto-recenter-timer]
1098 ["Dedicated Frame" reftex-toc-toggle-dedicated-frame t])
1a9461d0
CD
1099 "--"
1100 ["Help" reftex-toc-show-help t]))
1101
1102
cbee283d 1103;; arch-tag: 92400ce2-0b86-4c89-a606-4ed71acea17e
f3c18bd0 1104;;; reftex-toc.el ends here