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