1 |
;;; reftex-index.el --- index support with RefTeX |
;;; reftex-index.el --- index support with RefTeX |
2 |
;; Copyright (c) 1997, 1998, 1999, 2000 Free Software Foundation, Inc. |
;; Copyright (c) 1997, 1998, 1999, 2000 Free Software Foundation, Inc. |
3 |
|
|
4 |
;; Author: Carsten Dominik <dominik@strw.LeidenUniv.nl> |
;; Author: Carsten Dominik <dominik@science.uva.nl> |
5 |
;; Version: 4.16 |
;; Version: 4.18 |
6 |
|
|
7 |
;; This file is part of GNU Emacs. |
;; This file is part of GNU Emacs. |
8 |
|
|
30 |
(require 'reftex) |
(require 'reftex) |
31 |
;;; |
;;; |
32 |
|
|
33 |
|
;; START remove for XEmacs release |
34 |
(defvar mark-active) |
(defvar mark-active) |
35 |
(defvar zmacs-regions) |
(defvar zmacs-regions) |
36 |
(defvar transient-mark-mode) |
(defvar transient-mark-mode) |
37 |
|
;; END remove for XEmacs release |
38 |
(defun reftex-index-selection-or-word (&optional arg phrase) |
(defun reftex-index-selection-or-word (&optional arg phrase) |
39 |
"Put selection or the word near point into the default index macro. |
"Put selection or the word near point into the default index macro. |
40 |
This uses the information in `reftex-index-default-macro' to make an index |
This uses the information in `reftex-index-default-macro' to make an index |
51 |
(active (if (boundp 'zmacs-regions) |
(active (if (boundp 'zmacs-regions) |
52 |
(and zmacs-regions (region-exists-p)) ; XEmacs |
(and zmacs-regions (region-exists-p)) ; XEmacs |
53 |
(and transient-mark-mode mark-active))) ; Emacs |
(and transient-mark-mode mark-active))) ; Emacs |
54 |
(beg (if active |
(beg (if active |
55 |
(region-beginning) |
(region-beginning) |
56 |
(save-excursion |
(save-excursion |
57 |
(skip-syntax-backward "w\\") (point)))) |
(skip-syntax-backward "w\\") (point)))) |
58 |
(end (if active |
(end (if active |
59 |
(region-end) |
(region-end) |
60 |
(save-excursion |
(save-excursion |
61 |
(skip-syntax-forward "w\\") (point)))) |
(skip-syntax-forward "w\\") (point)))) |
62 |
(sel (buffer-substring beg end)) |
(sel (buffer-substring beg end)) |
63 |
(mathp (condition-case nil (texmathp) (error nil))) |
(mathp (condition-case nil (texmathp) (error nil))) |
88 |
;; Delete what is in the buffer and make the index entry |
;; Delete what is in the buffer and make the index entry |
89 |
(delete-region beg end) |
(delete-region beg end) |
90 |
(reftex-index def-char full-entry def-tag sel))))) |
(reftex-index def-char full-entry def-tag sel))))) |
91 |
|
|
92 |
(defun reftex-index (&optional char key tag sel no-insert) |
(defun reftex-index (&optional char key tag sel no-insert) |
93 |
"Query for an index macro and insert it along with its argments. |
"Query for an index macro and insert it along with its argments. |
94 |
The index macros available are those defined in `reftex-index-macro' or |
The index macros available are those defined in `reftex-index-macro' or |
164 |
;; OPT-ARGS is a list of optional argument indices, as given by |
;; OPT-ARGS is a list of optional argument indices, as given by |
165 |
;; `reftex-parse-args'. |
;; `reftex-parse-args'. |
166 |
(let* ((opt (and (integerp itag) (member itag opt-args))) |
(let* ((opt (and (integerp itag) (member itag opt-args))) |
167 |
(index-tags (cdr (assq 'index-tags |
(index-tags (cdr (assq 'index-tags |
168 |
(symbol-value reftex-docstruct-symbol)))) |
(symbol-value reftex-docstruct-symbol)))) |
169 |
(default (reftex-default-index)) |
(default (reftex-default-index)) |
170 |
(prompt (concat "Index tag" |
(prompt (concat "Index tag" |
178 |
(defun reftex-index-select-tag () |
(defun reftex-index-select-tag () |
179 |
;; Have the user select an index tag. |
;; Have the user select an index tag. |
180 |
;; FIXME: should we cache tag-alist, prompt and help? |
;; FIXME: should we cache tag-alist, prompt and help? |
181 |
(let* ((index-tags (cdr (assoc 'index-tags |
(let* ((index-tags (cdr (assoc 'index-tags |
182 |
(symbol-value reftex-docstruct-symbol)))) |
(symbol-value reftex-docstruct-symbol)))) |
183 |
(default (reftex-default-index))) |
(default (reftex-default-index))) |
184 |
(cond |
(cond |
185 |
((null index-tags) |
((null index-tags) |
186 |
(error "No index tags available")) |
(error "No index tags available")) |
187 |
|
|
188 |
((= (length index-tags) 1) |
((= (length index-tags) 1) |
189 |
;; Just one index, use it |
;; Just one index, use it |
190 |
(car index-tags)) |
(car index-tags)) |
191 |
|
|
192 |
((> (length index-tags) 1) |
((> (length index-tags) 1) |
193 |
;; Several indices, ask. |
;; Several indices, ask. |
194 |
(let* ((tags (copy-sequence index-tags)) |
(let* ((tags (copy-sequence index-tags)) |
209 |
(unless (assq (aref tag i) tag-alist) |
(unless (assq (aref tag i) tag-alist) |
210 |
(push (list (aref tag i) |
(push (list (aref tag i) |
211 |
tag |
tag |
212 |
(concat (substring tag 0 i) |
(concat (substring tag 0 i) |
213 |
"[" (substring tag i (incf i)) "]" |
"[" (substring tag i (incf i)) "]" |
214 |
(substring tag i))) |
(substring tag i))) |
215 |
tag-alist) |
tag-alist) |
216 |
(throw 'exit t))) |
(throw 'exit t))) |
217 |
(push (list (+ ?0 (incf cnt)) tag |
(push (list (+ ?0 (incf cnt)) tag |
218 |
(concat "[" (int-to-string cnt) "]:" tag)) |
(concat "[" (int-to-string cnt) "]:" tag)) |
219 |
tag-alist))) |
tag-alist))) |
220 |
(setq tag-alist (nreverse tag-alist)) |
(setq tag-alist (nreverse tag-alist)) |
229 |
(if default |
(if default |
230 |
(format "[^M] %s (the default)\n" default) |
(format "[^M] %s (the default)\n" default) |
231 |
"") |
"") |
232 |
(mapconcat (lambda(x) |
(mapconcat (lambda(x) |
233 |
(apply 'format "[%c] %s" x)) |
(apply 'format "[%c] %s" x)) |
234 |
tag-alist "\n"))) |
tag-alist "\n"))) |
235 |
;; Query the user for an index-tag |
;; Query the user for an index-tag |
258 |
key)) |
key)) |
259 |
|
|
260 |
(defun reftex-index-update-taglist (newtag) |
(defun reftex-index-update-taglist (newtag) |
261 |
;; add NEWTAG to the list of available index tags. |
;; add NEWTAG to the list of available index tags. |
262 |
(let ((cell (assoc 'index-tags (symbol-value reftex-docstruct-symbol)))) |
(let ((cell (assoc 'index-tags (symbol-value reftex-docstruct-symbol)))) |
263 |
(and newtag (cdr cell) (not (member newtag (cdr cell))) |
(and newtag (cdr cell) (not (member newtag (cdr cell))) |
264 |
(push newtag (cdr cell))))) |
(push newtag (cdr cell))))) |
301 |
" R<" 'reftex-index-restriction-indicator ">" |
" R<" 'reftex-index-restriction-indicator ">" |
302 |
" -%-")) |
" -%-")) |
303 |
(setq truncate-lines t) |
(setq truncate-lines t) |
304 |
|
(when (featurep 'xemacs) |
305 |
|
;; XEmacs needs the call to make-local-hook |
306 |
|
(make-local-hook 'post-command-hook) |
307 |
|
(make-local-hook 'pre-command-hook)) |
308 |
(make-local-variable 'reftex-last-follow-point) |
(make-local-variable 'reftex-last-follow-point) |
309 |
(easy-menu-add reftex-index-menu reftex-index-map) |
(easy-menu-add reftex-index-menu reftex-index-map) |
310 |
(add-hook 'post-command-hook 'reftex-index-post-command-hook nil t) |
(add-hook 'post-command-hook 'reftex-index-post-command-hook nil t) |
339 |
;; Note: This function just looks for the nearest match of the |
;; Note: This function just looks for the nearest match of the |
340 |
;; context string and may fail if the entry moved and an identical |
;; context string and may fail if the entry moved and an identical |
341 |
;; entry is close to the old position. Frequent rescans make this |
;; entry is close to the old position. Frequent rescans make this |
342 |
;; safer. |
;; safer. |
343 |
(let* ((file (nth 3 data)) |
(let* ((file (nth 3 data)) |
344 |
(literal (nth 2 data)) |
(literal (nth 2 data)) |
345 |
(pos (nth 4 data)) |
(pos (nth 4 data)) |
387 |
(calling-file (buffer-file-name)) |
(calling-file (buffer-file-name)) |
388 |
(restriction |
(restriction |
389 |
(or overriding-restriction |
(or overriding-restriction |
390 |
(and (interactive-p) |
(and (interactive-p) |
391 |
(reftex-get-restriction current-prefix-arg docstruct)))) |
(reftex-get-restriction current-prefix-arg docstruct)))) |
392 |
(locations |
(locations |
393 |
;; See if we are on an index macro as initial position |
;; See if we are on an index macro as initial position |
396 |
(macro (car what-macro)) |
(macro (car what-macro)) |
397 |
(here-I-am (when (member macro reftex-macros-with-index) |
(here-I-am (when (member macro reftex-macros-with-index) |
398 |
(save-excursion |
(save-excursion |
399 |
(goto-char (+ (cdr what-macro) |
(goto-char (+ (cdr what-macro) |
400 |
(length macro))) |
(length macro))) |
401 |
(reftex-move-over-touching-args) |
(reftex-move-over-touching-args) |
402 |
(reftex-where-am-I))))) |
(reftex-where-am-I))))) |
407 |
(setq buffer-name (reftex-make-index-buffer-name index-tag)) |
(setq buffer-name (reftex-make-index-buffer-name index-tag)) |
408 |
|
|
409 |
;; Goto the buffer and put it into the correct mode |
;; Goto the buffer and put it into the correct mode |
410 |
|
|
411 |
(when (or restriction current-prefix-arg) |
(when (or restriction current-prefix-arg) |
412 |
(reftex-kill-buffer buffer-name)) |
(reftex-kill-buffer buffer-name)) |
413 |
|
|
500 |
;; Delete the entry at place |
;; Delete the entry at place |
501 |
(and (bolp) (forward-char 1)) |
(and (bolp) (forward-char 1)) |
502 |
(delete-region (previous-single-property-change (1+ (point)) :data) |
(delete-region (previous-single-property-change (1+ (point)) :data) |
503 |
(or (next-single-property-change (point) :data) |
(or (next-single-property-change (point) :data) |
504 |
(point-max)))) |
(point-max)))) |
505 |
|
|
506 |
;; Walk through the list and insert all entries |
;; Walk through the list and insert all entries |
521 |
(insert indent (nth 7 cell)) |
(insert indent (nth 7 cell)) |
522 |
(when font |
(when font |
523 |
(setq to (point)) |
(setq to (point)) |
524 |
(put-text-property |
(put-text-property |
525 |
(- (point) (length (nth 7 cell))) to |
(- (point) (length (nth 7 cell))) to |
526 |
'face index-face) |
'face index-face) |
527 |
(goto-char to)) |
(goto-char to)) |
549 |
(defun reftex-index-insert-new-letter (letter &optional font) |
(defun reftex-index-insert-new-letter (letter &optional font) |
550 |
;; Start a new section in the index |
;; Start a new section in the index |
551 |
(let ((from (point))) |
(let ((from (point))) |
552 |
(insert "\n" letter letter letter |
(insert "\n" letter letter letter |
553 |
"-----------------------------------------------------------------") |
"-----------------------------------------------------------------") |
554 |
(when font |
(when font |
555 |
(put-text-property from (point) 'face reftex-index-section-face)) |
(put-text-property from (point) 'face reftex-index-section-face)) |
626 |
(interactive "p") |
(interactive "p") |
627 |
(setq reftex-callback-fwd t) |
(setq reftex-callback-fwd t) |
628 |
(or (eobp) (forward-char 1)) |
(or (eobp) (forward-char 1)) |
629 |
(goto-char (or (next-single-property-change (point) :data) |
(goto-char (or (next-single-property-change (point) :data) |
630 |
(point))) |
(point))) |
631 |
(unless (get-text-property (point) :data) |
(unless (get-text-property (point) :data) |
632 |
(goto-char (or (next-single-property-change (point) :data) |
(goto-char (or (next-single-property-change (point) :data) |
633 |
(point))))) |
(point))))) |
634 |
(defun reftex-index-previous (&optional arg) |
(defun reftex-index-previous (&optional arg) |
635 |
"Move to previous selectable item." |
"Move to previous selectable item." |
772 |
(reftex-index-restrict-to-section t) |
(reftex-index-restrict-to-section t) |
773 |
(setq reftex-index-restriction-indicator (nth 6 bor) |
(setq reftex-index-restriction-indicator (nth 6 bor) |
774 |
reftex-index-restriction-data |
reftex-index-restriction-data |
775 |
(list bor |
(list bor |
776 |
(car (memq (assq 'toc (cdr (memq bor docstruct))) |
(car (memq (assq 'toc (cdr (memq bor docstruct))) |
777 |
docstruct)))) |
docstruct)))) |
778 |
(reftex-index-revert)))) |
(reftex-index-revert)))) |
804 |
show-window show-buffer match) |
show-window show-buffer match) |
805 |
|
|
806 |
(unless data (error "Don't know which index entry to visit")) |
(unless data (error "Don't know which index entry to visit")) |
807 |
|
|
808 |
(if (eq (car data) 'index) |
(if (eq (car data) 'index) |
809 |
(setq match (reftex-index-show-entry data no-revisit))) |
(setq match (reftex-index-show-entry data no-revisit))) |
810 |
|
|
875 |
attr (nth 2 analyze)) |
attr (nth 2 analyze)) |
876 |
(setf (nth 2 analyze) (if (string= attr bor) "" bor)) |
(setf (nth 2 analyze) (if (string= attr bor) "" bor)) |
877 |
(setq new (apply 'concat analyze)) |
(setq new (apply 'concat analyze)) |
878 |
(reftex-index-change-entry |
(reftex-index-change-entry |
879 |
new (if (string= (nth 2 analyze) bor) |
new (if (string= (nth 2 analyze) bor) |
880 |
"Entry is now START-OF-PAGE-RANGE" |
"Entry is now START-OF-PAGE-RANGE" |
881 |
"START-OF-PAGE-RANGE canceled")))) |
"START-OF-PAGE-RANGE canceled")))) |
933 |
(t (setf (nth n analyze) (concat initial npart)))) |
(t (setf (nth n analyze) (concat initial npart)))) |
934 |
(setq new (apply 'concat analyze)) |
(setq new (apply 'concat analyze)) |
935 |
;; Change the entry and insert the changed version into the index. |
;; Change the entry and insert the changed version into the index. |
936 |
(reftex-index-change-entry |
(reftex-index-change-entry |
937 |
new (if (string= npart "") |
new (if (string= npart "") |
938 |
(format "Deleted: %s" opart) |
(format "Deleted: %s" opart) |
939 |
(format "New value is: %s" npart))))) |
(format "New value is: %s" npart))))) |
947 |
(unless data (error "Don't know which index entry to change")) |
(unless data (error "Don't know which index entry to change")) |
948 |
(setq old (nth 2 data) |
(setq old (nth 2 data) |
949 |
key (nth 6 data) |
key (nth 6 data) |
950 |
prefix (completing-read |
prefix (completing-read |
951 |
"Prefix: " |
"Prefix: " |
952 |
(reftex-sublist-nth |
(reftex-sublist-nth |
953 |
docstruct 6 |
docstruct 6 |
954 |
(lambda (x) |
(lambda (x) |
955 |
(and (eq (car x) 'index) |
(and (eq (car x) 'index) |
956 |
(string= (nth 1 x) reftex-index-tag))) t))) |
(string= (nth 1 x) reftex-index-tag))) t))) |
957 |
(unless (string-match |
(unless (string-match |
958 |
(concat (regexp-quote (car reftex-index-special-chars)) "\\'") |
(concat (regexp-quote (car reftex-index-special-chars)) "\\'") |
959 |
prefix) |
prefix) |
960 |
(setq prefix (concat prefix (car reftex-index-special-chars)))) |
(setq prefix (concat prefix (car reftex-index-special-chars)))) |
994 |
(defun reftex-index-change-entry (new &optional message) |
(defun reftex-index-change-entry (new &optional message) |
995 |
;; Change the full context string of the index entry at point to |
;; Change the full context string of the index entry at point to |
996 |
;; NEW. This actually edits the buffer where the entry is defined. |
;; NEW. This actually edits the buffer where the entry is defined. |
997 |
|
|
998 |
(let* ((data (get-text-property (point) :data)) |
(let* ((data (get-text-property (point) :data)) |
999 |
old beg end info) |
old beg end info) |
1000 |
(unless data (error "Cannot change entry")) |
(unless data (error "Cannot change entry")) |
1086 |
(if (eq char ?!) |
(if (eq char ?!) |
1087 |
(error "This <%s> index does not contain entries sorted before the letters" |
(error "This <%s> index does not contain entries sorted before the letters" |
1088 |
reftex-index-tag) |
reftex-index-tag) |
1089 |
(error "This <%s> index does not contain entries starting with `%c'" |
(error "This <%s> index does not contain entries starting with `%c'" |
1090 |
reftex-index-tag char))))) |
reftex-index-tag char))))) |
1091 |
|
|
1092 |
(easy-menu-define |
(easy-menu-define |
1093 |
reftex-index-menu reftex-index-map |
reftex-index-menu reftex-index-map |
1094 |
"Menu for Index buffer" |
"Menu for Index buffer" |
1095 |
`("Index" |
`("Index" |
1096 |
["Goto section A-Z" |
["Goto section A-Z" |
1097 |
(message "To go to a section, just press any of: !%s" |
(message "To go to a section, just press any of: !%s" |
1098 |
reftex-index-section-letters) t] |
reftex-index-section-letters) t] |
1099 |
["Show Entry" reftex-index-view-entry t] |
["Show Entry" reftex-index-view-entry t] |
1133 |
["Context" reftex-index-toggle-context :style toggle |
["Context" reftex-index-toggle-context :style toggle |
1134 |
:selected reftex-index-include-context] |
:selected reftex-index-include-context] |
1135 |
"--" |
"--" |
1136 |
["Follow Mode" reftex-index-toggle-follow :style toggle |
["Follow Mode" reftex-index-toggle-follow :style toggle |
1137 |
:selected reftex-index-follow-mode]) |
:selected reftex-index-follow-mode]) |
1138 |
"--" |
"--" |
1139 |
["Help" reftex-index-show-help t])) |
["Help" reftex-index-show-help t])) |
1185 |
(set-marker reftex-index-return-marker (point)) |
(set-marker reftex-index-return-marker (point)) |
1186 |
(reftex-index-selection-or-word arg 'phrase) |
(reftex-index-selection-or-word arg 'phrase) |
1187 |
(if (eq major-mode 'reftex-index-phrases-mode) |
(if (eq major-mode 'reftex-index-phrases-mode) |
1188 |
(message |
(message |
1189 |
(substitute-command-keys |
(substitute-command-keys |
1190 |
"Return to LaTeX with \\[reftex-index-phrases-save-and-return]")))) |
"Return to LaTeX with \\[reftex-index-phrases-save-and-return]")))) |
1191 |
|
|
1214 |
(sort (copy-sequence reftex-index-macro-alist) |
(sort (copy-sequence reftex-index-macro-alist) |
1215 |
(lambda (a b) (equal (car a) default-macro)))) |
(lambda (a b) (equal (car a) default-macro)))) |
1216 |
macro entry key repeat) |
macro entry key repeat) |
1217 |
|
|
1218 |
(if master (set (make-local-variable 'TeX-master) |
(if master (set (make-local-variable 'TeX-master) |
1219 |
(file-name-nondirectory master))) |
(file-name-nondirectory master))) |
1220 |
|
|
1227 |
(if (looking-at reftex-index-phrases-comment-regexp) |
(if (looking-at reftex-index-phrases-comment-regexp) |
1228 |
(beginning-of-line 2)) |
(beginning-of-line 2)) |
1229 |
(while (looking-at "^[ \t]*$") |
(while (looking-at "^[ \t]*$") |
1230 |
(beginning-of-line 2)) |
(beginning-of-line 2)) |
1231 |
(cond ((fboundp 'zmacs-activate-region) (zmacs-activate-region)) |
(cond ((fboundp 'zmacs-activate-region) (zmacs-activate-region)) |
1232 |
((boundp 'make-active) (setq mark-active t))) |
((boundp 'make-active) (setq mark-active t))) |
1233 |
(if (yes-or-no-p "Delete and rebuilt header ") |
(if (yes-or-no-p "Delete and rebuilt header ") |
1303 |
(setq major-mode 'reftex-index-phrases-mode |
(setq major-mode 'reftex-index-phrases-mode |
1304 |
mode-name "Phrases") |
mode-name "Phrases") |
1305 |
(use-local-map reftex-index-phrases-map) |
(use-local-map reftex-index-phrases-map) |
1306 |
(set (make-local-variable 'font-lock-defaults) |
(set (make-local-variable 'font-lock-defaults) |
1307 |
reftex-index-phrases-font-lock-defaults) |
reftex-index-phrases-font-lock-defaults) |
1308 |
(easy-menu-add reftex-index-phrases-menu reftex-index-phrases-map) |
(easy-menu-add reftex-index-phrases-menu reftex-index-phrases-map) |
1309 |
(set (make-local-variable 'reftex-index-phrases-marker) (make-marker)) |
(set (make-local-variable 'reftex-index-phrases-marker) (make-marker)) |
1313 |
;; Font Locking stuff |
;; Font Locking stuff |
1314 |
(let ((ss (if (featurep 'xemacs) 'secondary-selection ''secondary-selection))) |
(let ((ss (if (featurep 'xemacs) 'secondary-selection ''secondary-selection))) |
1315 |
(setq reftex-index-phrases-font-lock-keywords |
(setq reftex-index-phrases-font-lock-keywords |
1316 |
(list |
(list |
1317 |
(cons reftex-index-phrases-comment-regexp 'font-lock-comment-face) |
(cons reftex-index-phrases-comment-regexp 'font-lock-comment-face) |
1318 |
(list reftex-index-phrases-macrodef-regexp |
(list reftex-index-phrases-macrodef-regexp |
1319 |
'(1 font-lock-type-face) |
'(1 font-lock-type-face) |
1337 |
(setq reftex-index-phrases-font-lock-defaults |
(setq reftex-index-phrases-font-lock-defaults |
1338 |
'((reftex-index-phrases-font-lock-keywords) |
'((reftex-index-phrases-font-lock-keywords) |
1339 |
nil t nil beginning-of-line)) |
nil t nil beginning-of-line)) |
1340 |
(put 'reftex-index-phrases-mode 'font-lock-defaults |
(put 'reftex-index-phrases-mode 'font-lock-defaults |
1341 |
reftex-index-phrases-font-lock-defaults) ; XEmacs |
reftex-index-phrases-font-lock-defaults) ; XEmacs |
1342 |
) |
) |
1343 |
|
|
1400 |
(move-marker reftex-index-phrases-marker |
(move-marker reftex-index-phrases-marker |
1401 |
(match-beginning 0) (current-buffer)) |
(match-beginning 0) (current-buffer)) |
1402 |
;; Start the query-replace |
;; Start the query-replace |
1403 |
(reftex-query-index-phrase-globally |
(reftex-query-index-phrase-globally |
1404 |
files phrase macro-fmt |
files phrase macro-fmt |
1405 |
index-key repeat as-words) |
index-key repeat as-words) |
1406 |
(message "%s replaced" |
(message "%s replaced" |
1407 |
(reftex-number replace-count "occurrence")))))) |
(reftex-number replace-count "occurrence")))))) |
1408 |
(t (error "Cannot parse this line"))))) |
(t (error "Cannot parse this line"))))) |
1409 |
|
|
1446 |
(unless buf (error "Master file %s not found" master)) |
(unless buf (error "Master file %s not found" master)) |
1447 |
(set-buffer buf) |
(set-buffer buf) |
1448 |
(reftex-access-scan-info) |
(reftex-access-scan-info) |
1449 |
(setq reftex-index-phrases-files |
(setq reftex-index-phrases-files |
1450 |
(reftex-all-document-files)))) |
(reftex-all-document-files)))) |
1451 |
;; Parse the files header for macro definitions |
;; Parse the files header for macro definitions |
1452 |
(setq reftex-index-phrases-macro-data nil) |
(setq reftex-index-phrases-macro-data nil) |
1461 |
;; Reverse the list, so that the first macro is first |
;; Reverse the list, so that the first macro is first |
1462 |
(if (null reftex-index-phrases-macro-data) |
(if (null reftex-index-phrases-macro-data) |
1463 |
(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)) |
1464 |
(setq reftex-index-phrases-macro-data |
(setq reftex-index-phrases-macro-data |
1465 |
(nreverse reftex-index-phrases-macro-data)) |
(nreverse reftex-index-phrases-macro-data)) |
1466 |
(goto-char (point-min))))) |
(goto-char (point-min))))) |
1467 |
|
|
1473 |
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." |
1474 |
(interactive "r") |
(interactive "r") |
1475 |
(let ((win-conf (current-window-configuration)) |
(let ((win-conf (current-window-configuration)) |
1476 |
(reftex-index-phrases-restrict-file (buffer-file-name))) |
(reftex-index-phrases-restrict-file (buffer-file-name))) |
1477 |
(save-excursion |
(save-excursion |
1478 |
(save-restriction |
(save-restriction |
1479 |
(narrow-to-region beg end) |
(narrow-to-region beg end) |
1496 |
(setq text (reftex-index-simplify-phrase text)) |
(setq text (reftex-index-simplify-phrase text)) |
1497 |
(goto-char (point-min)) |
(goto-char (point-min)) |
1498 |
(if (re-search-forward |
(if (re-search-forward |
1499 |
(concat "^\\(\\S-*\\)\t\\(" (regexp-quote text) |
(concat "^\\(\\S-*\\)\t\\(" (regexp-quote text) |
1500 |
"\\) *[\t\n]") nil t) |
"\\) *[\t\n]") nil t) |
1501 |
(progn |
(progn |
1502 |
(goto-char (match-end 2)) |
(goto-char (match-end 2)) |
1526 |
(let* ((phrase (match-string 3)) |
(let* ((phrase (match-string 3)) |
1527 |
(case-fold-search reftex-index-phrases-case-fold-search) |
(case-fold-search reftex-index-phrases-case-fold-search) |
1528 |
(re (reftex-index-phrases-find-dup-re phrase t))) |
(re (reftex-index-phrases-find-dup-re phrase t))) |
1529 |
(if (save-excursion |
(if (save-excursion |
1530 |
(goto-char (point-min)) |
(goto-char (point-min)) |
1531 |
(and (re-search-forward re nil t) |
(and (re-search-forward re nil t) |
1532 |
(re-search-forward re nil t))) |
(re-search-forward re nil t))) |
1619 |
(progn |
(progn |
1620 |
(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" |
1621 |
(reftex-number ntimes2 "line"))) |
(reftex-number ntimes2 "line"))) |
1622 |
(mapcar (lambda(x) |
(mapcar (lambda(x) |
1623 |
(princ (format " Line %4d: %s\n" (car x) (cdr x)))) |
(princ (format " Line %4d: %s\n" (car x) (cdr x)))) |
1624 |
(nreverse superphrases)))))))) |
(nreverse superphrases)))))))) |
1625 |
|
|
1672 |
beg end) |
beg end) |
1673 |
(goto-char (point-min)) |
(goto-char (point-min)) |
1674 |
;; Find first and last phrase line in buffer |
;; Find first and last phrase line in buffer |
1675 |
(setq beg |
(setq beg |
1676 |
(and (re-search-forward reftex-index-phrases-phrase-regexp12 nil t) |
(and (re-search-forward reftex-index-phrases-phrase-regexp12 nil t) |
1677 |
(match-beginning 0))) |
(match-beginning 0))) |
1678 |
(goto-char (point-max)) |
(goto-char (point-max)) |
1699 |
(if (string-match reftex-index-phrases-phrase-regexp12 a) |
(if (string-match reftex-index-phrases-phrase-regexp12 a) |
1700 |
(progn |
(progn |
1701 |
;; Extract macro char and phrase-or-key for a |
;; Extract macro char and phrase-or-key for a |
1702 |
(setq ca (match-string 1 a) |
(setq ca (match-string 1 a) |
1703 |
pa (downcase |
pa (downcase |
1704 |
(or (and reftex-index-phrases-sort-prefers-entry |
(or (and reftex-index-phrases-sort-prefers-entry |
1705 |
(match-string 6 a)) |
(match-string 6 a)) |
1706 |
(match-string 3 a)))) |
(match-string 3 a)))) |
1707 |
(if (string-match reftex-index-phrases-phrase-regexp12 b) |
(if (string-match reftex-index-phrases-phrase-regexp12 b) |
1708 |
(progn |
(progn |
1709 |
;; Extract macro char and phrase-or-key for b |
;; Extract macro char and phrase-or-key for b |
1710 |
(setq cb (match-string 1 b) |
(setq cb (match-string 1 b) |
1711 |
pb (downcase |
pb (downcase |
1712 |
(or (and reftex-index-phrases-sort-prefers-entry |
(or (and reftex-index-phrases-sort-prefers-entry |
1713 |
(match-string 6 b)) |
(match-string 6 b)) |
1715 |
(setq c-p (string< ca cb) |
(setq c-p (string< ca cb) |
1716 |
p-p (string< pa pb)) |
p-p (string< pa pb)) |
1717 |
;; Do the right comparison, based on the value of `chars-first' |
;; Do the right comparison, based on the value of `chars-first' |
1718 |
;; `chars-first' is bound locally in the calling function |
;; `chars-first' is bound locally in the calling function |
1719 |
(if chars-first |
(if chars-first |
1720 |
(if (string= ca cb) p-p c-p) |
(if (string= ca cb) p-p c-p) |
1721 |
(if (string= pa pb) c-p p-p))))) |
(if (string= pa pb) c-p p-p))))) |
1726 |
(not reftex-index-phrases-sort-in-blocks)))) |
(not reftex-index-phrases-sort-in-blocks)))) |
1727 |
|
|
1728 |
(defvar reftex-index-phrases-menu) |
(defvar reftex-index-phrases-menu) |
1729 |
(defun reftex-index-make-phrase-regexp (phrase &optional |
(defun reftex-index-make-phrase-regexp (phrase &optional |
1730 |
as-words allow-newline) |
as-words allow-newline) |
1731 |
"Return a regexp matching PHRASE, even if distributed over lines. |
"Return a regexp matching PHRASE, even if distributed over lines. |
1732 |
With optional arg AS-WORDS, require word boundary at beginning and end. |
With optional arg AS-WORDS, require word boundary at beginning and end. |
1739 |
"\\<" "") |
"\\<" "") |
1740 |
(mapconcat (lambda (w) (regexp-quote (downcase w))) |
(mapconcat (lambda (w) (regexp-quote (downcase w))) |
1741 |
words space-re) |
words space-re) |
1742 |
(if (and as-words |
(if (and as-words |
1743 |
(string-match "\\w\\'" (nth (1- (length words)) words))) |
(string-match "\\w\\'" (nth (1- (length words)) words))) |
1744 |
"\\>" "")))) |
"\\>" "")))) |
1745 |
|
|
1762 |
(let ((index-keys (split-string (or index-key match) |
(let ((index-keys (split-string (or index-key match) |
1763 |
reftex-index-phrases-logical-and-regexp))) |
reftex-index-phrases-logical-and-regexp))) |
1764 |
(concat |
(concat |
1765 |
(mapconcat (lambda (x) |
(mapconcat (lambda (x) |
1766 |
(format macro-fmt |
(format macro-fmt |
1767 |
(format (if mathp reftex-index-math-format "%s") x))) |
(format (if mathp reftex-index-math-format "%s") x))) |
1768 |
index-keys "") |
index-keys "") |
1769 |
(if repeat (reftex-index-simplify-phrase match) "")))) |
(if repeat (reftex-index-simplify-phrase match) "")))) |
1775 |
(unless files (error "No files")) |
(unless files (error "No files")) |
1776 |
(unwind-protect |
(unwind-protect |
1777 |
(progn |
(progn |
1778 |
(switch-to-buffer-other-window (reftex-get-file-buffer-force |
(switch-to-buffer-other-window (reftex-get-file-buffer-force |
1779 |
(car files))) |
(car files))) |
1780 |
(catch 'no-more-files |
(catch 'no-more-files |
1781 |
(while (setq file (pop files)) |
(while (setq file (pop files)) |
1815 |
both ends." |
both ends." |
1816 |
(let* ((re (reftex-index-make-phrase-regexp phrase as-words 'allow-newline)) |
(let* ((re (reftex-index-make-phrase-regexp phrase as-words 'allow-newline)) |
1817 |
(case-fold-search reftex-index-phrases-case-fold-search) |
(case-fold-search reftex-index-phrases-case-fold-search) |
1818 |
(index-keys (split-string |
(index-keys (split-string |
1819 |
(or index-key phrase) |
(or index-key phrase) |
1820 |
reftex-index-phrases-logical-or-regexp)) |
reftex-index-phrases-logical-or-regexp)) |
1821 |
(nkeys (length index-keys)) |
(nkeys (length index-keys)) |
1822 |
(ckey (nth 0 index-keys)) |
(ckey (nth 0 index-keys)) |
1823 |
(all-yes nil) |
(all-yes nil) |
1824 |
match rpl char beg end mathp) |
match rpl char beg end mathp) |
1825 |
(unwind-protect |
(unwind-protect |
1826 |
(while (re-search-forward re nil t) |
(while (re-search-forward re nil t) |
1827 |
(catch 'next-match |
(catch 'next-match |
1828 |
|
(if (and (fboundp reftex-index-verify-function) |
1829 |
|
(not (funcall reftex-index-verify-function))) |
1830 |
|
(throw 'next-match nil)) |
1831 |
(setq match (match-string 0)) |
(setq match (match-string 0)) |
1832 |
(setq mathp |
(setq mathp |
1833 |
(save-match-data |
(save-match-data |
1840 |
end))) |
end))) |
1841 |
(throw 'next-match nil)) |
(throw 'next-match nil)) |
1842 |
(reftex-highlight 0 (match-beginning 0) (match-end 0)) |
(reftex-highlight 0 (match-beginning 0) (match-end 0)) |
1843 |
(setq rpl |
(setq rpl |
1844 |
(save-match-data |
(save-match-data |
1845 |
(reftex-index-make-replace-string |
(reftex-index-make-replace-string |
1846 |
macro-fmt (match-string 0) ckey repeat mathp))) |
macro-fmt (match-string 0) ckey repeat mathp))) |
1847 |
(while |
(while |
1848 |
(not |
(not |
1849 |
(catch 'loop |
(catch 'loop |
1850 |
(message "REPLACE: %s? (yn!qoe%s?)" |
(message "REPLACE: %s? (yn!qoe%s?)" |
1851 |
rpl |
rpl |
1852 |
(if (> nkeys 1) |
(if (> nkeys 1) |
1853 |
(concat "1-" (int-to-string nkeys)) |
(concat "1-" (int-to-string nkeys)) |
1854 |
"")) |
"")) |
1855 |
(setq char (if all-yes ?y (read-char-exclusive))) |
(setq char (if all-yes ?y (read-char-exclusive))) |
1883 |
((member char '(?o ?O)) |
((member char '(?o ?O)) |
1884 |
;; Select a differnt macro |
;; Select a differnt macro |
1885 |
(let* ((nc (reftex-index-select-phrases-macro 2)) |
(let* ((nc (reftex-index-select-phrases-macro 2)) |
1886 |
(macro-data |
(macro-data |
1887 |
(cdr (assoc nc reftex-index-phrases-macro-data))) |
(cdr (assoc nc reftex-index-phrases-macro-data))) |
1888 |
(macro-fmt (car macro-data)) |
(macro-fmt (car macro-data)) |
1889 |
(repeat (nth 1 macro-data))) |
(repeat (nth 1 macro-data))) |
1901 |
;; Recursive edit |
;; Recursive edit |
1902 |
(save-match-data |
(save-match-data |
1903 |
(save-excursion |
(save-excursion |
1904 |
(message |
(message |
1905 |
(substitute-command-keys |
(substitute-command-keys |
1906 |
"Recursive edit. Resume with \\[exit-recursive-edit]")) |
"Recursive edit. Resume with \\[exit-recursive-edit]")) |
1907 |
(recursive-edit)))) |
(recursive-edit)))) |
1948 |
(and after-macro |
(and after-macro |
1949 |
(member after-macro reftex-macros-with-index)))))) |
(member after-macro reftex-macros-with-index)))))) |
1950 |
|
|
1951 |
|
|
1952 |
(defun reftex-index-phrases-fixup-line (beg end) |
(defun reftex-index-phrases-fixup-line (beg end) |
1953 |
"Insert newlines before BEG and/or after END to shorten line." |
"Insert newlines before BEG and/or after END to shorten line." |
1954 |
(let (bol eol space1 space2) |
(let (bol eol space1 space2) |
2032 |
("\C-i" . self-insert-command)) |
("\C-i" . self-insert-command)) |
2033 |
do (define-key reftex-index-phrases-map (car x) (cdr x))) |
do (define-key reftex-index-phrases-map (car x) (cdr x))) |
2034 |
|
|
2035 |
(easy-menu-define |
(easy-menu-define |
2036 |
reftex-index-phrases-menu reftex-index-phrases-map |
reftex-index-phrases-menu reftex-index-phrases-map |
2037 |
"Menu for Phrases buffer" |
"Menu for Phrases buffer" |
2038 |
'("Phrases" |
'("Phrases" |