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.18 |
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. |
68 |
(unless (eq (get 'reftex-default-bibliography :reftex-raw) |
(unless (eq (get 'reftex-default-bibliography :reftex-raw) |
69 |
reftex-default-bibliography) |
reftex-default-bibliography) |
70 |
(put 'reftex-default-bibliography :reftex-expanded |
(put 'reftex-default-bibliography :reftex-expanded |
71 |
(reftex-locate-bibliography-files |
(reftex-locate-bibliography-files |
72 |
default-directory reftex-default-bibliography)) |
default-directory reftex-default-bibliography)) |
73 |
(put 'reftex-default-bibliography :reftex-raw |
(put 'reftex-default-bibliography :reftex-raw |
74 |
reftex-default-bibliography)) |
reftex-default-bibliography)) |
75 |
(get 'reftex-default-bibliography :reftex-expanded)) |
(get 'reftex-default-bibliography :reftex-expanded)) |
76 |
|
|
77 |
|
(defun reftex-bib-or-thebib () |
78 |
|
;; Tests if BibTeX or \begin{tehbibliography} should be used for the |
79 |
|
;; citation |
80 |
|
;; Find the bof of the current file |
81 |
|
(let* ((docstruct (symbol-value reftex-docstruct-symbol)) |
82 |
|
(rest (or (member (list 'bof (buffer-file-name)) docstruct) |
83 |
|
docstruct)) |
84 |
|
(bib (assq 'bib rest)) |
85 |
|
(thebib (assq 'thebib rest)) |
86 |
|
(bibmem (memq bib rest)) |
87 |
|
(thebibmem (memq thebib rest))) |
88 |
|
(when (not (or thebib bib)) |
89 |
|
(setq bib (assq 'bib docstruct) |
90 |
|
thebib (assq 'thebib docstruct) |
91 |
|
bibmem (memq bib docstruct) |
92 |
|
thebibmem (memq thebib docstruct))) |
93 |
|
(if (> (length bibmem) (length thebibmem)) |
94 |
|
(if bib 'bib nil) |
95 |
|
(if thebib 'thebib nil)))) |
96 |
|
|
97 |
(defun reftex-get-bibfile-list () |
(defun reftex-get-bibfile-list () |
98 |
;; Return list of bibfiles for current document. |
;; Return list of bibfiles for current document. |
99 |
;; When using the chapterbib or bibunits package you should either |
;; When using the chapterbib or bibunits package you should either |
127 |
;; If RETURN is non-nil, just return the entry. |
;; If RETURN is non-nil, just return the entry. |
128 |
|
|
129 |
(let* ((re |
(let* ((re |
130 |
(if item |
(if item |
131 |
(concat "\\\\bibitem\\(\\[[^]]*\\]\\)?{" (regexp-quote key) "}") |
(concat "\\\\bibitem\\(\\[[^]]*\\]\\)?{" (regexp-quote key) "}") |
132 |
(concat "@[a-zA-Z]+[ \t\n\r]*[{(][ \t\n\r]*" (regexp-quote key) |
(concat "@[a-zA-Z]+[ \t\n\r]*[{(][ \t\n\r]*" (regexp-quote key) |
133 |
"[, \t\r\n}]"))) |
"[, \t\r\n}]"))) |
149 |
(when return |
(when return |
150 |
;; Just return the relevant entry |
;; Just return the relevant entry |
151 |
(if item (goto-char (match-end 0))) |
(if item (goto-char (match-end 0))) |
152 |
(setq return (buffer-substring |
(setq return (buffer-substring |
153 |
(point) (reftex-end-of-bib-entry item))) |
(point) (reftex-end-of-bib-entry item))) |
154 |
(set-buffer buffer-conf) |
(set-buffer buffer-conf) |
155 |
(throw 'exit return)) |
(throw 'exit return)) |
165 |
(error "No BibTeX entry with citation key %s" key))))) |
(error "No BibTeX entry with citation key %s" key))))) |
166 |
|
|
167 |
(defun reftex-end-of-bib-entry (item) |
(defun reftex-end-of-bib-entry (item) |
168 |
(save-excursion |
(save-excursion |
169 |
(condition-case nil |
(condition-case nil |
170 |
(if item |
(if item |
171 |
(progn (end-of-line) |
(progn (end-of-line) |
172 |
(re-search-forward |
(re-search-forward |
173 |
"\\\\bibitem\\|\\end{thebibliography}") |
"\\\\bibitem\\|\\end{thebibliography}") |
184 |
(let* (re-list first-re rest-re |
(let* (re-list first-re rest-re |
185 |
(buffer-list (if (listp buffers) buffers (list buffers))) |
(buffer-list (if (listp buffers) buffers (list buffers))) |
186 |
found-list entry buffer1 buffer alist |
found-list entry buffer1 buffer alist |
187 |
key-point start-point end-point) |
key-point start-point end-point default) |
188 |
|
|
189 |
;; Read a regexp, completing on known citation keys. |
;; Read a regexp, completing on known citation keys. |
190 |
(setq re-list |
(setq default (regexp-quote (reftex-get-bibkey-default))) |
191 |
(split-string |
(setq re-list |
192 |
(completing-read |
(split-string |
193 |
"RegExp [ && RegExp...]: " |
(completing-read |
194 |
|
(concat |
195 |
|
"Regex { && Regex...}: " |
196 |
|
"[" default "]: ") |
197 |
(if reftex-mode |
(if reftex-mode |
198 |
(if (fboundp 'LaTeX-bibitem-list) |
(if (fboundp 'LaTeX-bibitem-list) |
199 |
(LaTeX-bibitem-list) |
(LaTeX-bibitem-list) |
200 |
(cdr (assoc 'bibview-cache |
(cdr (assoc 'bibview-cache |
201 |
(symbol-value reftex-docstruct-symbol)))) |
(symbol-value reftex-docstruct-symbol)))) |
202 |
nil) |
nil) |
203 |
nil nil nil 'reftex-cite-regexp-hist) |
nil nil nil 'reftex-cite-regexp-hist) |
204 |
"[ \t]*&&[ \t]*")) |
"[ \t]*&&[ \t]*")) |
205 |
|
|
206 |
|
(if (or (null re-list ) (equal re-list '(""))) |
207 |
|
(setq re-list (list default))) |
208 |
|
|
209 |
(setq first-re (car re-list) ; We'll use the first re to find things, |
(setq first-re (car re-list) ; We'll use the first re to find things, |
210 |
rest-re (cdr re-list)) ; the others to narrow down. |
rest-re (cdr re-list)) ; the others to narrow down. |
211 |
(if (string-match "\\`[ \t]*\\'" (or first-re "")) |
(if (string-match "\\`[ \t]*\\'" (or first-re "")) |
228 |
(message "Scanning bibliography database %s" buffer1)) |
(message "Scanning bibliography database %s" buffer1)) |
229 |
|
|
230 |
(set-buffer buffer1) |
(set-buffer buffer1) |
231 |
(save-excursion |
(reftex-with-special-syntax-for-bib |
232 |
(goto-char (point-min)) |
(save-excursion |
233 |
(while (re-search-forward first-re nil t) |
(goto-char (point-min)) |
234 |
(catch 'search-again |
(while (re-search-forward first-re nil t) |
235 |
(setq key-point (point)) |
(catch 'search-again |
236 |
(unless (re-search-backward |
(setq key-point (point)) |
237 |
"\\(\\`\\|[\n\r]\\)[ \t]*@\\([a-zA-Z]+\\)[ \t\n\r]*[{(]" nil t) |
(unless (re-search-backward |
238 |
(throw 'search-again nil)) |
"\\(\\`\\|[\n\r]\\)[ \t]*@\\([a-zA-Z]+\\)[ \t\n\r]*[{(]" nil t) |
239 |
(setq start-point (point)) |
(throw 'search-again nil)) |
240 |
(goto-char (match-end 0)) |
(setq start-point (point)) |
241 |
(condition-case nil |
(goto-char (match-end 0)) |
242 |
(up-list 1) |
(condition-case nil |
243 |
(error (goto-char key-point) |
(up-list 1) |
244 |
|
(error (goto-char key-point) |
245 |
(throw 'search-again nil))) |
(throw 'search-again nil))) |
246 |
(setq end-point (point)) |
(setq end-point (point)) |
247 |
|
|
248 |
;; Ignore @string, @comment and @c entries or things |
;; Ignore @string, @comment and @c entries or things |
249 |
;; outside entries |
;; outside entries |
250 |
(when (or (string= (downcase (match-string 2)) "string") |
(when (or (string= (downcase (match-string 2)) "string") |
251 |
(string= (downcase (match-string 2)) "comment") |
(string= (downcase (match-string 2)) "comment") |
252 |
(string= (downcase (match-string 2)) "c") |
(string= (downcase (match-string 2)) "c") |
253 |
(< (point) key-point)) ; this means match not in {} |
(< (point) key-point)) ; this means match not in {} |
254 |
(goto-char key-point) |
(goto-char key-point) |
255 |
(throw 'search-again nil)) |
(throw 'search-again nil)) |
256 |
|
|
257 |
;; Well, we have got a match |
;; Well, we have got a match |
258 |
(setq entry (concat |
(setq entry (concat |
259 |
(buffer-substring start-point (point)) "\n")) |
(buffer-substring start-point (point)) "\n")) |
260 |
|
|
261 |
;; Check if other regexp match as well |
;; Check if other regexp match as well |
262 |
(setq re-list rest-re) |
(setq re-list rest-re) |
263 |
(while re-list |
(while re-list |
264 |
(unless (string-match (car re-list) entry) |
(unless (string-match (car re-list) entry) |
265 |
;; nope - move on |
;; nope - move on |
266 |
(throw 'search-again nil)) |
(throw 'search-again nil)) |
267 |
(pop re-list)) |
(pop re-list)) |
268 |
|
|
269 |
(setq alist (reftex-parse-bibtex-entry |
(setq alist (reftex-parse-bibtex-entry |
270 |
nil start-point end-point)) |
nil start-point end-point)) |
271 |
(push (cons "&entry" entry) alist) |
(push (cons "&entry" entry) alist) |
272 |
|
|
273 |
;; check for crossref entries |
;; check for crossref entries |
274 |
(if (assoc "crossref" alist) |
(if (assoc "crossref" alist) |
275 |
(setq alist |
(setq alist |
276 |
(append |
(append |
277 |
alist (reftex-get-crossref-alist alist)))) |
alist (reftex-get-crossref-alist alist)))) |
278 |
|
|
279 |
;; format the entry |
;; format the entry |
280 |
(push (cons "&formatted" (reftex-format-bib-entry alist)) |
(push (cons "&formatted" (reftex-format-bib-entry alist)) |
281 |
alist) |
alist) |
282 |
|
|
283 |
;; make key the first element |
;; make key the first element |
284 |
(push (reftex-get-bib-field "&key" alist) alist) |
(push (reftex-get-bib-field "&key" alist) alist) |
285 |
|
|
286 |
;; add it to the list |
;; add it to the list |
287 |
(push alist found-list)))) |
(push alist found-list))))) |
288 |
(reftex-kill-temporary-buffers)))) |
(reftex-kill-temporary-buffers)))) |
289 |
(setq found-list (nreverse found-list)) |
(setq found-list (nreverse found-list)) |
290 |
|
|
291 |
;; Sorting |
;; Sorting |
341 |
;; Parsing is not as good as for the BibTeX database stuff. |
;; Parsing is not as good as for the BibTeX database stuff. |
342 |
;; The environment should be located in file FILE. |
;; The environment should be located in file FILE. |
343 |
|
|
344 |
(let* (start end buf entries re re-list file) |
(let* (start end buf entries re re-list file default) |
345 |
(unless files |
(unless files |
346 |
(error "Need file name to find thebibliography environment")) |
(error "Need file name to find thebibliography environment")) |
347 |
(while (setq file (pop files)) |
(while (setq file (pop files)) |
348 |
(setq buf (reftex-get-file-buffer-force |
(setq buf (reftex-get-file-buffer-force |
349 |
file (not reftex-keep-temporary-buffers))) |
file (not reftex-keep-temporary-buffers))) |
350 |
(unless buf |
(unless buf |
351 |
(error "No such file %s" file)) |
(error "No such file %s" file)) |
356 |
(save-restriction |
(save-restriction |
357 |
(widen) |
(widen) |
358 |
(goto-char (point-min)) |
(goto-char (point-min)) |
359 |
(while (re-search-forward |
(while (re-search-forward |
360 |
"\\(\\`\\|[\n\r]\\)[ \t]*\\\\begin{thebibliography}" nil t) |
"\\(\\`\\|[\n\r]\\)[ \t]*\\\\begin{thebibliography}" nil t) |
361 |
(beginning-of-line 2) |
(beginning-of-line 2) |
362 |
(setq start (point)) |
(setq start (point)) |
363 |
(if (re-search-forward |
(if (re-search-forward |
364 |
"\\(\\`\\|[\n\r]\\)[ \t]*\\\\end{thebibliography}" nil t) |
"\\(\\`\\|[\n\r]\\)[ \t]*\\\\end{thebibliography}" nil t) |
365 |
(progn |
(progn |
366 |
(beginning-of-line 1) |
(beginning-of-line 1) |
367 |
(setq end (point)))) |
(setq end (point)))) |
368 |
(when (and start end) |
(when (and start end) |
369 |
(setq entries |
(setq entries |
370 |
(append entries |
(append entries |
371 |
(mapcar 'reftex-parse-bibitem |
(mapcar 'reftex-parse-bibitem |
372 |
(delete "" |
(delete "" |
373 |
(split-string |
(split-string |
374 |
(buffer-substring-no-properties start end) |
(buffer-substring-no-properties start end) |
375 |
"[ \t\n\r]*\\\\bibitem\\(\\[[^]]*]\\)*")))))) |
"[ \t\n\r]*\\\\bibitem\\(\\[[^]]*]\\)*")))))) |
376 |
(goto-char end))))) |
(goto-char end))))) |
377 |
(unless entries |
(unless entries |
378 |
(error "No bibitems found")) |
(error "No bibitems found")) |
379 |
|
|
380 |
(setq re-list (split-string |
;; Read a regexp, completing on known citation keys. |
381 |
(read-string "RegExp [ && RegExp...]: " |
(setq default (regexp-quote (reftex-get-bibkey-default))) |
382 |
nil 'reftex-cite-regexp-hist) |
(setq re-list |
383 |
"[ \t]*&&[ \t]*")) |
(split-string |
384 |
|
(completing-read |
385 |
|
(concat |
386 |
|
"Regex { && Regex...}: " |
387 |
|
"[" default "]: ") |
388 |
|
(if reftex-mode |
389 |
|
(if (fboundp 'LaTeX-bibitem-list) |
390 |
|
(LaTeX-bibitem-list) |
391 |
|
(cdr (assoc 'bibview-cache |
392 |
|
(symbol-value reftex-docstruct-symbol)))) |
393 |
|
nil) |
394 |
|
nil nil nil 'reftex-cite-regexp-hist) |
395 |
|
"[ \t]*&&[ \t]*")) |
396 |
|
|
397 |
|
(if (or (null re-list ) (equal re-list '(""))) |
398 |
|
(setq re-list (list default))) |
399 |
|
|
400 |
(if (string-match "\\`[ \t]*\\'" (car re-list)) |
(if (string-match "\\`[ \t]*\\'" (car re-list)) |
401 |
(error "Empty regular expression")) |
(error "Empty regular expression")) |
402 |
|
|
403 |
(while (and (setq re (pop re-list)) entries) |
(while (and (setq re (pop re-list)) entries) |
404 |
(setq entries |
(setq entries |
405 |
(delq nil (mapcar |
(delq nil (mapcar |
406 |
(lambda (x) |
(lambda (x) |
407 |
(if (string-match re (cdr (assoc "&entry" x))) |
(if (string-match re (cdr (assoc "&entry" x))) |
408 |
x nil)) |
x nil)) |
409 |
entries)))) |
entries)))) |
410 |
(setq entries |
(setq entries |
411 |
(mapcar |
(mapcar |
412 |
(lambda (x) |
(lambda (x) |
413 |
(push (cons "&formatted" (reftex-format-bibitem x)) x) |
(push (cons "&formatted" (reftex-format-bibitem x)) x) |
414 |
(push (reftex-get-bib-field "&key" x) x) |
(push (reftex-get-bib-field "&key" x) x) |
417 |
|
|
418 |
entries)) |
entries)) |
419 |
|
|
420 |
|
(defun reftex-get-bibkey-default () |
421 |
|
;; Return the word before the cursor. If the cursor is in a |
422 |
|
;; citation macro, return the word before the macro. |
423 |
|
(let* ((macro (reftex-what-macro 1))) |
424 |
|
(save-excursion |
425 |
|
(if (and macro (string-match "cite" (car macro))) |
426 |
|
(goto-char (cdr macro))) |
427 |
|
(skip-chars-backward "^a-zA-Z0-9") |
428 |
|
(reftex-this-word)))) |
429 |
|
|
430 |
;; Parse and format individual entries |
;; Parse and format individual entries |
431 |
|
|
432 |
(defun reftex-get-bib-names (field entry) |
(defun reftex-get-bib-names (field entry) |
452 |
(progn |
(progn |
453 |
(set-buffer (get-buffer-create " *RefTeX-scratch*")) |
(set-buffer (get-buffer-create " *RefTeX-scratch*")) |
454 |
(fundamental-mode) |
(fundamental-mode) |
455 |
|
(set-syntax-table reftex-syntax-table-for-bib) |
456 |
(erase-buffer) |
(erase-buffer) |
457 |
(insert entry)) |
(insert entry)) |
458 |
(widen) |
(widen) |
591 |
"Make a citation using BibTeX database files. |
"Make a citation using BibTeX database files. |
592 |
After prompting for a regular expression, scans the buffers with |
After prompting for a regular expression, scans the buffers with |
593 |
bibtex entries (taken from the \\bibliography command) and offers the |
bibtex entries (taken from the \\bibliography command) and offers the |
594 |
matching entries for selection. The selected entry is formated according |
matching entries for selection. The selected entry is formatted according |
595 |
to `reftex-cite-format' and inserted into the buffer. |
to `reftex-cite-format' and inserted into the buffer. |
596 |
|
|
597 |
If NO-INSERT is non-nil, nothing is inserted, only the selected key returned. |
If NO-INSERT is non-nil, nothing is inserted, only the selected key returned. |
647 |
;; All keys go into a single command - we need to trick a little |
;; All keys go into a single command - we need to trick a little |
648 |
(pop selected-entries) |
(pop selected-entries) |
649 |
(let ((concat-keys (mapconcat 'car selected-entries ","))) |
(let ((concat-keys (mapconcat 'car selected-entries ","))) |
650 |
(setq insert-entries |
(setq insert-entries |
651 |
(list (list concat-keys (cons "&key" concat-keys)))))) |
(list (list concat-keys (cons "&key" concat-keys)))))) |
652 |
|
|
653 |
(unless no-insert |
(unless no-insert |
654 |
|
|
655 |
;; We shall insert this into the buffer... |
;; We shall insert this into the buffer... |
670 |
(delete-char 1)) |
(delete-char 1)) |
671 |
|
|
672 |
;; Tell AUCTeX |
;; Tell AUCTeX |
673 |
(when (and reftex-mode |
(when (and reftex-mode |
674 |
(fboundp 'LaTeX-add-bibitems) |
(fboundp 'LaTeX-add-bibitems) |
675 |
reftex-plug-into-AUCTeX) |
reftex-plug-into-AUCTeX) |
676 |
(apply 'LaTeX-add-bibitems (mapcar 'car selected-entries))) |
(apply 'LaTeX-add-bibitems (mapcar 'car selected-entries))) |
677 |
|
|
678 |
;; Produce the cite-view strings |
;; Produce the cite-view strings |
679 |
(when (and reftex-mode reftex-cache-cite-echo cite-view) |
(when (and reftex-mode reftex-cache-cite-echo cite-view) |
680 |
(mapcar (lambda (entry) |
(mapcar (lambda (entry) |
681 |
(reftex-make-cite-echo-string entry docstruct-symbol)) |
(reftex-make-cite-echo-string entry docstruct-symbol)) |
682 |
selected-entries)) |
selected-entries)) |
683 |
|
|
685 |
|
|
686 |
(set-marker reftex-select-return-marker nil) |
(set-marker reftex-select-return-marker nil) |
687 |
(reftex-kill-buffer "*RefTeX Select*") |
(reftex-kill-buffer "*RefTeX Select*") |
688 |
|
|
689 |
;; Check if the prefix arg was numeric, and call recursively |
;; Check if the prefix arg was numeric, and call recursively |
690 |
(when (integerp arg) |
(when (integerp arg) |
691 |
(if (> arg 1) |
(if (> arg 1) |
692 |
(progn |
(progn |
693 |
(skip-chars-backward "}") |
(skip-chars-backward "}") |
694 |
(decf arg) |
(decf arg) |
695 |
(reftex-do-citation arg)) |
(reftex-do-citation arg)) |
696 |
(forward-char 1))) |
(forward-char 1))) |
697 |
|
|
698 |
;; Return the citation key |
;; Return the citation key |
699 |
(car (car selected-entries)))) |
(car (car selected-entries)))) |
700 |
|
|
708 |
(no-insert |
(no-insert |
709 |
;; Format does not really matter because nothing will be inserted. |
;; Format does not really matter because nothing will be inserted. |
710 |
(setq format "%l")) |
(setq format "%l")) |
711 |
|
|
712 |
((and (stringp macro) |
((and (stringp macro) |
713 |
(string-match "\\`\\\\cite\\|cite\\'" macro)) |
(string-match "\\`\\\\cite\\|cite\\'" macro)) |
714 |
;; We are already inside a cite macro |
;; We are already inside a cite macro |
729 |
(when (listp format) |
(when (listp format) |
730 |
(setq key |
(setq key |
731 |
(or format-key |
(or format-key |
732 |
(reftex-select-with-char |
(reftex-select-with-char |
733 |
"" (concat "SELECT A CITATION FORMAT\n\n" |
"" (concat "SELECT A CITATION FORMAT\n\n" |
734 |
(mapconcat |
(mapconcat |
735 |
(lambda (x) |
(lambda (x) |
756 |
(defun reftex-offer-bib-menu () |
(defun reftex-offer-bib-menu () |
757 |
;; Offer bib menu and return list of selected items |
;; Offer bib menu and return list of selected items |
758 |
|
|
759 |
(let (found-list rtn key data selected-entries) |
(let ((bibtype (reftex-bib-or-thebib)) |
760 |
(while |
found-list rtn key data selected-entries) |
761 |
(not |
(while |
762 |
|
(not |
763 |
(catch 'done |
(catch 'done |
764 |
;; Scan bibtex files |
;; Scan bibtex files |
765 |
(setq found-list |
(setq found-list |
766 |
(cond |
(cond |
767 |
((assq 'bib (symbol-value reftex-docstruct-symbol)) |
((eq bibtype 'bib) |
768 |
|
; ((assq 'bib (symbol-value reftex-docstruct-symbol)) |
769 |
;; using BibTeX database files. |
;; using BibTeX database files. |
770 |
(reftex-extract-bib-entries (reftex-get-bibfile-list))) |
(reftex-extract-bib-entries (reftex-get-bibfile-list))) |
771 |
((assq 'thebib (symbol-value reftex-docstruct-symbol)) |
((eq bibtype 'thebib) |
772 |
|
; ((assq 'thebib (symbol-value reftex-docstruct-symbol)) |
773 |
;; using thebibliography environment. |
;; using thebibliography environment. |
774 |
(reftex-extract-bib-entries-from-thebibliography |
(reftex-extract-bib-entries-from-thebibliography |
775 |
(reftex-uniquify |
(reftex-uniquify |
776 |
(mapcar 'cdr |
(mapcar 'cdr |
777 |
(reftex-all-assq |
(reftex-all-assq |
778 |
'thebib (symbol-value reftex-docstruct-symbol)))))) |
'thebib (symbol-value reftex-docstruct-symbol)))))) |
779 |
(reftex-default-bibliography |
(reftex-default-bibliography |
780 |
(message "Using default bibliography") |
(message "Using default bibliography") |
781 |
(reftex-extract-bib-entries (reftex-default-bibliography))) |
(reftex-extract-bib-entries (reftex-default-bibliography))) |
782 |
(t (error "No valid bibliography in this document, and no default available")))) |
(t (error "No valid bibliography in this document, and no default available")))) |
783 |
|
|
784 |
(unless found-list |
(unless found-list |
785 |
(error "Sorry, no matches found")) |
(error "Sorry, no matches found")) |
786 |
|
|
787 |
;; Remember where we came from |
;; Remember where we came from |
788 |
(setq reftex-call-back-to-this-buffer (current-buffer)) |
(setq reftex-call-back-to-this-buffer (current-buffer)) |
789 |
(set-marker reftex-select-return-marker (point)) |
(set-marker reftex-select-return-marker (point)) |
790 |
|
|
791 |
;; Offer selection |
;; Offer selection |
792 |
(save-window-excursion |
(save-window-excursion |
793 |
(delete-other-windows) |
(delete-other-windows) |
828 |
(goto-char 1)) |
(goto-char 1)) |
829 |
((eq key ?A) |
((eq key ?A) |
830 |
;; Take all (marked) |
;; Take all (marked) |
831 |
(setq selected-entries |
(setq selected-entries |
832 |
(if reftex-select-marked |
(if reftex-select-marked |
833 |
(mapcar 'car (nreverse reftex-select-marked)) |
(mapcar 'car (nreverse reftex-select-marked)) |
834 |
found-list)) |
found-list)) |
835 |
(throw 'done t)) |
(throw 'done t)) |
836 |
((eq key ?a) |
((eq key ?a) |
837 |
;; Take all (marked), and push the symbol 'concat |
;; Take all (marked), and push the symbol 'concat |
838 |
(setq selected-entries |
(setq selected-entries |
839 |
(cons 'concat |
(cons 'concat |
840 |
(if reftex-select-marked |
(if reftex-select-marked |
841 |
(mapcar 'car (nreverse reftex-select-marked)) |
(mapcar 'car (nreverse reftex-select-marked)) |
842 |
found-list))) |
found-list))) |
844 |
((or (eq key ?\C-m) |
((or (eq key ?\C-m) |
845 |
(eq key 'return)) |
(eq key 'return)) |
846 |
;; Take selected |
;; Take selected |
847 |
(setq selected-entries |
(setq selected-entries |
848 |
(if reftex-select-marked |
(if reftex-select-marked |
849 |
(cons 'concat |
(cons 'concat |
850 |
(mapcar 'car (nreverse reftex-select-marked))) |
(mapcar 'car (nreverse reftex-select-marked))) |
851 |
(if data (list data) nil))) |
(if data (list data) nil))) |
852 |
(throw 'done t)) |
(throw 'done t)) |
888 |
reftex-mouse-selected-face |
reftex-mouse-selected-face |
889 |
nil)) |
nil)) |
890 |
tmp len) |
tmp len) |
891 |
(mapcar |
(mapcar |
892 |
(lambda (x) |
(lambda (x) |
893 |
(setq tmp (cdr (assoc "&formatted" x)) |
(setq tmp (cdr (assoc "&formatted" x)) |
894 |
len (length tmp)) |
len (length tmp)) |
900 |
|
|
901 |
(defun reftex-format-names (namelist n) |
(defun reftex-format-names (namelist n) |
902 |
(let (last (len (length namelist))) |
(let (last (len (length namelist))) |
903 |
|
(if (= n 0) (setq n len)) |
904 |
(cond |
(cond |
905 |
((< len 1) "") |
((< len 1) "") |
906 |
((= 1 len) (car namelist)) |
((= 1 len) (car namelist)) |
983 |
(defun reftex-make-cite-echo-string (entry docstruct-symbol) |
(defun reftex-make-cite-echo-string (entry docstruct-symbol) |
984 |
;; Format a bibtex entry for the echo area and cache the result. |
;; Format a bibtex entry for the echo area and cache the result. |
985 |
(let* ((key (reftex-get-bib-field "&key" entry)) |
(let* ((key (reftex-get-bib-field "&key" entry)) |
986 |
(string |
(string |
987 |
(let* ((reftex-cite-punctuation '(" " " & " " etal."))) |
(let* ((reftex-cite-punctuation '(" " " & " " etal."))) |
988 |
(reftex-format-citation entry reftex-cite-view-format))) |
(reftex-format-citation entry reftex-cite-view-format))) |
989 |
(cache (assq 'bibview-cache (symbol-value docstruct-symbol))) |
(cache (assq 'bibview-cache (symbol-value docstruct-symbol))) |
1010 |
;; recommended for follow mode. It works OK for individual lookups. |
;; recommended for follow mode. It works OK for individual lookups. |
1011 |
(let ((win (selected-window)) |
(let ((win (selected-window)) |
1012 |
(key (reftex-get-bib-field "&key" data)) |
(key (reftex-get-bib-field "&key" data)) |
1013 |
bibfile-list item) |
bibfile-list item bibtype) |
1014 |
|
|
1015 |
(catch 'exit |
(catch 'exit |
1016 |
(save-excursion |
(save-excursion |
1017 |
(set-buffer reftex-call-back-to-this-buffer) |
(set-buffer reftex-call-back-to-this-buffer) |
1018 |
|
(setq bibtype (reftex-bib-or-thebib)) |
1019 |
(cond |
(cond |
1020 |
((assq 'bib (symbol-value reftex-docstruct-symbol)) |
((eq bibtype 'bib) |
1021 |
|
; ((assq 'bib (symbol-value reftex-docstruct-symbol)) |
1022 |
(setq bibfile-list (reftex-get-bibfile-list))) |
(setq bibfile-list (reftex-get-bibfile-list))) |
1023 |
((assq 'thebib (symbol-value reftex-docstruct-symbol)) |
((eq bibtype 'thebib) |
1024 |
|
; ((assq 'thebib (symbol-value reftex-docstruct-symbol)) |
1025 |
(setq bibfile-list |
(setq bibfile-list |
1026 |
(reftex-uniquify |
(reftex-uniquify |
1027 |
(mapcar 'cdr |
(mapcar 'cdr |
1028 |
(reftex-all-assq |
(reftex-all-assq |
1029 |
'thebib (symbol-value reftex-docstruct-symbol)))) |
'thebib (symbol-value reftex-docstruct-symbol)))) |
1030 |
item t)) |
item t)) |
1031 |
(reftex-default-bibliography |
(reftex-default-bibliography |
1036 |
(setq bibfile-list (reftex-visited-files bibfile-list))) |
(setq bibfile-list (reftex-visited-files bibfile-list))) |
1037 |
|
|
1038 |
(condition-case nil |
(condition-case nil |
1039 |
(reftex-pop-to-bibtex-entry |
(reftex-pop-to-bibtex-entry |
1040 |
key bibfile-list (not reftex-keep-temporary-buffers) t item) |
key bibfile-list (not reftex-keep-temporary-buffers) t item) |
1041 |
(error (ding)))) |
(error (ding)))) |
1042 |
|
|
1043 |
(select-window win))) |
(select-window win))) |
1044 |
|
|
1045 |
;;; reftex-cite.el ends here |
;;; reftex-cite.el ends here |