]> code.delx.au - gnu-emacs/blob - lisp/textmodes/refbib.el
*** empty log message ***
[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 (defvar r2b-stop-regexp
168 (concat "\\`\\(\\("
169 r2b-additional-stop-words "\\|" capitalize-title-stop-words
170 "\\)\\('\\w*\\)?\\W+\\)*\\([A-Z0-9]+\\)"))
171
172
173 (defun r2b-trace (&rest args)
174 (if r2b-trace-on
175 (progn
176 (apply (function message) args)
177 (sit-for 0))))
178
179 (defun r2b-match (exp)
180 "Returns string matched in current buffer."
181 (buffer-substring (match-beginning exp) (match-end exp)))
182
183 (defvar r2b-out-buf-name "*Out*" "*output from refer-to-bibtex" )
184 (defvar r2b-log-name "*Log*" "*logs errors from refer-to-bibtex" )
185 (defvar r2b-in-buf nil)
186 (defvar r2b-out-buf nil)
187 (defvar r2b-log nil)
188
189 (defvar r2b-error-found nil)
190
191 (setq r2b-variables '(
192 r2b-error-found
193 r2bv-author
194 r2bv-primary-author
195 r2bv-date
196 r2bv-year
197 r2bv-decade
198 r2bv-month
199 r2bv-title
200 r2bv-title-first-word
201 r2bv-editor
202 r2bv-annote
203 r2bv-tr
204 r2bv-address
205 r2bv-institution
206 r2bv-keywords
207 r2bv-booktitle
208 r2bv-journal
209 r2bv-volume
210 r2bv-number
211 r2bv-pages
212 r2bv-booktitle
213 r2bv-kn
214 r2bv-publisher
215 r2bv-organization
216 r2bv-school
217 r2bv-type
218 r2bv-where
219 r2bv-note
220 r2bv-ordering
221 ))
222
223 (defun r2b-clear-variables ()
224 "Set all global vars used by r2b to nil."
225 (let ((vars r2b-variables))
226 (while vars
227 (set (car vars) nil)
228 (setq vars (cdr vars)))))
229
230 (defun r2b-warning (&rest args)
231 (setq r2b-error-found t)
232 (princ (apply (function format) args) r2b-log)
233 (princ "\n" r2b-log)
234 (princ "\n" r2b-out-buf)
235 (princ "% " r2b-out-buf)
236 (princ (apply (function format) args) r2b-out-buf))
237
238 (defun r2b-get-field (var field &optional unique required capitalize)
239 "Set VAR to string value of FIELD, if any. If none, VAR is set to
240 nil. If multiple fields appear, then separate values with the
241 '\\nand\\t\\t', unless UNIQUE is non-nil, in which case log a warning
242 and just concatenate the values. Trim off leading blanks and tabs on
243 first line, and trailing blanks and tabs of every line. Log a warning
244 and set VAR to the empty string if REQUIRED is true. Capitalize as a
245 title if CAPITALIZE is true. Returns value of VAR."
246 (let (item val (not-past-end t))
247 (r2b-trace "snarfing %s" field)
248 (goto-char (point-min))
249 (while (and not-past-end
250 (re-search-forward
251 (concat "^" field "\\b[ \t]*\\(.*[^ \t\n]\\)[ \t]*") nil t))
252 (setq item (r2b-match 1))
253 (while (and (setq not-past-end (zerop (forward-line 1)))
254 (not (looking-at "[ \t]*$\\|%")))
255 (looking-at "\\(.*[^ \t\n]\\)[ \t]*$")
256 (setq item (concat item "\n" (r2b-match 1)))
257 )
258 (if (null val)
259 (setq val item)
260 (if unique
261 (progn
262 (r2b-warning "*Illegal multiple field %s %s" field item)
263 (setq val (concat val "\n" item))
264 )
265 (setq val (concat val "\n\t\tand " item))
266 )
267 )
268 )
269 (if (and val capitalize)
270 (setq val (capitalize-title val)))
271 (set var val)
272 (if (and (null val) required)
273 (r2b-require var))
274 ))
275
276 (defun r2b-set-match (var n regexp string )
277 "Set VAR to the Nth subpattern in REGEXP matched by STRING, or nil if none."
278 (set var
279 (if (and (stringp string) (string-match regexp string))
280 (substring string (match-beginning n) (match-end n))
281 nil)
282 )
283 )
284
285 (defvar r2b-month-abbrevs
286 '(("jan") ("feb") ("mar") ("apr") ("may") ("jun") ("jul") ("aug")
287 ("sep") ("oct") ("nov") ("dec")))
288
289 (defun r2b-convert-month ()
290 "Try to convert `r2bv-month' to a standard 3 letter name."
291 (if r2bv-month
292 (let ((months r2b-month-abbrevs))
293 (if (string-match "[^0-9]" r2bv-month)
294 (progn
295 (while (and months (not (string-match (car (car months))
296 r2bv-month)))
297 (setq months (cdr months)))
298 (if months
299 (setq r2bv-month (car (car months)))))
300 (progn
301 (setq months (car (read-from-string r2bv-month)))
302 (if (and (numberp months)
303 (> months 0)
304 (< months 13))
305 (setq r2bv-month (car (nth months r2b-month-abbrevs)))
306 (progn
307 (r2b-warning "* Ridiculous month")
308 (setq r2bv-month nil))
309 ))
310 ))
311 )
312 )
313
314 (defun r2b-snarf-input ()
315 "Parse buffer into global variables."
316 (let ((case-fold-search t))
317 (r2b-trace "snarfing...")
318 (sit-for 0)
319 (set-buffer r2b-in-buf)
320 (goto-char (point-min))
321 (princ " " r2b-log)
322 (princ (buffer-substring (point) (progn (end-of-line) (point))) r2b-log)
323 (terpri r2b-log)
324
325 (r2b-get-field 'r2bv-author "%A")
326 (r2b-get-field 'r2bv-editor "%E")
327 (cond
328 (r2bv-author
329 (r2b-set-match 'r2bv-primary-author 1
330 "\\b\\(\\w+\\)[ \t]*\\($\\|,\\)" r2bv-author)
331 )
332 (r2bv-editor
333 (r2b-set-match 'r2bv-primary-author 1
334 "\\b\\(\\w+\\)[ \t]*\\($\\|,\\)" r2bv-editor)
335 )
336 (t
337 (setq r2bv-primary-author "")
338 )
339 )
340
341 (r2b-get-field 'r2bv-date "%D" t t)
342 (r2b-set-match 'r2bv-year 0 "[12][0-9][0-9][0-9]" r2bv-date)
343 (and (null r2bv-year)
344 (r2b-set-match 'r2bv-year 1 "[^0-9]\\([0-9][0-9]\\)$" r2bv-date)
345 (setq r2bv-year (concat "19" r2bv-year)))
346 (r2b-set-match 'r2bv-decade 1 "..\\(..\\)" r2bv-year)
347 (r2b-set-match 'r2bv-month 0
348 "[0-9]+/\\|[a-zA-Z]+" r2bv-date)
349 (if (and (stringp r2bv-month) (string-match "\\(.*\\)/$" r2bv-month))
350 (setq r2bv-month (substring r2bv-month 0 (match-end 1))))
351 (r2b-convert-month)
352
353 (r2b-get-field 'r2bv-title "%T" t t t)
354 (r2b-set-match 'r2bv-title-first-word 4
355 r2b-stop-regexp
356 r2bv-title)
357
358 (r2b-get-field 'r2bv-annote "%X" t )
359 (r2b-get-field 'r2bv-tr "%R" t)
360 (r2b-get-field 'r2bv-address "%C" t)
361 (r2b-get-field 'r2bv-institution "%I" t)
362 (r2b-get-field 'r2bv-keywords "%K")
363 (r2b-get-field 'r2bv-booktitle "%B" t nil t)
364 (r2b-get-field 'r2bv-journal "%J" t nil t)
365 (r2b-get-field 'r2bv-volume "%V" t)
366 (r2b-get-field 'r2bv-number "%N" t)
367 (r2b-get-field 'r2bv-pages "%P" t)
368 (r2b-get-field 'r2bv-where "%W" t)
369 (r2b-get-field 'r2bv-ordering "%O" t)
370 )
371 )
372
373
374 (defun r2b-put-field (field data &optional abbrevs)
375 "Print bibtex FIELD = {DATA} if DATA not null; precede
376 with a comma and newline; if ABBREVS list is given, then
377 try to replace the {DATA} with an abbreviation."
378 (if data
379 (let (match nodelim multi-line index)
380 (cond
381 ((and abbrevs (setq match (assoc data abbrevs)))
382 (if (null (cdr match))
383 (setq data (car match))
384 (setq data (car (cdr match))))
385 (setq nodelim t))
386 ((and (not (equal data ""))
387 (not (string-match "[^0-9]" data)))
388 (setq nodelim t))
389 (t
390 (setq index 0)
391 (while (string-match "[\\~^]" data index)
392 (setq data (concat (substring data 0 (match-beginning 0))
393 "\\verb+"
394 (substring data (match-beginning 0) (match-end 0))
395 "+"
396 (substring data (match-end 0))))
397 (setq index (+ (match-end 0) 7)))
398 (setq index 0)
399 (while (string-match "[$&%#_{}]" data index)
400 (setq data (concat (substring data 0 (match-beginning 0))
401 "\\"
402 (substring data (match-beginning 0))))
403 (setq index (+ (match-end 0) 1)))
404 (setq index 0)
405 (if r2b-delimit-with-quote
406 (while (string-match "\"" data index)
407 (setq data (concat (substring data 0 (match-beginning 0))
408 "{\"}"
409 (substring data (match-end 0))))
410 (setq index (+ (match-end 0) 2))))
411 ))
412 (princ ", \n ")
413 (princ field)
414 (princ " =\t")
415 (if (not nodelim)
416 (if r2b-delimit-with-quote
417 (princ "\"")
418 (princ "{")))
419 (string-match ".*" data)
420 (if (> (match-end 0) 59)
421 (princ "\n"))
422 (princ data)
423 (if (not nodelim)
424 (if r2b-delimit-with-quote
425 (princ "\"")
426 (princ "}")))
427 )
428 ))
429
430
431 (defun r2b-require (vars)
432 "If any of VARS is null, set to empty string and log error."
433 (cond
434 ((null vars))
435 ((listp vars) (r2b-require (car vars)) (r2b-require (cdr vars)))
436 (t
437 (if (null (symbol-value vars))
438 (progn
439 (r2b-warning "*Missing value for field %s" vars)
440 (set vars "")
441 )))
442 )
443 )
444
445
446 (defmacro r2b-moveq (new old)
447 "Set NEW to OLD and set OLD to nil."
448 (list 'progn (list 'setq new old) (list 'setq old 'nil)))
449
450 (defun r2b-isa-proceedings (name)
451 "Return t if NAME is the name of proceedings."
452 (and
453 name
454 (or
455 (string-match "proceedings\\|conference" name)
456 (assoc name r2b-proceedings-list)
457 (let ((match (assoc name r2b-booktitle-abbrevs)))
458 (and match
459 (string-match "proceedings\\|conference" (car (cdr match)))))
460 )))
461
462 (defun r2b-isa-university (name)
463 "Return t if NAME is a university or similar organization,
464 but not a publisher."
465 (and
466 name
467 (string-match "university" name)
468 (not (string-match "press" name))
469
470 ))
471
472 (defun r2b-barf-output ()
473 "Generate bibtex based on global variables."
474 (let ((standard-output r2b-out-buf) (case-fold-search t) match)
475
476 (r2b-trace "...barfing")
477 (sit-for 0)
478 (set-buffer r2b-out-buf)
479
480 (setq r2bv-kn (concat r2bv-primary-author r2bv-decade
481 r2bv-title-first-word))
482
483 (setq r2bv-entry-kind
484 (cond
485 ((r2b-isa-proceedings r2bv-journal)
486 (r2b-moveq r2bv-booktitle r2bv-journal)
487 (if (r2b-isa-university r2bv-institution)
488 (r2b-moveq r2bv-organization r2bv-institution)
489 (r2b-moveq r2bv-publisher r2bv-institution))
490 (r2b-moveq r2bv-note r2bv-tr)
491 (r2b-require 'r2bv-author)
492 'inproceedings)
493 ((r2b-isa-proceedings r2bv-booktitle)
494 (if (r2b-isa-university r2bv-institution)
495 (r2b-moveq r2bv-organization r2bv-institution)
496 (r2b-moveq r2bv-publisher r2bv-institution))
497 (r2b-moveq r2bv-note r2bv-tr)
498 (r2b-require 'r2bv-author)
499 'inproceedings)
500 ((and r2bv-tr (string-match "phd" r2bv-tr))
501 (r2b-moveq r2bv-school r2bv-institution)
502 (r2b-require 'r2bv-school )
503 (r2b-require 'r2bv-author)
504 'phdthesis)
505 ((and r2bv-tr (string-match "master" r2bv-tr))
506 (r2b-moveq r2bv-school r2bv-institution)
507 (r2b-require 'r2bv-school )
508 (r2b-require 'r2bv-author)
509 'mastersthesis)
510 ((and r2bv-tr (string-match "draft\\|unpublish" r2bv-tr))
511 (r2b-moveq r2bv-note r2bv-institution)
512 (r2b-require 'r2bv-author)
513 'unpublished)
514 (r2bv-journal
515 (r2b-require 'r2bv-author)
516 'article)
517 (r2bv-booktitle
518 (r2b-moveq r2bv-publisher r2bv-institution)
519 (r2b-moveq r2bv-note r2bv-tr)
520 (r2b-require 'r2bv-publisher)
521 (r2b-require 'r2bv-author)
522 'incollection)
523 ((and r2bv-author
524 (null r2bv-editor)
525 (string-match "\\`personal communication\\'" r2bv-title))
526 'misc)
527 ((r2b-isa-proceedings r2bv-title)
528 (if (r2b-isa-university r2bv-institution)
529 (r2b-moveq r2bv-organization r2bv-institution)
530 (r2b-moveq r2bv-publisher r2bv-institution))
531 (r2b-moveq r2bv-note r2bv-tr)
532 'proceedings)
533 ((or r2bv-editor
534 (and r2bv-author
535 (or
536 (null r2bv-tr)
537 (string-match "\\bisbn\\b" r2bv-tr))))
538 (r2b-moveq r2bv-publisher r2bv-institution)
539 (r2b-moveq r2bv-note r2bv-tr)
540 (r2b-require 'r2bv-publisher)
541 (if (null r2bv-editor)
542 (r2b-require 'r2bv-author))
543 'book)
544 (r2bv-tr
545 (r2b-require 'r2bv-institution)
546 (if (string-match
547 "\\`\\(\\(.\\|\n\\)+\\)[ \t\n]+\\([^ \t\n]\\)+\\'"
548 r2bv-tr)
549 (progn
550 (setq r2bv-type (substring r2bv-tr 0 (match-end 1)))
551 (setq r2bv-number (substring r2bv-tr
552 (match-beginning 3)))
553 (setq r2bv-tr nil))
554 (r2b-moveq r2bv-number r2bv-tr))
555 (r2b-require 'r2bv-author)
556 'techreport)
557 (r2bv-institution
558 (r2b-moveq r2bv-organization r2bv-institution)
559 'manual)
560 (t
561 'misc)
562 ))
563
564 (r2b-require '( r2bv-year))
565
566 (if r2b-error-found
567 (princ "\n% Warning -- Errors During Conversion Next Entry\n"))
568
569 (princ "\n@")
570 (princ r2bv-entry-kind)
571 (princ "( ")
572 (princ r2bv-kn)
573
574 (r2b-put-field "author" r2bv-author )
575 (r2b-put-field "title" r2bv-title r2b-booktitle-abbrevs)
576 (r2b-put-field "year" r2bv-year )
577
578 (r2b-put-field "month" r2bv-month r2b-month-abbrevs)
579 (r2b-put-field "journal" r2bv-journal r2b-journal-abbrevs)
580 (r2b-put-field "volume" r2bv-volume)
581 (r2b-put-field "type" r2bv-type)
582 (r2b-put-field "number" r2bv-number)
583 (r2b-put-field "booktitle" r2bv-booktitle r2b-booktitle-abbrevs)
584 (r2b-put-field "editor" r2bv-editor)
585 (r2b-put-field "publisher" r2bv-publisher)
586 (r2b-put-field "institution" r2bv-institution)
587 (r2b-put-field "organization" r2bv-organization)
588 (r2b-put-field "school" r2bv-school)
589 (r2b-put-field "pages" r2bv-pages)
590 (r2b-put-field "address" r2bv-address)
591 (r2b-put-field "note" r2bv-note)
592 (r2b-put-field "keywords" r2bv-keywords)
593 (r2b-put-field "where" r2bv-where)
594 (r2b-put-field "ordering" r2bv-ordering)
595 (r2b-put-field "annote" r2bv-annote)
596
597 (princ " )\n")
598 )
599 )
600
601
602 (defun r2b-convert-record (output-name)
603 "Transform current bib entry and append to buffer OUTPUT;
604 do \"M-x r2b-help\" for more info."
605 (interactive
606 (list (read-string "Output to buffer: " r2b-out-buf-name)))
607 (let (rec-end rec-begin not-done)
608 (setq r2b-out-buf-name output-name)
609 (setq r2b-out-buf (get-buffer-create output-name))
610 (setq r2b-in-buf (current-buffer))
611 (set-buffer r2b-out-buf)
612 (goto-char (point-max))
613 (setq r2b-log (get-buffer-create r2b-log-name))
614 (set-buffer r2b-log)
615 (goto-char (point-max))
616 (set-buffer r2b-in-buf)
617 (setq not-done (re-search-forward "[^ \t\n]" nil t))
618 (if not-done
619 (progn
620 (re-search-backward "^[ \t]*$" nil 2)
621 (re-search-forward "^%")
622 (beginning-of-line nil)
623 (setq rec-begin (point))
624 (re-search-forward "^[ \t]*$" nil 2)
625 (setq rec-end (point))
626 (narrow-to-region rec-begin rec-end)
627 (r2b-clear-variables)
628 (r2b-snarf-input)
629 (r2b-barf-output)
630 (set-buffer r2b-in-buf)
631 (widen)
632 (goto-char rec-end)
633 t)
634 nil
635 )
636 ))
637
638
639 (defun r2b-convert-buffer (output-name)
640 "Transform current buffer and append to buffer OUTPUT;
641 do \"M-x r2b-help\" for more info."
642 (interactive
643 (list (read-string "Output to buffer: " r2b-out-buf-name)))
644 (save-excursion
645 (setq r2b-log (get-buffer-create r2b-log-name))
646 (set-buffer r2b-log)
647 (erase-buffer))
648 (widen)
649 (goto-char (point-min))
650 (message "Working, please be patient...")
651 (sit-for 0)
652 (while (r2b-convert-record output-name) t)
653 (message "Done, results in %s, errors in %s"
654 r2b-out-buf-name r2b-log-name)
655 )
656
657 (defvar r2b-load-quietly nil "*Don't print help message when loaded")
658
659 (defvar r2b-help-message
660 " Refer to Bibtex Bibliography Conversion
661
662 A refer-style database is of the form:
663
664 %A Joe Blow
665 %T Great Thoughts I've Thought
666 %D 1977
667 etc.
668
669 This utility converts these kind of databases to bibtex form, for
670 users of TeX and LaTex. Instructions:
671 1. Visit the file containing the refer-style database.
672 2. The command
673 M-x r2b-convert-buffer
674 converts the entire buffer, appending it's output by default in a
675 buffer named *Out*, and logging progress and errors in a buffer
676 named *Log*. The original file is never modified.
677 Note that results are appended to *Out*, so if that buffer
678 buffer already exists and contains material you don't want to
679 save, you should kill it first.
680 3. Switch to the buffer *Out* and save it as a named file.
681 4. To convert a single refer-style entry, simply position the cursor
682 at the entry and enter
683 M-x r2b-convert-record
684 Again output is appended to *Out* and errors are logged in *Log*.
685
686 This utility is very robust and pretty smart about determining the
687 type of the entry. It includes facilities for expanding refer macros
688 to text, or substituting bibtex macros. Do M-x describe-variable on
689 r2b-journal-abbrevs
690 r2b-booktitle-abbrevs
691 r2b-proceedings-list
692 for information on these features.
693
694 If you don't want to see this help message when you load this utility,
695 then include the following line in your .emacs file:
696 (setq r2b-load-quietly t)
697 To see this message again, perform
698 M-x r2b-help")
699
700
701 (defun r2b-help ()
702 "Print help message."
703 (interactive)
704 (with-output-to-temp-buffer "*Help*"
705 (princ r2b-help-message)))
706
707 (if (not r2b-load-quietly)
708 (r2b-help))
709
710 (message "r2b loaded")