* ISBN to BibTeX; and, soccer/football and FP
@ 2015-04-18 22:20 Emanuel Berg
0 siblings, 0 replies; only message in thread
From: Emanuel Berg @ 2015-04-18 22:20 UTC (permalink / raw)
To: help-gnu-emacs
Here is an interesting demo of a great idea: get
BibTeX entries from only the ISBN as input!
You know, some people say it is "functional
programming", some say it is "database normalization"
- or even "relational algebra" or "set theory"... That
sounds a bit complicated, so let me instead put it the
form of a metaphor.
Now, you might be familiar with the tic-tac-toe style
(and ditto game plan) which the top European club and
national teams in football/soccer relied on for some
time (and perhaps still do). It was Barcelona and
Spain who took it to the world, and for a while they
took the world as well, using precisely it.
The strategy is simple. Keep the ball within your team
and constantly move it between your players using
short passes. Then you try to pick the lock slow and
steady until...
Stop it! One more time: don't let the opposite team
have the ball... move the ball fast within your team -
hey, that sounds like a good, simple strategy, one
that would come to mind at once, for anyone in the
game, one would think! Then why didn't the teams play
like that in the 50s or 70s or in even more
recent days?
Indeed, the truth to the matter is: people who can't
do something like to explain how other people can do
something by giving it a fancy name. The demystifies
it to them, makes it a little less disturbing, their
egos are kept intact... phew, we can all breath,
inhale and exhale, relax...
Personally, I don't have any such concerns.
Some people spell it tic-tac-toe. I spell it
S K I L L S.
'nuff said.
;; 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 depends 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
(require 'w3m-unisearch)
(defun isbn-search (&optional isbn)
(interactive)
(w3m-web-search "http://www.isbnsearch.org/isbn/%s#book"
(if isbn isbn (get-search-string "ISBN")) ))
(defun key-value (key &optional delimiter)
(save-excursion
(if (search-forward-regexp (concat key (if delimiter delimiter ": "))
(point-max) t) ; NOERROR
(let ((start (point)))
(end-of-line)
(let ((end (point)))
(buffer-substring-no-properties start end) )))))
(defun get-title ()
(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 ()
(interactive)
(save-excursion
(goto-char (point-min))
(let ((title (get-title))
(data (mapcar 'key-value
'("author" "publisher" "published" "isbn-10")) ))
(eval `(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 title = {%s},\n author = {%s},\n publisher = {%s},\n year = {%s},\n ISBN = {%s}\n}"
title author publisher year isbn))
(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 () (interactive) (create-book t))
--
underground experts united
http://user.it.uu.se/~embe8573
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2015-04-18 22:20 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-18 22:20 ISBN to BibTeX; and, soccer/football and FP Emanuel Berg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).