annotate lisp/textmodes/reftex-toc.el @ 25285:b4f8e285c891

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