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