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