comparison lisp/textmodes/reftex-index.el @ 59534:9bad65481674

2005-01-14 Carsten Dominik <dominik@science.uva.nl> * reftex-cite.el (reftex-bib-sort-year): Catch the case if the year is not given. * reftex-ref.el (reftex-replace-prefix-escapes): Added new escapes %m and %M, fixed bug with %F by adding save-match-data. (reftex-reference): Removed ?. from list of spaces. (reftex-label-info): Added automatic label prefix recognition * reftex-index.el (reftex-index-next-phrase): Added slave parameter to call of `reftex-index-this-phrase' (reftex-index-this-phrase): New optional argument (reftex-index-region-phrases): Added slave parameter to call of `reftex-index-this-phrase' (reftex-display-index): New argument redo (reftex-index-rescan): Added 'redo to arguments of `reftex-display-index' (reftex-index-Rescan, reftex-index-revert) (reftex-index-switch-index-tag): Added 'redo to arguments of `reftex-display-index' (reftex-index-make-phrase-regexp): Fixed bug with case-sensitive indexing. Fixed bug with matching is there is a quote before or after the word. * reftex-cite.el (reftex-all-used-citation-keys): Fix bug when collecting citation keys in lines with comments. (reftex-citation): Prefix argument no longer rescans the document, but forces prompting for optional arguments of cite macros. (reftex-do-citation): Prompting for optional arguments implemented. * reftex-vars.el (reftex-cite-format-builtin): Added optional arguments to most cite commands. (reftex-cite-cleanup-optional-args): New option (reftex-cite-prompt-optional-args): New option. (reftex-trust-label-prefix): New option * reftex-toc.el (reftex-toc-find-section): Added push-mark before changing the position in the buffer. * reftex.el (reftex-prefix-to-typekey-alist): New variable (reftex-compile-variables): Compute reftex-prefix-to-typekey-alist
author Carsten Dominik <dominik@science.uva.nl>
date Fri, 14 Jan 2005 10:12:03 +0000
parents 695cf19ef79e
children 58a53f588384 cb67264d6096
comparison
equal deleted inserted replaced
59533:2a346f1b2a9f 59534:9bad65481674
1 ;;; reftex-index.el --- index support with RefTeX 1 ;;; reftex-index.el --- index support with RefTeX
2 ;; Copyright (c) 1997, 1998, 1999, 2000, 2003 Free Software Foundation, Inc. 2 ;; Copyright (c) 1997, 1998, 1999, 2000, 2003, 2004 Free Software Foundation, Inc.
3 3
4 ;; Author: Carsten Dominik <dominik@science.uva.nl> 4 ;; Author: Carsten Dominik <dominik@science.uva.nl>
5 ;; Version: 4.21 5 ;; Version: 4.26
6 6
7 ;; This file is part of GNU Emacs. 7 ;; This file is part of GNU Emacs.
8 8
9 ;; GNU Emacs is free software; you can redistribute it and/or modify 9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by 10 ;; it under the terms of the GNU General Public License as published by
358 (goto-char (match-beginning 0)) 358 (goto-char (match-beginning 0))
359 (recenter '(4)) 359 (recenter '(4))
360 (reftex-highlight 0 (match-beginning 0) (match-end 0) (current-buffer))) 360 (reftex-highlight 0 (match-beginning 0) (match-end 0) (current-buffer)))
361 match)) 361 match))
362 362
363 (defun reftex-display-index (&optional tag overriding-restriction 363 (defun reftex-display-index (&optional tag overriding-restriction redo
364 &rest locations) 364 &rest locations)
365 "Display a buffer with an index compiled from the current document. 365 "Display a buffer with an index compiled from the current document.
366 When the document has multiple indices, first prompts for the correct one. 366 When the document has multiple indices, first prompts for the correct one.
367 When index support is turned off, offer to turn it on. 367 When index support is turned off, offer to turn it on.
368 With one or two `C-u' prefixes, rescan document first. 368 With one or two `C-u' prefixes, rescan document first.
385 (index-tag (or tag (reftex-index-select-tag))) 385 (index-tag (or tag (reftex-index-select-tag)))
386 (master (reftex-TeX-master-file)) 386 (master (reftex-TeX-master-file))
387 (calling-file (buffer-file-name)) 387 (calling-file (buffer-file-name))
388 (restriction 388 (restriction
389 (or overriding-restriction 389 (or overriding-restriction
390 (and (interactive-p) 390 (and (not redo)
391 (reftex-get-restriction current-prefix-arg docstruct)))) 391 (reftex-get-restriction current-prefix-arg docstruct))))
392 (locations 392 (locations
393 ;; See if we are on an index macro as initial position 393 ;; See if we are on an index macro as initial position
394 (or locations 394 (or locations
395 (let* ((what-macro (reftex-what-macro-safe 1)) 395 (let* ((what-macro (reftex-what-macro-safe 1))
425 (set (make-local-variable 'reftex-index-tag) index-tag) 425 (set (make-local-variable 'reftex-index-tag) index-tag)
426 (set (make-local-variable 'reftex-docstruct-symbol) docstruct-symbol) 426 (set (make-local-variable 'reftex-docstruct-symbol) docstruct-symbol)
427 (if restriction 427 (if restriction
428 (setq reftex-index-restriction-indicator (car restriction) 428 (setq reftex-index-restriction-indicator (car restriction)
429 reftex-index-restriction-data (cdr restriction)) 429 reftex-index-restriction-data (cdr restriction))
430 (if (interactive-p) 430 (if (not redo)
431 (setq reftex-index-restriction-indicator nil 431 (setq reftex-index-restriction-indicator nil
432 reftex-index-restriction-data nil))) 432 reftex-index-restriction-data nil)))
433 (when (= (buffer-size) 0) 433 (when (= (buffer-size) 0)
434 ;; buffer is empty - fill it 434 ;; buffer is empty - fill it
435 (message "Building %s buffer..." buffer-name) 435 (message "Building %s buffer..." buffer-name)
701 (line (+ (count-lines (point-min) (point)) (if (bolp) 1 0)))) 701 (line (+ (count-lines (point-min) (point)) (if (bolp) 1 0))))
702 (if (not file) 702 (if (not file)
703 (error "Don't know which file to rescan. Try `C-u r'") 703 (error "Don't know which file to rescan. Try `C-u r'")
704 (switch-to-buffer (reftex-get-file-buffer-force file)) 704 (switch-to-buffer (reftex-get-file-buffer-force file))
705 (setq current-prefix-arg '(4)) 705 (setq current-prefix-arg '(4))
706 (reftex-display-index index-tag nil line))) 706 (reftex-display-index index-tag nil 'redo line)))
707 (reftex-index-Rescan)) 707 (reftex-index-Rescan))
708 (reftex-kill-temporary-buffers))) 708 (reftex-kill-temporary-buffers)))
709 (defun reftex-index-Rescan (&rest ignore) 709 (defun reftex-index-Rescan (&rest ignore)
710 "Regenerate the *Index* buffer after reparsing the entire document." 710 "Regenerate the *Index* buffer after reparsing the entire document."
711 (interactive) 711 (interactive)
712 (let ((index-tag reftex-index-tag) 712 (let ((index-tag reftex-index-tag)
713 (line (+ (count-lines (point-min) (point)) (if (bolp) 1 0)))) 713 (line (+ (count-lines (point-min) (point)) (if (bolp) 1 0))))
714 (switch-to-buffer 714 (switch-to-buffer
715 (reftex-get-file-buffer-force reftex-last-index-file)) 715 (reftex-get-file-buffer-force reftex-last-index-file))
716 (setq current-prefix-arg '(16)) 716 (setq current-prefix-arg '(16))
717 (reftex-display-index index-tag nil line))) 717 (reftex-display-index index-tag nil 'redo line)))
718 (defun reftex-index-revert (&rest ignore) 718 (defun reftex-index-revert (&rest ignore)
719 "Regenerate the *Index* from the internal lists. No reparsing os done." 719 "Regenerate the *Index* from the internal lists. No reparsing os done."
720 (interactive) 720 (interactive)
721 (let ((buf (current-buffer)) 721 (let ((buf (current-buffer))
722 (index-tag reftex-index-tag) 722 (index-tag reftex-index-tag)
725 (switch-to-buffer 725 (switch-to-buffer
726 (reftex-get-file-buffer-force reftex-last-index-file)) 726 (reftex-get-file-buffer-force reftex-last-index-file))
727 (reftex-erase-buffer buf) 727 (reftex-erase-buffer buf)
728 (setq current-prefix-arg nil 728 (setq current-prefix-arg nil
729 reftex-last-follow-point 1) 729 reftex-last-follow-point 1)
730 (reftex-display-index index-tag nil data line))) 730 (reftex-display-index index-tag nil 'redo data line)))
731 (defun reftex-index-switch-index-tag (&rest ignore) 731 (defun reftex-index-switch-index-tag (&rest ignore)
732 "Switch to a different index of the same document." 732 "Switch to a different index of the same document."
733 (interactive) 733 (interactive)
734 (switch-to-buffer 734 (switch-to-buffer
735 (reftex-get-file-buffer-force reftex-last-index-file)) 735 (reftex-get-file-buffer-force reftex-last-index-file))
736 (setq current-prefix-arg nil) 736 (setq current-prefix-arg nil)
737 (reftex-display-index)) 737 (reftex-display-index nil nil 'redo))
738 738
739 (defun reftex-index-restrict-to-section (&optional force) 739 (defun reftex-index-restrict-to-section (&optional force)
740 "Restrict index to entries defined in same document sect. as entry at point." 740 "Restrict index to entries defined in same document sect. as entry at point."
741 ;; Optional FORCE means, even if point is not on an index entry. 741 ;; Optional FORCE means, even if point is not on an index entry.
742 (interactive) 742 (interactive)
1350 (decf arg) 1350 (decf arg)
1351 (end-of-line) 1351 (end-of-line)
1352 (if (re-search-forward reftex-index-phrases-phrase-regexp12 nil t) 1352 (if (re-search-forward reftex-index-phrases-phrase-regexp12 nil t)
1353 (progn 1353 (progn
1354 (goto-char (match-beginning 0)) 1354 (goto-char (match-beginning 0))
1355 (reftex-index-this-phrase)) 1355 (reftex-index-this-phrase 'slave))
1356 (error "No more phrase lines after point")))) 1356 (error "No more phrase lines after point"))))
1357 1357
1358 (defun reftex-index-this-phrase () 1358 (defun reftex-index-this-phrase (&optional slave)
1359 "Index the phrase in the current line. 1359 "Index the phrase in the current line.
1360 Does a global search and replace in the entire document. At each 1360 Does a global search and replace in the entire document. At each
1361 match, the user will be asked to confirm the replacement." 1361 match, the user will be asked to confirm the replacement."
1362 (interactive) 1362 (interactive)
1363 (if (interactive-p) (reftex-index-phrases-parse-header t)) 1363 (if (not slave) (reftex-index-phrases-parse-header t))
1364 (save-excursion 1364 (save-excursion
1365 (beginning-of-line) 1365 (beginning-of-line)
1366 (cond ((looking-at reftex-index-phrases-comment-regexp) 1366 (cond ((looking-at reftex-index-phrases-comment-regexp)
1367 (if (interactive-p) (error "Comment line"))) 1367 (if (not slave) (error "Comment line")))
1368 ((looking-at "^[ \t]*$") 1368 ((looking-at "^[ \t]*$")
1369 (if (interactive-p) (error "Empty line"))) 1369 (if (not slave) (error "Empty line")))
1370 ((looking-at reftex-index-phrases-macrodef-regexp) 1370 ((looking-at reftex-index-phrases-macrodef-regexp)
1371 (if (interactive-p) (error "Macro definition line"))) 1371 (if (not slave) (error "Macro definition line")))
1372 ((looking-at reftex-index-phrases-phrase-regexp12) 1372 ((looking-at reftex-index-phrases-phrase-regexp12)
1373 ;; This is a phrase 1373 ;; This is a phrase
1374 (let* ((char (if (not (equal (match-string 1) "")) 1374 (let* ((char (if (not (equal (match-string 1) ""))
1375 (string-to-char (match-string 1)))) 1375 (string-to-char (match-string 1))))
1376 (phrase (match-string 3)) 1376 (phrase (match-string 3))
1427 (interactive "r") 1427 (interactive "r")
1428 (reftex-index-phrases-parse-header t) 1428 (reftex-index-phrases-parse-header t)
1429 (goto-char beg) 1429 (goto-char beg)
1430 (while (not (or (eobp) 1430 (while (not (or (eobp)
1431 (>= (point) end))) 1431 (>= (point) end)))
1432 (save-excursion (reftex-index-this-phrase)) 1432 (save-excursion (reftex-index-this-phrase 'slave))
1433 (beginning-of-line 2))) 1433 (beginning-of-line 2)))
1434 1434
1435 (defun reftex-index-phrases-parse-header (&optional get-files) 1435 (defun reftex-index-phrases-parse-header (&optional get-files)
1436 "Parse the header of a phrases file to extract the macro definitions. 1436 "Parse the header of a phrases file to extract the macro definitions.
1437 The definitions get stored in `reftex-index-phrases-macro-data'. 1437 The definitions get stored in `reftex-index-phrases-macro-data'.
1734 (let* ((words (split-string phrase)) 1734 (let* ((words (split-string phrase))
1735 (space-re (if allow-newline 1735 (space-re (if allow-newline
1736 "\\([ \t]*\\(\n[ \t]*\\)?\\|[ \t]\\)" 1736 "\\([ \t]*\\(\n[ \t]*\\)?\\|[ \t]\\)"
1737 "\\([ \t]+\\)"))) 1737 "\\([ \t]+\\)")))
1738 (concat (if (and as-words (string-match "\\`\\w" (car words))) 1738 (concat (if (and as-words (string-match "\\`\\w" (car words)))
1739 "\\<" "") 1739 "\\(\\<\\|[`']\\)" "")
1740 (mapconcat (lambda (w) (regexp-quote (downcase w))) 1740 (mapconcat (lambda (w) (regexp-quote
1741 (if reftex-index-phrases-case-fold-search
1742 (downcase w)
1743 w)))
1741 words space-re) 1744 words space-re)
1742 (if (and as-words 1745 (if (and as-words
1743 (string-match "\\w\\'" (nth (1- (length words)) words))) 1746 (string-match "\\w\\'" (nth (1- (length words)) words)))
1744 "\\>" "")))) 1747 "\\(\\>\\|'\\)" ""))))
1745 1748
1746 (defun reftex-index-simplify-phrase (phrase) 1749 (defun reftex-index-simplify-phrase (phrase)
1747 "Make phrase single spaces and single line." 1750 "Make phrase single spaces and single line."
1748 (mapconcat 'identity (split-string phrase) " ")) 1751 (mapconcat 'identity (split-string phrase) " "))
1749 1752
1823 (all-yes nil) 1826 (all-yes nil)
1824 match rpl char beg end mathp) 1827 match rpl char beg end mathp)
1825 (unwind-protect 1828 (unwind-protect
1826 (while (re-search-forward re nil t) 1829 (while (re-search-forward re nil t)
1827 (catch 'next-match 1830 (catch 'next-match
1831 (if (reftex-in-comment)
1832 (throw 'next-match nil))
1828 (if (and (fboundp reftex-index-verify-function) 1833 (if (and (fboundp reftex-index-verify-function)
1829 (not (funcall reftex-index-verify-function))) 1834 (not (funcall reftex-index-verify-function)))
1830 (throw 'next-match nil)) 1835 (throw 'next-match nil))
1831 (setq match (match-string 0)) 1836 (setq match (match-string 0))
1832 (setq mathp 1837 (setq mathp
1923 (message "") 1928 (message "")
1924 (setq all-yes nil) 1929 (setq all-yes nil)
1925 (reftex-unhighlight 0)))) 1930 (reftex-unhighlight 0))))
1926 1931
1927 (defun reftex-index-phrase-match-is-indexed (beg end) 1932 (defun reftex-index-phrase-match-is-indexed (beg end)
1928 ;; CHeck if match is in an argument of an index macro, or if an 1933 ;; Check if match is in an argument of an index macro, or if an
1929 ;; index macro is directly attached to the match. 1934 ;; index macro is directly attached to the match.
1930 (save-excursion 1935 (save-excursion
1931 (goto-char end) 1936 (goto-char end)
1932 (let* ((all-macros (reftex-what-macro t)) 1937 (let* ((all-macros (reftex-what-macro t))
1933 (this-macro (car (car all-macros))) 1938 (this-macro (car (car all-macros)))