Function: reftex-index

reftex-index is an autoloaded, interactive and byte-compiled function defined in reftex-index.el.gz.

Signature

(reftex-index &optional CHAR KEY TAG SEL NO-INSERT)

Documentation

Query for an index macro and insert it along with its arguments.

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. RefteX provides completion for the index tag and the index key, and will prompt for other arguments.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/reftex-index.el.gz
;;;###autoload
(defun reftex-index (&optional char key tag sel _no-insert)
  "Query for an index macro and insert it along with its arguments.
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.
RefteX provides completion for the index tag and the index key, and
will prompt for other arguments."

  (interactive)

  ;; Ensure access to scanning info
  (reftex-ensure-index-support t)
  (reftex-access-scan-info current-prefix-arg)

  ;; Find out which macro we are going to use
  (let* ((char (or char
                   (reftex-select-with-char reftex-query-index-macro-prompt
                                            reftex-query-index-macro-help)))
         (macro (nth 1 (assoc char reftex-key-to-index-macro-alist)))
         (entry (or (assoc macro reftex-index-macro-alist)
                    (error "No index macro associated with %c" char)))
         (ntag (nth 1 entry))
         (tag (or tag (nth 1 entry)))
         (nargs (nth 4 entry))
         (nindex (nth 5 entry))
         (opt-args (nth 6 entry))
         (repeat (nth 7 entry))
         opt tag1 value)

    ;; Get the supported arguments
    (if (stringp tag)
        (setq tag1 tag)
      (setq tag1 (or (reftex-index-complete-tag tag opt-args) "")))
    (setq key (or key
                  (reftex-index-complete-key
                   (if (string= tag1 "") "idx" tag1)
                   (member nindex opt-args))))

    ;; Insert the macro and ask for any additional args
    (insert macro)
    (cl-loop for i from 1 to nargs do
      (setq opt (member i opt-args)
            value (cond ((= nindex i) key)
                        ((equal ntag i) tag1)
                        (t (read-string (concat "Macro arg nr. "
                                                (int-to-string i)
                                                (if opt " (optional)" "")
                                                ": ")))))
      (unless (and opt (string= value ""))
        (insert (if opt "[" "{") value (if opt "]" "}"))))
    (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)
    (reftex-notice-new)))