annotate lisp/textmodes/reftex-cite.el @ 49446:21086b629b21

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