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 |
|
|
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 |
|
|
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. |
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))) |
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 |
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" |
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)) |
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)) |
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 |
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))))) |
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 |
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)) |
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 |
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))))) |
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 |
|
|
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 |
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)) |
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)) |
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." |
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)))) |
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 |
|
|
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")))) |
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))))) |
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)))) |
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")) |
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] |
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])) |
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 |
|
|
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 |
|
|
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 ") |
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 () |
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) |
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 |
|
|
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 |
|
|
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) |
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 |
|
|
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) |
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)) |
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))) |
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 |
|
|
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)) |
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)) |
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))))) |
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. |
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 |
|
|
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) "")))) |
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)) |
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 |
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))) |
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))) |
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)))) |
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 |
|
|
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)) |
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" |