1 |
;;; reftex-toc.el --- RefTeX's table of contents mode |
;;; reftex-toc.el --- RefTeX's table of contents mode |
2 |
;; Copyright (c) 1997, 1998, 1999, 2000 Free Software Foundation, Inc. |
;; Copyright (c) 1997, 1998, 1999, 2000 Free Software Foundation, Inc. |
3 |
|
|
4 |
;; Author: Carsten Dominik <dominik@strw.LeidenUniv.nl> |
;; Author: Carsten Dominik <dominik@science.uva.nl> |
5 |
;; Version: 4.16 |
;; Version: 4.18 |
6 |
|
|
7 |
;; This file is part of GNU Emacs. |
;; This file is part of GNU Emacs. |
8 |
|
|
62 |
" T<" 'reftex-toc-max-level-indicator ">" |
" T<" 'reftex-toc-max-level-indicator ">" |
63 |
" -%-")) |
" -%-")) |
64 |
(setq truncate-lines t) |
(setq truncate-lines t) |
65 |
|
(when (featurep 'xemacs) |
66 |
|
;; XEmacs needs the call to make-local-hook |
67 |
|
(make-local-hook 'post-command-hook) |
68 |
|
(make-local-hook 'pre-command-hook)) |
69 |
(make-local-variable 'reftex-last-follow-point) |
(make-local-variable 'reftex-last-follow-point) |
70 |
(add-hook 'post-command-hook 'reftex-toc-post-command-hook nil t) |
(add-hook 'post-command-hook 'reftex-toc-post-command-hook nil t) |
71 |
(add-hook 'pre-command-hook 'reftex-toc-pre-command-hook nil t) |
(add-hook 'pre-command-hook 'reftex-toc-pre-command-hook nil t) |
76 |
"Stores the file name from which `reftex-toc' was called. For redo command.") |
"Stores the file name from which `reftex-toc' was called. For redo command.") |
77 |
|
|
78 |
(defvar reftex-last-window-height nil) |
(defvar reftex-last-window-height nil) |
79 |
|
(defvar reftex-last-window-width nil) |
80 |
(defvar reftex-toc-include-labels-indicator nil) |
(defvar reftex-toc-include-labels-indicator nil) |
81 |
(defvar reftex-toc-include-index-indicator nil) |
(defvar reftex-toc-include-index-indicator nil) |
82 |
(defvar reftex-toc-max-level-indicator nil) |
(defvar reftex-toc-max-level-indicator nil) |
95 |
q / k Hide/Kill *toc* buffer, return to position of reftex-toc command. |
q / k Hide/Kill *toc* buffer, return to position of reftex-toc command. |
96 |
l i c F Toggle display of [l]abels, [i]ndex, [c]ontext, [F]ile borders. |
l i c F Toggle display of [l]abels, [i]ndex, [c]ontext, [F]ile borders. |
97 |
t Change maximum toc depth (e.g. `3 t' hides levels greater than 3). |
t Change maximum toc depth (e.g. `3 t' hides levels greater than 3). |
98 |
f / g Toggle follow mode on and off / Refresh *toc* buffer. |
f / a / g Toggle follow mode / toggle auto recenter / Refresh *toc* buffer. |
99 |
r / C-u r Reparse the LaTeX document / Reparse entire LaTeX document. |
r / C-u r Reparse the LaTeX document / Reparse entire LaTeX document. |
100 |
. In other window, show position from where `reftex-toc' was called. |
. In other window, show position from where `reftex-toc' was called. |
101 |
x Switch to TOC of external document (with LaTeX package `xr'). |
x Switch to TOC of external document (with LaTeX package `xr'). |
132 |
(docstruct-symbol reftex-docstruct-symbol) |
(docstruct-symbol reftex-docstruct-symbol) |
133 |
(xr-data (assq 'xr (symbol-value reftex-docstruct-symbol))) |
(xr-data (assq 'xr (symbol-value reftex-docstruct-symbol))) |
134 |
(xr-alist (cons (cons "" (buffer-file-name)) (nth 1 xr-data))) |
(xr-alist (cons (cons "" (buffer-file-name)) (nth 1 xr-data))) |
135 |
(here-I-am (if rebuild |
(here-I-am (if (boundp 'reftex-rebuilding-toc) |
136 |
(get 'reftex-toc :reftex-data) |
(get 'reftex-toc :reftex-data) |
137 |
(car (reftex-where-am-I)))) |
(car (reftex-where-am-I)))) |
138 |
offset) |
offset) |
142 |
(when (or (not reftex-toc-keep-other-windows) |
(when (or (not reftex-toc-keep-other-windows) |
143 |
(< (window-height) (* 2 window-min-height))) |
(< (window-height) (* 2 window-min-height))) |
144 |
(delete-other-windows)) |
(delete-other-windows)) |
145 |
(setq reftex-last-window-height (window-height)) ; remember |
|
146 |
(split-window) |
(setq reftex-last-window-width (window-width) |
147 |
|
reftex-last-window-height (window-height)) ; remember |
148 |
|
(if reftex-toc-split-windows-horizontally |
149 |
|
(split-window-horizontally |
150 |
|
(floor (* (frame-width) reftex-toc-split-windows-horizontally-fraction))) |
151 |
|
(split-window)) |
152 |
|
|
153 |
(let ((default-major-mode 'reftex-toc-mode)) |
(let ((default-major-mode 'reftex-toc-mode)) |
154 |
(switch-to-buffer "*toc*"))) |
(switch-to-buffer "*toc*"))) |
155 |
|
|
191 |
reftex-toc-include-context |
reftex-toc-include-context |
192 |
nil ; counter |
nil ; counter |
193 |
nil ; commented |
nil ; commented |
194 |
here-I-am |
here-I-am |
195 |
"" ; xr-prefix |
"" ; xr-prefix |
196 |
t ; a toc buffer |
t ; a toc buffer |
197 |
)) |
)) |
198 |
|
|
199 |
(run-hooks 'reftex-display-copied-context-hook) |
(run-hooks 'reftex-display-copied-context-hook) |
200 |
(message "Building *toc* buffer...done.") |
(message "Building *toc* buffer...done.") |
201 |
(setq buffer-read-only t)) |
(setq buffer-read-only t)) |
207 |
t |
t |
208 |
reftex-toc-include-index-entries |
reftex-toc-include-index-entries |
209 |
reftex-toc-include-file-boundaries) |
reftex-toc-include-file-boundaries) |
210 |
(reftex-last-assoc-before-elt |
(reftex-last-assoc-before-elt |
211 |
'toc here-I-am |
'toc here-I-am |
212 |
(symbol-value reftex-docstruct-symbol)))) |
(symbol-value reftex-docstruct-symbol)))) |
213 |
(put 'reftex-toc :reftex-line 3) |
(put 'reftex-toc :reftex-line 3) |
218 |
(reftex-find-start-point (point) offset (get 'reftex-toc :reftex-line)) |
(reftex-find-start-point (point) offset (get 'reftex-toc :reftex-line)) |
219 |
(setq reftex-last-follow-point (point)))) |
(setq reftex-last-follow-point (point)))) |
220 |
|
|
221 |
|
(defun reftex-toc-recenter (&optional arg) |
222 |
|
"Display the TOC window and highlight line corresponding to current position." |
223 |
|
(interactive "P") |
224 |
|
(let ((buf (current-buffer))) |
225 |
|
(reftex-toc arg) |
226 |
|
(if (= (count-lines 1 (point)) 2) |
227 |
|
(let ((current-prefix-arg nil)) |
228 |
|
(select-window (get-buffer-window buf)) |
229 |
|
(reftex-toc nil))) |
230 |
|
(and (> (point) 1) |
231 |
|
(not (get-text-property (point) 'intangible)) |
232 |
|
(memq reftex-highlight-selection '(cursor both)) |
233 |
|
(reftex-highlight 2 |
234 |
|
(or (previous-single-property-change |
235 |
|
(min (point-max) (1+ (point))) :data) |
236 |
|
(point-min)) |
237 |
|
(or (next-single-property-change (point) :data) |
238 |
|
(point-max)))) |
239 |
|
(select-window (get-buffer-window buf)))) |
240 |
|
|
241 |
(defun reftex-toc-pre-command-hook () |
(defun reftex-toc-pre-command-hook () |
242 |
;; used as pre command hook in *toc* buffer |
;; used as pre command hook in *toc* buffer |
243 |
(reftex-unhighlight 0) |
(reftex-unhighlight 0) |
244 |
(reftex-unhighlight 1)) |
;; (reftex-unhighlight 1) ;; remove highlight on leaving buffer. |
245 |
|
) |
246 |
|
|
247 |
(defun reftex-toc-post-command-hook () |
(defun reftex-toc-post-command-hook () |
248 |
;; used in the post-command-hook for the *toc* buffer |
;; used in the post-command-hook for the *toc* buffer |
251 |
(and (> (point) 1) |
(and (> (point) 1) |
252 |
(not (get-text-property (point) 'intangible)) |
(not (get-text-property (point) 'intangible)) |
253 |
(memq reftex-highlight-selection '(cursor both)) |
(memq reftex-highlight-selection '(cursor both)) |
254 |
(reftex-highlight 1 |
(reftex-highlight 2 |
255 |
(or (previous-single-property-change (1+ (point)) :data) |
(or (previous-single-property-change (1+ (point)) :data) |
256 |
(point-min)) |
(point-min)) |
257 |
(or (next-single-property-change (point) :data) |
(or (next-single-property-change (point) :data) |
269 |
|
|
270 |
(defun reftex-re-enlarge () |
(defun reftex-re-enlarge () |
271 |
;; Enlarge windiw to a remembered size |
;; Enlarge windiw to a remembered size |
272 |
(enlarge-window |
(if reftex-toc-split-windows-horizontally |
273 |
(max 0 (- (or reftex-last-window-height (window-height)) |
(enlarge-window-horizontally |
274 |
(window-height))))) |
(max 0 (- (or reftex-last-window-width (window-width)) |
275 |
|
(window-width)))) |
276 |
|
(enlarge-window |
277 |
|
(max 0 (- (or reftex-last-window-height (window-height)) |
278 |
|
(window-height)))))) |
279 |
|
|
280 |
(defun reftex-toc-show-help () |
(defun reftex-toc-show-help () |
281 |
"Show a summary of special key bindings." |
"Show a summary of special key bindings." |
292 |
(interactive "p") |
(interactive "p") |
293 |
(setq reftex-callback-fwd t) |
(setq reftex-callback-fwd t) |
294 |
(or (eobp) (forward-char 1)) |
(or (eobp) (forward-char 1)) |
295 |
(goto-char (or (next-single-property-change (point) :data) |
(goto-char (or (next-single-property-change (point) :data) |
296 |
(point)))) |
(point)))) |
297 |
(defun reftex-toc-previous (&optional arg) |
(defun reftex-toc-previous (&optional arg) |
298 |
"Move to previous selectable item." |
"Move to previous selectable item." |
326 |
With prefix ARG, prompt for a label type and include only labels of |
With prefix ARG, prompt for a label type and include only labels of |
327 |
that specific type." |
that specific type." |
328 |
(interactive "P") |
(interactive "P") |
329 |
(setq reftex-toc-include-labels |
(setq reftex-toc-include-labels |
330 |
(if arg (reftex-query-label-type) |
(if arg (reftex-query-label-type) |
331 |
(not reftex-toc-include-labels))) |
(not reftex-toc-include-labels))) |
332 |
(reftex-toc-revert)) |
(reftex-toc-revert)) |
416 |
(defun reftex-toc-rescan (&rest ignore) |
(defun reftex-toc-rescan (&rest ignore) |
417 |
"Regenerate the *toc* buffer by reparsing file of section at point." |
"Regenerate the *toc* buffer by reparsing file of section at point." |
418 |
(interactive) |
(interactive) |
419 |
(if (and reftex-enable-partial-scans |
(if (and reftex-enable-partial-scans |
420 |
(null current-prefix-arg)) |
(null current-prefix-arg)) |
421 |
(let* ((data (get-text-property (point) :data)) |
(let* ((data (get-text-property (point) :data)) |
422 |
(what (car data)) |
(what (car data)) |
431 |
(switch-to-buffer-other-window |
(switch-to-buffer-other-window |
432 |
(reftex-get-file-buffer-force file)) |
(reftex-get-file-buffer-force file)) |
433 |
(setq current-prefix-arg '(4)) |
(setq current-prefix-arg '(4)) |
434 |
(reftex-toc t))) |
(let ((reftex-rebuilding-toc t)) |
435 |
|
(reftex-toc)))) |
436 |
(reftex-toc-Rescan)) |
(reftex-toc-Rescan)) |
437 |
(reftex-kill-temporary-buffers)) |
(reftex-kill-temporary-buffers)) |
438 |
(defun reftex-toc-Rescan (&rest ignore) |
(defun reftex-toc-Rescan (&rest ignore) |
439 |
"Regenerate the *toc* buffer by reparsing the entire document." |
"Regenerate the *toc* buffer by reparsing the entire document." |
440 |
(interactive) |
(interactive) |
441 |
|
(let* ((line (+ (count-lines (point-min) (point)) (if (bolp) 1 0)))) |
442 |
|
(put 'reftex-toc :reftex-line line)) |
443 |
(switch-to-buffer-other-window |
(switch-to-buffer-other-window |
444 |
(reftex-get-file-buffer-force reftex-last-toc-file)) |
(reftex-get-file-buffer-force reftex-last-toc-file)) |
445 |
(setq current-prefix-arg '(16)) |
(setq current-prefix-arg '(16)) |
446 |
(reftex-toc t)) |
(let ((reftex-rebuilding-toc t)) |
447 |
|
(reftex-toc))) |
448 |
(defun reftex-toc-revert (&rest ignore) |
(defun reftex-toc-revert (&rest ignore) |
449 |
"Regenerate the *toc* from the internal lists." |
"Regenerate the *toc* from the internal lists." |
450 |
(interactive) |
(interactive) |
452 |
(reftex-get-file-buffer-force reftex-last-toc-file)) |
(reftex-get-file-buffer-force reftex-last-toc-file)) |
453 |
(reftex-erase-buffer "*toc*") |
(reftex-erase-buffer "*toc*") |
454 |
(setq current-prefix-arg nil) |
(setq current-prefix-arg nil) |
455 |
(reftex-toc t)) |
(let ((reftex-rebuilding-toc t)) |
456 |
|
(reftex-toc t))) |
457 |
(defun reftex-toc-external (&rest ignore) |
(defun reftex-toc-external (&rest ignore) |
458 |
"Switch to table of contents of an external document." |
"Switch to table of contents of an external document." |
459 |
(interactive) |
(interactive) |
494 |
show-window show-buffer match) |
show-window show-buffer match) |
495 |
|
|
496 |
(unless toc (error "Don't know which toc line to visit")) |
(unless toc (error "Don't know which toc line to visit")) |
497 |
|
|
498 |
(cond |
(cond |
499 |
|
|
500 |
((eq (car toc) 'toc) |
((eq (car toc) 'toc) |
501 |
;; a toc entry |
;; a toc entry |
502 |
(setq match (reftex-toc-find-section toc no-revisit))) |
(setq match (reftex-toc-find-section toc no-revisit))) |
512 |
(file (nth 1 toc))) |
(file (nth 1 toc))) |
513 |
(if (or (not no-revisit) (reftex-get-buffer-visiting file)) |
(if (or (not no-revisit) (reftex-get-buffer-visiting file)) |
514 |
(progn |
(progn |
515 |
(switch-to-buffer-other-window |
(switch-to-buffer-other-window |
516 |
(reftex-get-file-buffer-force file nil)) |
(reftex-get-file-buffer-force file nil)) |
517 |
(goto-char (if (eq where 'bof) (point-min) (point-max)))) |
(goto-char (if (eq where 'bof) (point-min) (point-max)))) |
518 |
(message reftex-no-follow-message) nil)))) |
(message reftex-no-follow-message) nil)))) |
560 |
(looking-at (reftex-make-desperate-section-regexp literal)) |
(looking-at (reftex-make-desperate-section-regexp literal)) |
561 |
(looking-at (concat "\\\\" |
(looking-at (concat "\\\\" |
562 |
(regexp-quote |
(regexp-quote |
563 |
(car |
(car |
564 |
(rassq level |
(rassq level |
565 |
reftex-section-levels-all))) |
reftex-section-levels-all))) |
566 |
"[[{]?")))) |
"[[{]?")))) |
567 |
((or (not no-revisit) |
((or (not no-revisit) |
599 |
(setq old (substring old (match-end 0)))) |
(setq old (substring old (match-end 0)))) |
600 |
new)) |
new)) |
601 |
|
|
602 |
|
|
603 |
|
(defun reftex-recenter-toc-when-idle () |
604 |
|
(and (> (buffer-size) 5) |
605 |
|
reftex-mode |
606 |
|
(not (active-minibuffer-window)) |
607 |
|
(fboundp 'reftex-toc-mode) |
608 |
|
(get-buffer-window "*toc*") |
609 |
|
(string= reftex-last-toc-master (reftex-TeX-master-file)) |
610 |
|
(reftex-toc-recenter))) |
611 |
|
|
612 |
|
(defun reftex-toggle-auto-toc-recenter () |
613 |
|
"Toggle the automatic recentering of the toc window. |
614 |
|
When active, leaving point idle will make the toc window jump to the correct |
615 |
|
section." |
616 |
|
(interactive) |
617 |
|
(if reftex-toc-auto-recenter-timer |
618 |
|
(progn |
619 |
|
(if (featurep 'xemacs) |
620 |
|
(delete-itimer reftex-toc-auto-recenter-timer) |
621 |
|
(cancel-timer reftex-toc-auto-recenter-timer)) |
622 |
|
(setq reftex-toc-auto-recenter-timer nil) |
623 |
|
(message "Automatic recentering of toc buffer was turned off")) |
624 |
|
(setq reftex-toc-auto-recenter-timer |
625 |
|
(if (featurep 'xemacs) |
626 |
|
(start-itimer "RefTeX Idle Timer for recenter" |
627 |
|
'reftex-recenter-toc-when-idle |
628 |
|
reftex-idle-time reftex-idle-time t) |
629 |
|
(run-with-idle-timer |
630 |
|
reftex-idle-time t 'reftex-recenter-toc-when-idle))) |
631 |
|
(message "Automatic recentering of toc window was turned on"))) |
632 |
|
|
633 |
|
|
634 |
;; Table of Contents map |
;; Table of Contents map |
635 |
(define-key reftex-toc-map (if (featurep 'xemacs) [(button2)] [(mouse-2)]) |
(define-key reftex-toc-map (if (featurep 'xemacs) [(button2)] [(mouse-2)]) |
636 |
'reftex-toc-mouse-goto-line-and-hide) |
'reftex-toc-mouse-goto-line-and-hide) |
654 |
("q" . reftex-toc-quit) |
("q" . reftex-toc-quit) |
655 |
("k" . reftex-toc-quit-and-kill) |
("k" . reftex-toc-quit-and-kill) |
656 |
("f" . reftex-toc-toggle-follow) |
("f" . reftex-toc-toggle-follow) |
657 |
|
("a" . reftex-toggle-auto-toc-recenter) |
658 |
("F" . reftex-toc-toggle-file-boundary) |
("F" . reftex-toc-toggle-file-boundary) |
659 |
("i" . reftex-toc-toggle-index) |
("i" . reftex-toc-toggle-index) |
660 |
("l" . reftex-toc-toggle-labels) |
("l" . reftex-toc-toggle-labels) |
672 |
(define-key reftex-toc-map (vector (list key)) 'digit-argument)) |
(define-key reftex-toc-map (vector (list key)) 'digit-argument)) |
673 |
(define-key reftex-toc-map "-" 'negative-argument) |
(define-key reftex-toc-map "-" 'negative-argument) |
674 |
|
|
675 |
(easy-menu-define |
(easy-menu-define |
676 |
reftex-toc-menu reftex-toc-map |
reftex-toc-menu reftex-toc-map |
677 |
"Menu for Table of Contents buffer" |
"Menu for Table of Contents buffer" |
678 |
'("TOC" |
'("TOC" |
699 |
["Context" reftex-toc-toggle-context :style toggle |
["Context" reftex-toc-toggle-context :style toggle |
700 |
:selected reftex-toc-include-context] |
:selected reftex-toc-include-context] |
701 |
"--" |
"--" |
702 |
["Follow Mode" reftex-toc-toggle-follow :style toggle |
["Follow Mode" reftex-toc-toggle-follow :style toggle |
703 |
:selected reftex-toc-follow-mode]) |
:selected reftex-toc-follow-mode]) |
704 |
"--" |
"--" |
705 |
["Help" reftex-toc-show-help t])) |
["Help" reftex-toc-show-help t])) |