Mercurial > emacs
comparison lisp/textmodes/reftex-auc.el @ 89909:68c22ea6027c
Sync to HEAD
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Fri, 16 Apr 2004 12:51:06 +0000 |
parents | 375f2633d815 |
children | d8411455de48 |
comparison
equal
deleted
inserted
replaced
89908:ee1402f7b568 | 89909:68c22ea6027c |
---|---|
1 ;;; reftex-auc.el --- RefTeX's interface to AUC TeX | 1 ;;; reftex-auc.el --- RefTeX's interface to AUC TeX |
2 ;; Copyright (c) 1997, 1998, 1999, 2000 Free Software Foundation, Inc. | 2 ;; Copyright (c) 1997, 1998, 1999, 2000, 2003 Free Software Foundation, Inc. |
3 | 3 |
4 ;; Author: Carsten Dominik <dominik@science.uva.nl> | 4 ;; Author: Carsten Dominik <dominik@science.uva.nl> |
5 ;; Version: 4.18 | 5 ;; Version: 4.21 |
6 | 6 |
7 ;; This file is part of GNU Emacs. | 7 ;; This file is part of GNU Emacs. |
8 | 8 |
9 ;; GNU Emacs is free software; you can redistribute it and/or modify | 9 ;; GNU Emacs is free software; you can redistribute it and/or modify |
10 ;; it under the terms of the GNU General Public License as published by | 10 ;; it under the terms of the GNU General Public License as published by |
32 | 32 |
33 (defun reftex-plug-flag (which) | 33 (defun reftex-plug-flag (which) |
34 ;; Tell if a certain flag is set in reftex-plug-into-AUCTeX | 34 ;; Tell if a certain flag is set in reftex-plug-into-AUCTeX |
35 (or (eq t reftex-plug-into-AUCTeX) | 35 (or (eq t reftex-plug-into-AUCTeX) |
36 (and (listp reftex-plug-into-AUCTeX) | 36 (and (listp reftex-plug-into-AUCTeX) |
37 (nth which reftex-plug-into-AUCTeX)))) | 37 (nth which reftex-plug-into-AUCTeX)))) |
38 | 38 |
39 (defun reftex-arg-label (optional &optional prompt definition) | 39 (defun reftex-arg-label (optional &optional prompt definition) |
40 "Use `reftex-label', `reftex-reference' or AUCTeX's code to insert label arg. | 40 "Use `reftex-label', `reftex-reference' or AUCTeX's code to insert label arg. |
41 What is being used depends upon `reftex-plug-into-AUCTeX'." | 41 What is being used depends upon `reftex-plug-into-AUCTeX'." |
42 (let (label) | 42 (let (label) |
43 (cond | 43 (cond |
44 ((and definition (reftex-plug-flag 1)) | 44 ((and definition (reftex-plug-flag 1)) |
45 ;; Create a new label, with a temporary brace for `reftex-what-macro' | 45 ;; Create a new label, with a temporary brace for `reftex-what-macro' |
46 (unwind-protect | 46 (unwind-protect |
47 (progn (insert "{") (setq label (or (reftex-label nil t) ""))) | 47 (progn (insert "{") (setq label (or (reftex-label nil t) ""))) |
48 (delete-backward-char 1))) | 48 (delete-backward-char 1))) |
49 ((and (not definition) (reftex-plug-flag 2)) | 49 ((and (not definition) (reftex-plug-flag 2)) |
50 ;; Reference a label with RefTeX | 50 ;; Reference a label with RefTeX |
51 (setq label (reftex-reference nil t))) | 51 (setq label (reftex-reference nil t))) |
52 (t | 52 (t |
53 ;; AUCTeX's default mechanism | 53 ;; AUCTeX's default mechanism |
54 (setq label (completing-read (TeX-argument-prompt optional prompt "Key") | 54 (setq label (completing-read (TeX-argument-prompt optional prompt "Key") |
55 (LaTeX-label-list))))) | 55 (LaTeX-label-list))))) |
56 (if (and definition (not (string-equal "" label))) | 56 (if (and definition (not (string-equal "" label))) |
57 (LaTeX-add-labels label)) | 57 (LaTeX-add-labels label)) |
58 (TeX-argument-insert label optional))) | 58 (TeX-argument-insert label optional))) |
59 | 59 |
60 (defun reftex-arg-cite (optional &optional prompt definition) | 60 (defun reftex-arg-cite (optional &optional prompt definition) |
61 "Use `reftex-citation' or AUCTeX's code to insert a cite-key macro argument. | 61 "Use `reftex-citation' or AUCTeX's code to insert a cite-key macro argument. |
62 What is being used depends upon `reftex-plug-into-AUCTeX'." | 62 What is being used depends upon `reftex-plug-into-AUCTeX'." |
64 (cond | 64 (cond |
65 ((and (not definition) (reftex-plug-flag 3)) | 65 ((and (not definition) (reftex-plug-flag 3)) |
66 (setq items (list (or (reftex-citation t) "")))) | 66 (setq items (list (or (reftex-citation t) "")))) |
67 (t | 67 (t |
68 (setq prompt (concat (if optional "(Optional) " "") | 68 (setq prompt (concat (if optional "(Optional) " "") |
69 (if prompt prompt "Add key") | 69 (if prompt prompt "Add key") |
70 ": (default none) ")) | 70 ": (default none) ")) |
71 (setq items (multi-prompt "," t prompt (LaTeX-bibitem-list))))) | 71 (setq items (multi-prompt "," t prompt (LaTeX-bibitem-list))))) |
72 (apply 'LaTeX-add-bibitems items) | 72 (apply 'LaTeX-add-bibitems items) |
73 (TeX-argument-insert (mapconcat 'identity items ",") optional))) | 73 (TeX-argument-insert (mapconcat 'identity items ",") optional))) |
74 | 74 |
75 | 75 |
76 (defun reftex-arg-index-tag (optional &optional prompt &rest args) | 76 (defun reftex-arg-index-tag (optional &optional prompt &rest args) |
77 "Prompt for an index tag with completion. | 77 "Prompt for an index tag with completion. |
78 This is the name of an index, not the entry." | 78 This is the name of an index, not the entry." |
79 (let (tag taglist) | 79 (let (tag taglist) |
80 (setq prompt (concat (if optional "(Optional) " "") | 80 (setq prompt (concat (if optional "(Optional) " "") |
81 (if prompt prompt "Index tag") | 81 (if prompt prompt "Index tag") |
82 ": (default none) ")) | 82 ": (default none) ")) |
83 (if (and reftex-support-index (reftex-plug-flag 4)) | 83 (if (and reftex-support-index (reftex-plug-flag 4)) |
84 ;; Use RefTeX completion | 84 ;; Use RefTeX completion |
85 (progn | 85 (progn |
86 (reftex-access-scan-info nil) | 86 (reftex-access-scan-info nil) |
87 (setq taglist | 87 (setq taglist |
88 (cdr (assoc 'index-tags | 88 (cdr (assoc 'index-tags |
89 (symbol-value reftex-docstruct-symbol))) | 89 (symbol-value reftex-docstruct-symbol))) |
90 tag (completing-read prompt (mapcar 'list taglist)))) | 90 tag (completing-read prompt (mapcar 'list taglist)))) |
91 ;; Just ask like AUCTeX does. | 91 ;; Just ask like AUCTeX does. |
92 (setq tag (read-string prompt))) | 92 (setq tag (read-string prompt))) |
93 (TeX-argument-insert tag optional))) | 93 (TeX-argument-insert tag optional))) |
94 | 94 |
95 (defun reftex-arg-index (optional &optional prompt &rest args) | 95 (defun reftex-arg-index (optional &optional prompt &rest args) |
96 "Prompt for an index entry completing with known entries. | 96 "Prompt for an index entry completing with known entries. |
97 Completion is specific for just one index, if the macro or a tag | 97 Completion is specific for just one index, if the macro or a tag |
98 argument identify one of multiple indices." | 98 argument identify one of multiple indices." |
99 (let* (tag key) | 99 (let* (tag key) |
100 (if (and reftex-support-index (reftex-plug-flag 4)) | 100 (if (and reftex-support-index (reftex-plug-flag 4)) |
101 (progn | 101 (progn |
102 (reftex-access-scan-info nil) | 102 (reftex-access-scan-info nil) |
103 (setq tag (reftex-what-index-tag) | 103 (setq tag (reftex-what-index-tag) |
104 key (reftex-index-complete-key (or tag "idx")))) | 104 key (reftex-index-complete-key (or tag "idx")))) |
105 (setq key (completing-read (TeX-argument-prompt optional prompt "Key") | 105 (setq key (completing-read (TeX-argument-prompt optional prompt "Key") |
106 (LaTeX-index-entry-list)))) | 106 (LaTeX-index-entry-list)))) |
107 (unless (string-equal "" key) | 107 (unless (string-equal "" key) |
108 (LaTeX-add-index-entries key)) | 108 (LaTeX-add-index-entries key)) |
109 (TeX-argument-insert key optional))) | 109 (TeX-argument-insert key optional))) |
110 | 110 |
111 (defun reftex-what-index-tag () | 111 (defun reftex-what-index-tag () |
112 ;; Look backward to find out what index the macro at point belongs to | 112 ;; Look backward to find out what index the macro at point belongs to |
113 (let ((macro (save-excursion | 113 (let ((macro (save-excursion |
114 (and (re-search-backward "\\\\[a-zA-Z*]+" nil t) | 114 (and (re-search-backward "\\\\[a-zA-Z*]+" nil t) |
115 (match-string 0)))) | 115 (match-string 0)))) |
116 tag entry) | 116 tag entry) |
117 (when (and macro | 117 (when (and macro |
118 (setq entry (assoc macro reftex-index-macro-alist))) | 118 (setq entry (assoc macro reftex-index-macro-alist))) |
119 (setq tag (nth 1 entry)) | 119 (setq tag (nth 1 entry)) |
120 (cond | 120 (cond |
121 ((stringp tag) tag) | 121 ((stringp tag) tag) |
122 ((integerp tag) | 122 ((integerp tag) |
123 (save-excursion | 123 (save-excursion |
124 (goto-char (match-end 1)) | 124 (goto-char (match-end 1)) |
125 (or (reftex-nth-arg tag (nth 6 entry)) "idx"))) | 125 (or (reftex-nth-arg tag (nth 6 entry)) "idx"))) |
126 (t "idx"))))) | 126 (t "idx"))))) |
127 | 127 |
128 (defvar LaTeX-label-function) | 128 (defvar LaTeX-label-function) |
129 (defun reftex-plug-into-AUCTeX () | 129 (defun reftex-plug-into-AUCTeX () |
130 ;; Replace AUCTeX functions with RefTeX functions. | 130 ;; Replace AUCTeX functions with RefTeX functions. |
131 ;; Which functions are replaced is controlled by the variable | 131 ;; Which functions are replaced is controlled by the variable |
132 ;; `reftex-plug-into-AUCTeX'. | 132 ;; `reftex-plug-into-AUCTeX'. |
133 | 133 |
134 (if (reftex-plug-flag 0) | 134 (if (reftex-plug-flag 0) |
135 (setq LaTeX-label-function 'reftex-label) | 135 (setq LaTeX-label-function 'reftex-label) |
136 (setq LaTeX-label-function nil)) | 136 (setq LaTeX-label-function nil)) |
137 | 137 |
138 (and (or (reftex-plug-flag 1) (reftex-plug-flag 2)) | 138 (and (or (reftex-plug-flag 1) (reftex-plug-flag 2)) |
140 (fset 'TeX-arg-label 'reftex-arg-label)) | 140 (fset 'TeX-arg-label 'reftex-arg-label)) |
141 | 141 |
142 (and (reftex-plug-flag 3) | 142 (and (reftex-plug-flag 3) |
143 (fboundp 'TeX-arg-cite) | 143 (fboundp 'TeX-arg-cite) |
144 (fset 'TeX-arg-cite 'reftex-arg-cite)) | 144 (fset 'TeX-arg-cite 'reftex-arg-cite)) |
145 | 145 |
146 (and (reftex-plug-flag 4) | 146 (and (reftex-plug-flag 4) |
147 (fboundp 'TeX-arg-index-tag) | 147 (fboundp 'TeX-arg-index-tag) |
148 (fset 'TeX-arg-index-tag 'reftex-arg-index-tag)) | 148 (fset 'TeX-arg-index-tag 'reftex-arg-index-tag)) |
149 (and (reftex-plug-flag 4) | 149 (and (reftex-plug-flag 4) |
150 (fboundp 'TeX-arg-index) | 150 (fboundp 'TeX-arg-index) |
151 (fset 'TeX-arg-index 'reftex-arg-index))) | 151 (fset 'TeX-arg-index 'reftex-arg-index))) |
152 | 152 |
153 (defun reftex-toggle-plug-into-AUCTeX () | 153 (defun reftex-toggle-plug-into-AUCTeX () |
154 "Toggle Interface between AUCTeX and RefTeX on and off." | 154 "Toggle Interface between AUCTeX and RefTeX on and off." |
172 `reftex-label-alist-style' will raise a flag to the effect that | 172 `reftex-label-alist-style' will raise a flag to the effect that |
173 the label information is recompiled on next use." | 173 the label information is recompiled on next use." |
174 (unless reftex-docstruct-symbol | 174 (unless reftex-docstruct-symbol |
175 (reftex-tie-multifile-symbols)) | 175 (reftex-tie-multifile-symbols)) |
176 (when (and reftex-docstruct-symbol | 176 (when (and reftex-docstruct-symbol |
177 (symbolp reftex-docstruct-symbol)) | 177 (symbolp reftex-docstruct-symbol)) |
178 (let ((list (get reftex-docstruct-symbol 'reftex-label-alist-style)) | 178 (let ((list (get reftex-docstruct-symbol 'reftex-label-alist-style)) |
179 entry changed) | 179 entry changed) |
180 (while entry-list | 180 (while entry-list |
181 (setq entry (pop entry-list)) | 181 (setq entry (pop entry-list)) |
182 (unless (member entry list) | 182 (unless (member entry list) |
183 (setq reftex-tables-dirty t | 183 (setq reftex-tables-dirty t |
184 changed t) | 184 changed t) |
185 (push entry list))) | 185 (push entry list))) |
186 (when changed | 186 (when changed |
187 (put reftex-docstruct-symbol 'reftex-label-alist-style list))))) | 187 (put reftex-docstruct-symbol 'reftex-label-alist-style list))))) |
188 (defalias 'reftex-add-to-label-alist 'reftex-add-label-environments) | 188 (defalias 'reftex-add-to-label-alist 'reftex-add-label-environments) |
189 | 189 |
190 (defun reftex-add-section-levels (entry-list) | 190 (defun reftex-add-section-levels (entry-list) |
191 "Add entries to the value of `reftex-section-levels'. | 191 "Add entries to the value of `reftex-section-levels'. |
192 The added values are kept local to the current document. The format | 192 The added values are kept local to the current document. The format |
193 of ENTRY-LIST is a list of cons cells (\"MACRONAME\" . LEVEL). See | 193 of ENTRY-LIST is a list of cons cells (\"MACRONAME\" . LEVEL). See |
194 `reftex-section-levels' for an example." | 194 `reftex-section-levels' for an example." |
195 (unless reftex-docstruct-symbol | 195 (unless reftex-docstruct-symbol |
196 (reftex-tie-multifile-symbols)) | 196 (reftex-tie-multifile-symbols)) |
197 (when (and reftex-docstruct-symbol | 197 (when (and reftex-docstruct-symbol |
198 (symbolp reftex-docstruct-symbol)) | 198 (symbolp reftex-docstruct-symbol)) |
199 (let ((list (get reftex-docstruct-symbol 'reftex-section-levels)) | 199 (let ((list (get reftex-docstruct-symbol 'reftex-section-levels)) |
200 entry changed) | 200 entry changed) |
201 (while entry-list | 201 (while entry-list |
202 (setq entry (pop entry-list)) | 202 (setq entry (pop entry-list)) |
203 (unless (member entry list) | 203 (unless (member entry list) |
204 (setq reftex-tables-dirty t | 204 (setq reftex-tables-dirty t |
205 changed t) | 205 changed t) |
206 (push entry list))) | 206 (push entry list))) |
207 (when changed | 207 (when changed |
208 (put reftex-docstruct-symbol 'reftex-section-levels list))))) | 208 (put reftex-docstruct-symbol 'reftex-section-levels list))))) |
209 | 209 |
210 (defun reftex-notice-new-section () | 210 (defun reftex-notice-new-section () |
211 (reftex-notice-new 1 'force)) | 211 (reftex-notice-new 1 'force)) |
212 | 212 |
213 ;;; arch-tag: 4a798e68-3405-421c-a09b-0269aac64ab4 | |
213 ;;; reftex-auc.el ends here | 214 ;;; reftex-auc.el ends here |