;;; reftex-toc.el --- RefTeX's table of contents mode
-;; Copyright (C) 1997, 1998, 1999, 2000, 2003, 2004, 2005,
-;; 2006, 2007 Free Software Foundation, Inc.
+
+;; Copyright (C) 1997, 1998, 1999, 2000, 2003, 2004, 2005, 2006, 2007,
+;; 2008, 2009 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
+;; 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 2, or (at your option)
-;; any later version.
+;; 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
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
"Keymap used for *toc* buffer.")
(defvar reftex-toc-menu)
-(eval-when-compile (defvar zmacs-regions))
(defvar reftex-last-window-height nil)
(defvar reftex-last-window-width nil)
(defvar reftex-toc-include-labels-indicator nil)
mode-name "TOC")
(use-local-map reftex-toc-map)
(set (make-local-variable 'transient-mark-mode) t)
- (set (make-local-variable 'zmacs-regions) 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)
(frame-parameter (selected-frame) 'unsplittable)))
offset toc-window)
- (if (setq toc-window (get-buffer-window
+ (if (setq toc-window (get-buffer-window
"*toc*"
(if reuse 'visible)))
(select-window toc-window)
(split-window-horizontally
(floor (* (window-width)
reftex-toc-split-windows-fraction)))
- (split-window-vertically
+ (split-window-vertically
(floor (* (window-height)
reftex-toc-split-windows-fraction)))))
- (let ((default-major-mode 'reftex-toc-mode))
- (switch-to-buffer "*toc*")))
+ (switch-to-buffer "*toc*"))
(or (eq major-mode 'reftex-toc-mode) (reftex-toc-mode))
(set (make-local-variable 'reftex-docstruct-symbol) docstruct-symbol)
reftex-toc-include-context
nil ; counter
nil ; commented
- here-I-am
+ 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
reftex-toc-include-index-entries
reftex-toc-include-file-boundaries)
- (reftex-last-assoc-before-elt
+ (reftex-last-assoc-before-elt
'toc here-I-am
(symbol-value reftex-docstruct-symbol))))
(put 'reftex-toc :reftex-line 3)
- (goto-line 3)
- (beginning-of-line)))
+ (goto-char (point-min))
+ (forward-line 2)))
;; Find the correct starting point
(reftex-find-start-point (point) offset (get 'reftex-toc :reftex-line))
(not (get-text-property (point) 'intangible))
(memq reftex-highlight-selection '(cursor both))
(reftex-highlight 2
- (or (previous-single-property-change
+ (or (previous-single-property-change
(min (point-max) (1+ (point))) :data)
(point-min))
(or (next-single-property-change (point) :data)
(window-height))))))
(defun reftex-toc-dframe-p (&optional frame error)
- ;; Check if FRAME is the dedicated TOC frame.
+ ;; 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
+ (let ((res (equal
(if (fboundp 'frame-property)
(frame-property frame 'name)
(frame-parameter frame 'name))
(defun reftex-toc-next (&optional arg)
"Move to next selectable item."
(interactive "p")
- (if (boundp 'zmacs-region-stays) (setq zmacs-region-stays t))
+ (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)
+ (goto-char (or (next-single-property-change (point) :data)
(point))))
(defun reftex-toc-previous (&optional arg)
"Move to previous selectable item."
(interactive "p")
- (if (boundp 'zmacs-region-stays) (setq zmacs-region-stays t))
+ (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 contentes line."
(interactive "p")
- (if (boundp 'zmacs-region-stays) (setq zmacs-region-stays t))
+ (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 contentes line."
(interactive "p")
- (if (boundp 'zmacs-region-stays) (setq zmacs-region-stays t))
+ (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)."
With prefix ARG, prompt for a label type and include only labels of
that specific type."
(interactive "P")
- (setq reftex-toc-include-labels
+ (setq reftex-toc-include-labels
(if arg (reftex-query-label-type)
(not reftex-toc-include-labels)))
(reftex-toc-revert))
(defun reftex-toc-rescan (&rest ignore)
"Regenerate the *toc* buffer by reparsing file of section at point."
(interactive)
- (if (and reftex-enable-partial-scans
+ (if (and reftex-enable-partial-scans
(null current-prefix-arg))
(let* ((data (get-text-property (point) :data))
(what (car data))
(defun reftex-toc-revert (&rest ignore)
"Regenerate the *toc* from the internal lists."
(interactive)
- (let ((unsplittable
+ (let ((unsplittable
(if (fboundp 'frame-property)
(frame-property (selected-frame) 'unsplittable)
(frame-parameter (selected-frame) 'unsplittable)))
(goto-char start-pos)
(setq sections (reftex-toc-extract-section-number (car entries)))
(if (> (setq nsec (length entries)) 1)
- (setq sections
+ (setq sections
(concat sections "-"
(reftex-toc-extract-section-number
(nth (1- nsec) entries)))))
nil ; we have permission, do nothing
(error "Abort")) ; abort, we don't have permission
;; Do the changes
- (mapcar 'reftex-toc-promote-action entries)
+ (mapc 'reftex-toc-promote-action entries)
;; Rescan the document and rebuilt the toc buffer
(save-window-excursion
(reftex-toc-Rescan))
(reftex-toc-restore-region start-line mark-line)
- (message "%d section%s %smoted"
+ (message "%d section%s %smoted"
nsec (if (= 1 nsec) "" "s") pro-or-de)
nil))
- (if msg (progn (ding) (message msg)))))
+ (if msg (progn (ding) (message "%s" msg)))))
(defun reftex-toc-restore-region (point-line &optional mark-line)
- (if mark-line
- (progn (goto-line mark-line)
- (setq mpos (point))))
- (if point-line (goto-line point-line))
+ (when mark-line
+ (goto-char (point-min))
+ (forward-line (1- mark-line))
+ (setq mpos (point)))
+ (when point-line
+ (goto-char (point-min))
+ (forward-line (1- point-line)))
(if mark-line
(progn
(set-mark mpos)
- (if (fboundp 'zmacs-activate-region)
+ (if (featurep 'xemacs)
(zmacs-activate-region)
(setq mark-active t
deactivate-mark nil)))))
(beginning-of-line 1)
(if (looking-at reftex-section-regexp)
(setq name (reftex-match-string 2))
- (error "Something is wrong! Contact maintainer!")))
+ (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 loose the region.
(name (nth 1 x))
(newname (nth 2 x))
(marker (nth 4 data)))
- (save-excursion
- (set-buffer (marker-buffer marker))
+ (with-current-buffer (marker-buffer marker)
(goto-char (marker-position marker))
(if (looking-at (concat "\\([ \t]*\\\\\\)" (regexp-quote name)))
(replace-match (concat "\\1" newname))
(let* ((toc (get-text-property (point) :data))
(label (car toc)) newlabel)
(if (not (stringp label))
- (error "This is not a label entry."))
+ (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
+ (if (not (y-or-n-p
(format "Label '%s' exists. Use anyway? " label)))
(error "Abort")))
(save-excursion
(reftex-query-replace-document
(concat "{" (regexp-quote label) "}")
(format "{%s}" newlabel))
- (error t))))
+ (error t))))
(reftex-toc-rescan)))
show-window show-buffer 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)))
(file (nth 1 toc)))
(if (or (not no-revisit) (reftex-get-buffer-visiting file))
(progn
- (switch-to-buffer-other-window
+ (switch-to-buffer-other-window
(reftex-get-file-buffer-force file nil))
(goto-char (if (eq where 'bof) (point-min) (point-max))))
- (message reftex-no-follow-message) nil))))
+ (message "%s" reftex-no-follow-message) nil))))
((stringp (car toc))
;; a label
(looking-at (reftex-make-desperate-section-regexp literal))
(looking-at (concat "\\\\"
(regexp-quote
- (car
- (rassq level
+ (car
+ (rassq level
reftex-section-levels-all)))
"[[{]?"))))
((or (not no-revisit)
(reftex-make-regexp-allow-for-ctrl-m literal) len)
(reftex-nearest-match
(reftex-make-desperate-section-regexp literal) len)))))
- (t (message reftex-no-follow-message) nil))))
+ (t (message "%s" reftex-no-follow-message) nil))))
(when match
(goto-char (match-beginning 0))
(if (not (= (point) (point-max))) (recenter 1))
(select-frame current-toc-frame)
(switch-to-buffer "*toc*")
(select-frame current-frame)
- (if (fboundp 'focus-frame) (focus-frame current-frame)
- (if (fboundp 'x-focus-frame) (x-focus-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
(define-key reftex-toc-map (vector (list key)) 'digit-argument))
(define-key reftex-toc-map "-" 'negative-argument)
-(easy-menu-define
+(easy-menu-define
reftex-toc-menu reftex-toc-map
"Menu for Table of Contents buffer"
'("TOC"
["Context" reftex-toc-toggle-context :style toggle
:selected reftex-toc-include-context]
"--"
- ["Follow Mode" reftex-toc-toggle-follow :style toggle
+ ["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]
["Help" reftex-toc-show-help t]))
-;;; arch-tag: 92400ce2-0b86-4c89-a606-4ed71acea17e
+;; arch-tag: 92400ce2-0b86-4c89-a606-4ed71acea17e
;;; reftex-toc.el ends here