]> code.delx.au - gnu-emacs/blobdiff - lisp/textmodes/reftex-toc.el
Merge from mainline.
[gnu-emacs] / lisp / textmodes / reftex-toc.el
index 41ea83b077f7539410a4d1ef946d3c6a19e93f2b..a5f1e3d4f6b2a9a394cf0e4ce82e1eaee15ddafb 100644 (file)
@@ -1,7 +1,7 @@
 ;;; reftex-toc.el --- RefTeX's table of contents mode
 
 ;; Copyright (C) 1997, 1998, 1999, 2000, 2003, 2004, 2005, 2006, 2007,
-;;   2008, 2009, 2010  Free Software Foundation, Inc.
+;;   2008, 2009, 2010, 2011  Free Software Foundation, Inc.
 
 ;; Author: Carsten Dominik <dominik@science.uva.nl>
 ;; Maintainer: auctex-devel@gnu.org
 (require 'reftex)
 ;;;
 
-(defvar reftex-toc-map (make-sparse-keymap)
+(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.")
+(define-obsolete-variable-alias 'reftex-toc-map 'reftex-toc-mode-map "24.1")
 
 (defvar reftex-toc-menu)
 (defvar reftex-last-window-height nil)
 (defvar reftex-toc-include-index-indicator nil)
 (defvar reftex-toc-max-level-indicator nil)
 
-(defun reftex-toc-mode ()
+(define-derived-mode reftex-toc-mode fundamental-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-map}"
-  (interactive)
-  (kill-all-local-variables)
-  (setq major-mode 'reftex-toc-mode
-        mode-name "TOC")
-  (use-local-map reftex-toc-map)
+\\{reftex-toc-mode-map}"
   (set (make-local-variable 'transient-mark-mode) t)
   (when (featurep 'xemacs)
     (set (make-local-variable 'zmacs-regions) t))
@@ -79,8 +164,7 @@ Here are all local bindings.
   (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-map)
-  (run-hooks 'reftex-toc-mode-hook))
+  (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.")
@@ -545,8 +629,6 @@ Useful for large TOC's."
 
 ;; Promotion/Demotion stuff
 
-(defvar delta)
-(defvar mpos)
 (defvar pro-or-de)
 (defvar start-pos)
 (defvar start-line)
@@ -575,7 +657,7 @@ point."
                                            (if (bolp) 1 0)))))
          (start-pos (point))
          (pro-or-de (if (> delta 0) "de" "pro"))
-         beg end entries data sections nsec mpos msg)
+         beg end entries data sections nsec msg)
     (setq msg
           (catch 'exit
             (if (reftex-region-active-p)
@@ -602,7 +684,9 @@ point."
                               (reftex-toc-extract-section-number
                                (nth (1- nsec) entries)))))
             ;; Run through the list and prepare the changes.
-            (setq entries (mapcar 'reftex-toc-promote-prepare entries))
+            (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
@@ -629,31 +713,26 @@ point."
 
 
 (defun reftex-toc-restore-region (point-line &optional mark-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 (featurep 'xemacs)
-            (zmacs-activate-region)
-          (setq mark-active t
-                deactivate-mark nil)))))
-
-(defvar name1)
-(defvar dummy)
-(defvar dummy2)
-
-(defun reftex-toc-promote-prepare (x)
+  (let (mpos)
+    (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)))
+    (when mark-line
+      (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.
-Expects the level change DELTA to be dynamically scoped into this function.
 This function prepares everything for the changes, but does not do it.
 The return value is a list with information needed when doing the
-promotion/demotion later."
+promotion/demotion later.  DELTA is the level change."
   (let* ((data (car x))
          (toc-point (cdr x))
          (marker (nth 4 data))
@@ -678,7 +757,7 @@ promotion/demotion later."
                           (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.
+                    ;; 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
@@ -689,7 +768,6 @@ promotion/demotion later."
                     (progn
                       (goto-char toc-point)
                       (error "Cannot %smote special sections" pro-or-de))))
-         ;; Delta is dynamically scoped into here...
          (newlevel (if (>= level 0) (+ delta level) (- level delta)))
          (dummy2 (if (or (and (>= level 0) (= newlevel -1))
                          (and (< level 0)  (= newlevel 0)))
@@ -703,7 +781,7 @@ promotion/demotion later."
 
 (defun reftex-toc-promote-action (x)
   "Change the level of a toc entry.
-DELTA and PRO-OR-DE are assumed to be dynamically scoped into this function."
+PRO-OR-DE is assumed to be dynamically scoped into this function."
   (let* ((data (car x))
          (name (nth 1 x))
          (newname (nth 2 x))
@@ -1012,93 +1090,4 @@ always show the current section in connection with the option
       (progn
       (reftex-toggle-auto-toc-recenter))))
 
-;; Table of Contents map
-(define-key reftex-toc-map (if (featurep 'xemacs) [(button2)] [(mouse-2)])
-  'reftex-toc-mouse-goto-line-and-hide)
-(define-key reftex-toc-map [follow-link] 'mouse-face)
-
-(substitute-key-definition
- 'next-line 'reftex-toc-next reftex-toc-map global-map)
-(substitute-key-definition
- 'previous-line 'reftex-toc-previous reftex-toc-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 reftex-toc-map (car x) (cdr x)))
-
-(loop for key across "0123456789" do
-      (define-key reftex-toc-map (vector (list key)) 'digit-argument))
-(define-key reftex-toc-map "-" 'negative-argument)
-
-(easy-menu-define
- reftex-toc-menu reftex-toc-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]))
-
-
-;; arch-tag: 92400ce2-0b86-4c89-a606-4ed71acea17e
 ;;; reftex-toc.el ends here