Commit 7c4d13cc authored by Carsten Dominik's avatar Carsten Dominik

* reftex.el (reftex-compile-variables): respect new structure of

`reftex-index-macro'
(reftex-compile-variables): Use the changed structure of
`reftex-label-alist'.

* reftex-vars.el (reftex-index-math-format,
(reftex-toc-max-level): New option.
reftex-index-phrases-search-whole-words,
reftex-index-phrases-case-fold-search,
reftex-index-phrases-skip-indexed-matches,
reftex-index-phrases-wrap-long-lines,
reftex-index-phrases-sort-prefers-entry,
reftex-index-phrases-sort-in-blocks): New options.
(reftex-index-macros): Option structure changed.
(reftex-index-macros-builtin): Added `repeat' item to each entry.
(reftex-label-alist): Additional item in each entry to specify if
the environment should be listed in the TOC.
(eval-when-compile (require 'cl)) added.

* reftex-index.el (reftex-index-selection-or-word): No longer
deals with "repeat".
(reftex-index): "repeat property in `reftex-index-macro-alist' is
now used.
(reftex-index-phrases-comment-regexp,
reftex-index-phrases-macrodef-regexp,
reftex-index-phrases-phrase-regexp1,
reftex-index-phrases-phrase-regexp2,
reftex-index-phrases-phrase-regexp12, reftex-index-phrases-help):
New constants.
(reftex-index-phrases-macro-data, reftex-index-phrases-files,
reftex-index-phrases-font-lock-keywords,
reftex-index-phrases-font-lock-defaults, reftex-index-phrases-map,
reftex-index-phrases-restrict-file): New variables.
(reftex-index-phrase-selection-or-word,
reftex-index-visit-phrases-buffer,
reftex-index-initialize-phrases-buffer,
reftex-index-phrases-save-and-return, reftex-index-phrases-mode,
reftex-index-next-phrase, reftex-index-this-phrase,
reftex-index-all-phrases, reftex-index-region-phrases,
reftex-index-phrases-parse-header,
reftex-index-phrases-toggle-restricted, reftex-index-new-phrase,
reftex-index-find-next-conflict-phrase, reftex-index-phrases-info,
reftex-index-phrases-set-macro-key, reftex-index-sort-phrases,
reftex-compare-phrase-lines, reftex-index-make-phrase-regexp,
reftex-index-simplify-phrase, reftex-index-phrases-find-dup-re,
reftex-index-make-replace-string,
reftex-query-index-phrase-globally, reftex-query-index-phrase,
reftex-index-phrase-match-is-indexed,
reftex-index-phrases-fixup-line,
reftex-index-phrases-replace-space,
reftex-index-select-phrases-macro): New functions.
(reftex-index-globalize, reftex-index-globally): functions removed
(eval-when-compile (require 'cl)) added.

* reftex-toc.el (reftex-toc-mode): Create new indicator for max
level.
(reftex-toc-max-level-indicator): New variable.
(reftex-toc-max-level): New command.
(reftex-toc-map): New keybinding `t'.
(reftex-toc-help): Constant updated.
(eval-when-compile (require 'cl)) added.

* reftex-ref.el (reftex-offer-label-menu): Prefix to `t' command key
can change `reftex-toc-max-level'
(eval-when-compile (require 'cl)) added.

* reftex-sel (reftex-insert-docstruct): Respect
`reftex-toc-max-level'
(eval-when-compile (require 'cl)) added.

* reftex-auc.el (eval-when-compile (require 'cl)) added.

* reftex-vcr.el (eval-when-compile (require 'cl)) added.

* reftex-cite.el (reftex-citep, reftex-citet): New commands.
(reftex-citation, reftex-do-citation,
reftex-figure-out-cite-format): Additional argument FORMAT-KEY to
preselect a citation format.
(eval-when-compile (require 'cl)) added.

* reftex-parse.el (reftex-context-substring): Optional parameter
to-end
(reftex-section-info): Deal with environment matches.
(eval-when-compile (require 'cl)) added.

* reftex-global.el (eval-when-compile (require 'cl)) added.
parent cfad01b4
;;; reftex-auc.el - RefTeX's interface to AUC TeX
;;; Version: 4.6
;;; Version: 4.9
;;;
;;; See main file reftex.el for licensing information
(eval-when-compile (require 'cl))
(provide 'reftex-auc)
(require 'reftex)
;;;
......
;;; reftex-cite.el - Creating citations with RefTeX
;;; Version: 4.6
;;; Version: 4.9
;;;
;;; See main file reftex.el for licensing information
(eval-when-compile (require 'cl))
(provide 'reftex-cite)
(require 'reftex)
;;;
......@@ -501,7 +502,7 @@
;; Make a citation
;;;###autoload
(defun reftex-citation (&optional no-insert)
(defun reftex-citation (&optional no-insert format-key)
"Make a citation using BibTeX database files.
After prompting for a regular expression, scans the buffers with
bibtex entries (taken from the \\bibliography command) and offers the
......@@ -510,6 +511,8 @@ to `reftex-cite-format' and inserted into the buffer.
If NO-INSERT is non-nil, nothing is inserted, only the selected key returned.
FORAT-KEY can be used to pre-select a citation format.
When called with one or two `C-u' prefixes, first rescans the document.
When called with a numeric prefix, make that many citations. When
called with point inside the braces of a `\cite' command, it will
......@@ -533,13 +536,13 @@ While entering the regexp, completion on knows citation keys is possible.
;; Call reftex-do-citation, but protected
(unwind-protect
(reftex-do-citation current-prefix-arg no-insert)
(reftex-do-citation current-prefix-arg no-insert format-key)
(reftex-kill-temporary-buffers)))
(defun reftex-do-citation (&optional arg no-insert)
(defun reftex-do-citation (&optional arg no-insert format-key)
;; This really does the work of reftex-citation.
(let* ((format (reftex-figure-out-cite-format arg no-insert))
(let* ((format (reftex-figure-out-cite-format arg no-insert format-key))
(docstruct-symbol reftex-docstruct-symbol)
(selected-entries (reftex-offer-bib-menu))
(insert-entries selected-entries)
......@@ -610,7 +613,7 @@ While entering the regexp, completion on knows citation keys is possible.
;; Return the citation key
(car (car selected-entries))))
(defun reftex-figure-out-cite-format (arg no-insert)
(defun reftex-figure-out-cite-format (arg &optional no-insert format-key)
;; Check if there is already a cite command at point and change cite format
;; in order to only add another reference in the same cite command.
(let ((macro (car (reftex-what-macro 1)))
......@@ -640,19 +643,30 @@ While entering the regexp, completion on knows citation keys is possible.
cite-format-value))
(when (listp format)
(setq key
(reftex-select-with-char
"" (concat "SELECT A CITATION FORMAT\n\n"
(mapconcat
(lambda (x)
(format "[%c] %s %s" (car x)
(if (> (car x) 31) " " "")
(cdr x)))
format "\n"))))
(or format-key
(reftex-select-with-char
"" (concat "SELECT A CITATION FORMAT\n\n"
(mapconcat
(lambda (x)
(format "[%c] %s %s" (car x)
(if (> (car x) 31) " " "")
(cdr x)))
format "\n")))))
(if (assq key format)
(setq format (cdr (assq key format)))
(error "No citation format associated with key `%c'" key)))))
format))
(defun reftex-citep ()
"Call `reftex-citation' with a format selector `?p'."
(interactive)
(reftex-citation nil ?p))
(defun reftex-citet ()
"Call `reftex-citation' with a format selector `?t'."
(interactive)
(reftex-citation nil ?t))
(defvar reftex-select-bib-map)
(defun reftex-offer-bib-menu ()
;; Offer bib menu and return list of selected items
......
;;; reftex-global.el - Operations on entire documents with RefTeX
;;; Version: 4.6
;;; Version: 4.9
;;;
;;; See main file reftex.el for licensing information
(eval-when-compile (require 'cl))
(provide 'reftex-global)
(require 'reftex)
;;;
......@@ -191,7 +192,7 @@ one with the `xr' package."
(if (assoc label translate-alist)
(error "Duplicate label %s" label))
(setq new-label (concat (match-string 1 (car entry))
(incf (cdr nr-cell))))
(int-to-string (incf (cdr nr-cell)))))
(push (cons label new-label) translate-alist)
(or (string= label new-label) (setq changed-sequence t))))
......
;;; reftex-index.el - Index support with RefTeX
;;; Version: 4.6
;;; Version: 4.9
;;;
;;; See main file reftex.el for licensing information
(eval-when-compile (require 'cl))
(provide 'reftex-index)
(require 'reftex)
;;;
......@@ -10,7 +11,7 @@
(defvar mark-active)
(defvar zmacs-regions)
(defvar transient-mark-mode)
(defun reftex-index-selection-or-word (&optional arg)
(defun reftex-index-selection-or-word (&optional arg phrase)
"Put selection or the word near point into the default index macro.
This uses the information in `reftex-index-default-macro' to make an index
entry. The phrase indexed is the current selection or the word near point.
......@@ -37,33 +38,34 @@ which is part of AUCTeX, the string is first processed with the
(sel (buffer-substring beg end))
(mathp (condition-case nil (texmathp) (error nil)))
(current-prefix-arg nil) ; we want to call reftex-index without prefix.
key def-char def-tag full-entry repeat-word)
(if (equal sel "")
;; Nothing selecte, no word, so use full reftex-index command
(reftex-index)
;; OK, we have something to index here.
;; Add the dollars when necessary
(setq key (if mathp
(format reftex-index-math-format sel)
sel))
;; Get info from `reftex-index-default-macro'
(setq def-char (if use-default (car reftex-index-default-macro)))
(setq def-tag (if use-default (nth 1 reftex-index-default-macro)))
;; Does the user want to edit the entry?
(setq full-entry (if arg
(reftex-index-complete-key
def-tag nil (cons key 0))
key))
;; Do we neet to repeat the word outside the macro?
(setq repeat-word (if use-default
(nth 2 reftex-index-default-macro)
(y-or-n-p "Repeat phrase outside macro? ")))
;; Delete what is in the buffer and make the index entry
(delete-region beg end)
(reftex-index def-char full-entry def-tag (if repeat-word sel nil)))))
key def-char def-tag full-entry)
(defun reftex-index (&optional char key tag postfix no-insert)
(if phrase
(progn
(reftex-index-visit-phrases-buffer)
(reftex-index-new-phrase sel))
(if (equal sel "")
;; Nothing selected, no word, so use full reftex-index command
(reftex-index)
;; OK, we have something to index here.
;; Add the dollars when necessary
(setq key (if mathp
(format reftex-index-math-format sel)
sel))
;; Get info from `reftex-index-default-macro'
(setq def-char (if use-default (car reftex-index-default-macro)))
(setq def-tag (if use-default (nth 1 reftex-index-default-macro)))
;; Does the user want to edit the entry?
(setq full-entry (if arg
(reftex-index-complete-key
def-tag nil (cons key 0))
key))
;; 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
by a call to `reftex-add-index-macros', typically from an AUCTeX style file.
......@@ -88,6 +90,7 @@ will prompt for other arguments."
(nargs (nth 4 entry))
(nindex (nth 5 entry))
(opt-args (nth 6 entry))
(repeat (nth 7 entry))
opt tag1 value)
;; Get the supported arguments
......@@ -111,7 +114,7 @@ will prompt for other arguments."
": ")))))
(unless (and opt (string= value ""))
(insert (if opt "[" "{") value (if opt "]" "}"))))
(and (stringp postfix) (insert postfix))
(and repeat (stringp sel) (insert sel))
(and key reftex-plug-into-AUCTeX (fboundp 'LaTeX-add-index-entries)
(LaTeX-add-index-entries key))
(reftex-index-update-taglist tag1)
......@@ -236,98 +239,6 @@ will prompt for other arguments."
(and newtag (cdr cell) (not (member newtag (cdr cell)))
(push newtag (cdr cell)))))
(defvar reftex-last-index-file)
(defun reftex-index-globally (&optional data call-file)
"Index a word with a global search and replace.
This works very much like `reftex-query-replace-document', but the
defaults for the search and replace strings are derived from
local context.
When there is an index entry, we try to index similar words. The word
to search for is either a word in direct contact with the index macro
(like `\\index{WORD}WORD' or `WORD\\index{WORD}') or the index key.
The replacement text is the index macro with all its arguments and the
attached word.
When there is no index entry at point, we search for the word near point
and propose to index it like this: `\\index{word}word'.
You get a chance to edit the search and replacement strings.
DATA can be a docstruct entry describing an index entry, and then the
defaults will be derived from it.
CALL-FILE may be the file from where to call the global search command."
(interactive)
(let* ((call-file (cond (call-file call-file)
(reftex-mode (buffer-file-name))
((eq major-mode 'reftex-index-mode)
reftex-last-index-file)
(t (error "Need a call file here"))))
(pos (point))
(data (cond
(data data)
((and reftex-mode
(save-excursion
(forward-char 20)
(re-search-backward reftex-everything-regexp nil t)
(< (count-lines (min pos (point)) (max pos (point)))
2)))
(reftex-index-info (buffer-file-name)))
(t nil)))
(ksep (car reftex-index-special-chars))
(words-include-escapes t)
(case-replace nil)
(case-fold-search t)
word rpl start analyze-list pre key attr actual post)
;; Find the word and construct the replacement string
(if (and data (eq (car data) 'index))
;; OK, we have an index entry
(progn
(setq analyze-list (reftex-index-analyze-entry data)
pre (car analyze-list)
key (nth 1 analyze-list)
attr (nth 2 analyze-list)
actual (nth 3 analyze-list)
post (nth 4 analyze-list))
(when (string-match (concat "\\<\\(\\sw+\\)" reftex-index-re) pre)
(setq word (match-string 1 pre)
pre (concat "<<<1>>>" (substring pre (match-end 1)))
rpl (concat pre key attr actual post)))
(when (string-match "}\\(\\sw+\\)\\>[^}]*\\'" post)
(setq word (match-string 1 post)
post (concat (substring post 0 (match-beginning 1))
"<<<1>>>")
rpl (concat pre key attr actual post)))
(when (and (not word) key)
(if (string-match (concat ".*" (regexp-quote ksep)) key)
(setq word (substring key (match-end 0)))
(setq word key))
(setq rpl (concat pre key attr actual post))))
;; No index entry, just use local word.
(setq word (save-excursion
(buffer-substring-no-properties
(progn (skip-syntax-backward "w") (point))
(progn (skip-syntax-forward "w") (point))))
rpl (concat "\\index{" word "}<<<1>>>")))
;; Quote what is necessary
(setq word (regexp-quote (downcase word)))
(setq start 0)
(while (setq start (string-match "\\\\" rpl start))
(setq rpl (replace-match "\\\\" t t rpl)
start (+ 2 start)))
;; We used <<<1>>> instead of \1 to avoid the quoting. Fix this now.
(if (string-match "<<<1>>>" rpl)
(setq rpl (replace-match "\\1" t t rpl)))
;; Give the user a chance to edit the strings
(setq word (read-string "Search: "
(if word (format "\\<\\(%s\\)\\>" word)))
rpl (read-string "Replace with: " rpl))
;; Execute the command
(save-excursion
(switch-to-buffer (get-file-buffer call-file))
(condition-case nil
(reftex-query-replace-document word rpl)
(error nil)))))
(defvar reftex-index-map (make-sparse-keymap)
"Keymap used for *Index* buffers.")
......@@ -392,7 +303,6 @@ e / C-k Edit/Kill the entry.
With prefix: kill that part.
( ) Toggle entry's beginning/end of page range property.
_ ^ Add/Remove parent key (to make this item a subitem).
& Index the same word everywhere in the document.
} / { Restrict Index to a single document section / Widen.
< / > When restricted, move restriction to previous/next section.")
......@@ -918,22 +828,6 @@ When index is restricted, select the previous section as restriction criterion."
(post (substring context eoa)))
(list pre key attr actual post)))
(defun reftex-index-globalize (&optional arg)
"Globalize the current index entry.
This starts a global search and replace to index the same word
at other places in the document. After this function completes, you
need to rescan the document with `r' or `C-u r' in order to get the
entries into the index buffer.
Defaults for the search and replace strings are derived from
the current entry. See the command `reftex-index-globally'."
(interactive)
(let* ((data (get-text-property (point) :data))
(buf (current-buffer)))
(unless data
(error "No index entry at point"))
(reftex-index-globally data)
(switch-to-buffer buf)))
(defun reftex-index-edit ()
"Edit the index entry at point."
(interactive)
......@@ -964,7 +858,7 @@ the current entry. See the command `reftex-index-globally'."
"Toggle the page-range-end attribute `|)'."
(interactive)
(let* ((data (get-text-property (point) :data))
(eor (concat (nth 1 reftex-index-special-chars) "("))
(eor (concat (nth 1 reftex-index-special-chars) ")"))
new analyze attr)
(unless data (error "Don't know which index entry to edit"))
(setq analyze (reftex-index-analyze-entry data)
......@@ -1138,7 +1032,6 @@ the current entry. See the command `reftex-index-globally'."
("|" . reftex-index-edit-attribute)
("@" . reftex-index-edit-visual)
("*" . reftex-index-edit-key)
("&" . reftex-index-globalize)
("\C-c=". reftex-index-goto-toc)
("c" . reftex-index-toggle-context))
do (define-key reftex-index-map (car x) (cdr x)))
......@@ -1164,8 +1057,11 @@ the current entry. See the command `reftex-index-globally'."
(recenter 0)
(reftex-index-next))
(goto-char pos)
(error "This <%s> index does not contain entries starting with `%c'"
reftex-index-tag char))))
(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'"
reftex-index-tag char)))))
(easy-menu-define
reftex-index-menu reftex-index-map
......@@ -1204,7 +1100,6 @@ the current entry. See the command `reftex-index-globally'."
["Make Start-of-Range" reftex-index-toggle-range-beginning t]
["Make End-of-Range" reftex-index-toggle-range-end t]
"--"
["Globalize" reftex-index-globalize t]
["Kill Entry" reftex-index-kill nil]
"--"
["Undo" reftex-index-undo nil])
......@@ -1217,4 +1112,941 @@ the current entry. See the command `reftex-index-globally'."
"--"
["Help" reftex-index-show-help t]))
;;----------------------------------------------------------------------
;; The Index Phrases File
;; Some constants and variables
(defconst reftex-index-phrases-comment-regexp "^[ \t]*%.*"
"Regular expression to match comment lines in phrases buffer")
(defconst reftex-index-phrases-macrodef-regexp
"^\\(>>>INDEX_MACRO_DEFINITION:\\)[ \t]+\\(\\S-\\)\\( *\t[ \t]*\\)\\([^\t]*[^ \t]\\)\\( *\t[ \t]*\\)\\(\\S-+\\)"
"Regular expression to match macro definition lines the phrases buffer.")
;(defconst reftex-index-phrases-macrodef-regexp
; "^\\(>>>INDEX_MACRO_DEFINITION:\\)[ \t]+\\(\\S-\\)\\([ \t]*\\)\\([^\t]*[^ \t]\\)\\([ \t]*\\)\\(nil\\|t\\)[ \t]*$"
; "Regular expression to match macro definition lines the phrases buffer.
;This version would allow just spaces as separators.")
(defconst reftex-index-phrases-phrase-regexp1
"^\\(\\S-?\\)\\(\t\\)\\([^\t\n]*\\S-\\)\\([ \t]*\\)$"
"Regular expression matching phrases which have no separate index key.")
(defconst reftex-index-phrases-phrase-regexp2
"^\\(\\S-?\\)\\(\t\\)\\([^\t]*\\S-\\)\\(\t[ \t]*\\)\\([^\n\t]*\\S-\\)[ \t]*$"
"Regular expression matching phrases which have a separate index key.")
(defconst reftex-index-phrases-phrase-regexp12
"^\\(\\S-?\\)\\(\t\\)\\([^\n\t]*\\S-\\)\\(\\(\t[ \t]*\\)\\([^\n\t]*\\S-\\)\\)?[ \t]*$"
"Regular expression matching all types of phrase lines.")
(defvar reftex-index-phrases-macro-data nil
"Alist containing the information taken from the macro definition lines.
This gets refreshed in every phrases command.")
(defvar reftex-index-phrases-files nil
"List of document files relevant for the phrases file.")
(defvar reftex-index-phrases-font-lock-keywords nil
"Font lock keywords for reftex-index-phrases-mode.")
(defvar reftex-index-phrases-font-lock-defaults nil
"Font lock defaults for reftex-index-phrases-mode.")
(defvar reftex-index-phrases-map (make-sparse-keymap)
"Keymap used for *toc* buffer.")
(defun reftex-index-phrase-selection-or-word (arg)
"Add current selection or word at point to the phrases buffer.
When you are in transient-mark-mode and the region is active, the
selection will be used - otherwise the word at point.
You get a chance to edit the entry in the phrases buffer - finish with
`C-c C-c'."
(interactive "P")
(set-marker reftex-index-return-marker (point))
(reftex-index-selection-or-word arg 'phrase)
(if (eq major-mode 'reftex-index-phrases-mode)
(message
(substitute-command-keys
"Return to LaTeX with \\[reftex-index-phrases-save-and-return]"))))
(defun reftex-index-visit-phrases-buffer ()
"Switch to the phrases buffer, initialize if empty."
(interactive)
(reftex-access-scan-info)
(let* ((master (reftex-TeX-master-file))
(name (concat (file-name-sans-extension master) ".rip")))
(find-file name)
(unless (eq major-mode 'reftex-index-phrases-mode)
(reftex-index-phrases-mode))
(if (= (buffer-size) 0)
(reftex-index-initialize-phrases-buffer master))))
(defun reftex-index-initialize-phrases-buffer (&optional master)
"Initialize the phrases buffer by creating the header.
If the buffer is non-empty, delete the old header first."
(interactive)
(let* ((case-fold-search t)
(default-key (car reftex-index-default-macro))
(default-macro (nth 1 (assoc default-key
reftex-key-to-index-macro-alist)))
(macro-alist
(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)))
(when (> (buffer-size) 0)
(goto-char 1)
(set-mark (point))
(while (re-search-forward reftex-index-phrases-macrodef-regexp nil t)
(end-of-line))
(beginning-of-line 2)
(if (looking-at reftex-index-phrases-comment-regexp)
(beginning-of-line 2))
(while (looking-at "^[ \t]*$")
(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 ")
(delete-region (point-min) (point))))
;; Insert the mode line
(insert
(format "%% -*- mode: reftex-index-phrases; TeX-master: \"%s\" -*-\n"
(file-name-nondirectory (reftex-index-phrase-tex-master))))
;; Insert the macro definitions
(insert "% Key Macro Format Repeat\n")
(insert "%---------------------------------------------------------------------\n")
(while (setq entry (pop macro-alist))
(setq macro (car entry)
repeat (nth 7 entry)
key (car (delq nil (mapcar (lambda (x) (if (equal (nth 1 x) macro)
(car x)
nil))
reftex-key-to-index-macro-alist))))
(insert (format ">>>INDEX_MACRO_DEFINITION:\t%s\t%-20s\t%s\n"
(char-to-string key) (concat macro "{%s}")
(if repeat "t" "nil"))))
(insert "%---------------------------------------------------------------------\n\n\n")))
(defvar TeX-master)
(defun reftex-index-phrase-tex-master (&optional dir)
"Return the name of the master file associated with a phrase buffer."
(if (and (boundp 'TeX-master)
(local-variable-p 'TeX-master (current-buffer))
(stringp TeX-master))
;; We have a local variable which tells us which file to use
(expand-file-name TeX-master dir)
;; have to guess
(concat (file-name-sans-extension (buffer-file-name)) ".tex")))
(defun reftex-index-phrases-save-and-return ()
"Return to where the `reftex-index-phrase-selection-or-word' was called."
(interactive)
(save-buffer)
(switch-to-buffer (marker-buffer reftex-index-return-marker))
(goto-char (or (marker-position reftex-index-return-marker) (point))))
(defvar reftex-index-phrases-menu)
(defvar reftex-index-phrases-restrict-file nil)
;;;###autoload
(defun reftex-index-phrases-mode ()
"Major mode for managing the Index phrases of a LaTeX document.
This buffer was created with RefTeX.
To insert new phrases, use
- `C-c \\' in the LaTeX document to copy selection or word
- `\\[reftex-index-new-phrase]' in the phrases buffer.
To index phrases use one of:
\\[reftex-index-this-phrase] index current phrase
\\[reftex-index-next-phrase] index next phrase (or N with prefix arg)
\\[reftex-index-all-phrases] index all phrases
\\[reftex-index-remaining-phrases] index current and following phrases
\\[reftex-index-region-phrases] index the phrases in the region
You can sort the phrases in this buffer with \\[reftex-index-sort-phrases].
To display information about the phrase at point, use \\[reftex-index-phrases-info].
For more information see the RefTeX User Manual.
Here are all local bindings.
\\{reftex-index-phrases-map}"
(interactive)
(kill-all-local-variables)
(setq major-mode 'reftex-index-phrases-mode
mode-name "Phrases")
(use-local-map reftex-index-phrases-map)
(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-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
(cons reftex-index-phrases-comment-regexp 'font-lock-comment-face)
(list reftex-index-phrases-macrodef-regexp
'(1 font-lock-type-face)
'(2 font-lock-keyword-face)
(list 3 ss)
'(4 font-lock-function-name-face)
(list 5 ss)
'(6 font-lock-string-face))
(list reftex-index-phrases-phrase-regexp1
'(1 font-lock-keyword-face)
(list 2 ss)
'(3 font-lock-string-face)
(list 4 ss))
(list reftex-index-phrases-phrase-regexp2
'(1 font-lock-keyword-face)
(list 2 ss)
'(3 font-lock-string-face)
(list 4 ss)
'(5 font-lock-function-name-face))
(cons "^\t$" ss)))
(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
reftex-index-phrases-font-lock-defaults) ; XEmacs
)
(defvar reftex-index-phrases-marker)
(defun reftex-index-next-phrase (&optional arg)
"Index the next ARG phrases in the phrases buffer."
(interactive "p")
(reftex-index-phrases-parse-header t)
(while (> arg 0)
(decf arg)
(end-of-line)
(if (re-search-forward reftex-index-phrases-phrase-regexp12 nil t)
(progn
(goto-char (match-beginning 0))
(reftex-index-this-phrase))
(error "No more phrase lines after point"))))
(defun reftex-index-this-phrase ()
"Index the phrase in the current line.
Does a global search and replace in the entire document. At each
match, the user will be asked to confirm the replacement."
(interactive)
(if (interactive-p) (reftex-index-phrases-parse-header t))
(save-excursion
(beginning-of-line)
(cond ((looking-at reftex-index-phrases-comment-regexp)
(if (interactive-p) (error "Comment line")))
((looking-at "^[ \t]*$")
(if (interactive-p) (error "Empty line")))
((looking-at reftex-index-phrases-macrodef-regexp)
(if (interactive-p) (error "Macro definition line")))
((looking-at reftex-index-phrases-phrase-regexp12)
;; This is a phrase
(let* ((char (if (not (equal (match-string 1) ""))
(string-to-char (match-string 1))))
(phrase (match-string 3))
(index-key (match-string 6))
(macro-data (cdr (if (null char)
(car reftex-index-phrases-macro-data)
(assoc char reftex-index-phrases-macro-data))))
(macro-fmt (car macro-data))
(repeat (nth 1 macro-data))
(files
(cond ((and (stringp reftex-index-phrases-restrict-file)