/[emacs]/emacs/lisp/textmodes/reftex-index.el
ViewVC logotype

Diff of /emacs/lisp/textmodes/reftex-index.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.26 by lektu, Wed Aug 31 10:34:07 2005 UTC revision 1.27 by cdominik, Fri Sep 16 10:01:33 2005 UTC
# Line 1  Line 1 
1  ;;; reftex-index.el --- index support with RefTeX  ;;; reftex-index.el --- index support with RefTeX
2    ;; Copyright (c) 1997, 1998, 1999, 2000, 2003, 2004, 2005
3  ;; Copyright (C) 1997, 1998, 1999, 2000, 2002, 2003, 2004,  ;;  Free Software Foundation, Inc.
 ;;   2005 Free Software Foundation, Inc.  
4    
5  ;; Author: Carsten Dominik <dominik@science.uva.nl>  ;; Author: Carsten Dominik <dominik@science.uva.nl>
6  ;; Version: 4.28  ;; Version: VERSIONTAG
7    
8  ;; This file is part of GNU Emacs.  ;; This file is part of GNU Emacs.
9    
# Line 20  Line 19 
19    
20  ;; You should have received a copy of the GNU General Public License  ;; You should have received a copy of the GNU General Public License
21  ;; along with GNU Emacs; see the file COPYING.  If not, write to the  ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22  ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,  ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23  ;; Boston, MA 02110-1301, USA.  ;; Boston, MA 02111-1307, USA.
24    
25  ;;; Commentary:  ;;; Commentary:
26    
# Line 32  Line 31 
31  (require 'reftex)  (require 'reftex)
32  ;;;  ;;;
33    
 (defvar reftex-index-phrases-marker)  
 (defvar TeX-master)  
   
