-;;; reftex-toc.el - RefTeX's table of contents mode
+;;; reftex-toc.el --- RefTeX's table of contents mode
;; Copyright (c) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
-;; Author: Carsten Dominik <dominik@strw.LeidenUniv.nl>
-;; Version: 4.14
-;;
+;; Author: Carsten Dominik <dominik@science.uva.nl>
+;; Version: 4.18
;; This file is part of GNU Emacs.
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
+;;; Commentary:
+
+;;; Code:
+
(eval-when-compile (require 'cl))
(provide 'reftex-toc)
(require 'reftex)
" T<" 'reftex-toc-max-level-indicator ">"
" -%-"))
(setq truncate-lines t)
- (make-local-hook 'post-command-hook)
- (make-local-hook 'pre-command-hook)
+ (when (featurep 'xemacs)
+ ;; XEmacs needs the call to make-local-hook
+ (make-local-hook 'post-command-hook)
+ (make-local-hook 'pre-command-hook))
(make-local-variable 'reftex-last-follow-point)
(add-hook 'post-command-hook 'reftex-toc-post-command-hook nil t)
(add-hook 'pre-command-hook 'reftex-toc-pre-command-hook nil t)
"Stores the file name from which `reftex-toc' was called. For redo command.")
(defvar reftex-last-window-height nil)
+(defvar reftex-last-window-width nil)
(defvar reftex-toc-include-labels-indicator nil)
(defvar reftex-toc-include-index-indicator nil)
(defvar reftex-toc-max-level-indicator nil)
q / k Hide/Kill *toc* buffer, return to position of reftex-toc command.
l i c F Toggle display of [l]abels, [i]ndex, [c]ontext, [F]ile borders.
t Change maximum toc depth (e.g. `3 t' hides levels greater than 3).
-f / g Toggle follow mode on and off / Refresh *toc* buffer.
+f / a / g Toggle follow mode / toggle auto recenter / Refresh *toc* buffer.
r / C-u r Reparse the LaTeX document / Reparse entire LaTeX document.
. In other window, show position from where `reftex-toc' was called.
-x Switch to TOC of external document (with LaTeX package `xr').")
+x Switch to TOC of external document (with LaTeX package `xr').
+z Jump to a specific section (e.g. '3 z' goes to section 3")
(defun reftex-toc (&optional rebuild)
"Show the table of contents for the current document.
(docstruct-symbol reftex-docstruct-symbol)
(xr-data (assq 'xr (symbol-value reftex-docstruct-symbol)))
(xr-alist (cons (cons "" (buffer-file-name)) (nth 1 xr-data)))
- (here-I-am (if rebuild
+ (here-I-am (if (boundp 'reftex-rebuilding-toc)
(get 'reftex-toc :reftex-data)
(car (reftex-where-am-I))))
offset)
(when (or (not reftex-toc-keep-other-windows)
(< (window-height) (* 2 window-min-height)))
(delete-other-windows))
- (setq reftex-last-window-height (window-height)) ; remember
- (split-window)
+
+ (setq reftex-last-window-width (window-width)
+ reftex-last-window-height (window-height)) ; remember
+ (if reftex-toc-split-windows-horizontally
+ (split-window-horizontally
+ (floor (* (frame-width) reftex-toc-split-windows-horizontally-fraction)))
+ (split-window))
+
(let ((default-major-mode 'reftex-toc-mode))
(switch-to-buffer "*toc*")))
(reftex-find-start-point (point) offset (get 'reftex-toc :reftex-line))
(setq reftex-last-follow-point (point))))
+(defun reftex-toc-recenter (&optional arg)
+ "Display the TOC window and highlight line corresponding to current position."
+ (interactive "P")
+ (let ((buf (current-buffer)))
+ (reftex-toc arg)
+ (if (= (count-lines 1 (point)) 2)
+ (let ((current-prefix-arg nil))
+ (select-window (get-buffer-window buf))
+ (reftex-toc nil)))
+ (and (> (point) 1)
+ (not (get-text-property (point) 'intangible))
+ (memq reftex-highlight-selection '(cursor both))
+ (reftex-highlight 2
+ (or (previous-single-property-change
+ (min (point-max) (1+ (point))) :data)
+ (point-min))
+ (or (next-single-property-change (point) :data)
+ (point-max))))
+ (select-window (get-buffer-window buf))))
+
(defun reftex-toc-pre-command-hook ()
;; used as pre command hook in *toc* buffer
(reftex-unhighlight 0)
- (reftex-unhighlight 1))
+;; (reftex-unhighlight 1) ;; remove highlight on leaving buffer.
+ )
(defun reftex-toc-post-command-hook ()
;; used in the post-command-hook for the *toc* buffer
(and (> (point) 1)
(not (get-text-property (point) 'intangible))
(memq reftex-highlight-selection '(cursor both))
- (reftex-highlight 1
+ (reftex-highlight 2
(or (previous-single-property-change (1+ (point)) :data)
(point-min))
(or (next-single-property-change (point) :data)
(defun reftex-re-enlarge ()
;; Enlarge windiw to a remembered size
- (enlarge-window
- (max 0 (- (or reftex-last-window-height (window-height))
- (window-height)))))
+ (if reftex-toc-split-windows-horizontally
+ (enlarge-window-horizontally
+ (max 0 (- (or reftex-last-window-width (window-width))
+ (window-width))))
+ (enlarge-window
+ (max 0 (- (or reftex-last-window-height (window-height))
+ (window-height))))))
(defun reftex-toc-show-help ()
"Show a summary of special key bindings."
(switch-to-buffer-other-window
(reftex-get-file-buffer-force file))
(setq current-prefix-arg '(4))
- (reftex-toc t)))
+ (let ((reftex-rebuilding-toc t))
+ (reftex-toc))))
(reftex-toc-Rescan))
(reftex-kill-temporary-buffers))
(defun reftex-toc-Rescan (&rest ignore)
"Regenerate the *toc* buffer by reparsing the entire document."
(interactive)
+ (let* ((line (+ (count-lines (point-min) (point)) (if (bolp) 1 0))))
+ (put 'reftex-toc :reftex-line line))
(switch-to-buffer-other-window
(reftex-get-file-buffer-force reftex-last-toc-file))
(setq current-prefix-arg '(16))
- (reftex-toc t))
+ (let ((reftex-rebuilding-toc t))
+ (reftex-toc)))
(defun reftex-toc-revert (&rest ignore)
"Regenerate the *toc* from the internal lists."
(interactive)
(reftex-get-file-buffer-force reftex-last-toc-file))
(reftex-erase-buffer "*toc*")
(setq current-prefix-arg nil)
- (reftex-toc t))
+ (let ((reftex-rebuilding-toc t))
+ (reftex-toc t)))
(defun reftex-toc-external (&rest ignore)
"Switch to table of contents of an external document."
(interactive)
(message "")
(message "Switched document"))))
+(defun reftex-toc-jump (arg)
+ "Jump to a specific section. E.g. '3 z' jumps to section 3.
+Useful for large TOC's."
+ (interactive "P")
+ (goto-char (point-min))
+ (re-search-forward
+ (concat "^ *" (number-to-string (if (numberp arg) arg 1)) " ")
+ nil t)
+ (beginning-of-line))
+
(defun reftex-toc-visit-location (&optional final no-revisit)
;; Visit the tex file corresponding to the toc entry on the current line.
;; If FINAL is t, stay there
(setq old (substring old (match-end 0))))
new))
+
+(defun reftex-recenter-toc-when-idle ()
+ (and (> (buffer-size) 5)
+ reftex-mode
+ (not (active-minibuffer-window))
+ (fboundp 'reftex-toc-mode)
+ (get-buffer-window "*toc*")
+ (string= reftex-last-toc-master (reftex-TeX-master-file))
+ (reftex-toc-recenter)))
+
+(defun reftex-toggle-auto-toc-recenter ()
+ "Toggle the automatic recentering of the toc window.
+When active, leaving point idle will make the toc window jump to the correct
+section."
+ (interactive)
+ (if reftex-toc-auto-recenter-timer
+ (progn
+ (if (featurep 'xemacs)
+ (delete-itimer reftex-toc-auto-recenter-timer)
+ (cancel-timer reftex-toc-auto-recenter-timer))
+ (setq reftex-toc-auto-recenter-timer nil)
+ (message "Automatic recentering of toc buffer was turned off"))
+ (setq reftex-toc-auto-recenter-timer
+ (if (featurep 'xemacs)
+ (start-itimer "RefTeX Idle Timer for recenter"
+ 'reftex-recenter-toc-when-idle
+ reftex-idle-time reftex-idle-time t)
+ (run-with-idle-timer
+ reftex-idle-time t 'reftex-recenter-toc-when-idle)))
+ (message "Automatic recentering of toc window was turned on")))
+
+
;; Table of Contents map
(define-key reftex-toc-map (if (featurep 'xemacs) [(button2)] [(mouse-2)])
'reftex-toc-mouse-goto-line-and-hide)
("q" . reftex-toc-quit)
("k" . reftex-toc-quit-and-kill)
("f" . reftex-toc-toggle-follow)
+ ("a" . reftex-toggle-auto-toc-recenter)
("F" . reftex-toc-toggle-file-boundary)
("i" . reftex-toc-toggle-index)
("l" . reftex-toc-toggle-labels)
("c" . reftex-toc-toggle-context)
("%" . reftex-toc-toggle-commented)
("x" . reftex-toc-external)
+ ("z" . reftex-toc-jump)
("." . reftex-toc-show-calling-point)
("\C-c\C-n" . reftex-toc-next-heading)
("\C-c\C-p" . reftex-toc-previous-heading))
["External Document TOC " reftex-toc-external t]
"--"
("Update"
- ["Rebuild *toc* Buffer" revert-buffer t]
+ ["Rebuilt *toc* Buffer" revert-buffer t]
["Rescan One File" reftex-toc-rescan reftex-enable-partial-scans]
["Rescan Entire Document" reftex-toc-Rescan t])
("Options"