Mercurial > emacs
annotate lisp/textmodes/reftex-cite.el @ 46719:9fee2ba2f93d
(HAVE_SYS_WAIT_H): The #undef is conditional on HPUX8.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 29 Jul 2002 01:56:56 +0000 |
parents | 060f433ebf11 |
children | 11e08f9901ea |
rev | line source |
---|---|
38422
7a94f1c588c4
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37998
diff
changeset
|
1 ;;; reftex-cite.el --- creating citations with RefTeX |
27192
f70a80cecdd3
New version number.
Carsten Dominik <dominik@science.uva.nl>
parents:
27035
diff
changeset
|
2 ;; Copyright (c) 1997, 1998, 1999, 2000 Free Software Foundation, Inc. |
27035 | 3 |
46612
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
4 ;; Author: Carsten Dominik <dominik@science.uva.nl> |
46683
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
5 ;; Version: 4.18 |
27035 | 6 |
7 ;; This file is part of GNU Emacs. | |
8 | |
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 | |
11 ;; the Free Software Foundation; either version 2, or (at your option) | |
12 ;; any later version. | |
13 | |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
22 ;; Boston, MA 02111-1307, USA. | |
25280 | 23 |
38422
7a94f1c588c4
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37998
diff
changeset
|
24 ;;; Commentary: |
7a94f1c588c4
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37998
diff
changeset
|
25 |
7a94f1c588c4
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37998
diff
changeset
|
26 ;;; Code: |
7a94f1c588c4
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37998
diff
changeset
|
27 |
26910
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
28 (eval-when-compile (require 'cl)) |
25280 | 29 (provide 'reftex-cite) |
30 (require 'reftex) | |
31 ;;; | |
32 | |
33 ;; Variables and constants | |
34 | |
35 ;; The history list of regular expressions used for citations | |
36 (defvar reftex-cite-regexp-hist nil) | |
37 | |
38 ;; Prompt and help string for citation selection | |
39 (defconst reftex-citation-prompt | |
40 "Select: [n]ext [p]revious [r]estrict [ ]full_entry [q]uit RET [?]Help+more") | |
41 | |
42 (defconst reftex-citation-help | |
43 " n / p Go to next/previous entry (Cursor motion works as well). | |
44 g / r Start over with new regexp / Refine with additional regexp. | |
45 SPC Show full database entry in other window. | |
46 f Toggle follow mode: Other window will follow with full db entry. | |
47 . Show insertion point. | |
48 q Quit without inserting \\cite macro into buffer. | |
49 TAB Enter citation key with completion. | |
50 RET Accept current entry (also on mouse-2) and create \\cite macro. | |
51 m / u Mark/Unmark the entry. | |
52 a / A Put all (marked) entries into one/many \\cite commands.") | |
53 | |
54 ;; Find bibtex files | |
55 | |
46612
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
56 |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
57 (defmacro reftex-with-special-syntax-for-bib (&rest body) |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
58 `(let ((saved-syntax (syntax-table))) |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
59 (unwind-protect |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
60 (progn |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
61 (set-syntax-table reftex-syntax-table-for-bib) |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
62 ,@body) |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
63 (set-syntax-table saved-syntax)))) |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
64 |
25280 | 65 (defun reftex-default-bibliography () |
66 ;; Return the expanded value of `reftex-default-bibliography'. | |
67 ;; The expanded value is cached. | |
68 (unless (eq (get 'reftex-default-bibliography :reftex-raw) | |
69 reftex-default-bibliography) | |
70 (put 'reftex-default-bibliography :reftex-expanded | |
71 (reftex-locate-bibliography-files | |
72 default-directory reftex-default-bibliography)) | |
73 (put 'reftex-default-bibliography :reftex-raw | |
74 reftex-default-bibliography)) | |
75 (get 'reftex-default-bibliography :reftex-expanded)) | |
76 | |
77 (defun reftex-get-bibfile-list () | |
78 ;; Return list of bibfiles for current document. | |
79 ;; When using the chapterbib or bibunits package you should either | |
80 ;; use the same database files everywhere, or separate parts using | |
81 ;; different databases into different files (included into the mater file). | |
82 ;; Then this function will return the applicable database files. | |
83 | |
84 ;; Ensure access to scanning info | |
85 (reftex-access-scan-info) | |
86 (or | |
87 ;; Try inside this file (and its includes) | |
88 (cdr (reftex-last-assoc-before-elt | |
89 'bib (list 'eof (buffer-file-name)) | |
90 (member (list 'bof (buffer-file-name)) | |
91 (symbol-value reftex-docstruct-symbol)))) | |
92 ;; Try after the beginning of this file | |
93 (cdr (assq 'bib (member (list 'bof (buffer-file-name)) | |
94 (symbol-value reftex-docstruct-symbol)))) | |
95 ;; Anywhere in the entire document | |
96 (cdr (assq 'bib (symbol-value reftex-docstruct-symbol))) | |
97 (error "\\bibliography statement missing or .bib files not found"))) | |
98 | |
99 ;; Find a certain reference in any of the BibTeX files. | |
100 | |
101 (defun reftex-pop-to-bibtex-entry (key file-list &optional mark-to-kill | |
102 highlight item return) | |
103 ;; Find BibTeX KEY in any file in FILE-LIST in another window. | |
104 ;; If MARK-TO-KILL is non-nil, mark new buffer to kill. | |
105 ;; If HIGHLIGHT is non-nil, highlight the match. | |
106 ;; If ITEM in non-nil, search for bibitem instead of database entry. | |
107 ;; If RETURN is non-nil, just return the entry. | |
108 | |
109 (let* ((re | |
110 (if item | |
111 (concat "\\\\bibitem\\(\\[[^]]*\\]\\)?{" (regexp-quote key) "}") | |
112 (concat "@[a-zA-Z]+[ \t\n\r]*[{(][ \t\n\r]*" (regexp-quote key) | |
113 "[, \t\r\n}]"))) | |
114 (buffer-conf (current-buffer)) | |
25801
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
115 file buf pos) |
25280 | 116 |
117 (catch 'exit | |
118 (while file-list | |
119 (setq file (car file-list) | |
120 file-list (cdr file-list)) | |
121 (unless (setq buf (reftex-get-file-buffer-force file mark-to-kill)) | |
122 (error "No such file %s" file)) | |
123 (set-buffer buf) | |
124 (widen) | |
125 (goto-char (point-min)) | |
126 (when (re-search-forward re nil t) | |
127 (goto-char (match-beginning 0)) | |
25801
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
128 (setq pos (point)) |
25280 | 129 (when return |
130 ;; Just return the relevant entry | |
131 (if item (goto-char (match-end 0))) | |
132 (setq return (buffer-substring | |
133 (point) (reftex-end-of-bib-entry item))) | |
134 (set-buffer buffer-conf) | |
135 (throw 'exit return)) | |
136 (switch-to-buffer-other-window buf) | |
25801
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
137 (goto-char pos) |
25280 | 138 (recenter 0) |
139 (if highlight | |
140 (reftex-highlight 0 (match-beginning 0) (match-end 0))) | |
141 (throw 'exit (selected-window)))) | |
142 (set-buffer buffer-conf) | |
143 (if item | |
144 (error "No \\bibitem with citation key %s" key) | |
145 (error "No BibTeX entry with citation key %s" key))))) | |
146 | |
147 (defun reftex-end-of-bib-entry (item) | |
148 (save-excursion | |
149 (condition-case nil | |
150 (if item | |
151 (progn (end-of-line) | |
152 (re-search-forward | |
153 "\\\\bibitem\\|\\end{thebibliography}") | |
154 (1- (match-beginning 0))) | |
155 (progn (forward-list 1) (point))) | |
156 (error (min (point-max) (+ 300 (point))))))) | |
157 | |
158 ;; Parse bibtex buffers | |
159 | |
160 (defun reftex-extract-bib-entries (buffers) | |
161 ;; Extract bib entries which match regexps from BUFFERS. | |
162 ;; BUFFERS is a list of buffers or file names. | |
163 ;; Return list with entries." | |
164 (let* (re-list first-re rest-re | |
165 (buffer-list (if (listp buffers) buffers (list buffers))) | |
166 found-list entry buffer1 buffer alist | |
46683
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
167 key-point start-point end-point default) |
25280 | 168 |
169 ;; Read a regexp, completing on known citation keys. | |
46683
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
170 (setq default (regexp-quote (reftex-get-bibkey-default))) |
25280 | 171 (setq re-list |
172 (split-string | |
173 (completing-read | |
46683
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
174 (concat |
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
175 "Regex { && Regex...}: " |
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
176 "[" default "]: ") |
25280 | 177 (if reftex-mode |
178 (if (fboundp 'LaTeX-bibitem-list) | |
179 (LaTeX-bibitem-list) | |
180 (cdr (assoc 'bibview-cache | |
181 (symbol-value reftex-docstruct-symbol)))) | |
182 nil) | |
183 nil nil nil 'reftex-cite-regexp-hist) | |
184 "[ \t]*&&[ \t]*")) | |
185 | |
46683
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
186 (if (or (null re-list ) (equal re-list '(""))) |
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
187 (setq re-list (list default))) |
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
188 |
25280 | 189 (setq first-re (car re-list) ; We'll use the first re to find things, |
190 rest-re (cdr re-list)) ; the others to narrow down. | |
191 (if (string-match "\\`[ \t]*\\'" (or first-re "")) | |
192 (error "Empty regular expression")) | |
193 | |
194 (save-excursion | |
195 (save-window-excursion | |
196 | |
197 ;; Walk through all bibtex files | |
198 (while buffer-list | |
199 (setq buffer (car buffer-list) | |
200 buffer-list (cdr buffer-list)) | |
201 (if (and (bufferp buffer) | |
202 (buffer-live-p buffer)) | |
203 (setq buffer1 buffer) | |
204 (setq buffer1 (reftex-get-file-buffer-force | |
205 buffer (not reftex-keep-temporary-buffers)))) | |
206 (if (not buffer1) | |
207 (message "No such BibTeX file %s (ignored)" buffer) | |
208 (message "Scanning bibliography database %s" buffer1)) | |
209 | |
210 (set-buffer buffer1) | |
46612
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
211 (reftex-with-special-syntax-for-bib |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
212 (save-excursion |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
213 (goto-char (point-min)) |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
214 (while (re-search-forward first-re nil t) |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
215 (catch 'search-again |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
216 (setq key-point (point)) |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
217 (unless (re-search-backward |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
218 "\\(\\`\\|[\n\r]\\)[ \t]*@\\([a-zA-Z]+\\)[ \t\n\r]*[{(]" nil t) |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
219 (throw 'search-again nil)) |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
220 (setq start-point (point)) |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
221 (goto-char (match-end 0)) |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
222 (condition-case nil |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
223 (up-list 1) |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
224 (error (goto-char key-point) |
25280 | 225 (throw 'search-again nil))) |
46612
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
226 (setq end-point (point)) |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
227 |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
228 ;; Ignore @string, @comment and @c entries or things |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
229 ;; outside entries |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
230 (when (or (string= (downcase (match-string 2)) "string") |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
231 (string= (downcase (match-string 2)) "comment") |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
232 (string= (downcase (match-string 2)) "c") |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
233 (< (point) key-point)) ; this means match not in {} |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
234 (goto-char key-point) |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
235 (throw 'search-again nil)) |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
236 |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
237 ;; Well, we have got a match |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
238 (setq entry (concat |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
239 (buffer-substring start-point (point)) "\n")) |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
240 |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
241 ;; Check if other regexp match as well |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
242 (setq re-list rest-re) |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
243 (while re-list |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
244 (unless (string-match (car re-list) entry) |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
245 ;; nope - move on |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
246 (throw 'search-again nil)) |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
247 (pop re-list)) |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
248 |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
249 (setq alist (reftex-parse-bibtex-entry |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
250 nil start-point end-point)) |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
251 (push (cons "&entry" entry) alist) |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
252 |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
253 ;; check for crossref entries |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
254 (if (assoc "crossref" alist) |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
255 (setq alist |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
256 (append |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
257 alist (reftex-get-crossref-alist alist)))) |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
258 |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
259 ;; format the entry |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
260 (push (cons "&formatted" (reftex-format-bib-entry alist)) |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
261 alist) |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
262 |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
263 ;; make key the first element |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
264 (push (reftex-get-bib-field "&key" alist) alist) |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
265 |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
266 ;; add it to the list |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
267 (push alist found-list))))) |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
268 (reftex-kill-temporary-buffers)))) |
25280 | 269 (setq found-list (nreverse found-list)) |
270 | |
271 ;; Sorting | |
272 (cond | |
273 ((eq 'author reftex-sort-bibtex-matches) | |
274 (sort found-list 'reftex-bib-sort-author)) | |
275 ((eq 'year reftex-sort-bibtex-matches) | |
276 (sort found-list 'reftex-bib-sort-year)) | |
277 ((eq 'reverse-year reftex-sort-bibtex-matches) | |
278 (sort found-list 'reftex-bib-sort-year-reverse)) | |
279 (t found-list)))) | |
280 | |
281 (defun reftex-bib-sort-author (e1 e2) | |
282 (let ((al1 (reftex-get-bib-names "author" e1)) | |
283 (al2 (reftex-get-bib-names "author" e2))) | |
284 (while (and al1 al2 (string= (car al1) (car al2))) | |
285 (pop al1) | |
286 (pop al2)) | |
287 (if (and (stringp (car al1)) | |
288 (stringp (car al2))) | |
289 (string< (car al1) (car al2)) | |
290 (not (stringp (car al1)))))) | |
291 | |
292 (defun reftex-bib-sort-year (e1 e2) | |
293 (< (string-to-int (cdr (assoc "year" e1))) | |
294 (string-to-int (cdr (assoc "year" e2))))) | |
295 | |
296 (defun reftex-bib-sort-year-reverse (e1 e2) | |
297 (> (string-to-int (or (cdr (assoc "year" e1)) "0")) | |
298 (string-to-int (or (cdr (assoc "year" e2)) "0")))) | |
299 | |
300 (defun reftex-get-crossref-alist (entry) | |
301 ;; return the alist from a crossref entry | |
302 (let ((crkey (cdr (assoc "crossref" entry))) | |
303 start) | |
304 (save-excursion | |
305 (save-restriction | |
306 (widen) | |
307 (if (re-search-forward | |
308 (concat "@\\w+[{(][ \t\n\r]*" (regexp-quote crkey) | |
309 "[ \t\n\r]*,") nil t) | |
310 (progn | |
311 (setq start (match-beginning 0)) | |
312 (condition-case nil | |
313 (up-list 1) | |
314 (error nil)) | |
315 (reftex-parse-bibtex-entry nil start (point))) | |
316 nil))))) | |
317 | |
45318 | 318 ;; Parse the bibliography environment |
25801
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
319 (defun reftex-extract-bib-entries-from-thebibliography (files) |
25280 | 320 ;; Extract bib-entries from the \begin{thebibliography} environment. |
321 ;; Parsing is not as good as for the BibTeX database stuff. | |
322 ;; The environment should be located in file FILE. | |
323 | |
46683
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
324 (let* (start end buf entries re re-list file default) |
25801
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
325 (unless files |
25280 | 326 (error "Need file name to find thebibliography environment")) |
25801
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
327 (while (setq file (pop files)) |
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
328 (setq buf (reftex-get-file-buffer-force |
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
329 file (not reftex-keep-temporary-buffers))) |
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
330 (unless buf |
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
331 (error "No such file %s" file)) |
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
332 (message "Scanning thebibliography environment in %s" file) |
25280 | 333 |
25801
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
334 (save-excursion |
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
335 (set-buffer buf) |
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
336 (save-restriction |
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
337 (widen) |
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
338 (goto-char (point-min)) |
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
339 (while (re-search-forward |
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
340 "\\(\\`\\|[\n\r]\\)[ \t]*\\\\begin{thebibliography}" nil t) |
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
341 (beginning-of-line 2) |
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
342 (setq start (point)) |
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
343 (if (re-search-forward |
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
344 "\\(\\`\\|[\n\r]\\)[ \t]*\\\\end{thebibliography}" nil t) |
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
345 (progn |
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
346 (beginning-of-line 1) |
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
347 (setq end (point)))) |
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
348 (when (and start end) |
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
349 (setq entries |
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
350 (append entries |
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
351 (mapcar 'reftex-parse-bibitem |
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
352 (delete "" |
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
353 (split-string |
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
354 (buffer-substring-no-properties start end) |
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
355 "[ \t\n\r]*\\\\bibitem\\(\\[[^]]*]\\)*")))))) |
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
356 (goto-char end))))) |
25280 | 357 (unless entries |
358 (error "No bibitems found")) | |
359 | |
46683
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
360 ;; Read a regexp, completing on known citation keys. |
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
361 (setq default (regexp-quote (reftex-get-bibkey-default))) |
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
362 (setq re-list |
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
363 (split-string |
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
364 (completing-read |
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
365 (concat |
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
366 "Regex { && Regex...}: " |
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
367 "[" default "]: ") |
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
368 (if reftex-mode |
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
369 (if (fboundp 'LaTeX-bibitem-list) |
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
370 (LaTeX-bibitem-list) |
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
371 (cdr (assoc 'bibview-cache |
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
372 (symbol-value reftex-docstruct-symbol)))) |
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
373 nil) |
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
374 nil nil nil 'reftex-cite-regexp-hist) |
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
375 "[ \t]*&&[ \t]*")) |
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
376 |
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
377 (if (or (null re-list ) (equal re-list '(""))) |
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
378 (setq re-list (list default))) |
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
379 |
25280 | 380 (if (string-match "\\`[ \t]*\\'" (car re-list)) |
381 (error "Empty regular expression")) | |
382 | |
383 (while (and (setq re (pop re-list)) entries) | |
384 (setq entries | |
385 (delq nil (mapcar | |
386 (lambda (x) | |
387 (if (string-match re (cdr (assoc "&entry" x))) | |
388 x nil)) | |
389 entries)))) | |
390 (setq entries | |
391 (mapcar | |
392 (lambda (x) | |
393 (push (cons "&formatted" (reftex-format-bibitem x)) x) | |
394 (push (reftex-get-bib-field "&key" x) x) | |
395 x) | |
396 entries)) | |
397 | |
398 entries)) | |
399 | |
46683
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
400 (defun reftex-get-bibkey-default () |
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
401 ;; Return the word before the cursor. If the cursor is in a |
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
402 ;; citation macro, return the word before the macro. |
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
403 (let* ((macro (reftex-what-macro 1))) |
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
404 (save-excursion |
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
405 (if (and macro (string-match "cite" (car macro))) |
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
406 (goto-char (cdr macro))) |
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
407 (skip-chars-backward "^a-zA-Z0-9") |
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
408 (reftex-this-word)))) |
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
409 |
25280 | 410 ;; Parse and format individual entries |
411 | |
412 (defun reftex-get-bib-names (field entry) | |
413 ;; Return a list with the author or editor names in ENTRY | |
414 (let ((names (reftex-get-bib-field field entry))) | |
415 (if (equal "" names) | |
416 (setq names (reftex-get-bib-field "editor" entry))) | |
417 (while (string-match "\\band\\b[ \t]*" names) | |
418 (setq names (replace-match "\n" nil t names))) | |
419 (while (string-match "[\\.a-zA-Z\\-]+\\.[ \t]*\\|,.*\\|[{}]+" names) | |
420 (setq names (replace-match "" nil t names))) | |
421 (while (string-match "^[ \t]+\\|[ \t]+$" names) | |
422 (setq names (replace-match "" nil t names))) | |
423 (while (string-match "[ \t][ \t]+" names) | |
424 (setq names (replace-match " " nil t names))) | |
425 (split-string names "\n"))) | |
426 | |
427 (defun reftex-parse-bibtex-entry (entry &optional from to) | |
428 (let (alist key start field) | |
429 (save-excursion | |
430 (save-restriction | |
431 (if entry | |
432 (progn | |
433 (set-buffer (get-buffer-create " *RefTeX-scratch*")) | |
434 (fundamental-mode) | |
46612
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
435 (set-syntax-table reftex-syntax-table-for-bib) |
25280 | 436 (erase-buffer) |
437 (insert entry)) | |
438 (widen) | |
439 (narrow-to-region from to)) | |
440 (goto-char (point-min)) | |
441 | |
442 (if (re-search-forward | |
443 "@\\(\\w+\\)[ \t\n\r]*[{(][ \t\n\r]*\\([^ \t\n\r,]+\\)" nil t) | |
444 (setq alist | |
445 (list | |
446 (cons "&type" (downcase (reftex-match-string 1))) | |
447 (cons "&key" (reftex-match-string 2))))) | |
448 (while (re-search-forward "\\(\\w+\\)[ \t\n\r]*=[ \t\n\r]*" nil t) | |
449 (setq key (downcase (reftex-match-string 1))) | |
450 (cond | |
451 ((= (following-char) ?{) | |
452 (forward-char 1) | |
453 (setq start (point)) | |
454 (condition-case nil | |
455 (up-list 1) | |
456 (error nil))) | |
457 ((= (following-char) ?\") | |
458 (forward-char 1) | |
459 (setq start (point)) | |
460 (while (and (search-forward "\"" nil t) | |
461 (= ?\\ (char-after (- (point) 2)))))) | |
462 (t | |
463 (setq start (point)) | |
464 (re-search-forward "[ \t]*[\n\r,}]" nil 1))) | |
465 (setq field (buffer-substring-no-properties start (1- (point)))) | |
466 ;; remove extra whitespace | |
467 (while (string-match "[\n\t\r]\\|[ \t][ \t]+" field) | |
468 (setq field (replace-match " " nil t field))) | |
469 ;; remove leading garbage | |
470 (if (string-match "^[ \t{]+" field) | |
471 (setq field (replace-match "" nil t field))) | |
472 ;; remove trailing garbage | |
473 (if (string-match "[ \t}]+$" field) | |
474 (setq field (replace-match "" nil t field))) | |
475 (push (cons key field) alist)))) | |
476 alist)) | |
477 | |
478 (defun reftex-get-bib-field (fieldname entry &optional format) | |
479 ;; Extract the field FIELDNAME from an ENTRY | |
480 (let ((cell (assoc fieldname entry))) | |
481 (if cell | |
482 (if format | |
483 (format format (cdr cell)) | |
484 (cdr cell)) | |
485 ""))) | |
486 | |
487 (defun reftex-format-bib-entry (entry) | |
488 ;; Format a BibTeX ENTRY so that it is nice to look at | |
489 (let* | |
490 ((auth-list (reftex-get-bib-names "author" entry)) | |
491 (authors (mapconcat 'identity auth-list ", ")) | |
492 (year (reftex-get-bib-field "year" entry)) | |
493 (title (reftex-get-bib-field "title" entry)) | |
494 (type (reftex-get-bib-field "&type" entry)) | |
495 (key (reftex-get-bib-field "&key" entry)) | |
496 (extra | |
497 (cond | |
498 ((equal type "article") | |
499 (concat (reftex-get-bib-field "journal" entry) " " | |
500 (reftex-get-bib-field "volume" entry) ", " | |
501 (reftex-get-bib-field "pages" entry))) | |
502 ((equal type "book") | |
503 (concat "book (" (reftex-get-bib-field "publisher" entry) ")")) | |
504 ((equal type "phdthesis") | |
505 (concat "PhD: " (reftex-get-bib-field "school" entry))) | |
506 ((equal type "mastersthesis") | |
507 (concat "Master: " (reftex-get-bib-field "school" entry))) | |
508 ((equal type "inbook") | |
509 (concat "Chap: " (reftex-get-bib-field "chapter" entry) | |
510 ", pp. " (reftex-get-bib-field "pages" entry))) | |
511 ((or (equal type "conference") | |
512 (equal type "incollection") | |
513 (equal type "inproceedings")) | |
514 (reftex-get-bib-field "booktitle" entry "in: %s")) | |
515 (t "")))) | |
516 (setq authors (reftex-truncate authors 30 t t)) | |
517 (when (reftex-use-fonts) | |
518 (put-text-property 0 (length key) 'face | |
519 (reftex-verified-face reftex-label-face | |
520 'font-lock-constant-face | |
521 'font-lock-reference-face) | |
522 key) | |
523 (put-text-property 0 (length authors) 'face reftex-bib-author-face | |
524 authors) | |
525 (put-text-property 0 (length year) 'face reftex-bib-year-face | |
526 year) | |
527 (put-text-property 0 (length title) 'face reftex-bib-title-face | |
528 title) | |
529 (put-text-property 0 (length extra) 'face reftex-bib-extra-face | |
530 extra)) | |
531 (concat key "\n " authors " " year " " extra "\n " title "\n\n"))) | |
532 | |
533 (defun reftex-parse-bibitem (item) | |
534 ;; Parse a \bibitem entry | |
535 (let ((key "") (text "")) | |
37998
706af946b1e7
* reftex-ref.el (reftex-select-label-help): Added "z" key
Carsten Dominik <dominik@science.uva.nl>
parents:
34402
diff
changeset
|
536 (when (string-match "\\`{\\([^}]+\\)}\\([^\000]*\\)" item) |
25280 | 537 (setq key (match-string 1 item) |
538 text (match-string 2 item))) | |
539 ;; Clean up the text a little bit | |
540 (while (string-match "[\n\r\t]\\|[ \t][ \t]+" text) | |
541 (setq text (replace-match " " nil t text))) | |
542 (if (string-match "\\`[ \t]+" text) | |
543 (setq text (replace-match "" nil t text))) | |
544 (list | |
545 (cons "&key" key) | |
546 (cons "&text" text) | |
547 (cons "&entry" (concat key " " text))))) | |
548 | |
549 (defun reftex-format-bibitem (item) | |
550 ;; Format a \bibitem entry so that it is (relatively) nice to look at. | |
551 (let ((text (reftex-get-bib-field "&text" item)) | |
552 (key (reftex-get-bib-field "&key" item)) | |
553 (lines nil)) | |
554 | |
555 ;; Wrap the text into several lines. | |
556 (while (and (> (length text) 70) | |
557 (string-match " " (substring text 60))) | |
558 (push (substring text 0 (+ 60 (match-beginning 0))) lines) | |
559 (setq text (substring text (+ 61 (match-beginning 0))))) | |
560 (push text lines) | |
561 (setq text (mapconcat 'identity (nreverse lines) "\n ")) | |
562 | |
563 (when (reftex-use-fonts) | |
564 (put-text-property 0 (length text) 'face reftex-bib-author-face text)) | |
565 (concat key "\n " text "\n\n"))) | |
566 | |
567 ;; Make a citation | |
568 | |
569 ;;;###autoload | |
26910
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
570 (defun reftex-citation (&optional no-insert format-key) |
25280 | 571 "Make a citation using BibTeX database files. |
572 After prompting for a regular expression, scans the buffers with | |
573 bibtex entries (taken from the \\bibliography command) and offers the | |
46131
7255ef8cf60f
(reftex-citation): Fix typo.
Juanma Barranquero <lekktu@gmail.com>
parents:
45318
diff
changeset
|
574 matching entries for selection. The selected entry is formatted according |
25280 | 575 to `reftex-cite-format' and inserted into the buffer. |
576 | |
577 If NO-INSERT is non-nil, nothing is inserted, only the selected key returned. | |
578 | |
26910
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
579 FORAT-KEY can be used to pre-select a citation format. |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
580 |
25280 | 581 When called with one or two `C-u' prefixes, first rescans the document. |
582 When called with a numeric prefix, make that many citations. When | |
37998
706af946b1e7
* reftex-ref.el (reftex-select-label-help): Added "z" key
Carsten Dominik <dominik@science.uva.nl>
parents:
34402
diff
changeset
|
583 called with point inside the braces of a `\\cite' command, it will |
25280 | 584 add another key, ignoring the value of `reftex-cite-format'. |
585 | |
586 The regular expression uses an expanded syntax: && is interpreted as `and'. | |
587 Thus, `aaaa&&bbb' matches entries which contain both `aaaa' and `bbb'. | |
588 While entering the regexp, completion on knows citation keys is possible. | |
589 `=' is a good regular expression to match all entries in all files." | |
590 | |
591 (interactive) | |
592 | |
593 ;; check for recursive edit | |
594 (reftex-check-recursive-edit) | |
595 | |
596 ;; This function may also be called outside reftex-mode. | |
597 ;; Thus look for the scanning info only if in reftex-mode. | |
598 | |
599 (when reftex-mode | |
600 (reftex-access-scan-info current-prefix-arg)) | |
601 | |
602 ;; Call reftex-do-citation, but protected | |
603 (unwind-protect | |
26910
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
604 (reftex-do-citation current-prefix-arg no-insert format-key) |
25280 | 605 (reftex-kill-temporary-buffers))) |
606 | |
26910
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
607 (defun reftex-do-citation (&optional arg no-insert format-key) |
25280 | 608 ;; This really does the work of reftex-citation. |
609 | |
26910
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
610 (let* ((format (reftex-figure-out-cite-format arg no-insert format-key)) |
25280 | 611 (docstruct-symbol reftex-docstruct-symbol) |
612 (selected-entries (reftex-offer-bib-menu)) | |
613 (insert-entries selected-entries) | |
614 entry string cite-view) | |
615 | |
616 (unless selected-entries (error "Quit")) | |
617 | |
618 (if (stringp selected-entries) | |
619 ;; Nonexistent entry | |
620 (setq selected-entries nil | |
621 insert-entries (list (list selected-entries | |
622 (cons "&key" selected-entries)))) | |
623 ;; It makes sense to compute the cite-view strings. | |
624 (setq cite-view t)) | |
625 | |
626 (when (eq (car selected-entries) 'concat) | |
627 ;; All keys go into a single command - we need to trick a little | |
628 (pop selected-entries) | |
629 (let ((concat-keys (mapconcat 'car selected-entries ","))) | |
630 (setq insert-entries | |
631 (list (list concat-keys (cons "&key" concat-keys)))))) | |
632 | |
633 (unless no-insert | |
634 | |
635 ;; We shall insert this into the buffer... | |
636 (message "Formatting...") | |
637 | |
638 (while (setq entry (pop insert-entries)) | |
639 ;; Format the citation and insert it | |
640 (setq string (if reftex-format-cite-function | |
641 (funcall reftex-format-cite-function | |
642 (reftex-get-bib-field "&key" entry) | |
643 format) | |
644 (reftex-format-citation entry format))) | |
645 (insert string)) | |
646 | |
647 ;; Reposition cursor? | |
648 (when (string-match "\\?" string) | |
649 (search-backward "?") | |
650 (delete-char 1)) | |
651 | |
652 ;; Tell AUCTeX | |
653 (when (and reftex-mode | |
654 (fboundp 'LaTeX-add-bibitems) | |
655 reftex-plug-into-AUCTeX) | |
656 (apply 'LaTeX-add-bibitems (mapcar 'car selected-entries))) | |
657 | |
658 ;; Produce the cite-view strings | |
659 (when (and reftex-mode reftex-cache-cite-echo cite-view) | |
660 (mapcar (lambda (entry) | |
661 (reftex-make-cite-echo-string entry docstruct-symbol)) | |
662 selected-entries)) | |
663 | |
664 (message "")) | |
665 | |
666 (set-marker reftex-select-return-marker nil) | |
667 (reftex-kill-buffer "*RefTeX Select*") | |
668 | |
669 ;; Check if the prefix arg was numeric, and call recursively | |
670 (when (integerp arg) | |
671 (if (> arg 1) | |
672 (progn | |
673 (skip-chars-backward "}") | |
674 (decf arg) | |
675 (reftex-do-citation arg)) | |
676 (forward-char 1))) | |
677 | |
678 ;; Return the citation key | |
679 (car (car selected-entries)))) | |
680 | |
26910
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
681 (defun reftex-figure-out-cite-format (arg &optional no-insert format-key) |
25280 | 682 ;; Check if there is already a cite command at point and change cite format |
683 ;; in order to only add another reference in the same cite command. | |
684 (let ((macro (car (reftex-what-macro 1))) | |
685 (cite-format-value (reftex-get-cite-format)) | |
686 key format) | |
687 (cond | |
688 (no-insert | |
689 ;; Format does not really matter because nothing will be inserted. | |
690 (setq format "%l")) | |
691 | |
692 ((and (stringp macro) | |
693 (string-match "\\`\\\\cite\\|cite\\'" macro)) | |
694 ;; We are already inside a cite macro | |
695 (if (or (not arg) (not (listp arg))) | |
696 (setq format | |
697 (concat | |
698 (if (member (preceding-char) '(?\{ ?,)) "" ",") | |
699 "%l" | |
700 (if (member (following-char) '(?\} ?,)) "" ","))) | |
701 (setq format "%l"))) | |
702 (t | |
703 ;; Figure out the correct format | |
704 (setq format | |
705 (if (and (symbolp cite-format-value) | |
706 (assq cite-format-value reftex-cite-format-builtin)) | |
707 (nth 2 (assq cite-format-value reftex-cite-format-builtin)) | |
708 cite-format-value)) | |
709 (when (listp format) | |
710 (setq key | |
26910
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
711 (or format-key |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
712 (reftex-select-with-char |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
713 "" (concat "SELECT A CITATION FORMAT\n\n" |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
714 (mapconcat |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
715 (lambda (x) |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
716 (format "[%c] %s %s" (car x) |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
717 (if (> (car x) 31) " " "") |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
718 (cdr x))) |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
719 format "\n"))))) |
25280 | 720 (if (assq key format) |
721 (setq format (cdr (assq key format))) | |
722 (error "No citation format associated with key `%c'" key))))) | |
723 format)) | |
724 | |
26910
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
725 (defun reftex-citep () |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
726 "Call `reftex-citation' with a format selector `?p'." |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
727 (interactive) |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
728 (reftex-citation nil ?p)) |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
729 |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
730 (defun reftex-citet () |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
731 "Call `reftex-citation' with a format selector `?t'." |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
732 (interactive) |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
733 (reftex-citation nil ?t)) |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
734 |
25280 | 735 (defvar reftex-select-bib-map) |
736 (defun reftex-offer-bib-menu () | |
737 ;; Offer bib menu and return list of selected items | |
738 | |
739 (let (found-list rtn key data selected-entries) | |
740 (while | |
741 (not | |
742 (catch 'done | |
743 ;; Scan bibtex files | |
744 (setq found-list | |
745 (cond | |
746 ((assq 'bib (symbol-value reftex-docstruct-symbol)) | |
747 ;; using BibTeX database files. | |
748 (reftex-extract-bib-entries (reftex-get-bibfile-list))) | |
749 ((assq 'thebib (symbol-value reftex-docstruct-symbol)) | |
750 ;; using thebibliography environment. | |
751 (reftex-extract-bib-entries-from-thebibliography | |
25801
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
752 (reftex-uniquify |
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
753 (mapcar 'cdr |
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
754 (reftex-all-assq |
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
755 'thebib (symbol-value reftex-docstruct-symbol)))))) |
25280 | 756 (reftex-default-bibliography |
757 (message "Using default bibliography") | |
758 (reftex-extract-bib-entries (reftex-default-bibliography))) | |
759 (t (error "No valid bibliography in this document, and no default available")))) | |
760 | |
761 (unless found-list | |
762 (error "Sorry, no matches found")) | |
763 | |
764 ;; Remember where we came from | |
765 (setq reftex-call-back-to-this-buffer (current-buffer)) | |
766 (set-marker reftex-select-return-marker (point)) | |
767 | |
768 ;; Offer selection | |
769 (save-window-excursion | |
770 (delete-other-windows) | |
771 (let ((default-major-mode 'reftex-select-bib-mode)) | |
772 (reftex-kill-buffer "*RefTeX Select*") | |
773 (switch-to-buffer-other-window "*RefTeX Select*") | |
774 (unless (eq major-mode 'reftex-select-bib-mode) | |
775 (reftex-select-bib-mode)) | |
776 (let ((buffer-read-only nil)) | |
777 (erase-buffer) | |
778 (reftex-insert-bib-matches found-list))) | |
779 (setq buffer-read-only t) | |
780 (if (= 0 (buffer-size)) | |
781 (error "No matches found")) | |
782 (setq truncate-lines t) | |
783 (goto-char 1) | |
784 (while t | |
785 (setq rtn | |
786 (reftex-select-item | |
787 reftex-citation-prompt | |
788 reftex-citation-help | |
789 reftex-select-bib-map | |
790 nil | |
791 'reftex-bibtex-selection-callback nil)) | |
792 (setq key (car rtn) | |
793 data (nth 1 rtn)) | |
794 (unless key (throw 'done t)) | |
795 (cond | |
796 ((eq key ?g) | |
797 ;; Start over | |
798 (throw 'done nil)) | |
799 ((eq key ?r) | |
800 ;; Restrict with new regular expression | |
801 (setq found-list (reftex-restrict-bib-matches found-list)) | |
802 (let ((buffer-read-only nil)) | |
803 (erase-buffer) | |
804 (reftex-insert-bib-matches found-list)) | |
805 (goto-char 1)) | |
806 ((eq key ?A) | |
807 ;; Take all (marked) | |
808 (setq selected-entries | |
809 (if reftex-select-marked | |
810 (mapcar 'car (nreverse reftex-select-marked)) | |
811 found-list)) | |
812 (throw 'done t)) | |
813 ((eq key ?a) | |
814 ;; Take all (marked), and push the symbol 'concat | |
815 (setq selected-entries | |
816 (cons 'concat | |
817 (if reftex-select-marked | |
818 (mapcar 'car (nreverse reftex-select-marked)) | |
819 found-list))) | |
820 (throw 'done t)) | |
821 ((or (eq key ?\C-m) | |
822 (eq key 'return)) | |
823 ;; Take selected | |
824 (setq selected-entries | |
825 (if reftex-select-marked | |
826 (cons 'concat | |
827 (mapcar 'car (nreverse reftex-select-marked))) | |
828 (if data (list data) nil))) | |
829 (throw 'done t)) | |
830 ((stringp key) | |
831 ;; Got this one with completion | |
832 (setq selected-entries key) | |
833 (throw 'done t)) | |
834 (t | |
835 (ding)))))))) | |
836 selected-entries)) | |
837 | |
838 (defun reftex-restrict-bib-matches (found-list) | |
839 ;; Limit FOUND-LIST with more regular expressions | |
840 (let ((re-list (split-string (read-string | |
841 "RegExp [ && RegExp...]: " | |
842 nil 'reftex-cite-regexp-hist) | |
843 "[ \t]*&&[ \t]*")) | |
844 (found-list-r found-list) | |
845 re) | |
846 (while (setq re (pop re-list)) | |
847 (setq found-list-r | |
848 (delq nil | |
849 (mapcar | |
850 (lambda (x) | |
851 (if (string-match | |
852 re (cdr (assoc "&entry" x))) | |
853 x | |
854 nil)) | |
855 found-list-r)))) | |
856 (if found-list-r | |
857 found-list-r | |
858 (ding) | |
859 found-list))) | |
860 | |
861 (defun reftex-insert-bib-matches (list) | |
862 ;; Insert the bib matches and number them correctly | |
863 (let ((mouse-face | |
864 (if (memq reftex-highlight-selection '(mouse both)) | |
865 reftex-mouse-selected-face | |
866 nil)) | |
867 tmp len) | |
868 (mapcar | |
869 (lambda (x) | |
870 (setq tmp (cdr (assoc "&formatted" x)) | |
871 len (length tmp)) | |
872 (put-text-property 0 len :data x tmp) | |
873 (put-text-property 0 (1- len) 'mouse-face mouse-face tmp) | |
874 (insert tmp)) | |
875 list)) | |
876 (run-hooks 'reftex-display-copied-context-hook)) | |
877 | |
878 (defun reftex-format-names (namelist n) | |
879 (let (last (len (length namelist))) | |
46612
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
46131
diff
changeset
|
880 (if (= n 0) (setq n len)) |
25280 | 881 (cond |
882 ((< len 1) "") | |
883 ((= 1 len) (car namelist)) | |
884 ((> len n) (concat (car namelist) (nth 2 reftex-cite-punctuation))) | |
885 (t | |
886 (setq n (min len n) | |
887 last (nth (1- n) namelist)) | |
888 (setcdr (nthcdr (- n 2) namelist) nil) | |
889 (concat | |
890 (mapconcat 'identity namelist (nth 0 reftex-cite-punctuation)) | |
891 (nth 1 reftex-cite-punctuation) | |
892 last))))) | |
893 | |
894 (defun reftex-format-citation (entry format) | |
895 ;; Format a citation from the info in the BibTeX ENTRY | |
896 | |
897 (unless (stringp format) (setq format "\\cite{%l}")) | |
898 | |
899 (if (and reftex-comment-citations | |
900 (string-match "%l" reftex-cite-comment-format)) | |
901 (error "reftex-cite-comment-format contains illegal %%l")) | |
902 | |
903 (while (string-match | |
904 "\\(\\`\\|[^%]\\)\\(\\(%\\([0-9]*\\)\\([a-zA-Z]\\)\\)[.,;: ]*\\)" | |
905 format) | |
906 (let ((n (string-to-int (match-string 4 format))) | |
907 (l (string-to-char (match-string 5 format))) | |
908 rpl b e) | |
909 (save-match-data | |
910 (setq rpl | |
911 (cond | |
912 ((= l ?l) (concat | |
913 (reftex-get-bib-field "&key" entry) | |
914 (if reftex-comment-citations | |
915 reftex-cite-comment-format | |
916 ""))) | |
917 ((= l ?a) (reftex-format-names | |
918 (reftex-get-bib-names "author" entry) | |
919 (or n 2))) | |
920 ((= l ?A) (car (reftex-get-bib-names "author" entry))) | |
921 ((= l ?b) (reftex-get-bib-field "booktitle" entry "in: %s")) | |
922 ((= l ?B) (reftex-abbreviate-title | |
923 (reftex-get-bib-field "booktitle" entry "in: %s"))) | |
924 ((= l ?c) (reftex-get-bib-field "chapter" entry)) | |
925 ((= l ?d) (reftex-get-bib-field "edition" entry)) | |
926 ((= l ?e) (reftex-format-names | |
927 (reftex-get-bib-names "editor" entry) | |
928 (or n 2))) | |
929 ((= l ?E) (car (reftex-get-bib-names "editor" entry))) | |
930 ((= l ?h) (reftex-get-bib-field "howpublished" entry)) | |
931 ((= l ?i) (reftex-get-bib-field "institution" entry)) | |
932 ((= l ?j) (reftex-get-bib-field "journal" entry)) | |
933 ((= l ?k) (reftex-get-bib-field "key" entry)) | |
934 ((= l ?m) (reftex-get-bib-field "month" entry)) | |
935 ((= l ?n) (reftex-get-bib-field "number" entry)) | |
936 ((= l ?o) (reftex-get-bib-field "organization" entry)) | |
937 ((= l ?p) (reftex-get-bib-field "pages" entry)) | |
938 ((= l ?P) (car (split-string | |
939 (reftex-get-bib-field "pages" entry) | |
940 "[- .]+"))) | |
941 ((= l ?s) (reftex-get-bib-field "school" entry)) | |
942 ((= l ?u) (reftex-get-bib-field "publisher" entry)) | |
943 ((= l ?r) (reftex-get-bib-field "address" entry)) | |
944 ((= l ?t) (reftex-get-bib-field "title" entry)) | |
945 ((= l ?T) (reftex-abbreviate-title | |
946 (reftex-get-bib-field "title" entry))) | |
947 ((= l ?v) (reftex-get-bib-field "volume" entry)) | |
948 ((= l ?y) (reftex-get-bib-field "year" entry))))) | |
949 | |
950 (if (string= rpl "") | |
951 (setq b (match-beginning 2) e (match-end 2)) | |
952 (setq b (match-beginning 3) e (match-end 3))) | |
953 (setq format (concat (substring format 0 b) rpl (substring format e))))) | |
954 (while (string-match "%%" format) | |
955 (setq format (replace-match "%" t t format))) | |
956 (while (string-match "[ ,.;:]*%<" format) | |
957 (setq format (replace-match "" t t format))) | |
958 format) | |
959 | |
960 (defun reftex-make-cite-echo-string (entry docstruct-symbol) | |
961 ;; Format a bibtex entry for the echo area and cache the result. | |
962 (let* ((key (reftex-get-bib-field "&key" entry)) | |
963 (string | |
964 (let* ((reftex-cite-punctuation '(" " " & " " etal."))) | |
965 (reftex-format-citation entry reftex-cite-view-format))) | |
966 (cache (assq 'bibview-cache (symbol-value docstruct-symbol))) | |
967 (cache-entry (assoc key (cdr cache)))) | |
968 (unless cache | |
969 ;; This docstruct has no cache - make one. | |
970 (set docstruct-symbol (cons (cons 'bibview-cache nil) | |
971 (symbol-value docstruct-symbol)))) | |
972 (when reftex-cache-cite-echo | |
973 (setq key (copy-sequence key)) | |
974 (set-text-properties 0 (length key) nil key) | |
975 (set-text-properties 0 (length string) nil string) | |
976 (if cache-entry | |
977 (unless (string= (cdr cache-entry) string) | |
978 (setcdr cache-entry string) | |
979 (put reftex-docstruct-symbol 'modified t)) | |
980 (push (cons key string) (cdr cache)) | |
981 (put reftex-docstruct-symbol 'modified t))) | |
982 string)) | |
983 | |
984 (defun reftex-bibtex-selection-callback (data ignore no-revisit) | |
985 ;; Callback function to be called from the BibTeX selection, in | |
986 ;; order to display context. This function is relatively slow and not | |
987 ;; recommended for follow mode. It works OK for individual lookups. | |
988 (let ((win (selected-window)) | |
989 (key (reftex-get-bib-field "&key" data)) | |
25801
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
990 bibfile-list item) |
25280 | 991 |
992 (catch 'exit | |
993 (save-excursion | |
994 (set-buffer reftex-call-back-to-this-buffer) | |
995 (cond | |
996 ((assq 'bib (symbol-value reftex-docstruct-symbol)) | |
997 (setq bibfile-list (reftex-get-bibfile-list))) | |
25801
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
998 ((assq 'thebib (symbol-value reftex-docstruct-symbol)) |
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
999 (setq bibfile-list |
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
1000 (reftex-uniquify |
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
1001 (mapcar 'cdr |
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
1002 (reftex-all-assq |
8f6d4157f700
(reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
1003 'thebib (symbol-value reftex-docstruct-symbol)))) |
25280 | 1004 item t)) |
1005 (reftex-default-bibliography | |
1006 (setq bibfile-list (reftex-default-bibliography))) | |
30191
9bff03b82e7e
(reftex-bibtex-selection-callback): Call throw correctly.
Dave Love <fx@gnu.org>
parents:
29775
diff
changeset
|
1007 (t (ding) (throw 'exit nil)))) |
25280 | 1008 |
1009 (when no-revisit | |
1010 (setq bibfile-list (reftex-visited-files bibfile-list))) | |
1011 | |
1012 (condition-case nil | |
1013 (reftex-pop-to-bibtex-entry | |
1014 key bibfile-list (not reftex-keep-temporary-buffers) t item) | |
1015 (error (ding)))) | |
1016 | |
1017 (select-window win))) | |
1018 | |
1019 ;;; reftex-cite.el ends here |