34  ;; START remove for XEmacs release  ;; START remove for XEmacs release
35  (defvar mark-active)  (defvar mark-active)
36  (defvar zmacs-regions)  (defvar zmacs-regions)
37  (defvar transient-mark-mode)  (defvar transient-mark-mode)
38    (defvar TeX-master)
39  ;; END remove for XEmacs release  ;; END remove for XEmacs release
40  (defun reftex-index-selection-or-word (&optional arg phrase)  (defun reftex-index-selection-or-word (&optional arg phrase)
41    "Put selection or the word near point into the default index macro.    "Put selection or the word near point into the default index macro.
# Line 56  which is part of AUCTeX, the string is f Line 53  which is part of AUCTeX, the string is f
53           (active (if (boundp 'zmacs-regions)           (active (if (boundp 'zmacs-regions)
54                       (and zmacs-regions (region-exists-p))  ; XEmacs                       (and zmacs-regions (region-exists-p))  ; XEmacs
55                     (and transient-mark-mode mark-active)))  ; Emacs                     (and transient-mark-mode mark-active)))  ; Emacs
56           (beg (if active           (beg (if active
57                    (region-beginning)                    (region-beginning)
58                  (save-excursion                  (save-excursion
59                    (skip-syntax-backward "w\\") (point))))                    (skip-syntax-backward "w\\") (point))))
60           (end (if active           (end (if active
61                    (region-end)                    (region-end)
62                  (save-excursion                  (save-excursion
63                    (skip-syntax-forward "w\\") (point))))                    (skip-syntax-forward "w\\") (point))))
64           (sel (buffer-substring beg end))           (sel (buffer-substring beg end))
65           (mathp (condition-case nil (texmathp) (error nil)))           (mathp (condition-case nil (texmathp) (error nil)))
# Line 93  which is part of AUCTeX, the string is f Line 90  which is part of AUCTeX, the string is f
90          ;; Delete what is in the buffer and make the index entry          ;; Delete what is in the buffer and make the index entry
91          (delete-region beg end)          (delete-region beg end)
92          (reftex-index def-char full-entry def-tag sel)))))          (reftex-index def-char full-entry def-tag sel)))))
93      
94  (defun reftex-index (&optional char key tag sel no-insert)  (defun reftex-index (&optional char key tag sel no-insert)
95    "Query for an index macro and insert it along with its argments.    "Query for an index macro and insert it along with its argments.
96  The index macros available are those defined in `reftex-index-macro' or  The index macros available are those defined in `reftex-index-macro' or
# Line 169  will prompt for other arguments." Line 166  will prompt for other arguments."
166    ;; OPT-ARGS is a list of optional argument indices, as given by    ;; OPT-ARGS is a list of optional argument indices, as given by
167    ;; `reftex-parse-args'.    ;; `reftex-parse-args'.
168    (let* ((opt (and (integerp itag) (member itag opt-args)))    (let* ((opt (and (integerp itag) (member itag opt-args)))
169           (index-tags (cdr (assq 'index-tags           (index-tags (cdr (assq 'index-tags
170                                  (symbol-value reftex-docstruct-symbol))))                                  (symbol-value reftex-docstruct-symbol))))
171           (default (reftex-default-index))           (default (reftex-default-index))
172           (prompt (concat "Index tag"           (prompt (concat "Index tag"
# Line 183  will prompt for other arguments." Line 180  will prompt for other arguments."
180  (defun reftex-index-select-tag ()  (defun reftex-index-select-tag ()
181    ;; Have the user select an index tag.    ;; Have the user select an index tag.
182    ;; FIXME: should we cache tag-alist, prompt and help?    ;; FIXME: should we cache tag-alist, prompt and help?
183    (let* ((index-tags (cdr (assoc 'index-tags    (let* ((index-tags (cdr (assoc 'index-tags
184                                   (symbol-value reftex-docstruct-symbol))))                                   (symbol-value reftex-docstruct-symbol))))
185           (default (reftex-default-index)))           (default (reftex-default-index)))
186      (cond      (cond
187       ((null index-tags)       ((null index-tags)
188        (error "No index tags available"))        (error "No index tags available"))
189    
190       ((= (length index-tags) 1)       ((= (length index-tags) 1)
191        ;; Just one index, use it        ;; Just one index, use it
192        (car index-tags))        (car index-tags))
193              
194       ((> (length index-tags) 1)       ((> (length index-tags) 1)
195        ;; Several indices, ask.        ;; Several indices, ask.
196        (let* ((tags (copy-sequence index-tags))        (let* ((tags (copy-sequence index-tags))
# Line 214  will prompt for other arguments." Line 211  will prompt for other arguments."
211                (unless (assq (aref tag i) tag-alist)                (unless (assq (aref tag i) tag-alist)
212                  (push (list (aref tag i)                  (push (list (aref tag i)
213                              tag                              tag
214                              (concat (substring tag 0 i)                              (concat (substring tag 0 i)
215                                      "[" (substring tag i (incf i)) "]"                                      "[" (substring tag i (incf i)) "]"
216                                      (substring tag i)))                                      (substring tag i)))
217                        tag-alist)                        tag-alist)
218                  (throw 'exit t)))                  (throw 'exit t)))
219              (push (list (+ ?0 (incf cnt)) tag              (push (list (+ ?0 (incf cnt)) tag
220                          (concat "[" (int-to-string cnt) "]:" tag))                          (concat "[" (int-to-string cnt) "]:" tag))
221                    tag-alist)))                    tag-alist)))
222          (setq tag-alist (nreverse tag-alist))          (setq tag-alist (nreverse tag-alist))
# Line 234  will prompt for other arguments." Line 231  will prompt for other arguments."
231                        (if default                        (if default
232                            (format "[^M]  %s (the default)\n" default)                            (format "[^M]  %s (the default)\n" default)
233                          "")                          "")
234                        (mapconcat (lambda(x)                        (mapconcat (lambda(x)
235                                     (apply 'format "[%c]   %s" x))                                     (apply 'format "[%c]   %s" x))
236                                   tag-alist "\n")))                                   tag-alist "\n")))
237          ;; Query the user for an index-tag          ;; Query the user for an index-tag
# Line 263  will prompt for other arguments." Line 260  will prompt for other arguments."
260      key))      key))
261    
262  (defun reftex-index-update-taglist (newtag)  (defun reftex-index-update-taglist (newtag)
263    ;; add NEWTAG to the list of available index tags.    ;; add NEWTAG to the list of available index tags.
264    (let ((cell (assoc 'index-tags (symbol-value reftex-docstruct-symbol))))    (let ((cell (assoc 'index-tags (symbol-value reftex-docstruct-symbol))))
265      (and newtag (cdr cell) (not (member newtag (cdr cell)))      (and newtag (cdr cell) (not (member newtag (cdr cell)))
266           (push newtag (cdr cell)))))           (push newtag (cdr cell)))))
# Line 314  Here are all local bindings. Line 311  Here are all local bindings.
311    (easy-menu-add reftex-index-menu reftex-index-map)    (easy-menu-add reftex-index-menu reftex-index-map)
312    (add-hook 'post-command-hook 'reftex-index-post-command-hook nil t)    (add-hook 'post-command-hook 'reftex-index-post-command-hook nil t)
313    (add-hook 'pre-command-hook  'reftex-index-pre-command-hook nil t)    (add-hook 'pre-command-hook  'reftex-index-pre-command-hook nil t)
314    (run-mode-hooks 'reftex-index-mode-hook))    (run-hooks 'reftex-index-mode-hook))
315    
316  (defconst reftex-index-help  (defconst reftex-index-help
317  "                      AVAILABLE KEYS IN INDEX BUFFER  "                      AVAILABLE KEYS IN INDEX BUFFER
# Line 344  _ ^        Add/Remove parent key (to mak Line 341  _ ^        Add/Remove parent key (to mak
341    ;; Note:  This function just looks for the nearest match of the    ;; Note:  This function just looks for the nearest match of the
342    ;; context string and may fail if the entry moved and an identical    ;; context string and may fail if the entry moved and an identical
343    ;; entry is close to the old position.  Frequent rescans make this    ;; entry is close to the old position.  Frequent rescans make this
344    ;; safer.    ;; safer.
345    (let* ((file (nth 3 data))    (let* ((file (nth 3 data))
346           (literal (nth 2 data))           (literal (nth 2 data))
347           (pos (nth 4 data))           (pos (nth 4 data))
# Line 392  With prefix 3, restrict index to region. Line 389  With prefix 3, restrict index to region.
389           (calling-file (buffer-file-name))           (calling-file (buffer-file-name))
390           (restriction           (restriction
391            (or overriding-restriction            (or overriding-restriction
392                (and (not redo)                (and (not redo)
393                     (reftex-get-restriction current-prefix-arg docstruct))))                     (reftex-get-restriction current-prefix-arg docstruct))))
394           (locations           (locations
395            ;; See if we are on an index macro as initial position            ;; See if we are on an index macro as initial position
# Line 401  With prefix 3, restrict index to region. Line 398  With prefix 3, restrict index to region.
398                       (macro (car what-macro))                       (macro (car what-macro))
399                       (here-I-am (when (member macro reftex-macros-with-index)                       (here-I-am (when (member macro reftex-macros-with-index)
400                                    (save-excursion                                    (save-excursion
401                                      (goto-char (+ (cdr what-macro)                                      (goto-char (+ (cdr what-macro)
402                                                    (length macro)))                                                    (length macro)))
403                                      (reftex-move-over-touching-args)                                      (reftex-move-over-touching-args)
404                                      (reftex-where-am-I)))))                                      (reftex-where-am-I)))))
# Line 412  With prefix 3, restrict index to region. Line 409  With prefix 3, restrict index to region.
409      (setq buffer-name (reftex-make-index-buffer-name index-tag))      (setq buffer-name (reftex-make-index-buffer-name index-tag))
410    
411      ;; Goto the buffer and put it into the correct mode      ;; Goto the buffer and put it into the correct mode
412                          
413      (when (or restriction current-prefix-arg)      (when (or restriction current-prefix-arg)
414           (reftex-kill-buffer buffer-name))           (reftex-kill-buffer buffer-name))
415    
# Line 505  SPC=view TAB=goto RET=goto+hide [e]dit [ Line 502  SPC=view TAB=goto RET=goto+hide [e]dit [
502        ;; Delete the entry at place        ;; Delete the entry at place
503        (and (bolp) (forward-char 1))        (and (bolp) (forward-char 1))
504        (delete-region (previous-single-property-change (1+ (point)) :data)        (delete-region (previous-single-property-change (1+ (point)) :data)
505                       (or (next-single-property-change (point) :data)                       (or (next-single-property-change (point) :data)
506                           (point-max))))                           (point-max))))
507    
508      ;; Walk through the list and insert all entries      ;; Walk through the list and insert all entries
# Line 526  SPC=view TAB=goto RET=goto+hide [e]dit [ Line 523  SPC=view TAB=goto RET=goto+hide [e]dit [
523        (insert indent (nth 7 cell))        (insert indent (nth 7 cell))
524        (when font        (when font
525          (setq to (point))          (setq to (point))
526          (put-text-property          (put-text-property
527           (- (point) (length (nth 7 cell))) to           (- (point) (length (nth 7 cell))) to
528           'face index-face)           'face index-face)
529          (goto-char to))          (goto-char to))
# Line 554  SPC=view TAB=goto RET=goto+hide [e]dit [ Line 551  SPC=view TAB=goto RET=goto+hide [e]dit [
551  (defun reftex-index-insert-new-letter (letter &optional font)  (defun reftex-index-insert-new-letter (letter &optional font)
552    ;; Start a new section in the index    ;; Start a new section in the index
553    (let ((from (point)))    (let ((from (point)))
554      (insert "\n" letter letter letter      (insert "\n" letter letter letter
555              "-----------------------------------------------------------------")              "-----------------------------------------------------------------")
556      (when font      (when font
557        (put-text-property from (point) 'face reftex-index-section-face))        (put-text-property from (point) 'face reftex-index-section-face))
# Line 631  SPC=view TAB=goto RET=goto+hide [e]dit [ Line 628  SPC=view TAB=goto RET=goto+hide [e]dit [
628    (interactive "p")    (interactive "p")
629    (setq reftex-callback-fwd t)    (setq reftex-callback-fwd t)
630    (or (eobp) (forward-char 1))    (or (eobp) (forward-char 1))
631    (goto-char (or (next-single-property-change (point) :data)    (goto-char (or (next-single-property-change (point) :data)
632                   (point)))                   (point)))
633    (unless (get-text-property (point) :data)    (unless (get-text-property (point) :data)
634      (goto-char (or (next-single-property-change (point) :data)      (goto-char (or (next-single-property-change (point) :data)
635                     (point)))))                     (point)))))
636  (defun reftex-index-previous (&optional arg)  (defun reftex-index-previous (&optional arg)
637    "Move to previous selectable item."    "Move to previous selectable item."
# Line 777  When index is restricted, select the nex Line 774  When index is restricted, select the nex
774          (reftex-index-restrict-to-section t)          (reftex-index-restrict-to-section t)
775        (setq reftex-index-restriction-indicator (nth 6 bor)        (setq reftex-index-restriction-indicator (nth 6 bor)
776              reftex-index-restriction-data              reftex-index-restriction-data
777              (list bor              (list bor
778                    (car (memq (assq 'toc (cdr (memq bor docstruct)))                    (car (memq (assq 'toc (cdr (memq bor docstruct)))
779                               docstruct))))                               docstruct))))
780        (reftex-index-revert))))        (reftex-index-revert))))
# Line 809  When index is restricted, select the pre Line 806  When index is restricted, select the pre
806           show-window show-buffer match)           show-window show-buffer match)
807    
808      (unless data (error "Don't know which index entry to visit"))      (unless data (error "Don't know which index entry to visit"))
809        
810      (if (eq (car data) 'index)      (if (eq (car data) 'index)
811          (setq match (reftex-index-show-entry data no-revisit)))          (setq match (reftex-index-show-entry data no-revisit)))
812    
# Line 880  When index is restricted, select the pre Line 877  When index is restricted, select the pre
877            attr (nth 2 analyze))            attr (nth 2 analyze))
878      (setf (nth 2 analyze) (if (string= attr bor) "" bor))      (setf (nth 2 analyze) (if (string= attr bor) "" bor))
879      (setq new (apply 'concat analyze))      (setq new (apply 'concat analyze))
880      (reftex-index-change-entry      (reftex-index-change-entry
881       new (if (string= (nth 2 analyze) bor)       new (if (string= (nth 2 analyze) bor)
882               "Entry is now START-OF-PAGE-RANGE"               "Entry is now START-OF-PAGE-RANGE"
883             "START-OF-PAGE-RANGE canceled"))))             "START-OF-PAGE-RANGE canceled"))))
# Line 938  When index is restricted, select the pre Line 935  When index is restricted, select the pre
935            (t (setf (nth n analyze) (concat initial npart))))            (t (setf (nth n analyze) (concat initial npart))))
936      (setq new (apply 'concat analyze))      (setq new (apply 'concat analyze))
937      ;; Change the entry and insert the changed version into the index.      ;; Change the entry and insert the changed version into the index.
938      (reftex-index-change-entry      (reftex-index-change-entry
939       new (if (string= npart "")       new (if (string= npart "")
940               (format "Deleted: %s" opart)               (format "Deleted: %s" opart)
941             (format "New value is: %s" npart)))))             (format "New value is: %s" npart)))))
# Line 952  When index is restricted, select the pre Line 949  When index is restricted, select the pre
949      (unless data (error "Don't know which index entry to change"))      (unless data (error "Don't know which index entry to change"))
950      (setq old (nth 2 data)      (setq old (nth 2 data)
951            key (nth 6 data)            key (nth 6 data)
952            prefix (completing-read            prefix (completing-read
953                    "Prefix: "                    "Prefix: "
954                    (reftex-sublist-nth                    (reftex-sublist-nth
955                     docstruct 6                     docstruct 6
956                     (lambda (x)                     (lambda (x)
957                       (and (eq (car x) 'index)                       (and (eq (car x) 'index)
958                            (string= (nth 1 x) reftex-index-tag))) t)))                            (string= (nth 1 x) reftex-index-tag))) t)))
959      (unless (string-match      (unless (string-match
960               (concat (regexp-quote (car reftex-index-special-chars)) "\\'")               (concat (regexp-quote (car reftex-index-special-chars)) "\\'")
961               prefix)               prefix)
962        (setq prefix (concat prefix (car reftex-index-special-chars))))        (setq prefix (concat prefix (car reftex-index-special-chars))))
# Line 999  When index is restricted, select the pre Line 996  When index is restricted, select the pre
996  (defun reftex-index-change-entry (new &optional message)  (defun reftex-index-change-entry (new &optional message)
997    ;; Change the full context string of the index entry at point to    ;; Change the full context string of the index entry at point to
998    ;; NEW.  This actually edits the buffer where the entry is defined.    ;; NEW.  This actually edits the buffer where the entry is defined.
999      
1000    (let* ((data (get-text-property (point) :data))    (let* ((data (get-text-property (point) :data))
1001           old beg end info)           old beg end info)
1002      (unless data (error "Cannot change entry"))      (unless data (error "Cannot change entry"))
# Line 1091  When index is restricted, select the pre Line 1088  When index is restricted, select the pre
1088        (if (eq char ?!)        (if (eq char ?!)
1089            (error "This <%s> index does not contain entries sorted before the letters"            (error "This <%s> index does not contain entries sorted before the letters"
1090                   reftex-index-tag)                   reftex-index-tag)
1091          (error "This <%s> index does not contain entries starting with `%c'"          (error "This <%s> index does not contain entries starting with `%c'"
1092                 reftex-index-tag char)))))                 reftex-index-tag char)))))
1093    
1094  (easy-menu-define  (easy-menu-define
1095   reftex-index-menu reftex-index-map   reftex-index-menu reftex-index-map
1096   "Menu for Index buffer"   "Menu for Index buffer"
1097   `("Index"   `("Index"
1098     ["Goto section A-Z"     ["Goto section A-Z"
1099      (message "To go to a section, just press any of: !%s"      (message "To go to a section, just press any of: !%s"
1100               reftex-index-section-letters) t]               reftex-index-section-letters) t]
1101     ["Show Entry" reftex-index-view-entry t]     ["Show Entry" reftex-index-view-entry t]
# Line 1138  When index is restricted, select the pre Line 1135  When index is restricted, select the pre
1135      ["Context" reftex-index-toggle-context :style toggle      ["Context" reftex-index-toggle-context :style toggle
1136       :selected reftex-index-include-context]       :selected reftex-index-include-context]
1137      "--"      "--"
1138      ["Follow Mode" reftex-index-toggle-follow :style toggle      ["Follow Mode" reftex-index-toggle-follow :style toggle
1139       :selected reftex-index-follow-mode])       :selected reftex-index-follow-mode])
1140     "--"     "--"
1141     ["Help" reftex-index-show-help t]))     ["Help" reftex-index-show-help t]))
# Line 1190  You get a chance to edit the entry in th Line 1187  You get a chance to edit the entry in th
1187    (set-marker reftex-index-return-marker (point))    (set-marker reftex-index-return-marker (point))
1188    (reftex-index-selection-or-word arg 'phrase)    (reftex-index-selection-or-word arg 'phrase)
1189    (if (eq major-mode 'reftex-index-phrases-mode)    (if (eq major-mode 'reftex-index-phrases-mode)
1190        (message        (message
1191         (substitute-command-keys         (substitute-command-keys
1192          "Return to LaTeX with \\[reftex-index-phrases-save-and-return]"))))          "Return to LaTeX with \\[reftex-index-phrases-save-and-return]"))))
1193    
# Line 1219  If the buffer is non-empty, delete the o Line 1216  If the buffer is non-empty, delete the o
1216            (sort (copy-sequence reftex-index-macro-alist)            (sort (copy-sequence reftex-index-macro-alist)
1217                  (lambda (a b) (equal (car a) default-macro))))                  (lambda (a b) (equal (car a) default-macro))))
1218           macro entry key repeat)           macro entry key repeat)
1219        
1220      (if master (set (make-local-variable 'TeX-master)      (if master (set (make-local-variable 'TeX-master)
1221                      (file-name-nondirectory master)))                      (file-name-nondirectory master)))
1222    
# Line 1232  If the buffer is non-empty, delete the o Line 1229  If the buffer is non-empty, delete the o
1229        (if (looking-at reftex-index-phrases-comment-regexp)        (if (looking-at reftex-index-phrases-comment-regexp)
1230            (beginning-of-line 2))            (beginning-of-line 2))
1231        (while (looking-at "^[ \t]*$")        (while (looking-at "^[ \t]*$")
1232            (beginning-of-line 2))            (beginning-of-line 2))          
1233        (cond ((fboundp 'zmacs-activate-region) (zmacs-activate-region))        (cond ((fboundp 'zmacs-activate-region) (zmacs-activate-region))
1234              ((boundp 'make-active) (setq mark-active t)))              ((boundp 'make-active) (setq mark-active t)))
1235        (if (yes-or-no-p "Delete and rebuilt header ")        (if (yes-or-no-p "Delete and rebuilt header ")
# Line 1277  If the buffer is non-empty, delete the o Line 1274  If the buffer is non-empty, delete the o
1274    
1275    
1276  (defvar reftex-index-phrases-menu)  (defvar reftex-index-phrases-menu)
1277    (defvar reftex-index-phrases-marker)
1278  (defvar reftex-index-phrases-restrict-file nil)  (defvar reftex-index-phrases-restrict-file nil)
1279  ;;;###autoload  ;;;###autoload
1280  (defun reftex-index-phrases-mode ()  (defun reftex-index-phrases-mode ()
# Line 1308  Here are all local bindings. Line 1306  Here are all local bindings.
1306    (setq major-mode 'reftex-index-phrases-mode    (setq major-mode 'reftex-index-phrases-mode
1307          mode-name "Phrases")          mode-name "Phrases")
1308    (use-local-map reftex-index-phrases-map)    (use-local-map reftex-index-phrases-map)
1309    (set (make-local-variable 'font-lock-defaults)    (set (make-local-variable 'font-lock-defaults)
1310         reftex-index-phrases-font-lock-defaults)         reftex-index-phrases-font-lock-defaults)
1311    (easy-menu-add reftex-index-phrases-menu reftex-index-phrases-map)    (easy-menu-add reftex-index-phrases-menu reftex-index-phrases-map)
1312    (set (make-local-variable 'reftex-index-phrases-marker) (make-marker))    (set (make-local-variable 'reftex-index-phrases-marker) (make-marker))
1313    (run-mode-hooks 'reftex-index-phrases-mode-hook))    (run-hooks 'reftex-index-phrases-mode-hook))
1314  (add-hook 'reftex-index-phrases-mode-hook 'turn-on-font-lock)  (add-hook 'reftex-index-phrases-mode-hook 'turn-on-font-lock)
1315    
1316  ;; Font Locking stuff  ;; Font Locking stuff
1317  (let ((ss (if (featurep 'xemacs) 'secondary-selection ''secondary-selection)))  (let ((ss (if (featurep 'xemacs) 'secondary-selection ''secondary-selection)))
1318    (setq reftex-index-phrases-font-lock-keywords    (setq reftex-index-phrases-font-lock-keywords
1319          (list          (list
1320           (cons reftex-index-phrases-comment-regexp 'font-lock-comment-face)           (cons reftex-index-phrases-comment-regexp 'font-lock-comment-face)
1321           (list reftex-index-phrases-macrodef-regexp           (list reftex-index-phrases-macrodef-regexp
1322                 '(1 font-lock-type-face)                 '(1 font-lock-type-face)
# Line 1342  Here are all local bindings. Line 1340  Here are all local bindings.
1340    (setq reftex-index-phrases-font-lock-defaults    (setq reftex-index-phrases-font-lock-defaults
1341          '((reftex-index-phrases-font-lock-keywords)          '((reftex-index-phrases-font-lock-keywords)
1342            nil t nil beginning-of-line))            nil t nil beginning-of-line))
1343    (put 'reftex-index-phrases-mode 'font-lock-defaults    (put 'reftex-index-phrases-mode 'font-lock-defaults
1344         reftex-index-phrases-font-lock-defaults) ; XEmacs         reftex-index-phrases-font-lock-defaults) ; XEmacs
1345    )    )
1346    
# Line 1404  match, the user will be asked to confirm Line 1402  match, the user will be asked to confirm
1402                     (move-marker reftex-index-phrases-marker                     (move-marker reftex-index-phrases-marker
1403                                  (match-beginning 0) (current-buffer))                                  (match-beginning 0) (current-buffer))
1404                     ;; Start the query-replace                     ;; Start the query-replace
1405                     (reftex-query-index-phrase-globally                     (reftex-query-index-phrase-globally
1406                      files phrase macro-fmt                      files phrase macro-fmt
1407                      index-key repeat as-words)                      index-key repeat as-words)
1408                     (message "%s replaced"                     (message "%s replaced"
1409                              (reftex-number replace-count "occurrence"))))))                              (reftex-number replace-count "occurrence"))))))
1410            (t (error "Cannot parse this line")))))            (t (error "Cannot parse this line")))))
1411    
# Line 1450  the document and stores the list in `ref Line 1448  the document and stores the list in `ref
1448            (unless buf (error "Master file %s not found" master))            (unless buf (error "Master file %s not found" master))
1449            (set-buffer buf)            (set-buffer buf)
1450            (reftex-access-scan-info)            (reftex-access-scan-info)
1451            (setq reftex-index-phrases-files            (setq reftex-index-phrases-files
1452                  (reftex-all-document-files))))                  (reftex-all-document-files))))
1453      ;; Parse the files header for macro definitions      ;; Parse the files header for macro definitions
1454      (setq reftex-index-phrases-macro-data nil)      (setq reftex-index-phrases-macro-data nil)
# Line 1465  the document and stores the list in `ref Line 1463  the document and stores the list in `ref
1463        ;; Reverse the list, so that the first macro is first        ;; Reverse the list, so that the first macro is first
1464        (if (null reftex-index-phrases-macro-data)        (if (null reftex-index-phrases-macro-data)
1465            (error "No valid MACRO DEFINITION line in %s file (make sure to use TAB separators)" reftex-index-phrase-file-extension))            (error "No valid MACRO DEFINITION line in %s file (make sure to use TAB separators)" reftex-index-phrase-file-extension))
1466        (setq reftex-index-phrases-macro-data        (setq reftex-index-phrases-macro-data
1467              (nreverse reftex-index-phrases-macro-data))              (nreverse reftex-index-phrases-macro-data))
1468        (goto-char (point-min)))))        (goto-char (point-min)))))
1469    
# Line 1477  you need to add/change text in an alread Line 1475  you need to add/change text in an alread
1475  index the new part without having to go over the unchanged parts again."  index the new part without having to go over the unchanged parts again."
1476    (interactive "r")    (interactive "r")
1477    (let ((win-conf (current-window-configuration))    (let ((win-conf (current-window-configuration))
1478          (reftex-index-phrases-restrict-file (buffer-file-name)))          (reftex-index-phrases-restrict-file (buffer-file-name)))        
1479    (save-excursion    (save-excursion
1480      (save-restriction      (save-restriction
1481        (narrow-to-region beg end)        (narrow-to-region beg end)
# Line 1500  index the new part without having to go Line 1498  index the new part without having to go
1498          (setq text (reftex-index-simplify-phrase text))          (setq text (reftex-index-simplify-phrase text))
1499          (goto-char (point-min))          (goto-char (point-min))
1500          (if (re-search-forward          (if (re-search-forward
1501               (concat "^\\(\\S-*\\)\t\\(" (regexp-quote text)               (concat "^\\(\\S-*\\)\t\\(" (regexp-quote text)
1502                       "\\) *[\t\n]") nil t)                       "\\) *[\t\n]") nil t)
1503              (progn              (progn
1504                (goto-char (match-end 2))                (goto-char (match-end 2))
# Line 1530  this function repeatedly." Line 1528  this function repeatedly."
1528            (let* ((phrase (match-string 3))            (let* ((phrase (match-string 3))
1529                   (case-fold-search reftex-index-phrases-case-fold-search)                   (case-fold-search reftex-index-phrases-case-fold-search)
1530                   (re (reftex-index-phrases-find-dup-re phrase t)))                   (re (reftex-index-phrases-find-dup-re phrase t)))
1531              (if (save-excursion              (if (save-excursion
1532                    (goto-char (point-min))                    (goto-char (point-min))
1533                    (and (re-search-forward re nil t)                    (and (re-search-forward re nil t)
1534                         (re-search-forward re nil t)))                         (re-search-forward re nil t)))
# Line 1623  this function repeatedly." Line 1621  this function repeatedly."
1621              (progn              (progn
1622                (princ (format " Superphrases:  Phrase matches the following %s in the phrase buffer:\n"                (princ (format " Superphrases:  Phrase matches the following %s in the phrase buffer:\n"
1623                               (reftex-number ntimes2 "line")))                               (reftex-number ntimes2 "line")))
1624                (mapcar (lambda(x)                (mapcar (lambda(x)
1625                          (princ (format "                Line %4d:  %s\n" (car x) (cdr x))))                          (princ (format "                Line %4d:  %s\n" (car x) (cdr x))))
1626                        (nreverse superphrases))))))))                        (nreverse superphrases))))))))
1627    
# Line 1676  it first compares the macro identifying Line 1674  it first compares the macro identifying
1674          beg end)          beg end)
1675      (goto-char (point-min))      (goto-char (point-min))
1676      ;; Find first and last phrase line in buffer      ;; Find first and last phrase line in buffer
1677      (setq beg      (setq beg
1678            (and (re-search-forward reftex-index-phrases-phrase-regexp12 nil t)            (and (re-search-forward reftex-index-phrases-phrase-regexp12 nil t)
1679                 (match-beginning 0)))                 (match-beginning 0)))
1680      (goto-char (point-max))      (goto-char (point-max))
# Line 1703  it first compares the macro identifying Line 1701  it first compares the macro identifying
1701      (if (string-match reftex-index-phrases-phrase-regexp12 a)      (if (string-match reftex-index-phrases-phrase-regexp12 a)
1702          (progn          (progn
1703            ;; Extract macro char and phrase-or-key for a            ;; Extract macro char and phrase-or-key for a
1704            (setq ca (match-string 1 a)            (setq ca (match-string 1 a)
1705                  pa (downcase                  pa (downcase
1706                      (or (and reftex-index-phrases-sort-prefers-entry                      (or (and reftex-index-phrases-sort-prefers-entry
1707                               (match-string 6 a))                               (match-string 6 a))
1708                          (match-string 3 a))))                          (match-string 3 a))))
1709            (if (string-match reftex-index-phrases-phrase-regexp12 b)            (if (string-match reftex-index-phrases-phrase-regexp12 b)
1710                (progn                (progn
1711                  ;; Extract macro char and phrase-or-key for b                  ;; Extract macro char and phrase-or-key for b
1712                  (setq cb (match-string 1 b)                  (setq cb (match-string 1 b)
1713                        pb (downcase                        pb (downcase
1714                            (or (and reftex-index-phrases-sort-prefers-entry                            (or (and reftex-index-phrases-sort-prefers-entry
1715                                     (match-string 6 b))                                     (match-string 6 b))
# Line 1719  it first compares the macro identifying Line 1717  it first compares the macro identifying
1717                  (setq c-p (string< ca cb)                  (setq c-p (string< ca cb)
1718                        p-p (string< pa pb))                        p-p (string< pa pb))
1719                  ;; Do the right comparison, based on the value of `chars-first'                  ;; Do the right comparison, based on the value of `chars-first'
1720                  ;; `chars-first' is bound locally in the calling function                  ;; `chars-first' is bound locally in the calling function              
1721                  (if chars-first                  (if chars-first
1722                      (if (string= ca cb) p-p c-p)                      (if (string= ca cb) p-p c-p)
1723                    (if (string= pa pb) c-p p-p)))))                    (if (string= pa pb) c-p p-p)))))
# Line 1730  it first compares the macro identifying Line 1728  it first compares the macro identifying
1728        (not reftex-index-phrases-sort-in-blocks))))        (not reftex-index-phrases-sort-in-blocks))))
1729    
1730  (defvar reftex-index-phrases-menu)  (defvar reftex-index-phrases-menu)
1731  (defun reftex-index-make-phrase-regexp (phrase &optional  (defun reftex-index-make-phrase-regexp (phrase &optional
1732                                                 as-words allow-newline)                                                 as-words allow-newline)
1733    "Return a regexp matching PHRASE, even if distributed over lines.    "Return a regexp matching PHRASE, even if distributed over lines.
1734  With optional arg AS-WORDS, require word boundary at beginning and end.  With optional arg AS-WORDS, require word boundary at beginning and end.
# Line 1741  With optional arg ALLOW-NEWLINE, allow s Line 1739  With optional arg ALLOW-NEWLINE, allow s
1739                       "\\([ \t]+\\)")))                       "\\([ \t]+\\)")))
1740      (concat (if (and as-words (string-match "\\`\\w" (car words)))      (concat (if (and as-words (string-match "\\`\\w" (car words)))
1741                  "\\(\\<\\|[`']\\)" "")                  "\\(\\<\\|[`']\\)" "")
1742              (mapconcat (lambda (w) (regexp-quote              (mapconcat (lambda (w) (regexp-quote
1743                                      (if reftex-index-phrases-case-fold-search                                      (if reftex-index-phrases-case-fold-search
1744                                          (downcase w)                                          (downcase w)
1745                                        w)))                                        w)))
1746                         words space-re)                         words space-re)
1747              (if (and as-words              (if (and as-words
1748                       (string-match "\\w\\'" (nth (1- (length words)) words)))                       (string-match "\\w\\'" (nth (1- (length words)) words)))
1749                  "\\(\\>\\|'\\)" ""))))                  "\\(\\>\\|'\\)" ""))))
1750    
# Line 1769  Treats the logical `and' for index phras Line 1767  Treats the logical `and' for index phras
1767    (let ((index-keys (split-string (or index-key match)    (let ((index-keys (split-string (or index-key match)
1768                                    reftex-index-phrases-logical-and-regexp)))                                    reftex-index-phrases-logical-and-regexp)))
1769      (concat      (concat
1770       (mapconcat (lambda (x)       (mapconcat (lambda (x)
1771                    (format macro-fmt                    (format macro-fmt
1772                            (format (if mathp reftex-index-math-format "%s") x)))                            (format (if mathp reftex-index-math-format "%s") x)))
1773                  index-keys "")                  index-keys "")
1774     (if repeat (reftex-index-simplify-phrase match) ""))))     (if repeat (reftex-index-simplify-phrase match) ""))))
# Line 1782  Treats the logical `and' for index phras Line 1780  Treats the logical `and' for index phras
1780      (unless files (error "No files"))      (unless files (error "No files"))
1781      (unwind-protect      (unwind-protect
1782          (progn          (progn
1783            (switch-to-buffer-other-window (reftex-get-file-buffer-force            (switch-to-buffer-other-window (reftex-get-file-buffer-force
1784                                            (car files)))                                            (car files)))
1785            (catch 'no-more-files            (catch 'no-more-files
1786              (while (setq file (pop files))              (while (setq file (pop files))
# Line 1822  AS-WORDS means, the search for PHRASE sh Line 1820  AS-WORDS means, the search for PHRASE sh
1820  both ends."  both ends."
1821    (let* ((re (reftex-index-make-phrase-regexp phrase as-words 'allow-newline))    (let* ((re (reftex-index-make-phrase-regexp phrase as-words 'allow-newline))
1822           (case-fold-search reftex-index-phrases-case-fold-search)           (case-fold-search reftex-index-phrases-case-fold-search)
1823           (index-keys (split-string           (index-keys (split-string
1824                        (or index-key phrase)                        (or index-key phrase)
1825                        reftex-index-phrases-logical-or-regexp))                        reftex-index-phrases-logical-or-regexp))
1826           (nkeys (length index-keys))           (nkeys (length index-keys))
1827           (ckey (nth 0 index-keys))           (ckey (nth 0 index-keys))
1828           (all-yes nil)           (all-yes nil)
1829           match rpl char beg end mathp)           match rpl char (beg (make-marker)) (end (make-marker)) mathp)
1830        (move-marker beg 1)
1831        (move-marker end 1)
1832      (unwind-protect      (unwind-protect
1833          (while (re-search-forward re nil t)          (while (re-search-forward re nil t)
1834            (catch 'next-match            (catch 'next-match
# Line 1841  both ends." Line 1841  both ends."
1841              (setq mathp              (setq mathp
1842                    (save-match-data                    (save-match-data
1843                      (condition-case nil (texmathp) (error nil))))                      (condition-case nil (texmathp) (error nil))))
1844              (setq beg (car (match-data))              (setq beg (move-marker beg (match-beginning 0))
1845                    end (nth 1 (match-data)))                    end (move-marker end (match-end 0)))
1846              (if (and reftex-index-phrases-skip-indexed-matches              (if (and reftex-index-phrases-skip-indexed-matches
1847                       (save-match-data                       (save-match-data
1848                         (reftex-index-phrase-match-is-indexed beg                         (reftex-index-phrase-match-is-indexed beg
1849                                                               end)))                                                               end)))
1850                  (throw 'next-match nil))                  (throw 'next-match nil))
1851              (reftex-highlight 0 (match-beginning 0) (match-end 0))              (reftex-highlight 0 (match-beginning 0) (match-end 0))
1852              (setq rpl              (setq rpl
1853                    (save-match-data                    (save-match-data
1854                      (reftex-index-make-replace-string                      (reftex-index-make-replace-string
1855                       macro-fmt (match-string 0) ckey repeat mathp)))                       macro-fmt (match-string 0) ckey repeat mathp)))
1856              (while              (while
1857                  (not                  (not
1858                   (catch 'loop                   (catch 'loop
1859                     (message "REPLACE: %s?   (yn!qoe%s?)"                     (message "REPLACE: %s?   (yn!qoe%s?)"
1860                              rpl                              rpl
1861                              (if (> nkeys 1)                              (if (> nkeys 1)
1862                                  (concat "1-" (int-to-string nkeys))                                  (concat "1-" (int-to-string nkeys))
1863                                ""))                                ""))
1864                     (setq char (if all-yes ?y (read-char-exclusive)))                     (setq char (if all-yes ?y (read-char-exclusive)))
# Line 1892  both ends." Line 1892  both ends."
1892                           ((member char '(?o ?O))                           ((member char '(?o ?O))
1893                            ;; Select a differnt macro                            ;; Select a differnt macro
1894                            (let* ((nc (reftex-index-select-phrases-macro 2))                            (let* ((nc (reftex-index-select-phrases-macro 2))
1895                                   (macro-data                                   (macro-data
1896                                    (cdr (assoc nc reftex-index-phrases-macro-data)))                                    (cdr (assoc nc reftex-index-phrases-macro-data)))
1897                                   (macro-fmt (car macro-data))                                   (macro-fmt (car macro-data))
1898                                   (repeat (nth 1 macro-data)))                                   (repeat (nth 1 macro-data)))
# Line 1910  both ends." Line 1910  both ends."
1910                            ;; Recursive edit                            ;; Recursive edit
1911                            (save-match-data                            (save-match-data
1912                              (save-excursion                              (save-excursion
1913                                (message                                (message
1914                                 (substitute-command-keys                                 (substitute-command-keys
1915                                  "Recursive edit.  Resume with \\[exit-recursive-edit]"))                                  "Recursive edit.  Resume with \\[exit-recursive-edit]"))
1916                                (recursive-edit))))                                (recursive-edit))))
# Line 1930  both ends." Line 1930  both ends."
1930                           (t (ding)))                           (t (ding)))
1931                     nil)))))                     nil)))))
1932        (message "")        (message "")
1933          (move-marker beg nil)
1934          (move-marker end nil)
1935        (setq all-yes nil)        (setq all-yes nil)
1936        (reftex-unhighlight 0))))        (reftex-unhighlight 0))))
1937    
# Line 1939  both ends." Line 1941  both ends."
1941    (save-excursion    (save-excursion
1942      (goto-char end)      (goto-char end)
1943      (let* ((all-macros (reftex-what-macro t))      (let* ((all-macros (reftex-what-macro t))
1944             (this-macro (car (car all-macros)))  ;           (this-macro (car (car all-macros)))
1945             (before-macro             (before-macro
1946              (and (> beg 2)              (and (> beg 2)
1947                   (goto-char (1- beg))                   (goto-char (1- beg))
# Line 2043  Does not do a save-excursion." Line 2045  Does not do a save-excursion."
2045          ("\C-i"     . self-insert-command))          ("\C-i"     . self-insert-command))
2046        do (define-key reftex-index-phrases-map (car x) (cdr x)))        do (define-key reftex-index-phrases-map (car x) (cdr x)))
2047    
2048  (easy-menu-define  (easy-menu-define
2049   reftex-index-phrases-menu reftex-index-phrases-map   reftex-index-phrases-menu reftex-index-phrases-map
2050   "Menu for Phrases buffer"   "Menu for Phrases buffer"
2051   '("Phrases"   '("Phrases"

Legend:
Removed from v.1.26  
changed lines
  Added in v.1.27

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26