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