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