1 |
;;; reftex-auc.el --- RefTeX's interface to AUC TeX |
;;; reftex-auc.el --- RefTeX's interface to AUC TeX |
2 |
;; Copyright (c) 1997, 1998, 1999, 2000 Free Software Foundation, Inc. |
;; Copyright (c) 1997, 1998, 1999, 2000, 2003 Free Software Foundation, Inc. |
3 |
|
|
4 |
;; Author: Carsten Dominik <dominik@science.uva.nl> |
;; Author: Carsten Dominik <dominik@science.uva.nl> |
5 |
;; Version: 4.18 |
;; Version: 4.21 |
6 |
|
|
7 |
;; This file is part of GNU Emacs. |
;; This file is part of GNU Emacs. |
8 |
|
|
34 |
;; Tell if a certain flag is set in reftex-plug-into-AUCTeX |
;; Tell if a certain flag is set in reftex-plug-into-AUCTeX |
35 |
(or (eq t reftex-plug-into-AUCTeX) |
(or (eq t reftex-plug-into-AUCTeX) |
36 |
(and (listp reftex-plug-into-AUCTeX) |
(and (listp reftex-plug-into-AUCTeX) |
37 |
(nth which reftex-plug-into-AUCTeX)))) |
(nth which reftex-plug-into-AUCTeX)))) |
38 |
|
|
39 |
(defun reftex-arg-label (optional &optional prompt definition) |
(defun reftex-arg-label (optional &optional prompt definition) |
40 |
"Use `reftex-label', `reftex-reference' or AUCTeX's code to insert label arg. |
"Use `reftex-label', `reftex-reference' or AUCTeX's code to insert label arg. |
44 |
((and definition (reftex-plug-flag 1)) |
((and definition (reftex-plug-flag 1)) |
45 |
;; Create a new label, with a temporary brace for `reftex-what-macro' |
;; Create a new label, with a temporary brace for `reftex-what-macro' |
46 |
(unwind-protect |
(unwind-protect |
47 |
(progn (insert "{") (setq label (or (reftex-label nil t) ""))) |
(progn (insert "{") (setq label (or (reftex-label nil t) ""))) |
48 |
(delete-backward-char 1))) |
(delete-backward-char 1))) |
49 |
((and (not definition) (reftex-plug-flag 2)) |
((and (not definition) (reftex-plug-flag 2)) |
50 |
;; Reference a label with RefTeX |
;; Reference a label with RefTeX |
51 |
(setq label (reftex-reference nil t))) |
(setq label (reftex-reference nil t))) |
52 |
(t |
(t |
53 |
;; AUCTeX's default mechanism |
;; AUCTeX's default mechanism |
54 |
(setq label (completing-read (TeX-argument-prompt optional prompt "Key") |
(setq label (completing-read (TeX-argument-prompt optional prompt "Key") |
55 |
(LaTeX-label-list))))) |
(LaTeX-label-list))))) |
56 |
(if (and definition (not (string-equal "" label))) |
(if (and definition (not (string-equal "" label))) |
57 |
(LaTeX-add-labels label)) |
(LaTeX-add-labels label)) |
58 |
(TeX-argument-insert label optional))) |
(TeX-argument-insert label optional))) |
59 |
|
|
60 |
(defun reftex-arg-cite (optional &optional prompt definition) |
(defun reftex-arg-cite (optional &optional prompt definition) |
66 |
(setq items (list (or (reftex-citation t) "")))) |
(setq items (list (or (reftex-citation t) "")))) |
67 |
(t |
(t |
68 |
(setq prompt (concat (if optional "(Optional) " "") |
(setq prompt (concat (if optional "(Optional) " "") |
69 |
(if prompt prompt "Add key") |
(if prompt prompt "Add key") |
70 |
": (default none) ")) |
": (default none) ")) |
71 |
(setq items (multi-prompt "," t prompt (LaTeX-bibitem-list))))) |
(setq items (multi-prompt "," t prompt (LaTeX-bibitem-list))))) |
72 |
(apply 'LaTeX-add-bibitems items) |
(apply 'LaTeX-add-bibitems items) |
73 |
(TeX-argument-insert (mapconcat 'identity items ",") optional))) |
(TeX-argument-insert (mapconcat 'identity items ",") optional))) |
74 |
|
|
75 |
|
|
76 |
(defun reftex-arg-index-tag (optional &optional prompt &rest args) |
(defun reftex-arg-index-tag (optional &optional prompt &rest args) |
77 |
"Prompt for an index tag with completion. |
"Prompt for an index tag with completion. |
78 |
This is the name of an index, not the entry." |
This is the name of an index, not the entry." |
79 |
(let (tag taglist) |
(let (tag taglist) |
80 |
(setq prompt (concat (if optional "(Optional) " "") |
(setq prompt (concat (if optional "(Optional) " "") |
81 |
(if prompt prompt "Index tag") |
(if prompt prompt "Index tag") |
82 |
": (default none) ")) |
": (default none) ")) |
83 |
(if (and reftex-support-index (reftex-plug-flag 4)) |
(if (and reftex-support-index (reftex-plug-flag 4)) |
84 |
;; Use RefTeX completion |
;; Use RefTeX completion |
85 |
(progn |
(progn |
86 |
(reftex-access-scan-info nil) |
(reftex-access-scan-info nil) |
87 |
(setq taglist |
(setq taglist |
88 |
(cdr (assoc 'index-tags |
(cdr (assoc 'index-tags |
89 |
(symbol-value reftex-docstruct-symbol))) |
(symbol-value reftex-docstruct-symbol))) |
90 |
tag (completing-read prompt (mapcar 'list taglist)))) |
tag (completing-read prompt (mapcar 'list taglist)))) |
91 |
;; Just ask like AUCTeX does. |
;; Just ask like AUCTeX does. |
92 |
(setq tag (read-string prompt))) |
(setq tag (read-string prompt))) |
93 |
(TeX-argument-insert tag optional))) |
(TeX-argument-insert tag optional))) |
98 |
argument identify one of multiple indices." |
argument identify one of multiple indices." |
99 |
(let* (tag key) |
(let* (tag key) |
100 |
(if (and reftex-support-index (reftex-plug-flag 4)) |
(if (and reftex-support-index (reftex-plug-flag 4)) |
101 |
(progn |
(progn |
102 |
(reftex-access-scan-info nil) |
(reftex-access-scan-info nil) |
103 |
(setq tag (reftex-what-index-tag) |
(setq tag (reftex-what-index-tag) |
104 |
key (reftex-index-complete-key (or tag "idx")))) |
key (reftex-index-complete-key (or tag "idx")))) |
105 |
(setq key (completing-read (TeX-argument-prompt optional prompt "Key") |
(setq key (completing-read (TeX-argument-prompt optional prompt "Key") |
106 |
(LaTeX-index-entry-list)))) |
(LaTeX-index-entry-list)))) |
107 |
(unless (string-equal "" key) |
(unless (string-equal "" key) |
108 |
(LaTeX-add-index-entries key)) |
(LaTeX-add-index-entries key)) |
109 |
(TeX-argument-insert key optional))) |
(TeX-argument-insert key optional))) |
111 |
(defun reftex-what-index-tag () |
(defun reftex-what-index-tag () |
112 |
;; Look backward to find out what index the macro at point belongs to |
;; Look backward to find out what index the macro at point belongs to |
113 |
(let ((macro (save-excursion |
(let ((macro (save-excursion |
114 |
(and (re-search-backward "\\\\[a-zA-Z*]+" nil t) |
(and (re-search-backward "\\\\[a-zA-Z*]+" nil t) |
115 |
(match-string 0)))) |
(match-string 0)))) |
116 |
tag entry) |
tag entry) |
117 |
(when (and macro |
(when (and macro |
118 |
(setq entry (assoc macro reftex-index-macro-alist))) |
(setq entry (assoc macro reftex-index-macro-alist))) |
119 |
(setq tag (nth 1 entry)) |
(setq tag (nth 1 entry)) |
120 |
(cond |
(cond |
121 |
((stringp tag) tag) |
((stringp tag) tag) |
122 |
((integerp tag) |
((integerp tag) |
123 |
(save-excursion |
(save-excursion |
124 |
(goto-char (match-end 1)) |
(goto-char (match-end 1)) |
125 |
(or (reftex-nth-arg tag (nth 6 entry)) "idx"))) |
(or (reftex-nth-arg tag (nth 6 entry)) "idx"))) |
126 |
(t "idx"))))) |
(t "idx"))))) |
127 |
|
|
128 |
(defvar LaTeX-label-function) |
(defvar LaTeX-label-function) |
130 |
;; Replace AUCTeX functions with RefTeX functions. |
;; Replace AUCTeX functions with RefTeX functions. |
131 |
;; Which functions are replaced is controlled by the variable |
;; Which functions are replaced is controlled by the variable |
132 |
;; `reftex-plug-into-AUCTeX'. |
;; `reftex-plug-into-AUCTeX'. |
133 |
|
|
134 |
(if (reftex-plug-flag 0) |
(if (reftex-plug-flag 0) |
135 |
(setq LaTeX-label-function 'reftex-label) |
(setq LaTeX-label-function 'reftex-label) |
136 |
(setq LaTeX-label-function nil)) |
(setq LaTeX-label-function nil)) |
142 |
(and (reftex-plug-flag 3) |
(and (reftex-plug-flag 3) |
143 |
(fboundp 'TeX-arg-cite) |
(fboundp 'TeX-arg-cite) |
144 |
(fset 'TeX-arg-cite 'reftex-arg-cite)) |
(fset 'TeX-arg-cite 'reftex-arg-cite)) |
145 |
|
|
146 |
(and (reftex-plug-flag 4) |
(and (reftex-plug-flag 4) |
147 |
(fboundp 'TeX-arg-index-tag) |
(fboundp 'TeX-arg-index-tag) |
148 |
(fset 'TeX-arg-index-tag 'reftex-arg-index-tag)) |
(fset 'TeX-arg-index-tag 'reftex-arg-index-tag)) |
149 |
(and (reftex-plug-flag 4) |
(and (reftex-plug-flag 4) |
150 |
(fboundp 'TeX-arg-index) |
(fboundp 'TeX-arg-index) |
151 |
(fset 'TeX-arg-index 'reftex-arg-index))) |
(fset 'TeX-arg-index 'reftex-arg-index))) |
152 |
|
|
174 |
(unless reftex-docstruct-symbol |
(unless reftex-docstruct-symbol |
175 |
(reftex-tie-multifile-symbols)) |
(reftex-tie-multifile-symbols)) |
176 |
(when (and reftex-docstruct-symbol |
(when (and reftex-docstruct-symbol |
177 |
(symbolp reftex-docstruct-symbol)) |
(symbolp reftex-docstruct-symbol)) |
178 |
(let ((list (get reftex-docstruct-symbol 'reftex-label-alist-style)) |
(let ((list (get reftex-docstruct-symbol 'reftex-label-alist-style)) |
179 |
entry changed) |
entry changed) |
180 |
(while entry-list |
(while entry-list |
181 |
(setq entry (pop entry-list)) |
(setq entry (pop entry-list)) |
182 |
(unless (member entry list) |
(unless (member entry list) |
183 |
(setq reftex-tables-dirty t |
(setq reftex-tables-dirty t |
184 |
changed t) |
changed t) |
185 |
(push entry list))) |
(push entry list))) |
186 |
(when changed |
(when changed |
187 |
(put reftex-docstruct-symbol 'reftex-label-alist-style list))))) |
(put reftex-docstruct-symbol 'reftex-label-alist-style list))))) |
188 |
(defalias 'reftex-add-to-label-alist 'reftex-add-label-environments) |
(defalias 'reftex-add-to-label-alist 'reftex-add-label-environments) |
189 |
|
|
190 |
(defun reftex-add-section-levels (entry-list) |
(defun reftex-add-section-levels (entry-list) |
195 |
(unless reftex-docstruct-symbol |
(unless reftex-docstruct-symbol |
196 |
(reftex-tie-multifile-symbols)) |
(reftex-tie-multifile-symbols)) |
197 |
(when (and reftex-docstruct-symbol |
(when (and reftex-docstruct-symbol |
198 |
(symbolp reftex-docstruct-symbol)) |
(symbolp reftex-docstruct-symbol)) |
199 |
(let ((list (get reftex-docstruct-symbol 'reftex-section-levels)) |
(let ((list (get reftex-docstruct-symbol 'reftex-section-levels)) |
200 |
entry changed) |
entry changed) |
201 |
(while entry-list |
(while entry-list |
202 |
(setq entry (pop entry-list)) |
(setq entry (pop entry-list)) |
203 |
(unless (member entry list) |
(unless (member entry list) |
204 |
(setq reftex-tables-dirty t |
(setq reftex-tables-dirty t |
205 |
changed t) |
changed t) |
206 |
(push entry list))) |
(push entry list))) |
207 |
(when changed |
(when changed |
208 |
(put reftex-docstruct-symbol 'reftex-section-levels list))))) |
(put reftex-docstruct-symbol 'reftex-section-levels list))))) |
209 |
|
|
210 |
(defun reftex-notice-new-section () |
(defun reftex-notice-new-section () |
211 |
(reftex-notice-new 1 'force)) |
(reftex-notice-new 1 'force)) |