1 |
;;; reftex-cite.el --- creating citations with RefTeX |
;;; reftex-cite.el --- creating citations with RefTeX |
2 |
;; Copyright (c) 1997, 1998, 1999, 2000 Free Software Foundation, Inc. |
;; Copyright (c) 1997, 1998, 1999, 2000 Free Software Foundation, Inc. |
3 |
|
|
4 |
;; Author: Carsten Dominik <dominik@strw.LeidenUniv.nl> |
;; Author: Carsten Dominik <dominik@science.uva.nl> |
5 |
;; Version: 4.16 |
;; Version: 4.17 |
6 |
|
|
7 |
;; This file is part of GNU Emacs. |
;; This file is part of GNU Emacs. |
8 |
|
|
53 |
|
|
54 |
;; Find bibtex files |
;; Find bibtex files |
55 |
|
|
56 |
|
|
57 |
|
(defmacro reftex-with-special-syntax-for-bib (&rest body) |
58 |
|
`(let ((saved-syntax (syntax-table))) |
59 |
|
(unwind-protect |
60 |
|
(progn |
61 |
|
(set-syntax-table reftex-syntax-table-for-bib) |
62 |
|
,@body) |
63 |
|
(set-syntax-table saved-syntax)))) |
64 |
|
|
65 |
(defun reftex-default-bibliography () |
(defun reftex-default-bibliography () |
66 |
;; Return the expanded value of `reftex-default-bibliography'. |
;; Return the expanded value of `reftex-default-bibliography'. |
67 |
;; The expanded value is cached. |
;; The expanded value is cached. |
202 |
(message "Scanning bibliography database %s" buffer1)) |
(message "Scanning bibliography database %s" buffer1)) |
203 |
|
|
204 |
(set-buffer buffer1) |
(set-buffer buffer1) |
205 |
(save-excursion |
(reftex-with-special-syntax-for-bib |
206 |
(goto-char (point-min)) |
(save-excursion |
207 |
(while (re-search-forward first-re nil t) |
(goto-char (point-min)) |
208 |
(catch 'search-again |
(while (re-search-forward first-re nil t) |
209 |
(setq key-point (point)) |
(catch 'search-again |
210 |
(unless (re-search-backward |
(setq key-point (point)) |
211 |
"\\(\\`\\|[\n\r]\\)[ \t]*@\\([a-zA-Z]+\\)[ \t\n\r]*[{(]" nil t) |
(unless (re-search-backward |
212 |
(throw 'search-again nil)) |
"\\(\\`\\|[\n\r]\\)[ \t]*@\\([a-zA-Z]+\\)[ \t\n\r]*[{(]" nil t) |
213 |
(setq start-point (point)) |
(throw 'search-again nil)) |
214 |
(goto-char (match-end 0)) |
(setq start-point (point)) |
215 |
(condition-case nil |
(goto-char (match-end 0)) |
216 |
(up-list 1) |
(condition-case nil |
217 |
(error (goto-char key-point) |
(up-list 1) |
218 |
|
(error (goto-char key-point) |
219 |
(throw 'search-again nil))) |
(throw 'search-again nil))) |
220 |
(setq end-point (point)) |
(setq end-point (point)) |
221 |
|
|
222 |
;; Ignore @string, @comment and @c entries or things |
;; Ignore @string, @comment and @c entries or things |
223 |
;; outside entries |
;; outside entries |
224 |
(when (or (string= (downcase (match-string 2)) "string") |
(when (or (string= (downcase (match-string 2)) "string") |
225 |
(string= (downcase (match-string 2)) "comment") |
(string= (downcase (match-string 2)) "comment") |
226 |
(string= (downcase (match-string 2)) "c") |
(string= (downcase (match-string 2)) "c") |
227 |
(< (point) key-point)) ; this means match not in {} |
(< (point) key-point)) ; this means match not in {} |
228 |
(goto-char key-point) |
(goto-char key-point) |
229 |
(throw 'search-again nil)) |
(throw 'search-again nil)) |
230 |
|
|
231 |
;; Well, we have got a match |
;; Well, we have got a match |
232 |
(setq entry (concat |
(setq entry (concat |
233 |
(buffer-substring start-point (point)) "\n")) |
(buffer-substring start-point (point)) "\n")) |
234 |
|
|
235 |
;; Check if other regexp match as well |
;; Check if other regexp match as well |
236 |
(setq re-list rest-re) |
(setq re-list rest-re) |
237 |
(while re-list |
(while re-list |
238 |
(unless (string-match (car re-list) entry) |
(unless (string-match (car re-list) entry) |
239 |
;; nope - move on |
;; nope - move on |
240 |
(throw 'search-again nil)) |
(throw 'search-again nil)) |
241 |
(pop re-list)) |
(pop re-list)) |
242 |
|
|
243 |
(setq alist (reftex-parse-bibtex-entry |
(setq alist (reftex-parse-bibtex-entry |
244 |
nil start-point end-point)) |
nil start-point end-point)) |
245 |
(push (cons "&entry" entry) alist) |
(push (cons "&entry" entry) alist) |
246 |
|
|
247 |
;; check for crossref entries |
;; check for crossref entries |
248 |
(if (assoc "crossref" alist) |
(if (assoc "crossref" alist) |
249 |
(setq alist |
(setq alist |
250 |
(append |
(append |
251 |
alist (reftex-get-crossref-alist alist)))) |
alist (reftex-get-crossref-alist alist)))) |
252 |
|
|
253 |
;; format the entry |
;; format the entry |
254 |
(push (cons "&formatted" (reftex-format-bib-entry alist)) |
(push (cons "&formatted" (reftex-format-bib-entry alist)) |
255 |
alist) |
alist) |
256 |
|
|
257 |
;; make key the first element |
;; make key the first element |
258 |
(push (reftex-get-bib-field "&key" alist) alist) |
(push (reftex-get-bib-field "&key" alist) alist) |
259 |
|
|
260 |
;; add it to the list |
;; add it to the list |
261 |
(push alist found-list)))) |
(push alist found-list))))) |
262 |
(reftex-kill-temporary-buffers)))) |
(reftex-kill-temporary-buffers)))) |
263 |
(setq found-list (nreverse found-list)) |
(setq found-list (nreverse found-list)) |
264 |
|
|
265 |
;; Sorting |
;; Sorting |
400 |
(progn |
(progn |
401 |
(set-buffer (get-buffer-create " *RefTeX-scratch*")) |
(set-buffer (get-buffer-create " *RefTeX-scratch*")) |
402 |
(fundamental-mode) |
(fundamental-mode) |
403 |
|
(set-syntax-table reftex-syntax-table-for-bib) |
404 |
(erase-buffer) |
(erase-buffer) |
405 |
(insert entry)) |
(insert entry)) |
406 |
(widen) |
(widen) |
845 |
|
|
846 |
(defun reftex-format-names (namelist n) |
(defun reftex-format-names (namelist n) |
847 |
(let (last (len (length namelist))) |
(let (last (len (length namelist))) |
848 |
|
(if (= n 0) (setq n len)) |
849 |
(cond |
(cond |
850 |
((< len 1) "") |
((< len 1) "") |
851 |
((= 1 len) (car namelist)) |
((= 1 len) (car namelist)) |