;;; isbn --- make Bibtex entries out of ISBNs ;; ;;; Commentary: ;; ;; This file: http://user.it.uu.se/~embe8573/conf/emacs-init/isbn.el ;; ;; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-_ ;; :° cool ISBN, BibTeX, and Emacs-w3m demo `. : ;; : : ;; :.. by Emanuel Berg : ;; '-------------------------------------------------' ;; ;; This tool is used to get a BibTeX @book entry - ;; complete with data - with the ISBN of the book as ;; the only necessary input. Here is how it works: ;; ;; 1. The ISBN is inputted. ;; ;; 2. Emacs-w3m shows a web page with the search ;; result for that ISBN. ;; ;; 3. If the result is sensible, a second ;; function invocation will format, populate, ;; and push the resulting BibTeX entry onto ;; the kill ring. Then just yank it in the ;; .bib buffer, compile, and be done with it. ;; ;; To try, either evaluate this: ;; ;; (isbn-search "0525953094") ;; ;; Either that, or position point at/before the first ;; digit in the above ISBN (i.e., the zero digit), ;; then do `M-x isbn-search RET'. ;; ;; You should now see this page in Emacs-w3m: ;; ;; http://www.isbnsearch.org/isbn/0525953094 ;; ;; Now, do `book-page-to-bibtex' and notice the "OK" ;; in the echo area. Last, find your .bib file and ;; yank the entry: ;; ;; @book{, ;; title = {Edge of Eternity: ...}, ;; author = {Ken Follett}, ;; publisher = {Dutton}, ;; year = {September 2014}, ;; ISBN = {0525953094} ;; } ;; ;; Yes, this only works for BibTeX @books and the ;; particular web site http://www.isbnsearch.org - ;; but change the code to specify another type of ;; reference (or site) to make it work there as well ;; - it shouldn't be that different how those bozos ;; present their incomplete material. Use the source, ;; Luke! (The same goes if anything breaks - which is ;; likely, someday - because it depended on other ;; people's implementations of their stuff as ;; well...) ;; ;; [1] `isbn-search' is part of an Emacs-w3m ;; search interface I made. You can find it here: ;; http://user.it.uu.se/~embe8573/conf/emacs-init/w3m/w3m-unisearch.el ;; ;;; Code: (require 'w3m-unisearch) (defun isbn-search (&optional isbn) "Search the web for ISBN. Prompt string if ISBN isn't provided." (interactive) (w3m-web-search "http://www.isbnsearch.org/isbn/%s#book" (or isbn (get-search-string "ISBN")) )) (defun key-value (key &optional delimiter) "Search for the value of KEY followed by DELIMITER. DELIMITER defaults to a colon followed by a whitespace." (save-excursion (if (search-forward-regexp (concat key (or delimiter ": ")) (point-max) t) ; NOERROR (let ((start (point))) (end-of-line) (let ((end (point))) (buffer-substring-no-properties start end) ))))) (defun get-title () "Get the title of the book." (save-excursion (goto-char 107) ; as it works after http://www.isbnsearch.org search (substring (thing-at-point 'line t) 0 -1) )) ;; BibTeX @book required data/fields: author/editor, title, publisher, year (defun book-page-to-bibtex () "Make a Biblatex entry from the web page." (interactive) (save-excursion (goto-char (point-min)) (let ((title (get-title)) (data (mapcar #'key-value '("authors?" "publisher" "published" "isbn-10")) )) (apply (function create-book) nil title data)) )) ; don't INSERT ;; done with the w3m part, now BibTeX only - ;; after yank, try `my-bibtex-autokey' from: ;; ;; http://user.it.uu.se/~embe8573/conf/emacs-init/my-bibtex.el (defun create-book (insert &optional title author publisher year isbn) "INSERT \(or `kill-new'\) a BibTeX book. Use the optional data TITLE, AUTHOR, PUBLISHER, YEAR, and/or ISBN. If there is not any data, make a BibTeX skeleton entry." (interactive "sTitle: \nsAuthor: \nsPublisher: \nsYear: \nsISBN: ") (beginning-of-line) (let*((bib-str-nils (format "@book{,\n author = {%s},\n ISBN = {%s},\n publisher = {%s},\n title = {%s},\n year = {%s}\n}" author isbn publisher title year)) (bib-str (replace-regexp-in-string "{nil}" "{}" bib-str-nils)) ) (if insert (let ((start (point))) (insert bib-str) (goto-char start) (forward-char 24) ) ; point at first field (progn (kill-new bib-str) (message "OK") )))) (defun new-book () "Create a void Biblatex entry. This is an interface to `create-book'." (interactive) (create-book t)) ; INSERT (provide 'isbn) ;;; isbn.el ends here