annotate lisp/packages/refbib.el @ 2:ac2d302a0011 r19-15b2

Import from CVS: tag r19-15b2
author cvs
date Mon, 13 Aug 2007 08:46:35 +0200
parents 376386a54a3c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; refbib.el --- convert refer-style references to ones usable by Latex bib
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1989 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5 ;; Author: Henry Kautz <kautz@research.att.com>
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
6 ;; Keywords: bib, tex
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
7
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
23 ;; 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
25 ;;; Synched up with: FSF 19.34
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
26
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
27 ;;; Commentary:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; Use: from a buffer containing the refer-style bibliography,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; M-x r2b-convert-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; Program will prompt for an output buffer name, and will log
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; warnings during the conversion process in the buffer *Log*.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
34 ;;; Change Log:
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
35
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
36 ;; HISTORY
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
37 ;; 9/88, created H.Kautz
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
38 ;; modified 1/19/89, allow books with editor but no author;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
39 ;; added %O ordering field;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
40 ;; appended illegal multiple fields, instead of
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
41 ;; discarding;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
42 ;; added rule, a tech report whose %R number
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
43 ;; contains "ISBN" is really a book
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
44 ;; added rule, anything with an editor is a book
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
45 ;; or a proceedings
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
46 ;; added 'manual type, for items with institution
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
47 ;; but no author or editor
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
48 ;; fixed bug so trailing blanks are trimmed
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
49 ;; added 'proceedings type
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
50 ;; used "organization" field for proceedings
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
51 ;; modified 2/16/89, updated help messages
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
52 ;; modified 2/23/89, include capitalize stop words in r2b stop words,
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
53 ;; fixed problems with contractions (e.g. it's),
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
54 ;; caught multiple stop words in a row
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
55 ;; modified 3/1/89, fixed capitalize-title for first words all caps
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
56 ;; modified 3/15/89, allow use of " to delimit fields
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
57 ;; modified 4/18/89, properly "quote" special characters on output
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
58
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
59 ;;; Code:
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
60
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;**********************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ; User Parameters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (defvar r2b-trace-on nil "*trace conversion")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (defvar r2b-journal-abbrevs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 '(
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 " Abbreviation list for journal names.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 If the car of an element matches a journal name exactly, it is replaced by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 the cadr when output. Braces must be included if replacement is a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 {string}, but not if replacement is a bibtex abbreviation. The cadr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 may be eliminated if is exactly the same as the car.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 Because titles are capitalized before matching, the abbreviation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 for the journal name should be listed as beginning with a capital
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 letter, even if it really doesn't.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 For example, a value of '((\"Aij\" \"{Artificial Intelligence}\")
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
78 \(\"Ijcai81\" \"ijcai7\")) would expand Aij to the text string
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 \"Artificial Intelligence\", but would replace Ijcai81 with the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 BibTeX macro \"ijcai7\".")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (defvar r2b-booktitle-abbrevs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 '(
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 " Abbreviation list for book and proceedings names. If the car of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 an element matches a title or booktitle exactly, it is replaced by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 the cadr when output. Braces must be included if replacement is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 a {string}, but not if replacement is a bibtex abbreviation. The cadr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 may be eliminated if is exactly the same as the car.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 Because titles are capitalized before matching, the abbreviated title
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 should be listed as beginning with a capital letter, even if it doesn't.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 For example, a value of '((\"Aij\" \"{Artificial Intelligence}\")
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
93 \(\"Ijcai81\" \"ijcai7\")) would expand Aij to the text string
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 \"Artificial Intelligence\", but would replace Ijcai81 with the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 BibTeX macro \"ijcai7\".")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (defvar r2b-proceedings-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 '()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 " Assoc list of books or journals which are really conference proceedings,
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
100 but whose name and whose abbrev expansion (as defined in `r2b-journal-abbrevs'
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
101 and `r2b-booktitle-abbrevs') does not contain the words \"conference\" or
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
102 \"proceedings\". (Those cases are handled automatically.)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 The entry must match the given data exactly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 Because titles are capitalized before matching, the items in this list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 should begin with a capital letter.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 For example, suppose the title \"Ijcai81\" is used for the proceedings of
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
107 a conference, and its expansion is the BibTeX macro \"ijcai7\". Then
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
108 `r2b-proceedings-list' should be '((\"Ijcai81\") ...). If instead its
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 expansion were \"Proceedings of the Seventh International Conference
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
110 on Artificial Intelligence\", then you would NOT need to include Ijcai81
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
111 in `r2b-proceedings-list' (although it wouldn't cause an error).")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (defvar r2b-additional-stop-words
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 "Some\\|What"
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
115 "Words other than the `capitalize-title-stop-words'
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 which are not to be used to build the citation key")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (defvar r2b-delimit-with-quote
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 "*If true, then use \" to delimit fields, otherwise use braces")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 ;**********************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 ; Utility Functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (defvar capitalize-title-stop-words
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 "the\\|and\\|of\\|is\\|a\\|an\\|of\\|for\\|in\\|to\\|in\\|on\\|at\\|"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 "by\\|with\\|that\\|its")
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
130 "Words not to be capitalized in a title (unless they are the first
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 word in the title)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (defvar capitalize-title-stop-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (concat "\\(" capitalize-title-stop-words "\\)\\(\\b\\|'\\)"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (defun capitalize-title-region (begin end)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
137 "Like `capitalize-region', but don't capitalize stop words, except the first."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (interactive "r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (let ((case-fold-search nil) (orig-syntax-table (syntax-table)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (set-syntax-table text-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (narrow-to-region begin end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (if (looking-at "[A-Z][a-z]*[A-Z]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (forward-word 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (capitalize-word 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (while (re-search-forward "\\<" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (if (looking-at "[A-Z][a-z]*[A-Z]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (forward-word 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (if (let ((case-fold-search t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (looking-at capitalize-title-stop-regexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (downcase-word 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (capitalize-word 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (set-syntax-table orig-syntax-table))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (defun capitalize-title (s)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
160 "Like `capitalize', but don't capitalize stop words, except the first."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (set-buffer (get-buffer-create "$$$Scratch$$$"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (insert s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (capitalize-title-region (point-min) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (buffer-string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 ;*********************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (defun r2b-reset ()
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
170 "Unbind defvars, for debugging."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (makunbound 'r2b-journal-abbrevs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (makunbound 'r2b-booktitle-abbrevs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (makunbound 'r2b-proceedings-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (makunbound 'capitalize-title-stop-words)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (makunbound 'capitalize-title-stop-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (makunbound 'r2b-additional-stop-words)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
178 (makunbound 'r2b-stop-regexp))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (defvar r2b-stop-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (concat "\\`\\(\\("
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 r2b-additional-stop-words "\\|" capitalize-title-stop-words
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 "\\)\\('\\w*\\)?\\W+\\)*\\([A-Z0-9]+\\)"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (defun r2b-trace (&rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (if r2b-trace-on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (apply (function message) args)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
190 (sit-for 0))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (defun r2b-match (exp)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
193 "Returns string matched in current buffer."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (buffer-substring (match-beginning exp) (match-end exp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (defvar r2b-out-buf-name "*Out*" "*output from refer-to-bibtex" )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (defvar r2b-log-name "*Log*" "*logs errors from refer-to-bibtex" )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (defvar r2b-in-buf nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (defvar r2b-out-buf nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (defvar r2b-log nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (defvar r2b-error-found nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (setq r2b-variables '(
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 r2b-error-found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 r2bv-author
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 r2bv-primary-author
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 r2bv-date
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 r2bv-year
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 r2bv-decade
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 r2bv-month
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 r2bv-title
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 r2bv-title-first-word
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 r2bv-editor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 r2bv-annote
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 r2bv-tr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 r2bv-address
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 r2bv-institution
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 r2bv-keywords
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 r2bv-booktitle
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 r2bv-journal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 r2bv-volume
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 r2bv-number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 r2bv-pages
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 r2bv-booktitle
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 r2bv-kn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 r2bv-publisher
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 r2bv-organization
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 r2bv-school
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 r2bv-type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 r2bv-where
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 r2bv-note
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 r2bv-ordering
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (defun r2b-clear-variables ()
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
237 "Set all global vars used by r2b to nil."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (let ((vars r2b-variables))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (while vars
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (set (car vars) nil)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
241 (setq vars (cdr vars)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (defun r2b-warning (&rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (setq r2b-error-found t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (princ (apply (function format) args) r2b-log)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (princ "\n" r2b-log)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (princ "\n" r2b-out-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (princ "% " r2b-out-buf)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
249 (princ (apply (function format) args) r2b-out-buf))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (defun r2b-get-field (var field &optional unique required capitalize)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 "Set VAR to string value of FIELD, if any. If none, VAR is set to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 nil. If multiple fields appear, then separate values with the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 '\\nand\\t\\t', unless UNIQUE is non-nil, in which case log a warning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 and just concatenate the values. Trim off leading blanks and tabs on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 first line, and trailing blanks and tabs of every line. Log a warning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 and set VAR to the empty string if REQUIRED is true. Capitalize as a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 title if CAPITALIZE is true. Returns value of VAR."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (let (item val (not-past-end t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (r2b-trace "snarfing %s" field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (while (and not-past-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (re-search-forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (concat "^" field "\\b[ \t]*\\(.*[^ \t\n]\\)[ \t]*") nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (setq item (r2b-match 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (while (and (setq not-past-end (zerop (forward-line 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (not (looking-at "[ \t]*$\\|%")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (looking-at "\\(.*[^ \t\n]\\)[ \t]*$")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (setq item (concat item "\n" (r2b-match 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (if (null val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (setq val item)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (if unique
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (r2b-warning "*Illegal multiple field %s %s" field item)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (setq val (concat val "\n" item))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (setq val (concat val "\n\t\tand " item))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (if (and val capitalize)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (setq val (capitalize-title val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (set var val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (if (and (null val) required)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (r2b-require var))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (defun r2b-set-match (var n regexp string )
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
290 "Set VAR to the Nth subpattern in REGEXP matched by STRING, or nil if none."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (set var
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (if (and (stringp string) (string-match regexp string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (substring string (match-beginning n) (match-end n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (defvar r2b-month-abbrevs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 '(("jan") ("feb") ("mar") ("apr") ("may") ("jun") ("jul") ("aug")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 ("sep") ("oct") ("nov") ("dec")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (defun r2b-convert-month ()
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
303 "Try to convert `r2bv-month' to a standard 3 letter name."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (if r2bv-month
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (let ((months r2b-month-abbrevs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (if (string-match "[^0-9]" r2bv-month)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (while (and months (not (string-match (car (car months))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 r2bv-month)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (setq months (cdr months)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (if months
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (setq r2bv-month (car (car months)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (setq months (car (read-from-string r2bv-month)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (if (and (numberp months)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (> months 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (< months 13))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (setq r2bv-month (car (nth months r2b-month-abbrevs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (r2b-warning "* Ridiculous month")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (setq r2bv-month nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (defun r2b-snarf-input ()
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
328 "Parse buffer into global variables."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (let ((case-fold-search t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (r2b-trace "snarfing...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (sit-for 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (set-buffer r2b-in-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (princ " " r2b-log)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (princ (buffer-substring (point) (progn (end-of-line) (point))) r2b-log)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (terpri r2b-log)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (r2b-get-field 'r2bv-author "%A")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (r2b-get-field 'r2bv-editor "%E")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (r2bv-author
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (r2b-set-match 'r2bv-primary-author 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 "\\b\\(\\w+\\)[ \t]*\\($\\|,\\)" r2bv-author)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (r2bv-editor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (r2b-set-match 'r2bv-primary-author 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 "\\b\\(\\w+\\)[ \t]*\\($\\|,\\)" r2bv-editor)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (setq r2bv-primary-author "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (r2b-get-field 'r2bv-date "%D" t t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (r2b-set-match 'r2bv-year 0 "[12][0-9][0-9][0-9]" r2bv-date)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (and (null r2bv-year)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (r2b-set-match 'r2bv-year 1 "[^0-9]\\([0-9][0-9]\\)$" r2bv-date)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (setq r2bv-year (concat "19" r2bv-year)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (r2b-set-match 'r2bv-decade 1 "..\\(..\\)" r2bv-year)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (r2b-set-match 'r2bv-month 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 "[0-9]+/\\|[a-zA-Z]+" r2bv-date)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (if (and (stringp r2bv-month) (string-match "\\(.*\\)/$" r2bv-month))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (setq r2bv-month (substring r2bv-month 0 (match-end 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (r2b-convert-month)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (r2b-get-field 'r2bv-title "%T" t t t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (r2b-set-match 'r2bv-title-first-word 4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 r2b-stop-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 r2bv-title)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 (r2b-get-field 'r2bv-annote "%X" t )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 (r2b-get-field 'r2bv-tr "%R" t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (r2b-get-field 'r2bv-address "%C" t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (r2b-get-field 'r2bv-institution "%I" t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (r2b-get-field 'r2bv-keywords "%K")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (r2b-get-field 'r2bv-booktitle "%B" t nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 (r2b-get-field 'r2bv-journal "%J" t nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (r2b-get-field 'r2bv-volume "%V" t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (r2b-get-field 'r2bv-number "%N" t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (r2b-get-field 'r2bv-pages "%P" t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (r2b-get-field 'r2bv-where "%W" t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 (r2b-get-field 'r2bv-ordering "%O" t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 (defun r2b-put-field (field data &optional abbrevs)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
388 "Print bibtex FIELD = {DATA} if DATA not null; precede
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 with a comma and newline; if ABBREVS list is given, then
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
390 try to replace the {DATA} with an abbreviation."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (if data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 (let (match nodelim multi-line index)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 ((and abbrevs (setq match (assoc data abbrevs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (if (null (cdr match))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (setq data (car match))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 (setq data (car (cdr match))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 (setq nodelim t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 ((and (not (equal data ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (not (string-match "[^0-9]" data)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (setq nodelim t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (setq index 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (while (string-match "[\\~^]" data index)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (setq data (concat (substring data 0 (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 "\\verb+"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (substring data (match-beginning 0) (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 "+"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (substring data (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (setq index (+ (match-end 0) 7)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (setq index 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (while (string-match "[$&%#_{}]" data index)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (setq data (concat (substring data 0 (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 "\\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (substring data (match-beginning 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (setq index (+ (match-end 0) 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (setq index 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (if r2b-delimit-with-quote
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (while (string-match "\"" data index)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (setq data (concat (substring data 0 (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 "{\"}"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (substring data (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 (setq index (+ (match-end 0) 2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 (princ ", \n ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (princ field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (princ " =\t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (if (not nodelim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (if r2b-delimit-with-quote
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (princ "\"")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (princ "{")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (string-match ".*" data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (if (> (match-end 0) 59)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (princ "\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (princ data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (if (not nodelim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (if r2b-delimit-with-quote
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (princ "\"")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (princ "}")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (defun r2b-require (vars)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
445 "If any of VARS is null, set to empty string and log error."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 ((null vars))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 ((listp vars) (r2b-require (car vars)) (r2b-require (cdr vars)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (if (null (symbol-value vars))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (r2b-warning "*Missing value for field %s" vars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (set vars "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (defmacro r2b-moveq (new old)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
460 "Set NEW to OLD and set OLD to nil."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (list 'progn (list 'setq new old) (list 'setq old 'nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 (defun r2b-isa-proceedings (name)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
464 "Return t if NAME is the name of proceedings."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 (string-match "proceedings\\|conference" name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (assoc name r2b-proceedings-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (let ((match (assoc name r2b-booktitle-abbrevs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (and match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (string-match "proceedings\\|conference" (car (cdr match)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (defun r2b-isa-university (name)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
476 "Return t if NAME is a university or similar organization,
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
477 but not a publisher."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (string-match "university" name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (not (string-match "press" name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (defun r2b-barf-output ()
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
486 "Generate bibtex based on global variables."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (let ((standard-output r2b-out-buf) (case-fold-search t) match)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 (r2b-trace "...barfing")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (sit-for 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (set-buffer r2b-out-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (setq r2bv-kn (concat r2bv-primary-author r2bv-decade
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 r2bv-title-first-word))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (setq r2bv-entry-kind
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 ((r2b-isa-proceedings r2bv-journal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (r2b-moveq r2bv-booktitle r2bv-journal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (if (r2b-isa-university r2bv-institution)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (r2b-moveq r2bv-organization r2bv-institution)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (r2b-moveq r2bv-publisher r2bv-institution))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (r2b-moveq r2bv-note r2bv-tr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 (r2b-require 'r2bv-author)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 'inproceedings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 ((r2b-isa-proceedings r2bv-booktitle)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 (if (r2b-isa-university r2bv-institution)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 (r2b-moveq r2bv-organization r2bv-institution)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 (r2b-moveq r2bv-publisher r2bv-institution))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 (r2b-moveq r2bv-note r2bv-tr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (r2b-require 'r2bv-author)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 'inproceedings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 ((and r2bv-tr (string-match "phd" r2bv-tr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (r2b-moveq r2bv-school r2bv-institution)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 (r2b-require 'r2bv-school )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 (r2b-require 'r2bv-author)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 'phdthesis)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 ((and r2bv-tr (string-match "master" r2bv-tr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (r2b-moveq r2bv-school r2bv-institution)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 (r2b-require 'r2bv-school )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 (r2b-require 'r2bv-author)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 'mastersthesis)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 ((and r2bv-tr (string-match "draft\\|unpublish" r2bv-tr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 (r2b-moveq r2bv-note r2bv-institution)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (r2b-require 'r2bv-author)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 'unpublished)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 (r2bv-journal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 (r2b-require 'r2bv-author)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 'article)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (r2bv-booktitle
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 (r2b-moveq r2bv-publisher r2bv-institution)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 (r2b-moveq r2bv-note r2bv-tr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 (r2b-require 'r2bv-publisher)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 (r2b-require 'r2bv-author)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 'incollection)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 ((and r2bv-author
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 (null r2bv-editor)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 (string-match "\\`personal communication\\'" r2bv-title))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 'misc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 ((r2b-isa-proceedings r2bv-title)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 (if (r2b-isa-university r2bv-institution)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 (r2b-moveq r2bv-organization r2bv-institution)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 (r2b-moveq r2bv-publisher r2bv-institution))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 (r2b-moveq r2bv-note r2bv-tr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 'proceedings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 ((or r2bv-editor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 (and r2bv-author
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 (or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 (null r2bv-tr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 (string-match "\\bisbn\\b" r2bv-tr))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 (r2b-moveq r2bv-publisher r2bv-institution)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 (r2b-moveq r2bv-note r2bv-tr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 (r2b-require 'r2bv-publisher)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 (if (null r2bv-editor)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 (r2b-require 'r2bv-author))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 'book)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 (r2bv-tr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 (r2b-require 'r2bv-institution)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 (if (string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 "\\`\\(\\(.\\|\n\\)+\\)[ \t\n]+\\([^ \t\n]\\)+\\'"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 r2bv-tr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 (setq r2bv-type (substring r2bv-tr 0 (match-end 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 (setq r2bv-number (substring r2bv-tr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 (match-beginning 3)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 (setq r2bv-tr nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 (r2b-moveq r2bv-number r2bv-tr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 (r2b-require 'r2bv-author)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 'techreport)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 (r2bv-institution
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 (r2b-moveq r2bv-organization r2bv-institution)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 'manual)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 'misc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 (r2b-require '( r2bv-year))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 (if r2b-error-found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 (princ "\n% Warning -- Errors During Conversion Next Entry\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 (princ "\n@")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 (princ r2bv-entry-kind)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 (princ "( ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 (princ r2bv-kn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 (r2b-put-field "author" r2bv-author )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 (r2b-put-field "title" r2bv-title r2b-booktitle-abbrevs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 (r2b-put-field "year" r2bv-year )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 (r2b-put-field "month" r2bv-month r2b-month-abbrevs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 (r2b-put-field "journal" r2bv-journal r2b-journal-abbrevs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 (r2b-put-field "volume" r2bv-volume)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 (r2b-put-field "type" r2bv-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 (r2b-put-field "number" r2bv-number)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 (r2b-put-field "booktitle" r2bv-booktitle r2b-booktitle-abbrevs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 (r2b-put-field "editor" r2bv-editor)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 (r2b-put-field "publisher" r2bv-publisher)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 (r2b-put-field "institution" r2bv-institution)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 (r2b-put-field "organization" r2bv-organization)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 (r2b-put-field "school" r2bv-school)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 (r2b-put-field "pages" r2bv-pages)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 (r2b-put-field "address" r2bv-address)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 (r2b-put-field "note" r2bv-note)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 (r2b-put-field "keywords" r2bv-keywords)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 (r2b-put-field "where" r2bv-where)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 (r2b-put-field "ordering" r2bv-ordering)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 (r2b-put-field "annote" r2bv-annote)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 (princ " )\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 (defun r2b-convert-record (output-name)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
616 "Transform current bib entry and append to buffer OUTPUT;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
617 do \"M-x r2b-help\" for more info."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 (list (read-string "Output to buffer: " r2b-out-buf-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 (let (rec-end rec-begin not-done)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 (setq r2b-out-buf-name output-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 (setq r2b-out-buf (get-buffer-create output-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 (setq r2b-in-buf (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 (set-buffer r2b-out-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 (setq r2b-log (get-buffer-create r2b-log-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 (set-buffer r2b-log)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 (set-buffer r2b-in-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 (setq not-done (re-search-forward "[^ \t\n]" nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 (if not-done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 (re-search-backward "^[ \t]*$" nil 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 (re-search-forward "^%")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 (beginning-of-line nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 (setq rec-begin (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 (re-search-forward "^[ \t]*$" nil 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 (setq rec-end (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 (narrow-to-region rec-begin rec-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 (r2b-clear-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 (r2b-snarf-input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 (r2b-barf-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 (set-buffer r2b-in-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 (goto-char rec-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 (defun r2b-convert-buffer (output-name)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
653 "Transform current buffer and append to buffer OUTPUT;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
654 do \"M-x r2b-help\" for more info."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 (list (read-string "Output to buffer: " r2b-out-buf-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 (setq r2b-log (get-buffer-create r2b-log-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 (set-buffer r2b-log)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 (erase-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 (message "Working, please be patient...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 (sit-for 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 (while (r2b-convert-record output-name) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 (message "Done, results in %s, errors in %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 r2b-out-buf-name r2b-log-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 (defvar r2b-load-quietly nil "*Don't print help message when loaded")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 (defvar r2b-help-message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 " Refer to Bibtex Bibliography Conversion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 A refer-style database is of the form:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 %A Joe Blow
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 %T Great Thoughts I've Thought
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 %D 1977
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 This utility converts these kind of databases to bibtex form, for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 users of TeX and LaTex. Instructions:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 1. Visit the file containing the refer-style database.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 2. The command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 M-x r2b-convert-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 converts the entire buffer, appending it's output by default in a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 buffer named *Out*, and logging progress and errors in a buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 named *Log*. The original file is never modified.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 Note that results are appended to *Out*, so if that buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 buffer already exists and contains material you don't want to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 save, you should kill it first.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 3. Switch to the buffer *Out* and save it as a named file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 4. To convert a single refer-style entry, simply position the cursor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 at the entry and enter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 M-x r2b-convert-record
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 Again output is appended to *Out* and errors are logged in *Log*.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 This utility is very robust and pretty smart about determining the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 type of the entry. It includes facilities for expanding refer macros
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 to text, or substituting bibtex macros. Do M-x describe-variable on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 r2b-journal-abbrevs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 r2b-booktitle-abbrevs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 r2b-proceedings-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 for information on these features.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 If you don't want to see this help message when you load this utility,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 then include the following line in your .emacs file:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 (setq r2b-load-quietly t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 To see this message again, perform
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
711 M-x r2b-help
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
712 Please send bug reports and suggestions to
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
713 Henry Kautz
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
714 kautz@research.att.com
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
715 allegra!kautz")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 (defun r2b-help ()
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
719 "Print help message."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 (with-output-to-temp-buffer "*Help*"
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
722 (princ r2b-help-message)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
723 (save-excursion
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
724 (set-buffer standard-output)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
725 (help-mode))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 (if (not r2b-load-quietly)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 (r2b-help))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 (message "r2b loaded")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
732 (provide 'refer-to-bibtex)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
733
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
734 ;;; refbib.el ends here