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