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