| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
(eval-when-compile (require 'cl)) |
|---|
| 32 |
(provide 'reftex-auc) |
|---|
| 33 |
(require 'reftex) |
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
(defun reftex-plug-flag (which) |
|---|
| 37 |
|
|---|
| 38 |
(or (eq t reftex-plug-into-AUCTeX) |
|---|
| 39 |
(and (listp reftex-plug-into-AUCTeX) |
|---|
| 40 |
(nth which reftex-plug-into-AUCTeX)))) |
|---|
| 41 |
|
|---|
| 42 |
(defun reftex-arg-label (optional &optional prompt definition) |
|---|
| 43 |
"Use `reftex-label', `reftex-reference' or AUCTeX's code to insert label arg. |
|---|
| 44 |
What is being used depends upon `reftex-plug-into-AUCTeX'." |
|---|
| 45 |
(let (label) |
|---|
| 46 |
(cond |
|---|
| 47 |
((and definition (reftex-plug-flag 1)) |
|---|
| 48 |
|
|---|
| 49 |
(unwind-protect |
|---|
| 50 |
(progn (insert "{") (setq label (or (reftex-label nil t) ""))) |
|---|
| 51 |
(delete-backward-char 1))) |
|---|
| 52 |
((and (not definition) (reftex-plug-flag 2)) |
|---|
| 53 |
|
|---|
| 54 |
(setq label (reftex-reference nil t))) |
|---|
| 55 |
(t |
|---|
| 56 |
|
|---|
| 57 |
(setq label (completing-read (TeX-argument-prompt optional prompt "Key") |
|---|
| 58 |
(LaTeX-label-list))))) |
|---|
| 59 |
(if (and definition (not (string-equal "" label))) |
|---|
| 60 |
(LaTeX-add-labels label)) |
|---|
| 61 |
(TeX-argument-insert label optional))) |
|---|
| 62 |
|
|---|
| 63 |
(defun reftex-arg-cite (optional &optional prompt definition) |
|---|
| 64 |
"Use `reftex-citation' or AUCTeX's code to insert a cite-key macro argument. |
|---|
| 65 |
What is being used depends upon `reftex-plug-into-AUCTeX'." |
|---|
| 66 |
(let (items) |
|---|
| 67 |
(cond |
|---|
| 68 |
((and (not definition) (reftex-plug-flag 3)) |
|---|
| 69 |
(setq items (list (or (reftex-citation t) "")))) |
|---|
| 70 |
(t |
|---|
| 71 |
(setq prompt (concat (if optional "(Optional) " "") |
|---|
| 72 |
(if prompt prompt "Add key") |
|---|
| 73 |
" (default none): ")) |
|---|
| 74 |
(setq items (multi-prompt "," t prompt (LaTeX-bibitem-list))))) |
|---|
| 75 |
(apply 'LaTeX-add-bibitems items) |
|---|
| 76 |
(TeX-argument-insert (mapconcat 'identity items ",") optional))) |
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
(defun reftex-arg-index-tag (optional &optional prompt &rest args) |
|---|
| 80 |
"Prompt for an index tag with completion. |
|---|
| 81 |
This is the name of an index, not the entry." |
|---|
| 82 |
(let (tag taglist) |
|---|
| 83 |
(setq prompt (concat (if optional "(Optional) " "") |
|---|
| 84 |
(if prompt prompt "Index tag") |
|---|
| 85 |
" (default none): ")) |
|---|
| 86 |
(if (and reftex-support-index (reftex-plug-flag 4)) |
|---|
| 87 |
|
|---|
| 88 |
(progn |
|---|
| 89 |
(reftex-access-scan-info nil) |
|---|
| 90 |
(setq taglist |
|---|
| 91 |
(cdr (assoc 'index-tags |
|---|
| 92 |
(symbol-value reftex-docstruct-symbol))) |
|---|
| 93 |
tag (completing-read prompt (mapcar 'list taglist)))) |
|---|
| 94 |
|
|---|
| 95 |
(setq tag (read-string prompt))) |
|---|
| 96 |
(TeX-argument-insert tag optional))) |
|---|
| 97 |
|
|---|
| 98 |
(defun reftex-arg-index (optional &optional prompt &rest args) |
|---|
| 99 |
"Prompt for an index entry completing with known entries. |
|---|
| 100 |
Completion is specific for just one index, if the macro or a tag |
|---|
| 101 |
argument identify one of multiple indices." |
|---|
| 102 |
(let* (tag key) |
|---|
| 103 |
(if (and reftex-support-index (reftex-plug-flag 4)) |
|---|
| 104 |
(progn |
|---|
| 105 |
(reftex-access-scan-info nil) |
|---|
| 106 |
(setq tag (reftex-what-index-tag) |
|---|
| 107 |
key (reftex-index-complete-key (or tag "idx")))) |
|---|
| 108 |
(setq key (completing-read (TeX-argument-prompt optional prompt "Key") |
|---|
| 109 |
(LaTeX-index-entry-list)))) |
|---|
| 110 |
(unless (string-equal "" key) |
|---|
| 111 |
(LaTeX-add-index-entries key)) |
|---|
| 112 |
(TeX-argument-insert key optional))) |
|---|
| 113 |
|
|---|
| 114 |
(defun reftex-what-index-tag () |
|---|
| 115 |
|
|---|
| 116 |
(let ((macro (save-excursion |
|---|
| 117 |
(and (re-search-backward "\\\\[a-zA-Z*]+" nil t) |
|---|
| 118 |
(match-string 0)))) |
|---|
| 119 |
tag entry) |
|---|
| 120 |
(when (and macro |
|---|
| 121 |
(setq entry (assoc macro reftex-index-macro-alist))) |
|---|
| 122 |
(setq tag (nth 1 entry)) |
|---|
| 123 |
(cond |
|---|
| 124 |
((stringp tag) tag) |
|---|
| 125 |
((integerp tag) |
|---|
| 126 |
(save-excursion |
|---|
| 127 |
(goto-char (match-end 1)) |
|---|
| 128 |
(or (reftex-nth-arg tag (nth 6 entry)) "idx"))) |
|---|
| 129 |
(t "idx"))))) |
|---|
| 130 |
|
|---|
| 131 |
(defvar LaTeX-label-function) |
|---|
| 132 |
(defun reftex-plug-into-AUCTeX () |
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 |
(if (reftex-plug-flag 0) |
|---|
| 138 |
(setq LaTeX-label-function 'reftex-label) |
|---|
| 139 |
(setq LaTeX-label-function nil)) |
|---|
| 140 |
|
|---|
| 141 |
(and (or (reftex-plug-flag 1) (reftex-plug-flag 2)) |
|---|
| 142 |
(fboundp 'TeX-arg-label) |
|---|
| 143 |
(fset 'TeX-arg-label 'reftex-arg-label)) |
|---|
| 144 |
|
|---|
| 145 |
(and (reftex-plug-flag 3) |
|---|
| 146 |
(fboundp 'TeX-arg-cite) |
|---|
| 147 |
(fset 'TeX-arg-cite 'reftex-arg-cite)) |
|---|
| 148 |
|
|---|
| 149 |
(and (reftex-plug-flag 4) |
|---|
| 150 |
(fboundp 'TeX-arg-index-tag) |
|---|
| 151 |
(fset 'TeX-arg-index-tag 'reftex-arg-index-tag)) |
|---|
| 152 |
(and (reftex-plug-flag 4) |
|---|
| 153 |
(fboundp 'TeX-arg-index) |
|---|
| 154 |
(fset 'TeX-arg-index 'reftex-arg-index))) |
|---|
| 155 |
|
|---|
| 156 |
(defun reftex-toggle-plug-into-AUCTeX () |
|---|
| 157 |
"Toggle Interface between AUCTeX and RefTeX on and off." |
|---|
| 158 |
(interactive) |
|---|
| 159 |
(unless (and (featurep 'tex-site) (featurep 'latex)) |
|---|
| 160 |
(error "AUCTeX's LaTeX mode does not seem to be loaded")) |
|---|
| 161 |
(setq reftex-plug-into-AUCTeX (not reftex-plug-into-AUCTeX)) |
|---|
| 162 |
(reftex-plug-into-AUCTeX) |
|---|
| 163 |
(if reftex-plug-into-AUCTeX |
|---|
| 164 |
(message "RefTeX has been plugged into AUCTeX.") |
|---|
| 165 |
(message "RefTeX no longer interacts with AUCTeX."))) |
|---|
| 166 |
|
|---|
| 167 |
(defun reftex-add-label-environments (entry-list) |
|---|
| 168 |
"Add label environment descriptions to `reftex-label-alist-style'. |
|---|
| 169 |
The format of ENTRY-LIST is exactly like `reftex-label-alist'. See there |
|---|
| 170 |
for details. |
|---|
| 171 |
This function makes it possible to support RefTeX from AUCTeX style files. |
|---|
| 172 |
The entries in ENTRY-LIST will be processed after the user settings in |
|---|
| 173 |
`reftex-label-alist', and before the defaults (specified in |
|---|
| 174 |
`reftex-default-label-alist-entries'). Any changes made to |
|---|
| 175 |
`reftex-label-alist-style' will raise a flag to the effect that |
|---|
| 176 |
the label information is recompiled on next use." |
|---|
| 177 |
(unless reftex-docstruct-symbol |
|---|
| 178 |
(reftex-tie-multifile-symbols)) |
|---|
| 179 |
(when (and reftex-docstruct-symbol |
|---|
| 180 |
(symbolp reftex-docstruct-symbol)) |
|---|
| 181 |
(let ((list (get reftex-docstruct-symbol 'reftex-label-alist-style)) |
|---|
| 182 |
entry changed) |
|---|
| 183 |
(while entry-list |
|---|
| 184 |
(setq entry (pop entry-list)) |
|---|
| 185 |
(unless (member entry list) |
|---|
| 186 |
(setq reftex-tables-dirty t |
|---|
| 187 |
changed t) |
|---|
| 188 |
(push entry list))) |
|---|
| 189 |
(when changed |
|---|
| 190 |
(put reftex-docstruct-symbol 'reftex-label-alist-style list))))) |
|---|
| 191 |
(defalias 'reftex-add-to-label-alist 'reftex-add-label-environments) |
|---|
| 192 |
|
|---|
| 193 |
(defun reftex-add-section-levels (entry-list) |
|---|
| 194 |
"Add entries to the value of `reftex-section-levels'. |
|---|
| 195 |
The added values are kept local to the current document. The format |
|---|
| 196 |
of ENTRY-LIST is a list of cons cells (\"MACRONAME\" . LEVEL). See |
|---|
| 197 |
`reftex-section-levels' for an example." |
|---|
| 198 |
(unless reftex-docstruct-symbol |
|---|
| 199 |
(reftex-tie-multifile-symbols)) |
|---|
| 200 |
(when (and reftex-docstruct-symbol |
|---|
| 201 |
(symbolp reftex-docstruct-symbol)) |
|---|
| 202 |
(let ((list (get reftex-docstruct-symbol 'reftex-section-levels)) |
|---|
| 203 |
entry changed) |
|---|
| 204 |
(while entry-list |
|---|
| 205 |
(setq entry (pop entry-list)) |
|---|
| 206 |
(unless (member entry list) |
|---|
| 207 |
(setq reftex-tables-dirty t |
|---|
| 208 |
changed t) |
|---|
| 209 |
(push entry list))) |
|---|
| 210 |
(when changed |
|---|
| 211 |
(put reftex-docstruct-symbol 'reftex-section-levels list))))) |
|---|
| 212 |
|
|---|
| 213 |
(defun reftex-notice-new-section () |
|---|
| 214 |
(reftex-notice-new 1 'force)) |
|---|
| 215 |
|
|---|
| 216 |
|
|---|
| 217 |
|
|---|
| 218 |
|
|---|