X-Git-Url: https://git.donarmstrong.com/?p=org-ref.git;a=blobdiff_plain;f=arxiv.el;h=5b4a8e0427cdf6600a73aa94dfe5f1e134c0138e;hp=66ceafefb02e887f5b27397e81a39afa9c886a20;hb=0dbc1db6e2fedffc4725c6cd8680fa8f08098d67;hpb=3d258f2f382d98aa73fcf36ab1cb494a7bcd1cc3 diff --git a/arxiv.el b/arxiv.el index 66ceafe..5b4a8e0 100644 --- a/arxiv.el +++ b/arxiv.el @@ -79,7 +79,7 @@ (defun arxiv-add-bibtex-entry (arxiv-number bibfile) "Add bibtex entry for ARXIV-NUMBER to BIBFILE." (interactive - (list (read-input "arxiv: ") + (list (read-string "arxiv: ") ;; now get the bibfile to add it to (ido-completing-read "Bibfile: " @@ -93,5 +93,29 @@ (save-buffer))) +(defun arxiv-get-pdf (arxiv-number pdf) + "Retrieve a pdf for ARXIV-NUMBER and save it to PDF." + (interactive "sarxiv: \nsPDF: ") + (let ((pdf-url (with-current-buffer + (url-retrieve-synchronously + (concat + "http://arxiv.org/abs/" arxiv-number)) + ;; + (search-forward-regexp + "name=\\\"citation_pdf_url\\\" content=\\\"\\(.*\\)\\\"") + (match-string 1)))) + (url-copy-file pdf-url pdf) + ;; now check if we got a pdf + (with-temp-buffer + (insert-file-contents pdf-file) + ;; PDFS start with %PDF-1.x as the first few characters. + (if (not (string= (buffer-substring 1 6) "%PDF-")) + (progn + (message "%s" (buffer-string)) + (delete-file pdf-file)) + (message "%s saved" pdf-file))) + + (org-open-file pdf))) + (provide 'arxiv) ;;; arxiv.el ends here