reftex-toc.el 44 KB

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