[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ISBN to BibTeX; and, soccer/football and FP

From: Emanuel Berg
Subject: ISBN to BibTeX; and, soccer/football and FP
Date: Sun, 19 Apr 2015 00:20:34 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

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:
;;   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-_
;;   :°    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:
;;  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 -
;;  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:

(require 'w3m-unisearch)

(defun isbn-search (&optional isbn)
  (w3m-web-search "";
                  (if isbn isbn (get-search-string "ISBN")) ))

(defun key-value (key &optional delimiter)
    (if (search-forward-regexp (concat key (if delimiter delimiter ": "))
                               (point-max) t) ; NOERROR
        (let ((start (point)))
          (let ((end (point)))
            (buffer-substring-no-properties start end) )))))

(defun get-title ()
    (goto-char 107) ; as it works after search
    (substring (thing-at-point 'line t) 0 -1) ))

;; BibTeX @book required data/fields: author/editor, title, publisher, year

(defun book-page-to-bibtex ()
    (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:

(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: ")
  (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
        (kill-new bib-str)
        (message "OK") ))))

(defun new-book () (interactive) (create-book t))

underground experts united

reply via email to

[Prev in Thread] Current Thread [Next in Thread]