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