(tex-font-lock-append-prop, tex-font-lock-suscript, tex-insert-quote)
[bpt/emacs.git] / lisp / textmodes / reftex-index.el
index e532bb1..c987ed8 100644 (file)
@@ -1,8 +1,9 @@
 ;;; reftex-index.el --- index support with RefTeX
-;; Copyright (c) 1997, 1998, 1999, 2000, 2003 Free Software Foundation, Inc.
+;; Copyright (c) 1997, 1998, 1999, 2000, 2003, 2004, 2005
+;;  Free Software Foundation, Inc.
 
 ;; Author: Carsten Dominik <dominik@science.uva.nl>
-;; Version: 4.21
+;; Version: VERSIONTAG
 
 ;; This file is part of GNU Emacs.
 
@@ -18,8 +19,8 @@
 
 ;; 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., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 
@@ -34,6 +35,7 @@
 (defvar mark-active)
 (defvar zmacs-regions)
 (defvar transient-mark-mode)
+(defvar TeX-master)
 ;; END remove for XEmacs release
 (defun reftex-index-selection-or-word (&optional arg phrase)
   "Put selection or the word near point into the default index macro.
@@ -164,13 +166,20 @@ will prompt for other arguments."
   ;; OPT-ARGS is a list of optional argument indices, as given by
   ;; `reftex-parse-args'.
   (let* ((opt (and (integerp itag) (member itag opt-args)))
-         (index-tags (cdr (assq 'index-tags 
-                                (symbol-value reftex-docstruct-symbol))))
-         (default (reftex-default-index))
-         (prompt (concat "Index tag"
-                         (if default (format " (default: %s)" default) "")
-                         (if opt " (optional)" "") ": "))
-         (tag (completing-read prompt (mapcar 'list index-tags))))
+        (index-tags (cdr (assq 'index-tags
+                               (symbol-value reftex-docstruct-symbol))))
+        (default (reftex-default-index))
+        (prompt (concat "Index tag"
+                        (if (or opt default)
+                            (format " (%s): "
+                                    (concat
+                                     (if opt "optional" "")
+                                     (if default
+                                         (concat (if opt ", " "")
+                                                 (format "default %s" default))
+                                       "")))
+                          ": ")))
+        (tag (completing-read prompt (mapcar 'list index-tags))))
     (if (and default (equal tag "")) (setq tag default))
     (reftex-update-default-index tag)
     tag))
@@ -360,7 +369,7 @@ _ ^        Add/Remove parent key (to make this item a subitem).
       (reftex-highlight 0 (match-beginning 0) (match-end 0) (current-buffer)))
     match))
 
-(defun reftex-display-index (&optional tag overriding-restriction
+(defun reftex-display-index (&optional tag overriding-restriction redo
                                        &rest locations)
   "Display a buffer with an index compiled from the current document.
 When the document has multiple indices, first prompts for the correct one.
@@ -387,7 +396,7 @@ With prefix 3, restrict index to region."
          (calling-file (buffer-file-name))
          (restriction
           (or overriding-restriction
-              (and (interactive-p
+              (and (not redo
                    (reftex-get-restriction current-prefix-arg docstruct))))
          (locations
           ;; See if we are on an index macro as initial position
@@ -427,7 +436,7 @@ With prefix 3, restrict index to region."
     (if restriction
         (setq reftex-index-restriction-indicator (car restriction)
               reftex-index-restriction-data (cdr restriction))
-      (if (interactive-p)
+      (if (not redo)
           (setq reftex-index-restriction-indicator nil
                 reftex-index-restriction-data nil)))
     (when (= (buffer-size) 0)
@@ -703,7 +712,7 @@ The function will go to the section where the entry at point was defined."
               (error "Don't know which file to rescan.  Try `C-u r'")
             (switch-to-buffer (reftex-get-file-buffer-force file))
             (setq current-prefix-arg '(4))
-            (reftex-display-index index-tag nil line)))
+            (reftex-display-index index-tag nil 'redo line)))
       (reftex-index-Rescan))
     (reftex-kill-temporary-buffers)))
 (defun reftex-index-Rescan (&rest ignore)
@@ -714,7 +723,7 @@ The function will go to the section where the entry at point was defined."
     (switch-to-buffer
      (reftex-get-file-buffer-force reftex-last-index-file))
     (setq current-prefix-arg '(16))
-    (reftex-display-index index-tag nil line)))
+    (reftex-display-index index-tag nil 'redo line)))
 (defun reftex-index-revert (&rest ignore)
   "Regenerate the *Index* from the internal lists.  No reparsing os done."
   (interactive)
@@ -727,14 +736,14 @@ The function will go to the section where the entry at point was defined."
     (reftex-erase-buffer buf)
     (setq current-prefix-arg nil
           reftex-last-follow-point 1)
-    (reftex-display-index index-tag nil data line)))
+    (reftex-display-index index-tag nil 'redo data line)))
 (defun reftex-index-switch-index-tag (&rest ignore)
   "Switch to a different index of the same document."
   (interactive)
   (switch-to-buffer
    (reftex-get-file-buffer-force reftex-last-index-file))
   (setq current-prefix-arg nil)
-  (reftex-display-index))
+  (reftex-display-index nil nil 'redo))
 
 (defun reftex-index-restrict-to-section (&optional force)
   "Restrict index to entries defined in same document sect. as entry at point."
@@ -928,7 +937,7 @@ When index is restricted, select the previous section as restriction criterion."
            (error "Not changed"))
           ((string= npart "")
            (if dont-allow-empty
-               (error "Illegal value")
+               (error "Invalid value")
              (setf (nth n analyze) npart)))
           (t (setf (nth n analyze) (concat initial npart))))
     (setq new (apply 'concat analyze))
@@ -1020,7 +1029,7 @@ When index is restricted, select the previous section as restriction criterion."
         (reftex-insert-index (list data) reftex-index-tag t
                              "EDITED")))
     (setq reftex-last-follow-point 1)
-    (and message (message message))))
+    (and message (message "%s" message))))
 
 ;; Index map
 (define-key reftex-index-map (if (featurep 'xemacs) [(button2)] [(mouse-2)])
@@ -1185,7 +1194,7 @@ You get a chance to edit the entry in the phrases buffer - finish with
   (set-marker reftex-index-return-marker (point))
   (reftex-index-selection-or-word arg 'phrase)
   (if (eq major-mode 'reftex-index-phrases-mode)
-      (message 
+      (message "%s" 
        (substitute-command-keys
         "Return to LaTeX with \\[reftex-index-phrases-save-and-return]"))))
 
@@ -1272,6 +1281,7 @@ If the buffer is non-empty, delete the old header first."
 
 
 (defvar reftex-index-phrases-menu)
+(defvar reftex-index-phrases-marker)
 (defvar reftex-index-phrases-restrict-file nil)
 ;;;###autoload
 (defun reftex-index-phrases-mode ()
@@ -1341,7 +1351,6 @@ Here are all local bindings.
        reftex-index-phrases-font-lock-defaults) ; XEmacs
   )
 
-(defvar reftex-index-phrases-marker)
 (defun reftex-index-next-phrase (&optional arg)
   "Index the next ARG phrases in the phrases buffer."
   (interactive "p")
@@ -1352,23 +1361,23 @@ Here are all local bindings.
     (if (re-search-forward reftex-index-phrases-phrase-regexp12 nil t)
         (progn
           (goto-char (match-beginning 0))
-          (reftex-index-this-phrase))
+          (reftex-index-this-phrase 'slave))
       (error "No more phrase lines after point"))))
 
-(defun reftex-index-this-phrase ()
+(defun reftex-index-this-phrase (&optional slave)
   "Index the phrase in the current line.
 Does a global search and replace in the entire document.  At each
 match, the user will be asked to confirm the replacement."
   (interactive)
-  (if (interactive-p) (reftex-index-phrases-parse-header t))
+  (if (not slave) (reftex-index-phrases-parse-header t))
   (save-excursion
     (beginning-of-line)
     (cond ((looking-at reftex-index-phrases-comment-regexp)
-           (if (interactive-p) (error "Comment line")))
+           (if (not slave) (error "Comment line")))
           ((looking-at "^[ \t]*$")
-           (if (interactive-p) (error "Empty line")))
+           (if (not slave) (error "Empty line")))
           ((looking-at reftex-index-phrases-macrodef-regexp)
-           (if (interactive-p) (error "Macro definition line")))
+           (if (not slave) (error "Macro definition line")))
           ((looking-at reftex-index-phrases-phrase-regexp12)
            ;; This is a phrase
            (let* ((char (if (not (equal (match-string 1) ""))
@@ -1385,7 +1394,7 @@ match, the user will be asked to confirm the replacement."
                                (file-regular-p reftex-index-phrases-restrict-file))
                           (list reftex-index-phrases-restrict-file))
                          ((stringp reftex-index-phrases-restrict-file)
-                          (error "Illegal restriction file %s"
+                          (error "Invalid restriction file %s"
                                  reftex-index-phrases-restrict-file))
                          (t reftex-index-phrases-files)))
                   (as-words reftex-index-phrases-search-whole-words))
@@ -1429,7 +1438,7 @@ Calls `reftex-index-this-phrase' on each line in the region."
   (goto-char beg)
   (while (not (or (eobp)
                   (>= (point) end)))
-    (save-excursion (reftex-index-this-phrase))
+    (save-excursion (reftex-index-this-phrase 'slave))
     (beginning-of-line 2)))
 
 (defun reftex-index-phrases-parse-header (&optional get-files)
@@ -1736,12 +1745,15 @@ With optional arg ALLOW-NEWLINE, allow single newline between words."
                        "\\([ \t]*\\(\n[ \t]*\\)?\\|[ \t]\\)"
                      "\\([ \t]+\\)")))
     (concat (if (and as-words (string-match "\\`\\w" (car words)))
-                "\\<" "")
-            (mapconcat (lambda (w) (regexp-quote (downcase w)))
+                "\\(\\<\\|[`']\\)" "")
+            (mapconcat (lambda (w) (regexp-quote 
+                                    (if reftex-index-phrases-case-fold-search
+                                        (downcase w)
+                                      w)))
                        words space-re)
             (if (and as-words 
                      (string-match "\\w\\'" (nth (1- (length words)) words)))
-                "\\>" ""))))
+                "\\(\\>\\|'\\)" ""))))
 
 (defun reftex-index-simplify-phrase (phrase)
   "Make phrase single spaces and single line."
@@ -1821,10 +1833,14 @@ both ends."
          (nkeys (length index-keys))
          (ckey (nth 0 index-keys))
          (all-yes nil) 
-         match rpl char beg end mathp)
+         match rpl char (beg (make-marker)) (end (make-marker)) mathp)
+    (move-marker beg 1)
+    (move-marker end 1)
     (unwind-protect
         (while (re-search-forward re nil t)
           (catch 'next-match
+            (if (reftex-in-comment)
+                (throw 'next-match nil))
             (if (and (fboundp reftex-index-verify-function)
                      (not (funcall reftex-index-verify-function)))
                 (throw 'next-match nil))
@@ -1832,8 +1848,8 @@ both ends."
             (setq mathp
                   (save-match-data
                     (condition-case nil (texmathp) (error nil))))
-            (setq beg (car (match-data))
-                  end (nth 1 (match-data)))
+            (setq beg (move-marker beg (match-beginning 0))
+                  end (move-marker end (match-end 0)))
             (if (and reftex-index-phrases-skip-indexed-matches
                      (save-match-data
                        (reftex-index-phrase-match-is-indexed beg
@@ -1901,7 +1917,7 @@ both ends."
                           ;; Recursive edit
                           (save-match-data
                             (save-excursion
-                              (message 
+                              (message "%s" 
                                (substitute-command-keys
                                 "Recursive edit.  Resume with \\[exit-recursive-edit]"))
                               (recursive-edit))))
@@ -1921,16 +1937,18 @@ both ends."
                          (t (ding)))
                    nil)))))
       (message "")
+      (move-marker beg nil)
+      (move-marker end nil)
       (setq all-yes nil)
       (reftex-unhighlight 0))))
 
 (defun reftex-index-phrase-match-is-indexed (beg end)
-  ;; CHeck if match is in an argument of an index macro, or if an
+  ;; Check if match is in an argument of an index macro, or if an
   ;; index macro is directly attached to the match.
   (save-excursion
     (goto-char end)
     (let* ((all-macros (reftex-what-macro t))
-           (this-macro (car (car all-macros)))
+;           (this-macro (car (car all-macros)))
            (before-macro
             (and (> beg 2)
                  (goto-char (1- beg))
@@ -2081,4 +2099,5 @@ Does not do a save-excursion."
    ["Save and Return" reftex-index-phrases-save-and-return t]))
 
 
+;;; arch-tag: 4b2362af-c156-42c1-8932-ea2823e205c1
 ;;; reftex-index.el ends here