diff options
author | Carsten Dominik <dominik@science.uva.nl> | 2005-09-16 10:05:32 +0000 |
---|---|---|
committer | Carsten Dominik <dominik@science.uva.nl> | 2005-09-16 10:05:32 +0000 |
commit | 7b07114a177abd6bfc17f17450c7689f2e19e7ae (patch) | |
tree | f2f1bf251f682e55b0639f1073051505dfcc1179 /lisp/textmodes/reftex-index.el | |
parent | e3f509dd6ed52119a56806890a5954b5388573bb (diff) | |
download | emacs-7b07114a177abd6bfc17f17450c7689f2e19e7ae.tar.gz |
Little fixes to remove compiler warnings
reftex-index.el (reftex-query-index-phrase): More efficient use
of markers.
Diffstat (limited to 'lisp/textmodes/reftex-index.el')
-rw-r--r-- | lisp/textmodes/reftex-index.el | 168 |
1 files changed, 85 insertions, 83 deletions
diff --git a/lisp/textmodes/reftex-index.el b/lisp/textmodes/reftex-index.el index 804672c1847..1a7821c9d8e 100644 --- a/lisp/textmodes/reftex-index.el +++ b/lisp/textmodes/reftex-index.el @@ -1,10 +1,9 @@ ;;; reftex-index.el --- index support with RefTeX - -;; Copyright (C) 1997, 1998, 1999, 2000, 2002, 2003, 2004, -;; 2005 Free Software Foundation, Inc. +;; Copyright (c) 1997, 1998, 1999, 2000, 2003, 2004, 2005 +;; Free Software Foundation, Inc. ;; Author: Carsten Dominik <dominik@science.uva.nl> -;; Version: 4.28 +;; Version: VERSIONTAG ;; This file is part of GNU Emacs. @@ -20,8 +19,8 @@ ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the -;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -;; Boston, MA 02110-1301, USA. +;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, +;; Boston, MA 02111-1307, USA. ;;; Commentary: @@ -32,13 +31,11 @@ (require 'reftex) ;;; -(defvar reftex-index-phrases-marker) -(defvar TeX-master) - ;; START remove for XEmacs release (defvar mark-active) (defvar zmacs-regions) (defvar transient-mark-mode) +(defvar TeX-master) ;; END remove for XEmacs release (defun reftex-index-selection-or-word (&optional arg phrase) "Put selection or the word near point into the default index macro. @@ -56,13 +53,13 @@ which is part of AUCTeX, the string is first processed with the (active (if (boundp 'zmacs-regions) (and zmacs-regions (region-exists-p)) ; XEmacs (and transient-mark-mode mark-active))) ; Emacs - (beg (if active + (beg (if active (region-beginning) - (save-excursion + (save-excursion (skip-syntax-backward "w\\") (point)))) (end (if active (region-end) - (save-excursion + (save-excursion (skip-syntax-forward "w\\") (point)))) (sel (buffer-substring beg end)) (mathp (condition-case nil (texmathp) (error nil))) @@ -93,7 +90,7 @@ which is part of AUCTeX, the string is first processed with the ;; Delete what is in the buffer and make the index entry (delete-region beg end) (reftex-index def-char full-entry def-tag sel))))) - + (defun reftex-index (&optional char key tag sel no-insert) "Query for an index macro and insert it along with its argments. The index macros available are those defined in `reftex-index-macro' or @@ -169,7 +166,7 @@ will prompt for other arguments." ;; OPT-ARGS is a list of optional argument indices, as given by ;; `reftex-parse-args'. (let* ((opt (and (integerp itag) (member itag opt-args))) - (index-tags (cdr (assq 'index-tags + (index-tags (cdr (assq 'index-tags (symbol-value reftex-docstruct-symbol)))) (default (reftex-default-index)) (prompt (concat "Index tag" @@ -183,17 +180,17 @@ will prompt for other arguments." (defun reftex-index-select-tag () ;; Have the user select an index tag. ;; FIXME: should we cache tag-alist, prompt and help? - (let* ((index-tags (cdr (assoc 'index-tags + (let* ((index-tags (cdr (assoc 'index-tags (symbol-value reftex-docstruct-symbol)))) (default (reftex-default-index))) - (cond + (cond ((null index-tags) (error "No index tags available")) ((= (length index-tags) 1) ;; Just one index, use it (car index-tags)) - + ((> (length index-tags) 1) ;; Several indices, ask. (let* ((tags (copy-sequence index-tags)) @@ -214,12 +211,12 @@ will prompt for other arguments." (unless (assq (aref tag i) tag-alist) (push (list (aref tag i) tag - (concat (substring tag 0 i) + (concat (substring tag 0 i) "[" (substring tag i (incf i)) "]" (substring tag i))) tag-alist) (throw 'exit t))) - (push (list (+ ?0 (incf cnt)) tag + (push (list (+ ?0 (incf cnt)) tag (concat "[" (int-to-string cnt) "]:" tag)) tag-alist))) (setq tag-alist (nreverse tag-alist)) @@ -234,7 +231,7 @@ will prompt for other arguments." (if default (format "[^M] %s (the default)\n" default) "") - (mapconcat (lambda(x) + (mapconcat (lambda(x) (apply 'format "[%c] %s" x)) tag-alist "\n"))) ;; Query the user for an index-tag @@ -263,7 +260,7 @@ will prompt for other arguments." key)) (defun reftex-index-update-taglist (newtag) - ;; add NEWTAG to the list of available index tags. + ;; add NEWTAG to the list of available index tags. (let ((cell (assoc 'index-tags (symbol-value reftex-docstruct-symbol)))) (and newtag (cdr cell) (not (member newtag (cdr cell))) (push newtag (cdr cell))))) @@ -314,7 +311,7 @@ Here are all local bindings. (easy-menu-add reftex-index-menu reftex-index-map) (add-hook 'post-command-hook 'reftex-index-post-command-hook nil t) (add-hook 'pre-command-hook 'reftex-index-pre-command-hook nil t) - (run-mode-hooks 'reftex-index-mode-hook)) + (run-hooks 'reftex-index-mode-hook)) (defconst reftex-index-help " AVAILABLE KEYS IN INDEX BUFFER @@ -344,7 +341,7 @@ _ ^ Add/Remove parent key (to make this item a subitem). ;; Note: This function just looks for the nearest match of the ;; context string and may fail if the entry moved and an identical ;; entry is close to the old position. Frequent rescans make this - ;; safer. + ;; safer. (let* ((file (nth 3 data)) (literal (nth 2 data)) (pos (nth 4 data)) @@ -392,7 +389,7 @@ With prefix 3, restrict index to region." (calling-file (buffer-file-name)) (restriction (or overriding-restriction - (and (not redo) + (and (not redo) (reftex-get-restriction current-prefix-arg docstruct)))) (locations ;; See if we are on an index macro as initial position @@ -401,7 +398,7 @@ With prefix 3, restrict index to region." (macro (car what-macro)) (here-I-am (when (member macro reftex-macros-with-index) (save-excursion - (goto-char (+ (cdr what-macro) + (goto-char (+ (cdr what-macro) (length macro))) (reftex-move-over-touching-args) (reftex-where-am-I))))) @@ -412,7 +409,7 @@ With prefix 3, restrict index to region." (setq buffer-name (reftex-make-index-buffer-name index-tag)) ;; Goto the buffer and put it into the correct mode - + (when (or restriction current-prefix-arg) (reftex-kill-buffer buffer-name)) @@ -505,7 +502,7 @@ SPC=view TAB=goto RET=goto+hide [e]dit [q]uit [r]escan [f]ollow [?]Help ;; Delete the entry at place (and (bolp) (forward-char 1)) (delete-region (previous-single-property-change (1+ (point)) :data) - (or (next-single-property-change (point) :data) + (or (next-single-property-change (point) :data) (point-max)))) ;; Walk through the list and insert all entries @@ -526,7 +523,7 @@ SPC=view TAB=goto RET=goto+hide [e]dit [q]uit [r]escan [f]ollow [?]Help (insert indent (nth 7 cell)) (when font (setq to (point)) - (put-text-property + (put-text-property (- (point) (length (nth 7 cell))) to 'face index-face) (goto-char to)) @@ -554,7 +551,7 @@ SPC=view TAB=goto RET=goto+hide [e]dit [q]uit [r]escan [f]ollow [?]Help (defun reftex-index-insert-new-letter (letter &optional font) ;; Start a new section in the index (let ((from (point))) - (insert "\n" letter letter letter + (insert "\n" letter letter letter "-----------------------------------------------------------------") (when font (put-text-property from (point) 'face reftex-index-section-face)) @@ -631,10 +628,10 @@ SPC=view TAB=goto RET=goto+hide [e]dit [q]uit [r]escan [f]ollow [?]Help (interactive "p") (setq reftex-callback-fwd t) (or (eobp) (forward-char 1)) - (goto-char (or (next-single-property-change (point) :data) + (goto-char (or (next-single-property-change (point) :data) (point))) (unless (get-text-property (point) :data) - (goto-char (or (next-single-property-change (point) :data) + (goto-char (or (next-single-property-change (point) :data) (point))))) (defun reftex-index-previous (&optional arg) "Move to previous selectable item." @@ -777,7 +774,7 @@ When index is restricted, select the next section as restriction criterion." (reftex-index-restrict-to-section t) (setq reftex-index-restriction-indicator (nth 6 bor) reftex-index-restriction-data - (list bor + (list bor (car (memq (assq 'toc (cdr (memq bor docstruct))) docstruct)))) (reftex-index-revert)))) @@ -809,7 +806,7 @@ When index is restricted, select the previous section as restriction criterion." show-window show-buffer match) (unless data (error "Don't know which index entry to visit")) - + (if (eq (car data) 'index) (setq match (reftex-index-show-entry data no-revisit))) @@ -880,7 +877,7 @@ When index is restricted, select the previous section as restriction criterion." attr (nth 2 analyze)) (setf (nth 2 analyze) (if (string= attr bor) "" bor)) (setq new (apply 'concat analyze)) - (reftex-index-change-entry + (reftex-index-change-entry new (if (string= (nth 2 analyze) bor) "Entry is now START-OF-PAGE-RANGE" "START-OF-PAGE-RANGE canceled")))) @@ -938,7 +935,7 @@ When index is restricted, select the previous section as restriction criterion." (t (setf (nth n analyze) (concat initial npart)))) (setq new (apply 'concat analyze)) ;; Change the entry and insert the changed version into the index. - (reftex-index-change-entry + (reftex-index-change-entry new (if (string= npart "") (format "Deleted: %s" opart) (format "New value is: %s" npart))))) @@ -952,14 +949,14 @@ When index is restricted, select the previous section as restriction criterion." (unless data (error "Don't know which index entry to change")) (setq old (nth 2 data) key (nth 6 data) - prefix (completing-read - "Prefix: " - (reftex-sublist-nth + prefix (completing-read + "Prefix: " + (reftex-sublist-nth docstruct 6 (lambda (x) (and (eq (car x) 'index) (string= (nth 1 x) reftex-index-tag))) t))) - (unless (string-match + (unless (string-match (concat (regexp-quote (car reftex-index-special-chars)) "\\'") prefix) (setq prefix (concat prefix (car reftex-index-special-chars)))) @@ -999,7 +996,7 @@ When index is restricted, select the previous section as restriction criterion." (defun reftex-index-change-entry (new &optional message) ;; Change the full context string of the index entry at point to ;; NEW. This actually edits the buffer where the entry is defined. - + (let* ((data (get-text-property (point) :data)) old beg end info) (unless data (error "Cannot change entry")) @@ -1091,14 +1088,14 @@ When index is restricted, select the previous section as restriction criterion." (if (eq char ?!) (error "This <%s> index does not contain entries sorted before the letters" reftex-index-tag) - (error "This <%s> index does not contain entries starting with `%c'" + (error "This <%s> index does not contain entries starting with `%c'" reftex-index-tag char))))) -(easy-menu-define +(easy-menu-define reftex-index-menu reftex-index-map "Menu for Index buffer" `("Index" - ["Goto section A-Z" + ["Goto section A-Z" (message "To go to a section, just press any of: !%s" reftex-index-section-letters) t] ["Show Entry" reftex-index-view-entry t] @@ -1138,7 +1135,7 @@ When index is restricted, select the previous section as restriction criterion." ["Context" reftex-index-toggle-context :style toggle :selected reftex-index-include-context] "--" - ["Follow Mode" reftex-index-toggle-follow :style toggle + ["Follow Mode" reftex-index-toggle-follow :style toggle :selected reftex-index-follow-mode]) "--" ["Help" reftex-index-show-help t])) @@ -1190,7 +1187,7 @@ You get a chance to edit the entry in the phrases buffer - finish with (set-marker reftex-index-return-marker (point)) (reftex-index-selection-or-word arg 'phrase) (if (eq major-mode 'reftex-index-phrases-mode) - (message + (message (substitute-command-keys "Return to LaTeX with \\[reftex-index-phrases-save-and-return]")))) @@ -1219,7 +1216,7 @@ If the buffer is non-empty, delete the old header first." (sort (copy-sequence reftex-index-macro-alist) (lambda (a b) (equal (car a) default-macro)))) macro entry key repeat) - + (if master (set (make-local-variable 'TeX-master) (file-name-nondirectory master))) @@ -1232,7 +1229,7 @@ If the buffer is non-empty, delete the old header first." (if (looking-at reftex-index-phrases-comment-regexp) (beginning-of-line 2)) (while (looking-at "^[ \t]*$") - (beginning-of-line 2)) + (beginning-of-line 2)) (cond ((fboundp 'zmacs-activate-region) (zmacs-activate-region)) ((boundp 'make-active) (setq mark-active t))) (if (yes-or-no-p "Delete and rebuilt header ") @@ -1277,6 +1274,7 @@ If the buffer is non-empty, delete the old header first." (defvar reftex-index-phrases-menu) +(defvar reftex-index-phrases-marker) (defvar reftex-index-phrases-restrict-file nil) ;;;###autoload (defun reftex-index-phrases-mode () @@ -1308,17 +1306,17 @@ Here are all local bindings. (setq major-mode 'reftex-index-phrases-mode mode-name "Phrases") (use-local-map reftex-index-phrases-map) - (set (make-local-variable 'font-lock-defaults) + (set (make-local-variable 'font-lock-defaults) reftex-index-phrases-font-lock-defaults) (easy-menu-add reftex-index-phrases-menu reftex-index-phrases-map) (set (make-local-variable 'reftex-index-phrases-marker) (make-marker)) - (run-mode-hooks 'reftex-index-phrases-mode-hook)) + (run-hooks 'reftex-index-phrases-mode-hook)) (add-hook 'reftex-index-phrases-mode-hook 'turn-on-font-lock) ;; Font Locking stuff (let ((ss (if (featurep 'xemacs) 'secondary-selection ''secondary-selection))) (setq reftex-index-phrases-font-lock-keywords - (list + (list (cons reftex-index-phrases-comment-regexp 'font-lock-comment-face) (list reftex-index-phrases-macrodef-regexp '(1 font-lock-type-face) @@ -1342,7 +1340,7 @@ Here are all local bindings. (setq reftex-index-phrases-font-lock-defaults '((reftex-index-phrases-font-lock-keywords) nil t nil beginning-of-line)) - (put 'reftex-index-phrases-mode 'font-lock-defaults + (put 'reftex-index-phrases-mode 'font-lock-defaults reftex-index-phrases-font-lock-defaults) ; XEmacs ) @@ -1404,10 +1402,10 @@ match, the user will be asked to confirm the replacement." (move-marker reftex-index-phrases-marker (match-beginning 0) (current-buffer)) ;; Start the query-replace - (reftex-query-index-phrase-globally - files phrase macro-fmt + (reftex-query-index-phrase-globally + files phrase macro-fmt index-key repeat as-words) - (message "%s replaced" + (message "%s replaced" (reftex-number replace-count "occurrence")))))) (t (error "Cannot parse this line"))))) @@ -1450,7 +1448,7 @@ the document and stores the list in `reftex-index-phrases-files'." (unless buf (error "Master file %s not found" master)) (set-buffer buf) (reftex-access-scan-info) - (setq reftex-index-phrases-files + (setq reftex-index-phrases-files (reftex-all-document-files)))) ;; Parse the files header for macro definitions (setq reftex-index-phrases-macro-data nil) @@ -1465,7 +1463,7 @@ the document and stores the list in `reftex-index-phrases-files'." ;; Reverse the list, so that the first macro is first (if (null reftex-index-phrases-macro-data) (error "No valid MACRO DEFINITION line in %s file (make sure to use TAB separators)" reftex-index-phrase-file-extension)) - (setq reftex-index-phrases-macro-data + (setq reftex-index-phrases-macro-data (nreverse reftex-index-phrases-macro-data)) (goto-char (point-min))))) @@ -1477,7 +1475,7 @@ you need to add/change text in an already indexed document and want to index the new part without having to go over the unchanged parts again." (interactive "r") (let ((win-conf (current-window-configuration)) - (reftex-index-phrases-restrict-file (buffer-file-name))) + (reftex-index-phrases-restrict-file (buffer-file-name))) (save-excursion (save-restriction (narrow-to-region beg end) @@ -1500,7 +1498,7 @@ index the new part without having to go over the unchanged parts again." (setq text (reftex-index-simplify-phrase text)) (goto-char (point-min)) (if (re-search-forward - (concat "^\\(\\S-*\\)\t\\(" (regexp-quote text) + (concat "^\\(\\S-*\\)\t\\(" (regexp-quote text) "\\) *[\t\n]") nil t) (progn (goto-char (match-end 2)) @@ -1530,7 +1528,7 @@ this function repeatedly." (let* ((phrase (match-string 3)) (case-fold-search reftex-index-phrases-case-fold-search) (re (reftex-index-phrases-find-dup-re phrase t))) - (if (save-excursion + (if (save-excursion (goto-char (point-min)) (and (re-search-forward re nil t) (re-search-forward re nil t))) @@ -1623,7 +1621,7 @@ this function repeatedly." (progn (princ (format " Superphrases: Phrase matches the following %s in the phrase buffer:\n" (reftex-number ntimes2 "line"))) - (mapcar (lambda(x) + (mapcar (lambda(x) (princ (format " Line %4d: %s\n" (car x) (cdr x)))) (nreverse superphrases)))))))) @@ -1676,7 +1674,7 @@ it first compares the macro identifying chars and then the phrases." beg end) (goto-char (point-min)) ;; Find first and last phrase line in buffer - (setq beg + (setq beg (and (re-search-forward reftex-index-phrases-phrase-regexp12 nil t) (match-beginning 0))) (goto-char (point-max)) @@ -1703,15 +1701,15 @@ it first compares the macro identifying chars and then the phrases." (if (string-match reftex-index-phrases-phrase-regexp12 a) (progn ;; Extract macro char and phrase-or-key for a - (setq ca (match-string 1 a) - pa (downcase + (setq ca (match-string 1 a) + pa (downcase (or (and reftex-index-phrases-sort-prefers-entry (match-string 6 a)) (match-string 3 a)))) (if (string-match reftex-index-phrases-phrase-regexp12 b) (progn ;; Extract macro char and phrase-or-key for b - (setq cb (match-string 1 b) + (setq cb (match-string 1 b) pb (downcase (or (and reftex-index-phrases-sort-prefers-entry (match-string 6 b)) @@ -1719,7 +1717,7 @@ it first compares the macro identifying chars and then the phrases." (setq c-p (string< ca cb) p-p (string< pa pb)) ;; Do the right comparison, based on the value of `chars-first' - ;; `chars-first' is bound locally in the calling function + ;; `chars-first' is bound locally in the calling function (if chars-first (if (string= ca cb) p-p c-p) (if (string= pa pb) c-p p-p))))) @@ -1730,7 +1728,7 @@ it first compares the macro identifying chars and then the phrases." (not reftex-index-phrases-sort-in-blocks)))) (defvar reftex-index-phrases-menu) -(defun reftex-index-make-phrase-regexp (phrase &optional +(defun reftex-index-make-phrase-regexp (phrase &optional as-words allow-newline) "Return a regexp matching PHRASE, even if distributed over lines. With optional arg AS-WORDS, require word boundary at beginning and end. @@ -1741,12 +1739,12 @@ With optional arg ALLOW-NEWLINE, allow single newline between words." "\\([ \t]+\\)"))) (concat (if (and as-words (string-match "\\`\\w" (car words))) "\\(\\<\\|[`']\\)" "") - (mapconcat (lambda (w) (regexp-quote + (mapconcat (lambda (w) (regexp-quote (if reftex-index-phrases-case-fold-search (downcase w) w))) words space-re) - (if (and as-words + (if (and as-words (string-match "\\w\\'" (nth (1- (length words)) words))) "\\(\\>\\|'\\)" "")))) @@ -1769,8 +1767,8 @@ Treats the logical `and' for index phrases." (let ((index-keys (split-string (or index-key match) reftex-index-phrases-logical-and-regexp))) (concat - (mapconcat (lambda (x) - (format macro-fmt + (mapconcat (lambda (x) + (format macro-fmt (format (if mathp reftex-index-math-format "%s") x))) index-keys "") (if repeat (reftex-index-simplify-phrase match) "")))) @@ -1782,7 +1780,7 @@ Treats the logical `and' for index phrases." (unless files (error "No files")) (unwind-protect (progn - (switch-to-buffer-other-window (reftex-get-file-buffer-force + (switch-to-buffer-other-window (reftex-get-file-buffer-force (car files))) (catch 'no-more-files (while (setq file (pop files)) @@ -1822,13 +1820,15 @@ AS-WORDS means, the search for PHRASE should require word boundaries at both ends." (let* ((re (reftex-index-make-phrase-regexp phrase as-words 'allow-newline)) (case-fold-search reftex-index-phrases-case-fold-search) - (index-keys (split-string + (index-keys (split-string (or index-key phrase) reftex-index-phrases-logical-or-regexp)) (nkeys (length index-keys)) (ckey (nth 0 index-keys)) - (all-yes nil) - match rpl char beg end mathp) + (all-yes nil) + match rpl char (beg (make-marker)) (end (make-marker)) mathp) + (move-marker beg 1) + (move-marker end 1) (unwind-protect (while (re-search-forward re nil t) (catch 'next-match @@ -1841,24 +1841,24 @@ both ends." (setq mathp (save-match-data (condition-case nil (texmathp) (error nil)))) - (setq beg (car (match-data)) - end (nth 1 (match-data))) + (setq beg (move-marker beg (match-beginning 0)) + end (move-marker end (match-end 0))) (if (and reftex-index-phrases-skip-indexed-matches (save-match-data (reftex-index-phrase-match-is-indexed beg end))) (throw 'next-match nil)) (reftex-highlight 0 (match-beginning 0) (match-end 0)) - (setq rpl + (setq rpl (save-match-data (reftex-index-make-replace-string macro-fmt (match-string 0) ckey repeat mathp))) - (while + (while (not (catch 'loop (message "REPLACE: %s? (yn!qoe%s?)" rpl - (if (> nkeys 1) + (if (> nkeys 1) (concat "1-" (int-to-string nkeys)) "")) (setq char (if all-yes ?y (read-char-exclusive))) @@ -1892,7 +1892,7 @@ both ends." ((member char '(?o ?O)) ;; Select a differnt macro (let* ((nc (reftex-index-select-phrases-macro 2)) - (macro-data + (macro-data (cdr (assoc nc reftex-index-phrases-macro-data))) (macro-fmt (car macro-data)) (repeat (nth 1 macro-data))) @@ -1910,7 +1910,7 @@ both ends." ;; Recursive edit (save-match-data (save-excursion - (message + (message (substitute-command-keys "Recursive edit. Resume with \\[exit-recursive-edit]")) (recursive-edit)))) @@ -1930,6 +1930,8 @@ both ends." (t (ding))) nil))))) (message "") + (move-marker beg nil) + (move-marker end nil) (setq all-yes nil) (reftex-unhighlight 0)))) @@ -1939,7 +1941,7 @@ both ends." (save-excursion (goto-char end) (let* ((all-macros (reftex-what-macro t)) - (this-macro (car (car all-macros))) +; (this-macro (car (car all-macros))) (before-macro (and (> beg 2) (goto-char (1- beg)) @@ -2043,7 +2045,7 @@ Does not do a save-excursion." ("\C-i" . self-insert-command)) do (define-key reftex-index-phrases-map (car x) (cdr x))) -(easy-menu-define +(easy-menu-define reftex-index-phrases-menu reftex-index-phrases-map "Menu for Phrases buffer" '("Phrases" |