/[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.25 by ttn, Sat Aug 6 17:41:15 2005 UTC revision 1.26 by lektu, Wed Aug 31 10:34:07 2005 UTC
# Line 32  Line 32 
32  (require 'reftex)  (require 'reftex)
33  ;;;  ;;;
34    
35    (defvar reftex-index-phrases-marker)
36    (defvar TeX-master)
37    
38  ;; START remove for XEmacs release  ;; START remove for XEmacs release
39  (defvar mark-active)  (defvar mark-active)
40  (defvar zmacs-regions)  (defvar zmacs-regions)
# Line 53  which is part of AUCTeX, the string is f Line 56  which is part of AUCTeX, the string is f
56           (active (if (boundp 'zmacs-regions)           (active (if (boundp 'zmacs-regions)
57                       (and zmacs-regions (region-exists-p))  ; XEmacs                       (and zmacs-regions (region-exists-p))  ; XEmacs
58                     (and transient-mark-mode mark-active)))  ; Emacs                     (and transient-mark-mode mark-active)))  ; Emacs
59           (beg (if active           (beg (if active
60                    (region-beginning)                    (region-beginning)
61                  (save-excursion                  (save-excursion
62                    (skip-syntax-backward "w\\") (point))))                    (skip-syntax-backward "w\\") (point))))
63           (end (if active           (end (if active
64                    (region-end)                    (region-end)
65                  (save-excursion                  (save-excursion
66                    (skip-syntax-forward "w\\") (point))))                    (skip-syntax-forward "w\\") (point))))
67           (sel (buffer-substring beg end))           (sel (buffer-substring beg end))
68           (mathp (condition-case nil (texmathp) (error nil)))           (mathp (condition-case nil (texmathp) (error nil)))
# Line 90  which is part of AUCTeX, the string is f Line 93  which is part of AUCTeX, the string is f
93          ;; Delete what is in the buffer and make the index entry          ;; Delete what is in the buffer and make the index entry
94          (delete-region beg end)          (delete-region beg end)
95          (reftex-index def-char full-entry def-tag sel)))))          (reftex-index def-char full-entry def-tag sel)))))
96      
97  (defun reftex-index (&optional char key tag sel no-insert)  (defun reftex-index (&optional char key tag sel no-insert)
98    "Query for an index macro and insert it along with its argments.    "Query for an index macro and insert it along with its argments.
99  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 166  will prompt for other arguments." Line 169  will prompt for other arguments."
169    ;; OPT-ARGS is a list of optional argument indices, as given by    ;; OPT-ARGS is a list of optional argument indices, as given by
170    ;; `reftex-parse-args'.    ;; `reftex-parse-args'.
171    (let* ((opt (and (integerp itag) (member itag opt-args)))    (let* ((opt (and (integerp itag) (member itag opt-args)))
172           (index-tags (cdr (assq 'index-tags           (index-tags (cdr (assq 'index-tags
173                                  (symbol-value reftex-docstruct-symbol))))                                  (symbol-value reftex-docstruct-symbol))))
174           (default (reftex-default-index))           (default (reftex-default-index))
175           (prompt (concat "Index tag"           (prompt (concat "Index tag"
# Line 180  will prompt for other arguments." Line 183  will prompt for other arguments."
183  (defun reftex-index-select-tag ()  (defun reftex-index-select-tag ()
184    ;; Have the user select an index tag.    ;; Have the user select an index tag.
185    ;; FIXME: should we cache tag-alist, prompt and help?    ;; FIXME: should we cache tag-alist, prompt and help?
186    (let* ((index-tags (cdr (assoc 'index-tags    (let* ((index-tags (cdr (assoc 'index-tags
187                                   (symbol-value reftex-docstruct-symbol))))                                   (symbol-value reftex-docstruct-symbol))))
188           (default (reftex-default-index)))           (default (reftex-default-index)))
189      (cond      (cond
190       ((null index-tags)       ((null index-tags)
191        (error "No index tags available"))        (error "No index tags available"))
192    
193       ((= (length index-tags) 1)       ((= (length index-tags) 1)
194        ;; Just one index, use it        ;; Just one index, use it
195        (car index-tags))        (car index-tags))
196              
197       ((> (length index-tags) 1)       ((> (length index-tags) 1)
198        ;; Several indices, ask.        ;; Several indices, ask.
199        (let* ((tags (copy-sequence index-tags))        (let* ((tags (copy-sequence index-tags))
# Line 211  will prompt for other arguments." Line 214  will prompt for other arguments."
214                (unless (assq (aref tag i) tag-alist)                (unless (assq (aref tag i) tag-alist)
215                  (push (list (aref tag i)                  (push (list (aref tag i)
216                              tag                              tag
217                              (concat (substring tag 0 i)                              (concat (substring tag 0 i)
218                                      "[" (substring tag i (incf i)) "]"                                      "[" (substring tag i (incf i)) "]"
219                                      (substring tag i)))                                      (substring tag i)))
220                        tag-alist)                        tag-alist)
221                  (throw 'exit t)))                  (throw 'exit t)))
222              (push (list (+ ?0 (incf cnt)) tag              (push (list (+ ?0 (incf cnt)) tag
223                          (concat "[" (int-to-string cnt) "]:" tag))                          (concat "[" (int-to-string cnt) "]:" tag))
224                    tag-alist)))                    tag-alist)))
225          (setq tag-alist (nreverse tag-alist))          (setq tag-alist (nreverse tag-alist))
# Line 231  will prompt for other arguments." Line 234  will prompt for other arguments."
234                        (if default                        (if default
235                            (format "[^M]  %s (the default)\n" default)                            (format "[^M]  %s (the default)\n" default)
236                          "")                          "")
237                        (mapconcat (lambda(x)                        (mapconcat (lambda(x)
238                                     (apply 'format "[%c]   %s" x))                                     (apply 'format "[%c]   %s" x))
239                                   tag-alist "\n")))                                   tag-alist "\n")))
240          ;; Query the user for an index-tag          ;; Query the user for an index-tag
# Line 260  will prompt for other arguments." Line 263  will prompt for other arguments."
263      key))      key))
264    
265  (defun reftex-index-update-taglist (newtag)  (defun reftex-index-update-taglist (newtag)
266    ;; add NEWTAG to the list of available index tags.    ;; add NEWTAG to the list of available index tags.
267    (let ((cell (assoc 'index-tags (symbol-value reftex-docstruct-symbol))))    (let ((cell (assoc 'index-tags (symbol-value reftex-docstruct-symbol))))
268      (and newtag (cdr cell) (not (member newtag (cdr cell)))      (and newtag (cdr cell) (not (member newtag (cdr cell)))
269           (push newtag (cdr cell)))))           (push newtag (cdr cell)))))
# Line 341  _ ^        Add/Remove parent key (to mak Line 344  _ ^        Add/Remove parent key (to mak
344    ;; Note:  This function just looks for the nearest match of the    ;; Note:  This function just looks for the nearest match of the
345    ;; context string and may fail if the entry moved and an identical    ;; context string and may fail if the entry moved and an identical
346    ;; entry is close to the old position.  Frequent rescans make this    ;; entry is close to the old position.  Frequent rescans make this
347    ;; safer.    ;; safer.
348    (let* ((file (nth 3 data))    (let* ((file (nth 3 data))
349           (literal (nth 2 data))           (literal (nth 2 data))
350           (pos (nth 4 data))           (pos (nth 4 data))
# Line 389  With prefix 3, restrict index to region. Line 392  With prefix 3, restrict index to region.
392           (calling-file (buffer-file-name))           (calling-file (buffer-file-name))
393           (restriction           (restriction
394            (or overriding-restriction            (or overriding-restriction
395                (and (not redo)                (and (not redo)
396                     (reftex-get-restriction current-prefix-arg docstruct))))                     (reftex-get-restriction current-prefix-arg docstruct))))
397           (locations           (locations
398            ;; See if we are on an index macro as initial position            ;; See if we are on an index macro as initial position
# Line 398  With prefix 3, restrict index to region. Line 401  With prefix 3, restrict index to region.
401                       (macro (car what-macro))                       (macro (car what-macro))
402                       (here-I-am (when (member macro reftex-macros-with-index)                       (here-I-am (when (member macro reftex-macros-with-index)
403                                    (save-excursion                                    (save-excursion
404                                      (goto-char (+ (cdr what-macro)                                      (goto-char (+ (cdr what-macro)
405                                                    (length macro)))                                                    (length macro)))
406                                      (reftex-move-over-touching-args)                                      (reftex-move-over-touching-args)
407                                      (reftex-where-am-I)))))                                      (reftex-where-am-I)))))
# Line 409  With prefix 3, restrict index to region. Line 412  With prefix 3, restrict index to region.
412      (setq buffer-name (reftex-make-index-buffer-name index-tag))      (setq buffer-name (reftex-make-index-buffer-name index-tag))
413    
414      ;; Goto the buffer and put it into the correct mode      ;; Goto the buffer and put it into the correct mode
415                          
416      (when (or restriction current-prefix-arg)      (when (or restriction current-prefix-arg)
417           (reftex-kill-buffer buffer-name))           (reftex-kill-buffer buffer-name))
418    
# Line 502  SPC=view TAB=goto RET=goto+hide [e]dit [ Line 505  SPC=view TAB=goto RET=goto+hide [e]dit [
505        ;; Delete the entry at place        ;; Delete the entry at place
506        (and (bolp) (forward-char 1))        (and (bolp) (forward-char 1))
507        (delete-region (previous-single-property-change (1+ (point)) :data)        (delete-region (previous-single-property-change (1+ (point)) :data)
508                       (or (next-single-property-change (point) :data)                       (or (next-single-property-change (point) :data)
509                           (point-max))))                           (point-max))))
510    
511      ;; Walk through the list and insert all entries      ;; Walk through the list and insert all entries
# Line 523  SPC=view TAB=goto RET=goto+hide [e]dit [ Line 526  SPC=view TAB=goto RET=goto+hide [e]dit [
526        (insert indent (nth 7 cell))        (insert indent (nth 7 cell))
527        (when font        (when font
528          (setq to (point))          (setq to (point))
529          (put-text-property          (put-text-property
530           (- (point) (length (nth 7 cell))) to           (- (point) (length (nth 7 cell))) to
531           'face index-face)           'face index-face)
532          (goto-char to))          (goto-char to))
# Line 551  SPC=view TAB=goto RET=goto+hide [e]dit [ Line 554  SPC=view TAB=goto RET=goto+hide [e]dit [
554  (defun reftex-index-insert-new-letter (letter &optional font)  (defun reftex-index-insert-new-letter (letter &optional font)
555    ;; Start a new section in the index    ;; Start a new section in the index
556    (let ((from (point)))    (let ((from (point)))
557      (insert "\n" letter letter letter      (insert "\n" letter letter letter
558              "-----------------------------------------------------------------")              "-----------------------------------------------------------------")
559      (when font      (when font
560        (put-text-property from (point) 'face reftex-index-section-face))        (put-text-property from (point) 'face reftex-index-section-face))
# Line 628  SPC=view TAB=goto RET=goto+hide [e]dit [ Line 631  SPC=view TAB=goto RET=goto+hide [e]dit [
631    (interactive "p")    (interactive "p")
632    (setq reftex-callback-fwd t)    (setq reftex-callback-fwd t)
633    (or (eobp) (forward-char 1))    (or (eobp) (forward-char 1))
634    (goto-char (or (next-single-property-change (point) :data)    (goto-char (or (next-single-property-change (point) :data)
635                   (point)))                   (point)))
636    (unless (get-text-property (point) :data)    (unless (get-text-property (point) :data)
637      (goto-char (or (next-single-property-change (point) :data)      (goto-char (or (next-single-property-change (point) :data)
638                     (point)))))                     (point)))))
639  (defun reftex-index-previous (&optional arg)  (defun reftex-index-previous (&optional arg)
640    "Move to previous selectable item."    "Move to previous selectable item."
# Line 774  When index is restricted, select the nex Line 777  When index is restricted, select the nex
777          (reftex-index-restrict-to-section t)          (reftex-index-restrict-to-section t)
778        (setq reftex-index-restriction-indicator (nth 6 bor)        (setq reftex-index-restriction-indicator (nth 6 bor)
779              reftex-index-restriction-data              reftex-index-restriction-data
780              (list bor              (list bor
781                    (car (memq (assq 'toc (cdr (memq bor docstruct)))                    (car (memq (assq 'toc (cdr (memq bor docstruct)))
782                               docstruct))))                               docstruct))))
783        (reftex-index-revert))))        (reftex-index-revert))))
# Line 806  When index is restricted, select the pre Line 809  When index is restricted, select the pre
809           show-window show-buffer match)           show-window show-buffer match)
810    
811      (unless data (error "Don't know which index entry to visit"))      (unless data (error "Don't know which index entry to visit"))
812        
813      (if (eq (car data) 'index)      (if (eq (car data) 'index)
814          (setq match (reftex-index-show-entry data no-revisit)))          (setq match (reftex-index-show-entry data no-revisit)))
815    
# Line 877  When index is restricted, select the pre Line 880  When index is restricted, select the pre
880            attr (nth 2 analyze))            attr (nth 2 analyze))
881      (setf (nth 2 analyze) (if (string= attr bor) "" bor))      (setf (nth 2 analyze) (if (string= attr bor) "" bor))
882      (setq new (apply 'concat analyze))      (setq new (apply 'concat analyze))
883      (reftex-index-change-entry      (reftex-index-change-entry
884       new (if (string= (nth 2 analyze) bor)       new (if (string= (nth 2 analyze) bor)
885               "Entry is now START-OF-PAGE-RANGE"               "Entry is now START-OF-PAGE-RANGE"
886             "START-OF-PAGE-RANGE canceled"))))             "START-OF-PAGE-RANGE canceled"))))
# Line 935  When index is restricted, select the pre Line 938  When index is restricted, select the pre
938            (t (setf (nth n analyze) (concat initial npart))))            (t (setf (nth n analyze) (concat initial npart))))
939      (setq new (apply 'concat analyze))      (setq new (apply 'concat analyze))
940      ;; Change the entry and insert the changed version into the index.      ;; Change the entry and insert the changed version into the index.
941      (reftex-index-change-entry      (reftex-index-change-entry
942       new (if (string= npart "")       new (if (string= npart "")
943               (format "Deleted: %s" opart)               (format "Deleted: %s" opart)
944             (format "New value is: %s" npart)))))             (format "New value is: %s" npart)))))
# Line 949  When index is restricted, select the pre Line 952  When index is restricted, select the pre
952      (unless data (error "Don't know which index entry to change"))      (unless data (error "Don't know which index entry to change"))
953      (setq old (nth 2 data)      (setq old (nth 2 data)
954            key (nth 6 data)            key (nth 6 data)
955            prefix (completing-read            prefix (completing-read
956                    "Prefix: "                    "Prefix: "
957                    (reftex-sublist-nth                    (reftex-sublist-nth
958                     docstruct 6                     docstruct 6
959                     (lambda (x)                     (lambda (x)
960                       (and (eq (car x) 'index)                       (and (eq (car x) 'index)
961                            (string= (nth 1 x) reftex-index-tag))) t)))                            (string= (nth 1 x) reftex-index-tag))) t)))
962      (unless (string-match      (unless (string-match
963               (concat (regexp-quote (car reftex-index-special-chars)) "\\'")               (concat (regexp-quote (car reftex-index-special-chars)) "\\'")
964               prefix)               prefix)
965        (setq prefix (concat prefix (car reftex-index-special-chars))))        (setq prefix (concat prefix (car reftex-index-special-chars))))
# Line 996  When index is restricted, select the pre Line 999  When index is restricted, select the pre
999  (defun reftex-index-change-entry (new &optional message)  (defun reftex-index-change-entry (new &optional message)
1000    ;; Change the full context string of the index entry at point to    ;; Change the full context string of the index entry at point to
1001    ;; NEW.  This actually edits the buffer where the entry is defined.    ;; NEW.  This actually edits the buffer where the entry is defined.
1002      
1003    (let* ((data (get-text-property (point) :data))    (let* ((data (get-text-property (point) :data))
1004           old beg end info)           old beg end info)
1005      (unless data (error "Cannot change entry"))      (unless data (error "Cannot change entry"))
# Line 1088  When index is restricted, select the pre Line 1091  When index is restricted, select the pre
1091        (if (eq char ?!)        (if (eq char ?!)
1092            (error "This <%s> index does not contain entries sorted before the letters"            (error "This <%s> index does not contain entries sorted before the letters"
1093                   reftex-index-tag)                   reftex-index-tag)
1094          (error "This <%s> index does not contain entries starting with `%c'"          (error "This <%s> index does not contain entries starting with `%c'"
1095                 reftex-index-tag char)))))                 reftex-index-tag char)))))
1096    
1097  (easy-menu-define  (easy-menu-define
1098   reftex-index-menu reftex-index-map   reftex-index-menu reftex-index-map
1099   "Menu for Index buffer"   "Menu for Index buffer"
1100   `("Index"   `("Index"
1101     ["Goto section A-Z"     ["Goto section A-Z"
1102      (message "To go to a section, just press any of: !%s"      (message "To go to a section, just press any of: !%s"
1103               reftex-index-section-letters) t]               reftex-index-section-letters) t]
1104     ["Show Entry" reftex-index-view-entry t]     ["Show Entry" reftex-index-view-entry t]
# Line 1135  When index is restricted, select the pre Line 1138  When index is restricted, select the pre
1138      ["Context" reftex-index-toggle-context :style toggle      ["Context" reftex-index-toggle-context :style toggle
1139       :selected reftex-index-include-context]       :selected reftex-index-include-context]
1140      "--"      "--"
1141      ["Follow Mode" reftex-index-toggle-follow :style toggle      ["Follow Mode" reftex-index-toggle-follow :style toggle
1142       :selected reftex-index-follow-mode])       :selected reftex-index-follow-mode])
1143     "--"     "--"
1144     ["Help" reftex-index-show-help t]))     ["Help" reftex-index-show-help t]))
# Line 1187  You get a chance to edit the entry in th Line 1190  You get a chance to edit the entry in th
1190    (set-marker reftex-index-return-marker (point))    (set-marker reftex-index-return-marker (point))
1191    (reftex-index-selection-or-word arg 'phrase)    (reftex-index-selection-or-word arg 'phrase)
1192    (if (eq major-mode 'reftex-index-phrases-mode)    (if (eq major-mode 'reftex-index-phrases-mode)
1193        (message        (message
1194         (substitute-command-keys         (substitute-command-keys
1195          "Return to LaTeX with \\[reftex-index-phrases-save-and-return]"))))          "Return to LaTeX with \\[reftex-index-phrases-save-and-return]"))))
1196    
# Line 1216  If the buffer is non-empty, delete the o Line 1219  If the buffer is non-empty, delete the o
1219            (sort (copy-sequence reftex-index-macro-alist)            (sort (copy-sequence reftex-index-macro-alist)
1220                  (lambda (a b) (equal (car a) default-macro))))                  (lambda (a b) (equal (car a) default-macro))))
1221           macro entry key repeat)           macro entry key repeat)
1222        
1223      (if master (set (make-local-variable 'TeX-master)      (if master (set (make-local-variable 'TeX-master)
1224                      (file-name-nondirectory master)))                      (file-name-nondirectory master)))
1225    
# Line 1229  If the buffer is non-empty, delete the o Line 1232  If the buffer is non-empty, delete the o
1232        (if (looking-at reftex-index-phrases-comment-regexp)        (if (looking-at reftex-index-phrases-comment-regexp)
1233            (beginning-of-line 2))            (beginning-of-line 2))
1234        (while (looking-at "^[ \t]*$")        (while (looking-at "^[ \t]*$")
1235            (beginning-of-line 2))                      (beginning-of-line 2))
1236        (cond ((fboundp 'zmacs-activate-region) (zmacs-activate-region))        (cond ((fboundp 'zmacs-activate-region) (zmacs-activate-region))
1237              ((boundp 'make-active) (setq mark-active t)))              ((boundp 'make-active) (setq mark-active t)))
1238        (if (yes-or-no-p "Delete and rebuilt header ")        (if (yes-or-no-p "Delete and rebuilt header ")
# Line 1305  Here are all local bindings. Line 1308  Here are all local bindings.
1308    (setq major-mode 'reftex-index-phrases-mode    (setq major-mode 'reftex-index-phrases-mode
1309          mode-name "Phrases")          mode-name "Phrases")
1310    (use-local-map reftex-index-phrases-map)    (use-local-map reftex-index-phrases-map)
1311    (set (make-local-variable 'font-lock-defaults)    (set (make-local-variable 'font-lock-defaults)
1312         reftex-index-phrases-font-lock-defaults)         reftex-index-phrases-font-lock-defaults)
1313    (easy-menu-add reftex-index-phrases-menu reftex-index-phrases-map)    (easy-menu-add reftex-index-phrases-menu reftex-index-phrases-map)
1314    (set (make-local-variable 'reftex-index-phrases-marker) (make-marker))    (set (make-local-variable 'reftex-index-phrases-marker) (make-marker))
# Line 1315  Here are all local bindings. Line 1318  Here are all local bindings.
1318  ;; Font Locking stuff  ;; Font Locking stuff
1319  (let ((ss (if (featurep 'xemacs) 'secondary-selection ''secondary-selection)))  (let ((ss (if (featurep 'xemacs) 'secondary-selection ''secondary-selection)))
1320    (setq reftex-index-phrases-font-lock-keywords    (setq reftex-index-phrases-font-lock-keywords
1321          (list          (list
1322           (cons reftex-index-phrases-comment-regexp 'font-lock-comment-face)           (cons reftex-index-phrases-comment-regexp 'font-lock-comment-face)
1323           (list reftex-index-phrases-macrodef-regexp           (list reftex-index-phrases-macrodef-regexp
1324                 '(1 font-lock-type-face)                 '(1 font-lock-type-face)
# Line 1339  Here are all local bindings. Line 1342  Here are all local bindings.
1342    (setq reftex-index-phrases-font-lock-defaults    (setq reftex-index-phrases-font-lock-defaults
1343          '((reftex-index-phrases-font-lock-keywords)          '((reftex-index-phrases-font-lock-keywords)
1344            nil t nil beginning-of-line))            nil t nil beginning-of-line))
1345    (put 'reftex-index-phrases-mode 'font-lock-defaults    (put 'reftex-index-phrases-mode 'font-lock-defaults
1346         reftex-index-phrases-font-lock-defaults) ; XEmacs         reftex-index-phrases-font-lock-defaults) ; XEmacs
1347    )    )
1348    
 (defvar reftex-index-phrases-marker)  
1349  (defun reftex-index-next-phrase (&optional arg)  (defun reftex-index-next-phrase (&optional arg)
1350    "Index the next ARG phrases in the phrases buffer."    "Index the next ARG phrases in the phrases buffer."
1351    (interactive "p")    (interactive "p")
# Line 1402  match, the user will be asked to confirm Line 1404  match, the user will be asked to confirm
1404                     (move-marker reftex-index-phrases-marker                     (move-marker reftex-index-phrases-marker
1405                                  (match-beginning 0) (current-buffer))                                  (match-beginning 0) (current-buffer))
1406                     ;; Start the query-replace                     ;; Start the query-replace
1407                     (reftex-query-index-phrase-globally                     (reftex-query-index-phrase-globally
1408                      files phrase macro-fmt                      files phrase macro-fmt
1409                      index-key repeat as-words)                      index-key repeat as-words)
1410                     (message "%s replaced"                     (message "%s replaced"
1411                              (reftex-number replace-count "occurrence"))))))                              (reftex-number replace-count "occurrence"))))))
1412            (t (error "Cannot parse this line")))))            (t (error "Cannot parse this line")))))
1413    
# Line 1448  the document and stores the list in `ref Line 1450  the document and stores the list in `ref
1450            (unless buf (error "Master file %s not found" master))            (unless buf (error "Master file %s not found" master))
1451            (set-buffer buf)            (set-buffer buf)
1452            (reftex-access-scan-info)            (reftex-access-scan-info)
1453            (setq reftex-index-phrases-files            (setq reftex-index-phrases-files
1454                  (reftex-all-document-files))))                  (reftex-all-document-files))))
1455      ;; Parse the files header for macro definitions      ;; Parse the files header for macro definitions
1456      (setq reftex-index-phrases-macro-data nil)      (setq reftex-index-phrases-macro-data nil)
# Line 1463  the document and stores the list in `ref Line 1465  the document and stores the list in `ref
1465        ;; Reverse the list, so that the first macro is first        ;; Reverse the list, so that the first macro is first
1466        (if (null reftex-index-phrases-macro-data)        (if (null reftex-index-phrases-macro-data)
1467            (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))
1468        (setq reftex-index-phrases-macro-data        (setq reftex-index-phrases-macro-data
1469              (nreverse reftex-index-phrases-macro-data))              (nreverse reftex-index-phrases-macro-data))
1470        (goto-char (point-min)))))        (goto-char (point-min)))))
1471    
# Line 1475  you need to add/change text in an alread Line 1477  you need to add/change text in an alread
1477  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."
1478    (interactive "r")    (interactive "r")
1479    (let ((win-conf (current-window-configuration))    (let ((win-conf (current-window-configuration))
1480          (reftex-index-phrases-restrict-file (buffer-file-name)))                  (reftex-index-phrases-restrict-file (buffer-file-name)))
1481    (save-excursion    (save-excursion
1482      (save-restriction      (save-restriction
1483        (narrow-to-region beg end)        (narrow-to-region beg end)
# Line 1498  index the new part without having to go Line 1500  index the new part without having to go
1500          (setq text (reftex-index-simplify-phrase text))          (setq text (reftex-index-simplify-phrase text))
1501          (goto-char (point-min))          (goto-char (point-min))
1502          (if (re-search-forward          (if (re-search-forward
1503               (concat "^\\(\\S-*\\)\t\\(" (regexp-quote text)               (concat "^\\(\\S-*\\)\t\\(" (regexp-quote text)
1504                       "\\) *[\t\n]") nil t)                       "\\) *[\t\n]") nil t)
1505              (progn              (progn
1506                (goto-char (match-end 2))                (goto-char (match-end 2))
# Line 1528  this function repeatedly." Line 1530  this function repeatedly."
1530            (let* ((phrase (match-string 3))            (let* ((phrase (match-string 3))
1531                   (case-fold-search reftex-index-phrases-case-fold-search)                   (case-fold-search reftex-index-phrases-case-fold-search)
1532                   (re (reftex-index-phrases-find-dup-re phrase t)))                   (re (reftex-index-phrases-find-dup-re phrase t)))
1533              (if (save-excursion              (if (save-excursion
1534                    (goto-char (point-min))                    (goto-char (point-min))
1535                    (and (re-search-forward re nil t)                    (and (re-search-forward re nil t)
1536                         (re-search-forward re nil t)))                         (re-search-forward re nil t)))
# Line 1621  this function repeatedly." Line 1623  this function repeatedly."
1623              (progn              (progn
1624                (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"
1625                               (reftex-number ntimes2 "line")))                               (reftex-number ntimes2 "line")))
1626                (mapcar (lambda(x)                (mapcar (lambda(x)
1627                          (princ (format "                Line %4d:  %s\n" (car x) (cdr x))))                          (princ (format "                Line %4d:  %s\n" (car x) (cdr x))))
1628                        (nreverse superphrases))))))))                        (nreverse superphrases))))))))
1629    
# Line 1674  it first compares the macro identifying Line 1676  it first compares the macro identifying
1676          beg end)          beg end)
1677      (goto-char (point-min))      (goto-char (point-min))
1678      ;; Find first and last phrase line in buffer      ;; Find first and last phrase line in buffer
1679      (setq beg      (setq beg
1680            (and (re-search-forward reftex-index-phrases-phrase-regexp12 nil t)            (and (re-search-forward reftex-index-phrases-phrase-regexp12 nil t)
1681                 (match-beginning 0)))                 (match-beginning 0)))
1682      (goto-char (point-max))      (goto-char (point-max))
# Line 1701  it first compares the macro identifying Line 1703  it first compares the macro identifying
1703      (if (string-match reftex-index-phrases-phrase-regexp12 a)      (if (string-match reftex-index-phrases-phrase-regexp12 a)
1704          (progn          (progn
1705            ;; Extract macro char and phrase-or-key for a            ;; Extract macro char and phrase-or-key for a
1706            (setq ca (match-string 1 a)            (setq ca (match-string 1 a)
1707                  pa (downcase                  pa (downcase
1708                      (or (and reftex-index-phrases-sort-prefers-entry                      (or (and reftex-index-phrases-sort-prefers-entry
1709                               (match-string 6 a))                               (match-string 6 a))
1710                          (match-string 3 a))))                          (match-string 3 a))))
1711            (if (string-match reftex-index-phrases-phrase-regexp12 b)            (if (string-match reftex-index-phrases-phrase-regexp12 b)
1712                (progn                (progn
1713                  ;; Extract macro char and phrase-or-key for b                  ;; Extract macro char and phrase-or-key for b
1714                  (setq cb (match-string 1 b)                  (setq cb (match-string 1 b)
1715                        pb (downcase                        pb (downcase
1716                            (or (and reftex-index-phrases-sort-prefers-entry                            (or (and reftex-index-phrases-sort-prefers-entry
1717                                     (match-string 6 b))                                     (match-string 6 b))
# Line 1717  it first compares the macro identifying Line 1719  it first compares the macro identifying
1719                  (setq c-p (string< ca cb)                  (setq c-p (string< ca cb)
1720                        p-p (string< pa pb))                        p-p (string< pa pb))
1721                  ;; Do the right comparison, based on the value of `chars-first'                  ;; Do the right comparison, based on the value of `chars-first'
1722                  ;; `chars-first' is bound locally in the calling function                                ;; `chars-first' is bound locally in the calling function
1723                  (if chars-first                  (if chars-first
1724                      (if (string= ca cb) p-p c-p)                      (if (string= ca cb) p-p c-p)
1725                    (if (string= pa pb) c-p p-p)))))                    (if (string= pa pb) c-p p-p)))))
# Line 1728  it first compares the macro identifying Line 1730  it first compares the macro identifying
1730        (not reftex-index-phrases-sort-in-blocks))))        (not reftex-index-phrases-sort-in-blocks))))
1731    
1732  (defvar reftex-index-phrases-menu)  (defvar reftex-index-phrases-menu)
1733  (defun reftex-index-make-phrase-regexp (phrase &optional  (defun reftex-index-make-phrase-regexp (phrase &optional
1734                                                 as-words allow-newline)                                                 as-words allow-newline)
1735    "Return a regexp matching PHRASE, even if distributed over lines.    "Return a regexp matching PHRASE, even if distributed over lines.
1736  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 1739  With optional arg ALLOW-NEWLINE, allow s Line 1741  With optional arg ALLOW-NEWLINE, allow s
1741                       "\\([ \t]+\\)")))                       "\\([ \t]+\\)")))
1742      (concat (if (and as-words (string-match "\\`\\w" (car words)))      (concat (if (and as-words (string-match "\\`\\w" (car words)))
1743                  "\\(\\<\\|[`']\\)" "")                  "\\(\\<\\|[`']\\)" "")
1744              (mapconcat (lambda (w) (regexp-quote              (mapconcat (lambda (w) (regexp-quote
1745                                      (if reftex-index-phrases-case-fold-search                                      (if reftex-index-phrases-case-fold-search
1746                                          (downcase w)                                          (downcase w)
1747                                        w)))                                        w)))
1748                         words space-re)                         words space-re)
1749              (if (and as-words              (if (and as-words
1750                       (string-match "\\w\\'" (nth (1- (length words)) words)))                       (string-match "\\w\\'" (nth (1- (length words)) words)))
1751                  "\\(\\>\\|'\\)" ""))))                  "\\(\\>\\|'\\)" ""))))
1752    
# Line 1767  Treats the logical `and' for index phras Line 1769  Treats the logical `and' for index phras
1769    (let ((index-keys (split-string (or index-key match)    (let ((index-keys (split-string (or index-key match)
1770                                    reftex-index-phrases-logical-and-regexp)))                                    reftex-index-phrases-logical-and-regexp)))
1771      (concat      (concat
1772       (mapconcat (lambda (x)       (mapconcat (lambda (x)
1773                    (format macro-fmt                    (format macro-fmt
1774                            (format (if mathp reftex-index-math-format "%s") x)))                            (format (if mathp reftex-index-math-format "%s") x)))
1775                  index-keys "")                  index-keys "")
1776     (if repeat (reftex-index-simplify-phrase match) ""))))     (if repeat (reftex-index-simplify-phrase match) ""))))
# Line 1780  Treats the logical `and' for index phras Line 1782  Treats the logical `and' for index phras
1782      (unless files (error "No files"))      (unless files (error "No files"))
1783      (unwind-protect      (unwind-protect
1784          (progn          (progn
1785            (switch-to-buffer-other-window (reftex-get-file-buffer-force            (switch-to-buffer-other-window (reftex-get-file-buffer-force
1786                                            (car files)))                                            (car files)))
1787            (catch 'no-more-files            (catch 'no-more-files
1788              (while (setq file (pop files))              (while (setq file (pop files))
# Line 1820  AS-WORDS means, the search for PHRASE sh Line 1822  AS-WORDS means, the search for PHRASE sh
1822  both ends."  both ends."
1823    (let* ((re (reftex-index-make-phrase-regexp phrase as-words 'allow-newline))    (let* ((re (reftex-index-make-phrase-regexp phrase as-words 'allow-newline))
1824           (case-fold-search reftex-index-phrases-case-fold-search)           (case-fold-search reftex-index-phrases-case-fold-search)
1825           (index-keys (split-string           (index-keys (split-string
1826                        (or index-key phrase)                        (or index-key phrase)
1827                        reftex-index-phrases-logical-or-regexp))                        reftex-index-phrases-logical-or-regexp))
1828           (nkeys (length index-keys))           (nkeys (length index-keys))
1829           (ckey (nth 0 index-keys))           (ckey (nth 0 index-keys))
1830           (all-yes nil)           (all-yes nil)
1831           match rpl char beg end mathp)           match rpl char beg end mathp)
1832      (unwind-protect      (unwind-protect
1833          (while (re-search-forward re nil t)          (while (re-search-forward re nil t)
# Line 1847  both ends." Line 1849  both ends."
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 1890  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 1908  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 2041  Does not do a save-excursion." Line 2043  Does not do a save-excursion."
2043          ("\C-i"     . self-insert-command))          ("\C-i"     . self-insert-command))
2044        do (define-key reftex-index-phrases-map (car x) (cdr x)))        do (define-key reftex-index-phrases-map (car x) (cdr x)))
2045    
2046  (easy-menu-define  (easy-menu-define
2047   reftex-index-phrases-menu reftex-index-phrases-map   reftex-index-phrases-menu reftex-index-phrases-map
2048   "Menu for Phrases buffer"   "Menu for Phrases buffer"
2049   '("Phrases"   '("Phrases"

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

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