Function: reftex-compile-variables
reftex-compile-variables is a byte-compiled function defined in
reftex.el.gz.
Signature
(reftex-compile-variables)
Documentation
Compile the information in reftex-label-alist & Co.
Source Code
;; Defined in /usr/src/emacs/lisp/textmodes/reftex.el.gz
(defun reftex-compile-variables ()
"Compile the information in reftex-label-alist & Co."
(message "Compiling label environment definitions...")
;; Update AUCTeX style information
(when (and (featurep 'tex-site) (fboundp 'TeX-update-style))
(condition-case nil (TeX-update-style) (error nil)))
;; Record that we have done this, and what we have used.
(setq reftex-tables-dirty nil)
(setq reftex-memory
(list reftex-label-alist
(get reftex-docstruct-symbol 'reftex-section-levels)
(get reftex-docstruct-symbol 'reftex-label-alist-style)
reftex-default-label-alist-entries
reftex-index-macros
(get reftex-docstruct-symbol 'reftex-index-macros-style)))
;; Compile information in reftex-label-alist
(let ((all (reftex-uniquify-by-car
(reftex-splice-symbols-into-list
(append reftex-label-alist
(get reftex-docstruct-symbol
'reftex-label-alist-style)
reftex-default-label-alist-entries)
reftex-label-alist-builtin)
'(nil)))
(all-index (reftex-uniquify-by-car
(reftex-splice-symbols-into-list
(append reftex-index-macros
(get reftex-docstruct-symbol
'reftex-index-macros-style)
'(default))
reftex-index-macros-builtin)))
entry env-or-mac typekeychar typekey prefix context word
fmt reffmt labelfmt wordlist qh-list macros-with-labels
nargs nlabel opt-args cell sum i
macro verify repeat nindex tag key toc-level toc-levels)
(setq reftex-words-to-typekey-alist nil
reftex-prefix-to-typekey-alist
'(("sec:" . "s") ("cha:" . "s") ("chap:" . "s"))
reftex-typekey-list nil
reftex-typekey-to-format-alist nil
reftex-typekey-to-prefix-alist nil
reftex-env-or-mac-alist nil
reftex-label-env-list nil
reftex-label-mac-list nil)
(while all
(catch 'next-entry
(setq entry (car all)
env-or-mac (car entry)
entry (cdr entry)
all (cdr all))
(if (null env-or-mac)
(setq env-or-mac ""))
(if (stringp (car entry))
;; This is before version 2.00 - convert entry to new format
;; This is just to keep old users happy
(setq entry (cons (string-to-char (car entry))
(cons (concat (car entry) ":")
(cdr entry)))))
(setq typekeychar (nth 0 entry)
typekey (if typekeychar (char-to-string typekeychar) nil)
prefix (nth 1 entry)
fmt (nth 2 entry)
context (nth 3 entry)
wordlist (nth 4 entry)
toc-level (nth 5 entry))
(if (stringp wordlist)
;; This is before version 2.04 - convert to new format
(setq wordlist (nthcdr 4 entry)))
(if (and (stringp fmt)
(string-search "@" fmt))
;; Special syntax for specifying a label format
(setq fmt (split-string fmt "@+"))
(setq fmt (list "\\label{%s}" fmt)))
(setq labelfmt (car fmt)
reffmt (nth 1 fmt))
;; Note a new typekey
(if typekey
(cl-pushnew typekey reftex-typekey-list :test #'equal))
(if (and typekey prefix
(not (assoc prefix reftex-prefix-to-typekey-alist)))
(cl-pushnew (cons prefix typekey) reftex-prefix-to-typekey-alist
:test #'equal))
(if (and typekey prefix
(not (assoc typekey reftex-typekey-to-prefix-alist)))
(cl-pushnew (cons typekey prefix) reftex-typekey-to-prefix-alist
:test #'equal))
;; Check if this is a macro or environment
(cond
((symbolp env-or-mac)
;; A special parser function
(unless (fboundp env-or-mac)
(message "Warning: %s does not seem to be a valid function"
env-or-mac))
(setq nargs nil nlabel nil opt-args nil)
(cl-pushnew env-or-mac reftex-special-env-parsers)
(setq env-or-mac (symbol-name env-or-mac)))
((string-match "\\`\\\\" env-or-mac)
;; It's a macro
(let ((result (reftex-parse-args env-or-mac)))
(setq env-or-mac (or (cl-first result) env-or-mac)
nargs (cl-second result)
nlabel (cl-third result)
opt-args (cl-fourth result))
(if nlabel (cl-pushnew env-or-mac macros-with-labels :test #'equal)))
(if typekey (cl-pushnew env-or-mac reftex-label-mac-list :test #'equal)))
(t
;; It's an environment
(setq nargs nil nlabel nil opt-args nil)
(cond ((string= env-or-mac "any"))
((string= env-or-mac ""))
((string= env-or-mac "section"))
(t
(cl-pushnew env-or-mac reftex-label-env-list :test #'equal)
(if toc-level
(let ((string (format "begin{%s}" env-or-mac)))
(or (assoc string toc-levels)
(push (cons string toc-level) toc-levels))))))))
;; Translate some special context cases
(when (assq context reftex-default-context-regexps)
(setq context
(format
(cdr (assq context reftex-default-context-regexps))
(regexp-quote env-or-mac))))
;; See if this is the first format for this typekey
(and reffmt
(not (assoc typekey reftex-typekey-to-format-alist))
(push (cons typekey reffmt) reftex-typekey-to-format-alist))
;; See if this is the first definition for this env-or-mac
(and (not (string= env-or-mac "any"))
(not (string= env-or-mac ""))
(not (assoc env-or-mac reftex-env-or-mac-alist))
(push (list env-or-mac typekey context labelfmt
nargs nlabel opt-args)
reftex-env-or-mac-alist))
;; Are the magic words regular expressions? Quote normal words.
(if (eq (car wordlist) 'regexp)
(setq wordlist (cdr wordlist))
(setq wordlist (mapcar #'regexp-quote wordlist)))
;; Remember the first association of each word.
(while (stringp (setq word (pop wordlist)))
(or (assoc word reftex-words-to-typekey-alist)
(push (cons word typekey) reftex-words-to-typekey-alist)))
(cond
((string= "" env-or-mac) nil)
((setq cell (assoc typekey qh-list))
(push env-or-mac (cdr cell)))
(typekey
(push (list typekey env-or-mac) qh-list)))))
(setq reftex-typekey-to-prefix-alist
(nreverse reftex-typekey-to-prefix-alist))
;; Prepare the typekey query prompt and help string.
(setq qh-list
(sort qh-list
(lambda (x1 x2)
(string< (downcase (car x1)) (downcase (car x2))))))
(setq reftex-type-query-prompt
(concat "Label type: ["
(mapconcat (lambda(x) (format "%s" (car x)))
qh-list "")
"]"))
;; In the help string, we need to wrap lines...
(setq reftex-type-query-help
(concat
"SELECT A LABEL TYPE:\n--------------------\n"
(mapconcat
(lambda(x)
(setq sum 0)
(format " [%s] %s"
(car x)
(mapconcat (lambda(env)
(setq sum (+ sum (length env)))
(if (< sum 60)
env
(setq sum 0)
(concat "\n " env)))
(cdr x) " ")))
qh-list "\n")))
;; Convert magic words to regular expressions. We make regular expressions
;; which allow for some chars from the ref format to be in the buffer.
;; These characters will be seen and removed.
(setq reftex-words-to-typekey-alist
(mapcar
(lambda (x)
(setq word (car x)
typekey (cdr x)
fmt (cdr (assoc typekey reftex-typekey-to-format-alist)))
(setq word (concat "\\W\\(" word "[ \t\n\r]*\\)\\("))
(setq i 0)
(while (and (< i 10) ; maximum number of format chars allowed
(< i (length fmt))
(not (member (aref fmt i) '(?%))))
(setq word (concat word "\\|" (regexp-quote
(substring fmt 0 (1+ i)))))
(incf i))
(cons (concat word "\\)\\=") typekey))
(nreverse reftex-words-to-typekey-alist)))
;; Parse the index macros
(setq reftex-index-macro-alist nil
reftex-key-to-index-macro-alist nil
reftex-macros-with-index nil)
(while all-index
(setq entry (car all-index)
macro (car entry)
tag (nth 1 entry)
key (nth 2 entry)
prefix (or (nth 3 entry) "")
verify (nth 4 entry)
;; For repeat, we need to be compatible with older code
;; This information used to be given only for the default macro,
;; but later we required to have it for *every* index macro
repeat (cond ((> (length entry) 5) (nth 5 entry))
((and (eq key (car reftex-index-default-macro))
(> (length reftex-index-default-macro) 2))
;; User has old setting - respect it
(nth 2 reftex-index-default-macro))
(t t))
all-index (cdr all-index))
(let ((result (reftex-parse-args macro)))
(setq macro (or (cl-first result) macro)
nargs (cl-second result)
nindex (cl-third result)
opt-args (cl-fourth result))
(unless (member macro reftex-macros-with-index)
;; 0 1 2 3 4 5 6 7
(push (list macro tag prefix verify nargs nindex opt-args repeat)
reftex-index-macro-alist)
(or (assoc key reftex-key-to-index-macro-alist)
(push (list key macro) reftex-key-to-index-macro-alist))
(push macro reftex-macros-with-index))))
;; Make the prompt and help string for index macros query
(setq reftex-key-to-index-macro-alist
(sort reftex-key-to-index-macro-alist
(lambda (a b) (< (downcase (car a)) (downcase (car b))))))
(setq reftex-query-index-macro-prompt
(concat "Index macro: ["
(mapconcat (lambda (x) (char-to-string (car x)))
reftex-key-to-index-macro-alist "")
"]"))
(setq i 0
reftex-query-index-macro-help
(concat
"SELECT A MACRO:\n---------------\n"
(mapconcat
(lambda(x)
(format "[%c] %-20.20s%s" (car x) (nth 1 x)
(if (= 0 (mod (incf i) 3)) "\n" "")))
reftex-key-to-index-macro-alist "")))
;; Make the full list of section levels
(setq reftex-section-levels-all
(append toc-levels
(get reftex-docstruct-symbol 'reftex-section-levels)
reftex-section-levels))
;; Calculate the regular expressions
(let* (;; (wbol "\\(\\`\\|[\n\r]\\)[ \t]*")
;; Need to keep the empty group because match numbers are
;; hard coded
(wbol (concat "\\(^\\)"
(when (string-suffix-p ".dtx" (buffer-file-name) t)
"%")
"[ \t]*"))
(label-re (concat "\\(?:"
(mapconcat #'identity reftex-label-regexps "\\|")
"\\)"))
(include-re (concat wbol
"\\\\\\("
(mapconcat #'identity
reftex-include-file-commands "\\|")
"\\)[{ \t]+\\([^} \t\n\r]+\\)"))
(section-re
(concat wbol reftex-section-pre-regexp "\\("
(mapconcat (lambda (x) (regexp-quote (car x)))
reftex-section-levels-all "\\|")
"\\)" reftex-section-post-regexp))
(appendix-re (concat wbol "\\(\\\\appendix\\)"))
(macro-re
(if macros-with-labels
(concat "\\("
(mapconcat #'regexp-quote macros-with-labels "\\|")
"\\)[[{]")
""))
(index-re
(concat "\\("
(mapconcat #'regexp-quote reftex-macros-with-index "\\|")
"\\)[[{]"))
(find-index-re-format
(concat "\\("
(mapconcat #'regexp-quote reftex-macros-with-index "\\|")
"\\)\\([[{][^]}]*[]}]\\)*[[{]\\(%s\\)[]}]"))
(find-label-re-format
(concat "\\("
"label[[:space:]]*=[[:space:]]*"
"\\|"
(mapconcat #'regexp-quote (append '("\\label")
macros-with-labels)
"\\|")
"\\)\\([[{][^]}]*[]}]\\)*[[{]\\(%s\\)[]}]"))
(index-level-re
(regexp-quote (nth 0 reftex-index-special-chars)))
(index-key-end-re ;; ^]- not allowed
(concat "[^" (nth 3 reftex-index-special-chars) "]"
"[" (nth 1 reftex-index-special-chars)
(nth 2 reftex-index-special-chars) "]"))
)
(setq reftex-section-regexp section-re
reftex-section-or-include-regexp
(concat section-re "\\|" include-re)
reftex-everything-regexp
(concat label-re "\\|" section-re "\\|" include-re
"\\|" appendix-re
"\\|" index-re
(if macros-with-labels "\\|" "") macro-re)
reftex-everything-regexp-no-index
(concat label-re "\\|" section-re "\\|" include-re
"\\|" appendix-re
"\\|" "\\(\\\\6\\\\3\\\\1\\)" ; This is unlikely to match
(if macros-with-labels "\\|" "") macro-re)
reftex-index-re index-re
reftex-index-level-re index-level-re
reftex-index-key-end-re index-key-end-re
reftex-macros-with-labels macros-with-labels
reftex-find-index-entry-regexp-format find-index-re-format
reftex-find-label-regexp-format find-label-re-format
reftex-find-label-regexp-format2
"\\([]} \t\n\r]\\)\\([[{]\\)\\(%s\\)[]}]")
(message "Compiling label environment definitions...done")))
(put reftex-docstruct-symbol 'reftex-cache
(mapcar #'symbol-value reftex-cache-variables)))