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