X-Git-Url: https://git.donarmstrong.com/?p=org-ref.git;a=blobdiff_plain;f=doi-utils.el;h=78736871a7c4852c4bd24e5e82ddae9282b86040;hp=abfa9436aabf9377ed1ded185775ab13920faab4;hb=d9d107c9e0aeb8c285c6aeef774059fee0bbac6d;hpb=91014fe9da3996754cf62ffc6177f8813eb38bad diff --git a/doi-utils.el b/doi-utils.el index abfa943..7873687 100644 --- a/doi-utils.el +++ b/doi-utils.el @@ -22,7 +22,7 @@ ;;; Commentary: -;; This package provides functionality to download PDFs and bibtex entries from a DOI, as well as to update a bibtex entry from a DOI. It depends slightly on org-ref, to determine where to save pdf files too, and where to insert bibtex entries in the default bibliography. +;; This package provides functionality to download PDFs and bibtex entries from a DOI, as well as to update a bibtex entry from a DOI. It depends slightly on org-ref, to determine where to save pdf files too, and where to insert bibtex entries in the default bibliography. ;; The principle commands you will use from here are: @@ -41,13 +41,14 @@ ;; There are some subtleties in doing this that are described here. To get the redirect, we have to use url-retrieve, and a callback function. The callback does not return anything, so we communicate through global variables. url-retrieve is asynchronous, so we have to make sure to wait for it to finish. (defvar *doi-utils-waiting* t - "stores waiting state for url retrieval.") + "Stores waiting state for url retrieval.") (defvar *doi-utils-redirect* nil - "stores redirect url from a callback function") + "Stores redirect url from a callback function.") (defun doi-utils-redirect-callback (&optional status) - "callback for url-retrieve to set the redirect" + "Callback for `url-retrieve' to set the redirect. +Optional argument STATUS Unknown why this is optional." (when (plist-get status :error) (signal (car (plist-get status :error)) (cdr(plist-get status :error)))) (when (plist-get status :redirect) ; is nil if there none @@ -60,7 +61,7 @@ ;; To actually get the redirect we use url-retrieve like this. (defun doi-utils-get-redirect (doi) - "get redirect url from dx.doi.org/doi" + "Get redirect url from dx.DOI.org/doi." ;; we are going to wait until the url-retrieve is done (setq *doi-utils-waiting* t) ;; start with no redirect. it will be set in the callback. @@ -78,12 +79,13 @@ ;; Once we have a redirect for a particular doi, we need to compute the url to the pdf. We do this with a series of functions. Each function takes a single argument, the redirect url. If it knows how to compute the pdf url it does, and returns it. We store the functions in a variable: (defvar doi-utils-pdf-url-functions nil - "list of functions that return a url to a pdf from a redirect url. Each function takes one argument, the redirect url. The function must return a pdf-url, or nil.") + "List of functions that return a url to a pdf from a redirect url. Each function takes one argument, the redirect url. The function must return a pdf-url, or nil.") ;; ** APS journals (defun aps-pdf-url (*doi-utils-redirect*) + "Get url to the pdf from *DOI-UTILS-REDIRECT*." (when (string-match "^http://journals.aps.org" *doi-utils-redirect*) (replace-regexp-in-string "/abstract/" "/pdf/" *doi-utils-redirect*))) @@ -91,6 +93,7 @@ ;; ** Science (defun science-pdf-url (*doi-utils-redirect*) + "Get url to the pdf from *DOI-UTILS-REDIRECT*." (when (string-match "^http://www.sciencemag.org" *doi-utils-redirect*) (concat *doi-utils-redirect* ".full.pdf"))) @@ -98,6 +101,7 @@ ;; ** Nature (defun nature-pdf-url (*doi-utils-redirect*) + "Get url to the pdf from *DOI-UTILS-REDIRECT*." (when (string-match "^http://www.nature.com" *doi-utils-redirect*) (let ((result *doi-utils-redirect*)) (setq result (replace-regexp-in-string "/full/" "/pdf/" result)) @@ -116,18 +120,21 @@ (defun doi-utils-get-wiley-pdf-url (redirect-url) - "wileyscience direct hides the pdf url in html. we get it out here" + "Wileyscience direct hides the pdf url in html. +We get it out here by parsing the html. +Argument REDIRECT-URL URL you are redirected to." (setq *doi-utils-waiting* t) (url-retrieve redirect-url (lambda (status) - (beginning-of-buffer) + (goto-char (point-min)) (re-search-forward "