
This reverts almost all my recent changes to use curved quotes in docstrings and/or strings used for error diagnostics. There are a few exceptions, e.g., Bahá’í proper names. * admin/unidata/unidata-gen.el (unidata-gen-table): * lisp/abbrev.el (expand-region-abbrevs): * lisp/align.el (align-region): * lisp/allout.el (allout-mode, allout-solicit-alternate-bullet) (outlineify-sticky): * lisp/apropos.el (apropos-library): * lisp/bookmark.el (bookmark-default-annotation-text): * lisp/button.el (button-category-symbol, button-put) (make-text-button): * lisp/calc/calc-aent.el (math-read-if, math-read-factor): * lisp/calc/calc-embed.el (calc-do-embedded): * lisp/calc/calc-ext.el (calc-user-function-list): * lisp/calc/calc-graph.el (calc-graph-show-dumb): * lisp/calc/calc-help.el (calc-describe-key) (calc-describe-thing, calc-full-help): * lisp/calc/calc-lang.el (calc-c-language) (math-parse-fortran-vector-end, math-parse-tex-sum) (math-parse-eqn-matrix, math-parse-eqn-prime) (calc-yacas-language, calc-maxima-language, calc-giac-language) (math-read-giac-subscr, math-read-math-subscr) (math-read-big-rec, math-read-big-balance): * lisp/calc/calc-misc.el (calc-help, report-calc-bug): * lisp/calc/calc-mode.el (calc-auto-why, calc-save-modes) (calc-auto-recompute): * lisp/calc/calc-prog.el (calc-fix-token-name) (calc-read-parse-table-part, calc-user-define-invocation) (math-do-arg-check): * lisp/calc/calc-store.el (calc-edit-variable): * lisp/calc/calc-units.el (math-build-units-table-buffer): * lisp/calc/calc-vec.el (math-read-brackets): * lisp/calc/calc-yank.el (calc-edit-mode): * lisp/calc/calc.el (calc, calc-do, calc-user-invocation): * lisp/calendar/appt.el (appt-display-message): * lisp/calendar/diary-lib.el (diary-check-diary-file) (diary-mail-entries, diary-from-outlook): * lisp/calendar/icalendar.el (icalendar-export-region) (icalendar--convert-float-to-ical) (icalendar--convert-date-to-ical) (icalendar--convert-ical-to-diary) (icalendar--convert-recurring-to-diary) (icalendar--add-diary-entry): * lisp/calendar/time-date.el (format-seconds): * lisp/calendar/timeclock.el (timeclock-mode-line-display) (timeclock-make-hours-explicit, timeclock-log-data): * lisp/calendar/todo-mode.el (todo-prefix, todo-delete-category) (todo-item-mark, todo-check-format) (todo-insert-item--next-param, todo-edit-item--next-key) (todo-mode): * lisp/cedet/ede/pmake.el (ede-proj-makefile-insert-dist-rules): * lisp/cedet/mode-local.el (describe-mode-local-overload) (mode-local-print-binding, mode-local-describe-bindings-2): * lisp/cedet/semantic/complete.el (semantic-displayor-show-request): * lisp/cedet/srecode/srt-mode.el (srecode-macro-help): * lisp/cus-start.el (standard): * lisp/cus-theme.el (describe-theme-1): * lisp/custom.el (custom-add-dependencies, custom-check-theme) (custom--sort-vars-1, load-theme): * lisp/descr-text.el (describe-text-properties-1, describe-char): * lisp/dired-x.el (dired-do-run-mail): * lisp/dired.el (dired-log): * lisp/emacs-lisp/advice.el (ad-read-advised-function) (ad-read-advice-class, ad-read-advice-name, ad-enable-advice) (ad-disable-advice, ad-remove-advice, ad-set-argument) (ad-set-arguments, ad--defalias-fset, ad-activate) (ad-deactivate): * lisp/emacs-lisp/byte-opt.el (byte-compile-inline-expand) (byte-compile-unfold-lambda, byte-optimize-form-code-walker) (byte-optimize-while, byte-optimize-apply): * lisp/emacs-lisp/byte-run.el (defun, defsubst): * lisp/emacs-lisp/bytecomp.el (byte-compile-lapcode) (byte-compile-log-file, byte-compile-format-warn) (byte-compile-nogroup-warn, byte-compile-arglist-warn) (byte-compile-cl-warn) (byte-compile-warn-about-unresolved-functions) (byte-compile-file, byte-compile--declare-var) (byte-compile-file-form-defmumble, byte-compile-form) (byte-compile-normal-call, byte-compile-check-variable) (byte-compile-variable-ref, byte-compile-variable-set) (byte-compile-subr-wrong-args, byte-compile-setq-default) (byte-compile-negation-optimizer) (byte-compile-condition-case--old) (byte-compile-condition-case--new, byte-compile-save-excursion) (byte-compile-defvar, byte-compile-autoload) (byte-compile-lambda-form) (byte-compile-make-variable-buffer-local, display-call-tree) (batch-byte-compile): * lisp/emacs-lisp/cconv.el (cconv-convert, cconv--analyze-use): * lisp/emacs-lisp/chart.el (chart-space-usage): * lisp/emacs-lisp/check-declare.el (check-declare-scan) (check-declare-warn, check-declare-file) (check-declare-directory): * lisp/emacs-lisp/checkdoc.el (checkdoc-this-string-valid-engine) (checkdoc-message-text-engine): * lisp/emacs-lisp/cl-extra.el (cl-parse-integer) (cl--describe-class): * lisp/emacs-lisp/cl-generic.el (cl-defgeneric) (cl--generic-describe, cl-generic-generalizers): * lisp/emacs-lisp/cl-macs.el (cl--parse-loop-clause, cl-tagbody) (cl-symbol-macrolet): * lisp/emacs-lisp/cl.el (cl-unload-function, flet): * lisp/emacs-lisp/copyright.el (copyright) (copyright-update-directory): * lisp/emacs-lisp/edebug.el (edebug-read-list): * lisp/emacs-lisp/eieio-base.el (eieio-persistent-read): * lisp/emacs-lisp/eieio-core.el (eieio--slot-override) (eieio-oref): * lisp/emacs-lisp/eieio-opt.el (eieio-help-constructor): * lisp/emacs-lisp/eieio-speedbar.el: (eieio-speedbar-child-make-tag-lines) (eieio-speedbar-child-description): * lisp/emacs-lisp/eieio.el (defclass, change-class): * lisp/emacs-lisp/elint.el (elint-file, elint-get-top-forms) (elint-init-form, elint-check-defalias-form) (elint-check-let-form): * lisp/emacs-lisp/ert.el (ert-get-test, ert-results-mode-menu) (ert-results-pop-to-backtrace-for-test-at-point) (ert-results-pop-to-messages-for-test-at-point) (ert-results-pop-to-should-forms-for-test-at-point) (ert-describe-test): * lisp/emacs-lisp/find-func.el (find-function-search-for-symbol) (find-function-library): * lisp/emacs-lisp/generator.el (iter-yield): * lisp/emacs-lisp/gv.el (gv-define-simple-setter): * lisp/emacs-lisp/lisp-mnt.el (lm-verify): * lisp/emacs-lisp/macroexp.el (macroexp--obsolete-warning): * lisp/emacs-lisp/map-ynp.el (map-y-or-n-p): * lisp/emacs-lisp/nadvice.el (advice--make-docstring) (advice--make, define-advice): * lisp/emacs-lisp/package-x.el (package-upload-file): * lisp/emacs-lisp/package.el (package-version-join) (package-disabled-p, package-activate-1, package-activate) (package--download-one-archive) (package--download-and-read-archives) (package-compute-transaction, package-install-from-archive) (package-install, package-install-selected-packages) (package-delete, package-autoremove, describe-package-1) (package-install-button-action, package-delete-button-action) (package-menu-hide-package, package-menu--list-to-prompt) (package-menu--perform-transaction) (package-menu--find-and-notify-upgrades): * lisp/emacs-lisp/pcase.el (pcase-exhaustive, pcase--u1): * lisp/emacs-lisp/re-builder.el (reb-enter-subexp-mode): * lisp/emacs-lisp/ring.el (ring-previous, ring-next): * lisp/emacs-lisp/rx.el (rx-check, rx-anything) (rx-check-any-string, rx-check-any, rx-check-not, rx-=) (rx-repeat, rx-check-backref, rx-syntax, rx-check-category) (rx-form): * lisp/emacs-lisp/smie.el (smie-config-save): * lisp/emacs-lisp/subr-x.el (internal--check-binding): * lisp/emacs-lisp/tabulated-list.el (tabulated-list-put-tag): * lisp/emacs-lisp/testcover.el (testcover-1value): * lisp/emacs-lisp/timer.el (timer-event-handler): * lisp/emulation/viper-cmd.el (viper-toggle-parse-sexp-ignore-comments) (viper-toggle-search-style, viper-kill-buffer) (viper-brac-function): * lisp/emulation/viper-macs.el (viper-record-kbd-macro): * lisp/env.el (setenv): * lisp/erc/erc-button.el (erc-nick-popup): * lisp/erc/erc.el (erc-cmd-LOAD, erc-handle-login, english): * lisp/eshell/em-dirs.el (eshell/cd): * lisp/eshell/em-glob.el (eshell-glob-regexp) (eshell-glob-entries): * lisp/eshell/em-pred.el (eshell-parse-modifiers): * lisp/eshell/esh-opt.el (eshell-show-usage): * lisp/facemenu.el (facemenu-add-new-face) (facemenu-add-new-color): * lisp/faces.el (read-face-name, read-face-font, describe-face) (x-resolve-font-name): * lisp/files-x.el (modify-file-local-variable): * lisp/files.el (locate-user-emacs-file, find-alternate-file) (set-auto-mode, hack-one-local-variable--obsolete) (dir-locals-set-directory-class, write-file, basic-save-buffer) (delete-directory, copy-directory, recover-session) (recover-session-finish, insert-directory) (file-modes-char-to-who, file-modes-symbolic-to-number) (move-file-to-trash): * lisp/filesets.el (filesets-add-buffer, filesets-remove-buffer): * lisp/find-cmd.el (find-generic, find-to-string): * lisp/finder.el (finder-commentary): * lisp/font-lock.el (font-lock-fontify-buffer): * lisp/format.el (format-write-file, format-find-file) (format-insert-file): * lisp/frame.el (get-device-terminal, select-frame-by-name): * lisp/fringe.el (fringe--check-style): * lisp/gnus/nnmairix.el (nnmairix-widget-create-query): * lisp/help-fns.el (help-fns--key-bindings) (help-fns--compiler-macro, help-fns--parent-mode) (help-fns--obsolete, help-fns--interactive-only) (describe-function-1, describe-variable): * lisp/help.el (describe-mode) (describe-minor-mode-from-indicator): * lisp/image.el (image-type): * lisp/international/ccl.el (ccl-dump): * lisp/international/fontset.el (x-must-resolve-font-name): * lisp/international/mule-cmds.el (prefer-coding-system) (select-safe-coding-system-interactively) (select-safe-coding-system, activate-input-method) (toggle-input-method, describe-current-input-method) (describe-language-environment): * lisp/international/mule-conf.el (code-offset): * lisp/international/mule-diag.el (describe-character-set) (list-input-methods-1): * lisp/mail/feedmail.el (feedmail-run-the-queue): * lisp/mouse.el (minor-mode-menu-from-indicator): * lisp/mpc.el (mpc-playlist-rename): * lisp/msb.el (msb--choose-menu): * lisp/net/ange-ftp.el (ange-ftp-shell-command): * lisp/net/imap.el (imap-interactive-login): * lisp/net/mairix.el (mairix-widget-create-query): * lisp/net/newst-backend.el (newsticker--sentinel-work): * lisp/net/newst-treeview.el (newsticker--treeview-load): * lisp/net/rlogin.el (rlogin): * lisp/obsolete/iswitchb.el (iswitchb-possible-new-buffer): * lisp/obsolete/otodo-mode.el (todo-more-important-p): * lisp/obsolete/pgg-gpg.el (pgg-gpg-process-region): * lisp/obsolete/pgg-pgp.el (pgg-pgp-process-region): * lisp/obsolete/pgg-pgp5.el (pgg-pgp5-process-region): * lisp/org/ob-core.el (org-babel-goto-named-src-block) (org-babel-goto-named-result): * lisp/org/ob-fortran.el (org-babel-fortran-ensure-main-wrap): * lisp/org/ob-ref.el (org-babel-ref-resolve): * lisp/org/org-agenda.el (org-agenda-prepare): * lisp/org/org-clock.el (org-clock-notify-once-if-expired) (org-clock-resolve): * lisp/org/org-ctags.el (org-ctags-ask-rebuild-tags-file-then-find-tag): * lisp/org/org-feed.el (org-feed-parse-atom-entry): * lisp/org/org-habit.el (org-habit-parse-todo): * lisp/org/org-mouse.el (org-mouse-popup-global-menu) (org-mouse-context-menu): * lisp/org/org-table.el (org-table-edit-formulas): * lisp/org/ox.el (org-export-async-start): * lisp/proced.el (proced-log): * lisp/progmodes/ada-mode.el (ada-get-indent-case) (ada-check-matching-start, ada-goto-matching-start): * lisp/progmodes/ada-prj.el (ada-prj-display-page): * lisp/progmodes/ada-xref.el (ada-find-executable): * lisp/progmodes/ebrowse.el (ebrowse-tags-apropos): * lisp/progmodes/etags.el (etags-tags-apropos-additional): * lisp/progmodes/flymake.el (flymake-parse-err-lines) (flymake-start-syntax-check-process): * lisp/progmodes/python.el (python-shell-get-process-or-error) (python-define-auxiliary-skeleton): * lisp/progmodes/sql.el (sql-comint): * lisp/progmodes/verilog-mode.el (verilog-load-file-at-point): * lisp/progmodes/vhdl-mode.el (vhdl-widget-directory-validate): * lisp/recentf.el (recentf-open-files): * lisp/replace.el (query-replace-read-from) (occur-after-change-function, occur-1): * lisp/scroll-bar.el (scroll-bar-columns): * lisp/server.el (server-get-auth-key): * lisp/simple.el (execute-extended-command) (undo-outer-limit-truncate, list-processes--refresh) (compose-mail, set-variable, choose-completion-string) (define-alternatives): * lisp/startup.el (site-run-file, tty-handle-args, command-line) (command-line-1): * lisp/subr.el (noreturn, define-error, add-to-list) (read-char-choice, version-to-list): * lisp/term/common-win.el (x-handle-xrm-switch) (x-handle-name-switch, x-handle-args): * lisp/term/x-win.el (x-handle-parent-id, x-handle-smid): * lisp/textmodes/reftex-ref.el (reftex-label): * lisp/textmodes/reftex-toc.el (reftex-toc-rename-label): * lisp/textmodes/two-column.el (2C-split): * lisp/tutorial.el (tutorial--describe-nonstandard-key) (tutorial--find-changed-keys): * lisp/type-break.el (type-break-noninteractive-query): * lisp/wdired.el (wdired-do-renames, wdired-do-symlink-changes) (wdired-do-perm-changes): * lisp/whitespace.el (whitespace-report-region): Prefer grave quoting in source-code strings used to generate help and diagnostics. * lisp/faces.el (face-documentation): No need to convert quotes, since the result is a docstring. * lisp/info.el (Info-virtual-index-find-node) (Info-virtual-index, info-apropos): Simplify by generating only curved quotes, since info files are typically that ways nowadays anyway. * lisp/international/mule-diag.el (list-input-methods): Don’t assume text quoting style is curved. * lisp/org/org-bibtex.el (org-bibtex-fields): Revert my recent changes, going back to the old quoting style.
1115 lines
45 KiB
EmacsLisp
1115 lines
45 KiB
EmacsLisp
;;; reftex-toc.el --- RefTeX's table of contents mode
|
|
|
|
;; Copyright (C) 1997-2000, 2003-2015 Free Software Foundation, Inc.
|
|
|
|
;; Author: Carsten Dominik <dominik@science.uva.nl>
|
|
;; Maintainer: auctex-devel@gnu.org
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
;; it under the terms of the GNU General Public License as published by
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
;; (at your option) any later version.
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
;; GNU General Public License for more details.
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
;;; Commentary:
|
|
|
|
;;; Code:
|
|
|
|
(eval-when-compile (require 'cl))
|
|
(provide 'reftex-toc)
|
|
(require 'reftex)
|
|
;;;
|
|
|
|
(define-obsolete-variable-alias 'reftex-toc-map 'reftex-toc-mode-map "24.1")
|
|
(defvar reftex-toc-mode-map
|
|
(let ((map (make-sparse-keymap)))
|
|
|
|
(define-key map (if (featurep 'xemacs) [(button2)] [(mouse-2)])
|
|
'reftex-toc-mouse-goto-line-and-hide)
|
|
(define-key map [follow-link] 'mouse-face)
|
|
|
|
(substitute-key-definition
|
|
'next-line 'reftex-toc-next map global-map)
|
|
(substitute-key-definition
|
|
'previous-line 'reftex-toc-previous map global-map)
|
|
|
|
(loop for x in
|
|
'(("n" . reftex-toc-next)
|
|
("p" . reftex-toc-previous)
|
|
("?" . reftex-toc-show-help)
|
|
(" " . reftex-toc-view-line)
|
|
("\C-m" . reftex-toc-goto-line-and-hide)
|
|
("\C-i" . reftex-toc-goto-line)
|
|
("\C-c>" . reftex-toc-display-index)
|
|
("r" . reftex-toc-rescan)
|
|
("R" . reftex-toc-Rescan)
|
|
("g" . revert-buffer)
|
|
("q" . reftex-toc-quit) ;
|
|
("k" . reftex-toc-quit-and-kill)
|
|
("f" . reftex-toc-toggle-follow) ;
|
|
("a" . reftex-toggle-auto-toc-recenter)
|
|
("d" . reftex-toc-toggle-dedicated-frame)
|
|
("F" . reftex-toc-toggle-file-boundary)
|
|
("i" . reftex-toc-toggle-index)
|
|
("l" . reftex-toc-toggle-labels)
|
|
("t" . reftex-toc-max-level)
|
|
("c" . reftex-toc-toggle-context)
|
|
;; ("%" . reftex-toc-toggle-commented)
|
|
("\M-%" . reftex-toc-rename-label)
|
|
("x" . reftex-toc-external)
|
|
("z" . reftex-toc-jump)
|
|
("." . reftex-toc-show-calling-point)
|
|
("\C-c\C-n" . reftex-toc-next-heading)
|
|
("\C-c\C-p" . reftex-toc-previous-heading)
|
|
(">" . reftex-toc-demote)
|
|
("<" . reftex-toc-promote))
|
|
do (define-key map (car x) (cdr x)))
|
|
|
|
(loop for key across "0123456789" do
|
|
(define-key map (vector (list key)) 'digit-argument))
|
|
(define-key map "-" 'negative-argument)
|
|
|
|
(easy-menu-define
|
|
reftex-toc-menu map
|
|
"Menu for Table of Contents buffer"
|
|
'("TOC"
|
|
["Show Location" reftex-toc-view-line t]
|
|
["Go To Location" reftex-toc-goto-line t]
|
|
["Exit & Go To Location" reftex-toc-goto-line-and-hide t]
|
|
["Show Calling Point" reftex-toc-show-calling-point t]
|
|
["Quit" reftex-toc-quit t]
|
|
"--"
|
|
("Edit"
|
|
["Promote" reftex-toc-promote t]
|
|
["Demote" reftex-toc-demote t]
|
|
["Rename Label" reftex-toc-rename-label t])
|
|
"--"
|
|
["Index" reftex-toc-display-index t]
|
|
["External Document TOC " reftex-toc-external t]
|
|
"--"
|
|
("Update"
|
|
["Rebuilt *toc* Buffer" revert-buffer t]
|
|
["Rescan One File" reftex-toc-rescan reftex-enable-partial-scans]
|
|
["Rescan Entire Document" reftex-toc-Rescan t])
|
|
("Options"
|
|
"TOC Items"
|
|
["File Boundaries" reftex-toc-toggle-file-boundary :style toggle
|
|
:selected reftex-toc-include-file-boundaries]
|
|
["Labels" reftex-toc-toggle-labels :style toggle
|
|
:selected reftex-toc-include-labels]
|
|
["Index Entries" reftex-toc-toggle-index :style toggle
|
|
:selected reftex-toc-include-index-entries]
|
|
["Context" reftex-toc-toggle-context :style toggle
|
|
:selected reftex-toc-include-context]
|
|
"--"
|
|
["Follow Mode" reftex-toc-toggle-follow :style toggle
|
|
:selected reftex-toc-follow-mode]
|
|
["Auto Recenter" reftex-toggle-auto-toc-recenter :style toggle
|
|
:selected reftex-toc-auto-recenter-timer]
|
|
["Dedicated Frame" reftex-toc-toggle-dedicated-frame t])
|
|
"--"
|
|
["Help" reftex-toc-show-help t]))
|
|
|
|
map)
|
|
"Keymap used for *toc* buffer.")
|
|
|
|
(defvar reftex-toc-menu)
|
|
(defvar reftex-last-window-height nil)
|
|
(defvar reftex-last-window-width nil)
|
|
(defvar reftex-toc-include-labels-indicator nil)
|
|
(defvar reftex-toc-include-index-indicator nil)
|
|
(defvar reftex-toc-max-level-indicator nil)
|
|
|
|
(define-derived-mode reftex-toc-mode special-mode "TOC"
|
|
"Major mode for managing Table of Contents for LaTeX files.
|
|
This buffer was created with RefTeX.
|
|
Press `?' for a summary of important key bindings.
|
|
|
|
Here are all local bindings.
|
|
|
|
\\{reftex-toc-mode-map}"
|
|
(set (make-local-variable 'transient-mark-mode) t)
|
|
(when (featurep 'xemacs)
|
|
(set (make-local-variable 'zmacs-regions) t))
|
|
(set (make-local-variable 'revert-buffer-function) 'reftex-toc-revert)
|
|
(set (make-local-variable 'reftex-toc-include-labels-indicator) "")
|
|
(set (make-local-variable 'reftex-toc-max-level-indicator)
|
|
(if (= reftex-toc-max-level 100)
|
|
"ALL"
|
|
(int-to-string reftex-toc-max-level)))
|
|
(setq mode-line-format
|
|
(list "---- " 'mode-line-buffer-identification
|
|
" " 'global-mode-string " (" mode-name ")"
|
|
" L<" 'reftex-toc-include-labels-indicator ">"
|
|
" I<" 'reftex-toc-include-index-indicator ">"
|
|
" T<" 'reftex-toc-max-level-indicator ">"
|
|
" -%-"))
|
|
(setq truncate-lines t)
|
|
(when (featurep 'xemacs)
|
|
;; XEmacs needs the call to make-local-hook
|
|
(make-local-hook 'post-command-hook)
|
|
(make-local-hook 'pre-command-hook))
|
|
(make-local-variable 'reftex-last-follow-point)
|
|
(add-hook 'post-command-hook 'reftex-toc-post-command-hook nil t)
|
|
(add-hook 'pre-command-hook 'reftex-toc-pre-command-hook nil t)
|
|
(easy-menu-add reftex-toc-menu reftex-toc-mode-map))
|
|
|
|
(defvar reftex-last-toc-file nil
|
|
"Stores the file name from which `reftex-toc' was called. For redo command.")
|
|
|
|
|
|
(defvar reftex-toc-return-marker (make-marker)
|
|
"Marker which makes it possible to return from TOC to old position.")
|
|
|
|
(defconst reftex-toc-help
|
|
" AVAILABLE KEYS IN TOC BUFFER
|
|
============================
|
|
n / p next-line / previous-line
|
|
SPC Show the corresponding location of the LaTeX document.
|
|
TAB Goto the location and keep the TOC window.
|
|
RET Goto the location and hide the TOC window (also on mouse-2).
|
|
< / > Promote / Demote section, or all sections in region.
|
|
C-c > Display Index. With prefix arg, restrict index to current section.
|
|
q / k Hide/Kill *toc* buffer, return to position of reftex-toc command.
|
|
l i c F Toggle display of [l]abels, [i]ndex, [c]ontext, [F]ile borders.
|
|
t Change maximum toc depth (e.g. `3 t' hides levels greater than 3).
|
|
f / g Toggle follow mode / Refresh *toc* buffer.
|
|
a / d Toggle auto recenter / Toggle dedicated frame
|
|
r / C-u r Reparse the LaTeX document / Reparse entire LaTeX document.
|
|
. In other window, show position from where `reftex-toc' was called.
|
|
M-% Global search and replace to rename label at point.
|
|
x Switch to TOC of external document (with LaTeX package `xr').
|
|
z Jump to a specific section (e.g. '3 z' goes to section 3).")
|
|
|
|
(defvar reftex--rebuilding-toc nil)
|
|
|
|
;;;###autoload
|
|
(defun reftex-toc (&optional _rebuild reuse)
|
|
;; FIXME: Get rid of the `rebuild' argument.
|
|
"Show the table of contents for the current document.
|
|
When called with a raw C-u prefix, rescan the document first."
|
|
|
|
;; The REUSE argument means, search all visible frames for a window
|
|
;; displaying the toc window. If yes, reuse this window.
|
|
|
|
(interactive)
|
|
|
|
(if (or (not (string= reftex-last-toc-master (reftex-TeX-master-file)))
|
|
;; FIXME: use (interactive "P") to receive current-prefix-arg as
|
|
;; an argument instead of using the var here, which forces us to set
|
|
;; current-prefix-arg in the callers.
|
|
current-prefix-arg)
|
|
(reftex-erase-buffer "*toc*"))
|
|
|
|
(setq reftex-last-toc-file (buffer-file-name))
|
|
(setq reftex-last-toc-master (reftex-TeX-master-file))
|
|
|
|
(set-marker reftex-toc-return-marker (point))
|
|
|
|
;; If follow mode is active, arrange to delay it one command
|
|
(if reftex-toc-follow-mode
|
|
(setq reftex-toc-follow-mode 1))
|
|
|
|
(and reftex-toc-include-index-entries
|
|
(reftex-ensure-index-support))
|
|
(or reftex-support-index
|
|
(setq reftex-toc-include-index-entries nil))
|
|
|
|
;; Ensure access to scanning info and rescan buffer if prefix are is '(4)
|
|
(reftex-access-scan-info current-prefix-arg)
|
|
|
|
(let* ((this-buf (current-buffer))
|
|
(docstruct-symbol reftex-docstruct-symbol)
|
|
(xr-data (assq 'xr (symbol-value reftex-docstruct-symbol)))
|
|
(xr-alist (cons (cons "" (buffer-file-name)) (nth 1 xr-data)))
|
|
(here-I-am (if reftex--rebuilding-toc
|
|
(get 'reftex-toc :reftex-data)
|
|
(car (reftex-where-am-I))))
|
|
(unsplittable (if (fboundp 'frame-property)
|
|
(frame-property (selected-frame) 'unsplittable)
|
|
(frame-parameter nil 'unsplittable)))
|
|
offset toc-window)
|
|
|
|
(if (setq toc-window (get-buffer-window
|
|
"*toc*"
|
|
(if reuse 'visible)))
|
|
(select-window toc-window)
|
|
(when (or (not reftex-toc-keep-other-windows)
|
|
(< (window-height) (* 2 window-min-height)))
|
|
(delete-other-windows))
|
|
|
|
(setq reftex-last-window-width (window-total-width)
|
|
reftex-last-window-height (window-height)) ; remember
|
|
|
|
(unless unsplittable
|
|
(if reftex-toc-split-windows-horizontally
|
|
(split-window-right
|
|
(floor (* (window-total-width)
|
|
reftex-toc-split-windows-fraction)))
|
|
(split-window-below
|
|
(floor (* (window-height)
|
|
reftex-toc-split-windows-fraction)))))
|
|
|
|
(switch-to-buffer "*toc*"))
|
|
|
|
(or (eq major-mode 'reftex-toc-mode) (reftex-toc-mode))
|
|
(set (make-local-variable 'reftex-docstruct-symbol) docstruct-symbol)
|
|
(setq reftex-toc-include-labels-indicator
|
|
(if (eq reftex-toc-include-labels t)
|
|
"ALL"
|
|
reftex-toc-include-labels))
|
|
(setq reftex-toc-include-index-indicator
|
|
(if (eq reftex-toc-include-index-entries t)
|
|
"ALL"
|
|
reftex-toc-include-index-entries))
|
|
|
|
(cond
|
|
((= (buffer-size) 0)
|
|
;; buffer is empty - fill it with the table of contents
|
|
(message "Building *toc* buffer...")
|
|
|
|
(setq buffer-read-only nil)
|
|
(insert (format
|
|
"TABLE-OF-CONTENTS on %s
|
|
SPC=view TAB=goto RET=goto+hide [q]uit [r]escan [l]abels [f]ollow [x]r [?]Help
|
|
------------------------------------------------------------------------------
|
|
" (abbreviate-file-name reftex-last-toc-master)))
|
|
|
|
(if (reftex-use-fonts)
|
|
(put-text-property (point-min) (point) 'font-lock-face reftex-toc-header-face))
|
|
(if (fboundp 'cursor-intangible-mode)
|
|
(cursor-intangible-mode 1)
|
|
;; If `cursor-intangible' is not available, fallback on the old
|
|
;; intrusive `intangible' property.
|
|
(put-text-property (point-min) (point) 'intangible t))
|
|
(add-text-properties (point-min) (point)
|
|
'(cursor-intangible t
|
|
front-sticky (cursor-intangible)
|
|
rear-nonsticky (cursor-intangible)))
|
|
(put-text-property (point-min) (1+ (point-min)) 'xr-alist xr-alist)
|
|
|
|
(setq offset
|
|
(reftex-insert-docstruct
|
|
this-buf
|
|
t ; include TOC
|
|
reftex-toc-include-labels
|
|
reftex-toc-include-index-entries
|
|
reftex-toc-include-file-boundaries
|
|
reftex-toc-include-context
|
|
nil ; counter
|
|
nil ; commented
|
|
here-I-am
|
|
"" ; xr-prefix
|
|
t ; a TOC buffer
|
|
))
|
|
|
|
(run-hooks 'reftex-display-copied-context-hook)
|
|
(message "Building *toc* buffer...done.")
|
|
(setq buffer-read-only t))
|
|
(t
|
|
;; Only compute the offset
|
|
(setq offset
|
|
(or (reftex-get-offset this-buf here-I-am
|
|
(if reftex-toc-include-labels " " nil)
|
|
t
|
|
reftex-toc-include-index-entries
|
|
reftex-toc-include-file-boundaries)
|
|
(reftex-last-assoc-before-elt
|
|
'toc here-I-am
|
|
(symbol-value reftex-docstruct-symbol))))
|
|
(put 'reftex-toc :reftex-line 3)
|
|
(goto-char (point-min))
|
|
(forward-line 2)))
|
|
|
|
;; Find the correct starting point
|
|
(reftex-find-start-point (point) offset (get 'reftex-toc :reftex-line))
|
|
(setq reftex-last-follow-point (point))))
|
|
|
|
;;;###autoload
|
|
(defun reftex-toc-recenter (&optional arg)
|
|
"Display the TOC window and highlight line corresponding to current position."
|
|
(interactive "P")
|
|
(let ((buf (current-buffer))
|
|
(frame (selected-frame)))
|
|
(reftex-toc arg t)
|
|
(if (= (count-lines 1 (point)) 2)
|
|
(let ((current-prefix-arg nil))
|
|
(select-window (get-buffer-window buf frame))
|
|
(reftex-toc nil t)))
|
|
(and (> (point) 1) ;FIXME: Is this point-min or do we care about narrowing?
|
|
(not (get-text-property (point) 'cursor-intangible))
|
|
(memq reftex-highlight-selection '(cursor both))
|
|
(reftex-highlight 2
|
|
(or (previous-single-property-change
|
|
(min (point-max) (1+ (point))) :data)
|
|
(point-min))
|
|
(or (next-single-property-change (point) :data)
|
|
(point-max))))
|
|
(select-window (get-buffer-window buf frame))))
|
|
|
|
(defun reftex-toc-pre-command-hook ()
|
|
;; used as pre command hook in *toc* buffer
|
|
(reftex-unhighlight 0)
|
|
)
|
|
|
|
(defun reftex-toc-post-command-hook ()
|
|
;; used in the post-command-hook for the *toc* buffer
|
|
;; FIXME: Lots of redundancy with reftex-index-post-command-hook!
|
|
(when (get-text-property (point) :data)
|
|
(put 'reftex-toc :reftex-data (get-text-property (point) :data))
|
|
(and (> (point) 1) ;FIXME: Is this point-min or do we care about narrowing?
|
|
(not (get-text-property (point) 'cursor-intangible))
|
|
(memq reftex-highlight-selection '(cursor both))
|
|
(reftex-highlight 2
|
|
(or (previous-single-property-change (1+ (point)) :data)
|
|
(point-min))
|
|
(or (next-single-property-change (point) :data)
|
|
(point-max)))))
|
|
(if (integerp reftex-toc-follow-mode)
|
|
;; remove delayed action
|
|
(setq reftex-toc-follow-mode t)
|
|
(and (not (reftex-toc-dframe-p))
|
|
reftex-toc-follow-mode
|
|
(not (equal reftex-last-follow-point (point)))
|
|
;; show context in other window
|
|
(setq reftex-last-follow-point (point))
|
|
(condition-case nil
|
|
(reftex-toc-visit-location nil (not reftex-revisit-to-follow))
|
|
(error t)))))
|
|
|
|
(defun reftex-re-enlarge ()
|
|
"Enlarge window to a remembered size."
|
|
(let ((count (if reftex-toc-split-windows-horizontally
|
|
(- (or reftex-last-window-width (window-total-width))
|
|
(window-total-width))
|
|
(- (or reftex-last-window-height (window-height))
|
|
(window-height)))))
|
|
(when (> count 0)
|
|
(enlarge-window count reftex-toc-split-windows-horizontally))))
|
|
|
|
(defun reftex-toc-dframe-p (&optional frame error)
|
|
;; Check if FRAME is the dedicated TOC frame.
|
|
;; If yes, and ERROR is non-nil, throw an error.
|
|
(setq frame (or frame (selected-frame)))
|
|
(let ((res (equal
|
|
(if (fboundp 'frame-property)
|
|
(frame-property frame 'name)
|
|
(frame-parameter frame 'name))
|
|
"RefTeX TOC Frame")))
|
|
(if (and res error)
|
|
(error "This frame is view-only. Use `C-c =' to create TOC window for commands"))
|
|
res))
|
|
|
|
(defun reftex-toc-show-help ()
|
|
"Show a summary of special key bindings."
|
|
(interactive)
|
|
(reftex-toc-dframe-p nil 'error)
|
|
(with-output-to-temp-buffer "*RefTeX Help*"
|
|
(princ reftex-toc-help))
|
|
(reftex-enlarge-to-fit "*RefTeX Help*" t)
|
|
;; If follow mode is active, arrange to delay it one command
|
|
(if reftex-toc-follow-mode
|
|
(setq reftex-toc-follow-mode 1)))
|
|
|
|
(defun reftex-toc-next (&optional _arg)
|
|
"Move to next selectable item."
|
|
(interactive)
|
|
(when (featurep 'xemacs) (setq zmacs-region-stays t))
|
|
(setq reftex-callback-fwd t)
|
|
(or (eobp) (forward-char 1))
|
|
(goto-char (or (next-single-property-change (point) :data)
|
|
(point))))
|
|
(defun reftex-toc-previous (&optional _arg)
|
|
"Move to previous selectable item."
|
|
(interactive)
|
|
(when (featurep 'xemacs) (setq zmacs-region-stays t))
|
|
(setq reftex-callback-fwd nil)
|
|
(goto-char (or (previous-single-property-change (point) :data)
|
|
(point))))
|
|
(defun reftex-toc-next-heading (&optional arg)
|
|
"Move to next table of contents line."
|
|
(interactive "p")
|
|
(when (featurep 'xemacs) (setq zmacs-region-stays t))
|
|
(end-of-line)
|
|
(re-search-forward "^ " nil t arg)
|
|
(beginning-of-line))
|
|
(defun reftex-toc-previous-heading (&optional arg)
|
|
"Move to previous table of contents line."
|
|
(interactive "p")
|
|
(when (featurep 'xemacs) (setq zmacs-region-stays t))
|
|
(re-search-backward "^ " nil t arg))
|
|
(defun reftex-toc-toggle-follow ()
|
|
"Toggle follow (other window follows with context)."
|
|
(interactive)
|
|
(setq reftex-last-follow-point -1)
|
|
(setq reftex-toc-follow-mode (not reftex-toc-follow-mode)))
|
|
(defun reftex-toc-toggle-file-boundary ()
|
|
"Toggle inclusion of file boundaries in *toc* buffer."
|
|
(interactive)
|
|
(setq reftex-toc-include-file-boundaries
|
|
(not reftex-toc-include-file-boundaries))
|
|
(reftex-toc-revert))
|
|
(defun reftex-toc-toggle-labels (arg)
|
|
"Toggle inclusion of labels in *toc* buffer.
|
|
With prefix ARG, prompt for a label type and include only labels of
|
|
that specific type."
|
|
(interactive "P")
|
|
(setq reftex-toc-include-labels
|
|
(if arg (reftex-query-label-type)
|
|
(not reftex-toc-include-labels)))
|
|
(reftex-toc-revert))
|
|
(defun reftex-toc-toggle-index (arg)
|
|
"Toggle inclusion of index in *toc* buffer.
|
|
With prefix arg, prompt for an index tag and include only entries of that
|
|
specific index."
|
|
(interactive "P")
|
|
(setq reftex-toc-include-index-entries
|
|
(if arg (reftex-index-select-tag)
|
|
(not reftex-toc-include-index-entries)))
|
|
(reftex-toc-revert))
|
|
(defun reftex-toc-toggle-context ()
|
|
"Toggle inclusion of label context in *toc* buffer.
|
|
Label context is only displayed when the labels are there as well."
|
|
(interactive)
|
|
(setq reftex-toc-include-context (not reftex-toc-include-context))
|
|
(reftex-toc-revert))
|
|
(defun reftex-toc-max-level (arg)
|
|
"Set the maximum level of TOC lines in this buffer to value of prefix ARG.
|
|
When no prefix is given, set the max level to a large number, so that all
|
|
levels are shown. For example, to set the level to 3, type `3 m'."
|
|
(interactive "P")
|
|
(setq reftex-toc-max-level (if arg
|
|
(prefix-numeric-value arg)
|
|
100))
|
|
(setq reftex-toc-max-level-indicator
|
|
(if arg (int-to-string reftex-toc-max-level) "ALL"))
|
|
(reftex-toc-revert))
|
|
(defun reftex-toc-view-line ()
|
|
"View document location in other window."
|
|
(interactive)
|
|
(reftex-toc-dframe-p nil 'error)
|
|
(reftex-toc-visit-location))
|
|
(defun reftex-toc-goto-line-and-hide ()
|
|
"Go to document location in other window. Hide the TOC window."
|
|
(interactive)
|
|
(reftex-toc-dframe-p nil 'error)
|
|
(reftex-toc-visit-location 'hide))
|
|
(defun reftex-toc-goto-line ()
|
|
"Go to document location in other window. TOC window stays."
|
|
(interactive)
|
|
(reftex-toc-dframe-p nil 'error)
|
|
(reftex-toc-visit-location t))
|
|
(defun reftex-toc-mouse-goto-line-and-hide (ev)
|
|
"Go to document location in other window. Hide the TOC window."
|
|
(interactive "e")
|
|
(mouse-set-point ev)
|
|
(reftex-toc-dframe-p nil 'error)
|
|
(reftex-toc-visit-location 'hide))
|
|
(defun reftex-toc-show-calling-point ()
|
|
"Show point where `reftex-toc' was called from."
|
|
(interactive)
|
|
(reftex-toc-dframe-p nil 'error)
|
|
(let ((this-window (selected-window)))
|
|
(unwind-protect
|
|
(progn
|
|
(switch-to-buffer-other-window
|
|
(marker-buffer reftex-toc-return-marker))
|
|
(goto-char (marker-position reftex-toc-return-marker))
|
|
(recenter '(4)))
|
|
(select-window this-window))))
|
|
(defun reftex-toc-quit ()
|
|
"Hide the TOC window and do not move point.
|
|
If the TOC window is the only window on the dedicated TOC frame, the frame
|
|
is destroyed."
|
|
(interactive)
|
|
(if (and (one-window-p)
|
|
(reftex-toc-dframe-p)
|
|
(> (length (frame-list)) 1))
|
|
(delete-frame)
|
|
(or (one-window-p) (delete-window))
|
|
(switch-to-buffer (marker-buffer reftex-toc-return-marker))
|
|
(reftex-re-enlarge)
|
|
(goto-char (or (marker-position reftex-toc-return-marker) (point)))))
|
|
(defun reftex-toc-quit-and-kill ()
|
|
"Kill the *toc* buffer."
|
|
(interactive)
|
|
(kill-buffer "*toc*")
|
|
(or (one-window-p) (delete-window))
|
|
(switch-to-buffer (marker-buffer reftex-toc-return-marker))
|
|
(reftex-re-enlarge)
|
|
(goto-char (marker-position reftex-toc-return-marker)))
|
|
(defun reftex-toc-display-index (&optional arg)
|
|
"Display the index buffer for the current document.
|
|
This works just like `reftex-display-index' from a LaTeX buffer.
|
|
With prefix arg 1, restrict index to the section at point."
|
|
(interactive "P")
|
|
(reftex-toc-dframe-p nil 'error)
|
|
(let ((data (get-text-property (point) :data))
|
|
(docstruct (symbol-value reftex-docstruct-symbol))
|
|
bor eor restr)
|
|
(when (equal arg 2)
|
|
(setq bor (reftex-last-assoc-before-elt 'toc data docstruct)
|
|
eor (assoc 'toc (cdr (memq bor docstruct)))
|
|
restr (list (nth 6 bor) bor eor)))
|
|
(reftex-toc-goto-line)
|
|
(reftex-display-index (if restr nil arg) restr)))
|
|
|
|
;; Rescanning the document and rebuilding the TOC buffer.
|
|
(defun reftex-toc-rescan (&rest _)
|
|
"Regenerate the *toc* buffer by reparsing file of section at point."
|
|
(interactive)
|
|
(if (and reftex-enable-partial-scans
|
|
(null current-prefix-arg))
|
|
(let* ((data (get-text-property (point) :data))
|
|
(what (car data))
|
|
(file (cond ((eq what 'toc) (nth 3 data))
|
|
((memq what '(eof bof file-error)) (nth 1 data))
|
|
((stringp what) (nth 3 data))
|
|
((eq what 'index) (nth 3 data))))
|
|
(line (+ (count-lines (point-min) (point)) (if (bolp) 1 0))))
|
|
(if (not file)
|
|
(error "Don't know which file to rescan. Try `C-u r'")
|
|
(put 'reftex-toc :reftex-line line)
|
|
(switch-to-buffer-other-window
|
|
(reftex-get-file-buffer-force file))
|
|
(setq current-prefix-arg '(4))
|
|
(let ((reftex--rebuilding-toc t))
|
|
(reftex-toc))))
|
|
(reftex-toc-Rescan))
|
|
(reftex-kill-temporary-buffers))
|
|
|
|
(defun reftex-toc-Rescan (&rest _)
|
|
"Regenerate the *toc* buffer by reparsing the entire document."
|
|
(interactive)
|
|
(let* ((line (+ (count-lines (point-min) (point)) (if (bolp) 1 0))))
|
|
(put 'reftex-toc :reftex-line line))
|
|
(switch-to-buffer-other-window
|
|
(reftex-get-file-buffer-force reftex-last-toc-file))
|
|
(setq current-prefix-arg '(16))
|
|
(let ((reftex--rebuilding-toc t))
|
|
(reftex-toc)))
|
|
|
|
(defun reftex-toc-revert (&rest _)
|
|
"Regenerate the TOC from the internal lists."
|
|
(interactive)
|
|
(let ((unsplittable
|
|
(if (fboundp 'frame-property)
|
|
(frame-property (selected-frame) 'unsplittable)
|
|
(frame-parameter nil 'unsplittable)))
|
|
(reftex--rebuilding-toc t))
|
|
(if unsplittable
|
|
(switch-to-buffer
|
|
(reftex-get-file-buffer-force reftex-last-toc-file))
|
|
(switch-to-buffer-other-window
|
|
(reftex-get-file-buffer-force reftex-last-toc-file))))
|
|
(reftex-erase-buffer "*toc*")
|
|
(setq current-prefix-arg nil)
|
|
(reftex-toc t t))
|
|
|
|
(defun reftex-toc-external (&rest _)
|
|
"Switch to table of contents of an external document."
|
|
(interactive)
|
|
(reftex-toc-dframe-p nil 'error)
|
|
(let* ((old-buf (current-buffer))
|
|
(xr-alist (get-text-property 1 'xr-alist))
|
|
(xr-index (reftex-select-external-document
|
|
xr-alist 0)))
|
|
(switch-to-buffer-other-window (or (reftex-get-file-buffer-force
|
|
(cdr (nth xr-index xr-alist)))
|
|
(error "Cannot switch document")))
|
|
(reftex-toc)
|
|
(if (equal old-buf (current-buffer))
|
|
(message "")
|
|
(message "Switched document"))))
|
|
|
|
(defun reftex-toc-jump (arg)
|
|
"Jump to a specific section. E.g. '3 z' jumps to section 3.
|
|
Useful for large TOCs."
|
|
(interactive "P")
|
|
(goto-char (point-min))
|
|
(re-search-forward
|
|
(concat "^ *" (number-to-string (if (numberp arg) arg 1)) " ")
|
|
nil t)
|
|
(beginning-of-line))
|
|
|
|
;; Promotion/Demotion stuff
|
|
|
|
(defvar reftex--pro-or-de)
|
|
(defvar reftex--start-line)
|
|
(defvar reftex--mark-line)
|
|
|
|
(defun reftex-toc-demote (&optional _arg)
|
|
"Demote section at point. If region is active, apply to all in region."
|
|
(interactive)
|
|
(reftex-toc-do-promote 1))
|
|
(defun reftex-toc-promote (&optional _arg)
|
|
"Promote section at point. If region is active, apply to all in region."
|
|
(interactive)
|
|
(reftex-toc-do-promote -1))
|
|
(defun reftex-toc-do-promote (delta)
|
|
"Workhorse for `reftex-toc-promote' and `reftex-toc-demote'.
|
|
Changes the level of sections in the current region, or just the section at
|
|
point."
|
|
;; We should not do anything unless we are sure this is going to work for
|
|
;; each section in the region. Therefore we first collect information and
|
|
;; test.
|
|
(let* ((reftex--start-line (+ (count-lines (point-min) (point))
|
|
(if (bolp) 1 0)))
|
|
(reftex--mark-line
|
|
(if (reftex-region-active-p)
|
|
(save-excursion (goto-char (mark))
|
|
(+ (count-lines (point-min) (point))
|
|
(if (bolp) 1 0)))))
|
|
(start-pos (point))
|
|
(reftex--pro-or-de (if (> delta 0) "de" "pro"))
|
|
beg end entries data sections nsec msg)
|
|
(setq msg
|
|
(catch 'exit
|
|
(if (reftex-region-active-p)
|
|
;; A region is dangerous, check if we have a brand new scan,
|
|
;; to make sure we are not missing any section statements.
|
|
(if (not (reftex-toc-check-docstruct))
|
|
(reftex-toc-load-all-files-for-promotion) ;; exits
|
|
(setq beg (min (point) (mark))
|
|
end (max (point) (mark))))
|
|
(setq beg (point) end (point)))
|
|
(goto-char beg)
|
|
(while (and (setq data (get-text-property (point) :data))
|
|
(<= (point) end))
|
|
(if (eq (car data) 'toc) (push (cons data (point)) entries))
|
|
(goto-char (or (next-single-property-change (point) :data)
|
|
(point-max))))
|
|
(setq entries (nreverse entries))
|
|
;; Get the relevant section numbers, for an informative message
|
|
(goto-char start-pos)
|
|
(setq sections (reftex-toc-extract-section-number (car entries)))
|
|
(if (> (setq nsec (length entries)) 1)
|
|
(setq sections
|
|
(concat sections "-"
|
|
(reftex-toc-extract-section-number
|
|
(nth (1- nsec) entries)))))
|
|
;; Run through the list and prepare the changes.
|
|
(setq entries (mapcar
|
|
(lambda (e) (reftex-toc-promote-prepare e delta))
|
|
entries))
|
|
;; Ask for permission
|
|
(if (or (not reftex-toc-confirm-promotion) ; never confirm
|
|
(and (integerp reftex-toc-confirm-promotion) ; confirm if many
|
|
(< nsec reftex-toc-confirm-promotion))
|
|
(yes-or-no-p ; ask
|
|
(format "%s %d toc-entr%s (section%s %s)? "
|
|
(if (< delta 0) "Promote" "Demote")
|
|
nsec
|
|
(if (= 1 nsec) "y" "ies")
|
|
(if (= 1 nsec) "" "s")
|
|
sections)))
|
|
nil ; we have permission, do nothing
|
|
(error "Abort")) ; abort, we don't have permission
|
|
;; Do the changes
|
|
(mapc 'reftex-toc-promote-action entries)
|
|
;; Rescan the document and rebuilt the toc buffer
|
|
(save-window-excursion
|
|
(reftex-toc-Rescan))
|
|
(reftex-toc-restore-region reftex--start-line reftex--mark-line)
|
|
(message "%d section%s %smoted"
|
|
nsec (if (= 1 nsec) "" "s") reftex--pro-or-de)
|
|
nil))
|
|
(if msg (progn (ding) (message "%s" msg)))))
|
|
|
|
|
|
(defun reftex-toc-restore-region (point-line &optional mark-line)
|
|
(let ((mpos
|
|
(when mark-line
|
|
(goto-char (point-min))
|
|
(forward-line (1- mark-line))
|
|
(point))))
|
|
(when point-line
|
|
(goto-char (point-min))
|
|
(forward-line (1- point-line)))
|
|
(when mpos
|
|
(set-mark mpos)
|
|
(if (featurep 'xemacs)
|
|
(zmacs-activate-region)
|
|
(setq mark-active t
|
|
deactivate-mark nil)))))
|
|
|
|
(defun reftex-toc-promote-prepare (x delta)
|
|
"Look at a TOC entry and see if we could pro/demote it.
|
|
This function prepares everything for the change, but does not do it.
|
|
The return value is a list with information needed when doing the
|
|
promotion/demotion later. DELTA is the level change."
|
|
(let* ((data (car x))
|
|
(toc-point (cdr x))
|
|
(marker (nth 4 data))
|
|
(literal (nth 7 data))
|
|
(load nil)
|
|
(name nil)
|
|
;; Here follows some paranoid code to make very sure we are not
|
|
;; going to break anything
|
|
(_
|
|
(if (and (markerp marker) (marker-buffer marker))
|
|
;; Buffer is still live and we have the marker.
|
|
(progn
|
|
(with-current-buffer (marker-buffer marker)
|
|
;; Goto the buffer and check of section is unchanged
|
|
(goto-char (marker-position marker))
|
|
(if (looking-at (regexp-quote literal))
|
|
;; OK, get the makro name
|
|
(progn
|
|
(beginning-of-line 1)
|
|
(if (looking-at reftex-section-regexp)
|
|
(setq name (reftex-match-string 2))
|
|
(error "Something is wrong! Contact maintainer!")))
|
|
;; Section has changed, request scan and loading
|
|
;; We use a variable to delay until after the safe-exc.
|
|
;; because otherwise we lose the region.
|
|
(setq load t)))
|
|
;; Scan document and load all files, this exits command
|
|
(if load (reftex-toc-load-all-files-for-promotion))) ; exits
|
|
;; We don't have a live marker: scan and load files.
|
|
(reftex-toc-load-all-files-for-promotion)))
|
|
(level (cdr (assoc name reftex-section-levels-all)))
|
|
(_ (if (not (integerp level))
|
|
(progn
|
|
(goto-char toc-point)
|
|
(error "Cannot %smote special sections" reftex--pro-or-de))))
|
|
(newlevel (if (>= level 0) (+ delta level) (- level delta)))
|
|
(_ (if (or (and (>= level 0) (= newlevel -1))
|
|
(and (< level 0) (= newlevel 0)))
|
|
(error "Cannot %smote \\%s" reftex--pro-or-de name)))
|
|
(newname (reftex-toc-newhead-from-alist newlevel name
|
|
reftex-section-levels-all)))
|
|
(if (and name newname)
|
|
(list data name newname toc-point)
|
|
(goto-char toc-point)
|
|
(error "Cannot %smote \\%s" reftex--pro-or-de name))))
|
|
|
|
(defun reftex-toc-promote-action (x)
|
|
"Change the level of a TOC entry.
|
|
`reftex--pro-or-de' is assumed to be dynamically scoped into this function."
|
|
(let* ((data (car x))
|
|
(name (nth 1 x))
|
|
(newname (nth 2 x))
|
|
(marker (nth 4 data)))
|
|
(with-current-buffer (marker-buffer marker)
|
|
(goto-char (marker-position marker))
|
|
(if (looking-at (concat "\\([ \t]*" reftex-section-pre-regexp "\\)" (regexp-quote name)))
|
|
(replace-match (concat "\\1" newname))
|
|
(error "Fatal error during %smotion" reftex--pro-or-de)))))
|
|
|
|
(defun reftex-toc-extract-section-number (entry)
|
|
"Get the numbering of a TOC entry, for message purposes."
|
|
(if (string-match "\\s-*\\(\\S-+\\)" (nth 2 (car entry)))
|
|
(match-string 1 (nth 2 (car entry)))
|
|
"?"))
|
|
|
|
(defun reftex-toc-newhead-from-alist (nlevel head alist)
|
|
"Get new heading with level NLEVEL from ALIST.
|
|
If there are no such entries, return nil.
|
|
If there are several different entries with same new level, choose the
|
|
one with the smallest distance to the association of HEAD in the alist.
|
|
This makes it possible for promotion to work several sets of headings,
|
|
if these sets are sorted blocks in the alist."
|
|
(let* ((al alist)
|
|
(ass (assoc head al))
|
|
(pos (length (memq ass al)))
|
|
dist (mindist 1000) newhead)
|
|
(while al
|
|
(if (equal (cdar al) nlevel)
|
|
(progn
|
|
(setq dist (abs (- (length al) pos)))
|
|
(if (< dist mindist)
|
|
(setq newhead (car (car al))
|
|
mindist dist))))
|
|
(setq al (cdr al)))
|
|
newhead))
|
|
|
|
(defun reftex-toc-check-docstruct ()
|
|
"Check if the current docstruct is fully up to date and all files visited."
|
|
;; We do this by checking if all sections are on the right position
|
|
(let ((docstruct (symbol-value reftex-docstruct-symbol))
|
|
entry marker empoint)
|
|
(catch 'exit
|
|
(while (setq entry (pop docstruct))
|
|
(if (eq (car entry) 'toc)
|
|
(progn
|
|
(setq marker (nth 4 entry)
|
|
empoint (nth 8 entry))
|
|
(if (not (and (markerp marker)
|
|
(marker-buffer marker)
|
|
(= (marker-position marker) empoint)))
|
|
(throw 'exit nil)))))
|
|
t)))
|
|
|
|
(defun reftex-toc-load-all-files-for-promotion ()
|
|
"Make sure all files of the document are being visited by buffers,
|
|
and that the scanning info is absolutely up to date.
|
|
We do this by rescanning with `reftex-keep-temporary-buffers' bound to t.
|
|
The variable `reftex--pro-or-de' is assumed to be dynamically scoped into this function.
|
|
When finished, we exit with an error message."
|
|
(let ((reftex-keep-temporary-buffers t))
|
|
(reftex-toc-Rescan)
|
|
(reftex-toc-restore-region reftex--start-line reftex--mark-line)
|
|
(throw 'exit
|
|
"TOC had to be updated first. Please check selection and repeat the command.")))
|
|
|
|
(defun reftex-toc-rename-label ()
|
|
"Rename the currently selected label in the *toc* buffer.
|
|
This launches a global search and replace in order to rename a label.
|
|
Renaming a label is hardly ever necessary - the only exception is after
|
|
promotion/demotion in connection with a package like fancyref, where the
|
|
label prefix determines the wording of a reference."
|
|
(interactive)
|
|
(let* ((toc (get-text-property (point) :data))
|
|
(label (car toc)) newlabel)
|
|
(if (not (stringp label))
|
|
(error "This is not a label entry"))
|
|
(setq newlabel (read-string (format "Rename label \"%s\" to:" label)))
|
|
(if (assoc newlabel (symbol-value reftex-docstruct-symbol))
|
|
(if (not (y-or-n-p
|
|
(format-message "Label `%s' exists. Use anyway? " label)))
|
|
(error "Abort")))
|
|
(save-excursion
|
|
(save-window-excursion
|
|
(reftex-toc-visit-location t)
|
|
(condition-case nil
|
|
(reftex-query-replace-document
|
|
(concat "{" (regexp-quote label) "}")
|
|
(format "{%s}" newlabel))
|
|
(error t))))
|
|
(reftex-toc-rescan)))
|
|
|
|
|
|
(defun reftex-toc-visit-location (&optional final no-revisit)
|
|
;; Visit the tex file corresponding to the TOC entry on the current line.
|
|
;; If FINAL is t, stay there
|
|
;; If FINAL is 'hide, hide the TOC window.
|
|
;; Otherwise, move cursor back into TOC window.
|
|
;; NO-REVISIT means don't visit files, just use live buffers.
|
|
;; This function is pretty clever about finding back a section heading,
|
|
;; even if the buffer is not live, or things like outline, x-symbol etc.
|
|
;; have been active.
|
|
|
|
(let* ((toc (get-text-property (point) :data))
|
|
(toc-window (selected-window))
|
|
match)
|
|
|
|
(unless toc (error "Don't know which TOC line to visit"))
|
|
|
|
(cond
|
|
|
|
((eq (car toc) 'toc)
|
|
;; a toc entry
|
|
(setq match (reftex-toc-find-section toc no-revisit)))
|
|
|
|
((eq (car toc) 'index)
|
|
;; an index entry
|
|
(setq match (reftex-index-show-entry toc no-revisit)))
|
|
|
|
((memq (car toc) '(bof eof))
|
|
;; A file entry
|
|
(setq match
|
|
(let ((where (car toc))
|
|
(file (nth 1 toc)))
|
|
(if (or (not no-revisit) (reftex-get-buffer-visiting file))
|
|
(progn
|
|
(switch-to-buffer-other-window
|
|
(reftex-get-file-buffer-force file nil))
|
|
(goto-char (if (eq where 'bof) (point-min) (point-max))))
|
|
(message "%s" reftex-no-follow-message) nil))))
|
|
|
|
((stringp (car toc))
|
|
;; a label
|
|
(setq match (reftex-show-label-location toc reftex-callback-fwd
|
|
no-revisit t))))
|
|
|
|
(unless match
|
|
(select-window toc-window)
|
|
(error "Cannot find location"))
|
|
|
|
;; Use the `final' parameter to decide what to do next.
|
|
(cond
|
|
((eq final t)
|
|
(with-selected-window toc-window
|
|
(reftex-unhighlight 0)))
|
|
((eq final 'hide)
|
|
(let ((show-window (selected-window))
|
|
(show-buffer (window-buffer)))
|
|
(unless (eq show-window toc-window) ;FIXME: Can this happen?
|
|
(with-selected-window toc-window
|
|
(reftex-unhighlight 0)
|
|
(or (one-window-p) (delete-window))))
|
|
;; If `show-window' is still live, show-buffer is already visible
|
|
;; so let's not make it visible in yet-another-window.
|
|
(unless (window-live-p show-window)
|
|
;; FIXME: How could show-window not be live?
|
|
(switch-to-buffer show-buffer))
|
|
(reftex-re-enlarge)))
|
|
(t
|
|
(unless (eq (selected-frame) (window-frame toc-window))
|
|
;; Make sure `toc-window' is not just selected but has focus.
|
|
(select-frame-set-input-focus (window-frame toc-window)))
|
|
(select-window toc-window)))))
|
|
|
|
(defun reftex-toc-find-section (toc &optional no-revisit)
|
|
(let* ((file (nth 3 toc))
|
|
(marker (nth 4 toc))
|
|
(level (nth 5 toc))
|
|
(literal (nth 7 toc))
|
|
(emergency-point (nth 8 toc))
|
|
(match
|
|
(cond
|
|
((and (markerp marker) (marker-buffer marker))
|
|
;; Buffer is still live and we have the marker. Should be easy.
|
|
(switch-to-buffer-other-window (marker-buffer marker))
|
|
(push-mark nil)
|
|
(goto-char (marker-position marker))
|
|
(or (looking-at (regexp-quote literal))
|
|
(looking-at (reftex-make-regexp-allow-for-ctrl-m literal))
|
|
(looking-at (reftex-make-desperate-section-regexp literal))
|
|
(looking-at (concat "\\\\"
|
|
(regexp-quote
|
|
(car
|
|
(rassq level
|
|
reftex-section-levels-all)))
|
|
"[[{]?"))))
|
|
((or (not no-revisit)
|
|
(reftex-get-buffer-visiting file))
|
|
;; Marker is lost. Use the backup method.
|
|
(switch-to-buffer-other-window
|
|
(reftex-get-file-buffer-force file nil))
|
|
(goto-char (or emergency-point (point-min)))
|
|
(or (looking-at (regexp-quote literal))
|
|
(let ((len (length literal)))
|
|
(or (reftex-nearest-match (regexp-quote literal) len)
|
|
(reftex-nearest-match
|
|
(reftex-make-regexp-allow-for-ctrl-m literal) len)
|
|
(reftex-nearest-match
|
|
(reftex-make-desperate-section-regexp literal) len)))))
|
|
(t (message "%s" reftex-no-follow-message) nil))))
|
|
(when match
|
|
(goto-char (match-beginning 0))
|
|
(if (not (= (point) (point-max))) (recenter 1))
|
|
(reftex-highlight 0 (match-beginning 0) (match-end 0) (current-buffer)))
|
|
match))
|
|
|
|
(defun reftex-make-desperate-section-regexp (old)
|
|
;; Return a regexp which will still match a section statement even if
|
|
;; x-symbol or isotex or the like have been at work in the mean time.
|
|
(let* ((n (1+ (string-match "[[{]" old)))
|
|
(new (regexp-quote (substring old 0 (1+ (string-match "[[{]" old)))))
|
|
(old (substring old n)))
|
|
(while (string-match
|
|
"\\([\r\n]\\)\\|\\(\\`\\|[ \t\n\r]\\)\\([a-zA-Z0-9]+\\)\\([ \t\n\r]\\|}\\'\\)"
|
|
old)
|
|
(if (match-beginning 1)
|
|
(setq new (concat new "[^\n\r]*[\n\r]"))
|
|
(setq new (concat new "[^\n\r]*" (match-string 3 old))))
|
|
(setq old (substring old (match-end 0))))
|
|
new))
|
|
|
|
;; Auto recentering of TOC window
|
|
|
|
(defun reftex-recenter-toc-when-idle ()
|
|
(and (> (buffer-size) 5)
|
|
reftex-mode
|
|
(not (active-minibuffer-window))
|
|
(fboundp 'reftex-toc-mode)
|
|
(get-buffer-window "*toc*" 'visible)
|
|
(string= reftex-last-toc-master (reftex-TeX-master-file))
|
|
(let (current-prefix-arg)
|
|
(reftex-toc-recenter))))
|
|
|
|
;;;###autoload
|
|
(defun reftex-toggle-auto-toc-recenter ()
|
|
"Toggle the automatic recentering of the TOC window.
|
|
When active, leaving point idle will make the TOC window jump to the correct
|
|
section."
|
|
(interactive)
|
|
(if reftex-toc-auto-recenter-timer
|
|
(progn
|
|
(if (featurep 'xemacs)
|
|
(delete-itimer reftex-toc-auto-recenter-timer)
|
|
(cancel-timer reftex-toc-auto-recenter-timer))
|
|
(setq reftex-toc-auto-recenter-timer nil)
|
|
(message "Automatic recentering of TOC window was turned off"))
|
|
(setq reftex-toc-auto-recenter-timer
|
|
(if (featurep 'xemacs)
|
|
(start-itimer "RefTeX Idle Timer for recenter"
|
|
'reftex-recenter-toc-when-idle
|
|
reftex-idle-time reftex-idle-time t)
|
|
(run-with-idle-timer
|
|
reftex-idle-time t 'reftex-recenter-toc-when-idle)))
|
|
(message "Automatic recentering of TOC window was turned on")))
|
|
|
|
(defun reftex-toc-toggle-dedicated-frame ()
|
|
"Toggle the display of a separate frame for the TOC.
|
|
This frame is not used by the `reftex-toc' commands, but it is useful to
|
|
always show the current section in connection with the option
|
|
`reftex-auto-recenter-toc'."
|
|
(interactive)
|
|
(catch 'exit
|
|
(let* ((frames (frame-list)) frame
|
|
(get-frame-prop-func (if (fboundp 'frame-property)
|
|
'frame-property
|
|
'frame-parameter)))
|
|
(while (setq frame (pop frames))
|
|
(if (equal (funcall get-frame-prop-func frame 'name)
|
|
"RefTeX TOC Frame")
|
|
(progn
|
|
(delete-frame frame)
|
|
(throw 'exit nil))))
|
|
(reftex-make-separate-toc-frame))))
|
|
|
|
(defun reftex-make-separate-toc-frame ()
|
|
;; Create a new fame showing only the TOC buffer.
|
|
(let ((current-frame (selected-frame))
|
|
(current-window (selected-window))
|
|
(current-toc-window (get-buffer-window "*toc*" 'visible))
|
|
current-toc-frame)
|
|
(if (and current-toc-window
|
|
(not (equal (selected-frame) (window-frame current-toc-window))))
|
|
nil
|
|
(setq current-toc-frame
|
|
(make-frame
|
|
'((name . "RefTeX TOC Frame")
|
|
(height . 20) (width . 60)
|
|
(unsplittable . t)
|
|
(minibuffer . nil)
|
|
(default-toolbar-visible-p . nil)
|
|
(menubar-visible-p . nil)
|
|
(horizontal-scrollbar-visible-p . nil))))
|
|
(select-frame current-toc-frame)
|
|
(switch-to-buffer "*toc*")
|
|
(select-frame current-frame)
|
|
(cond ((fboundp 'x-focus-frame)
|
|
(x-focus-frame current-frame))
|
|
((and (featurep 'xemacs) ; `focus-frame' is a nop in Emacs.
|
|
(fboundp 'focus-frame))
|
|
(focus-frame current-frame)))
|
|
(select-window current-window)
|
|
(when (eq reftex-auto-recenter-toc 'frame)
|
|
(unless reftex-toc-auto-recenter-timer
|
|
(reftex-toggle-auto-toc-recenter))
|
|
(add-hook 'delete-frame-hook 'reftex-toc-delete-frame-hook)))))
|
|
|
|
(defun reftex-toc-delete-frame-hook (frame)
|
|
(if (and reftex-toc-auto-recenter-timer
|
|
(reftex-toc-dframe-p frame))
|
|
(progn
|
|
(reftex-toggle-auto-toc-recenter))))
|
|
|
|
;;; reftex-toc.el ends here
|
|
|
|
;; Local Variables:
|
|
;; generated-autoload-file: "reftex.el"
|
|
;; End:
|