summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2014-05-12 21:15:33 -0400
committerKyle Meyer <kyle@kyleam.com>2014-05-12 21:15:33 -0400
commit9df6689fabbcdd1e8fd68143ce2a529cc21ab7b8 (patch)
tree74cb892da90b30d3e3397053387849df0c7e2cc3 /lisp
parent241fdb1e67d44cf31de154f85f1465e820bf0f39 (diff)
downloademacs.d-9df6689fabbcdd1e8fd68143ce2a529cc21ab7b8.tar.gz
Add km/browse-doi
Diffstat (limited to 'lisp')
-rw-r--r--lisp/init-bib.el21
1 files changed, 21 insertions, 0 deletions
diff --git a/lisp/init-bib.el b/lisp/init-bib.el
index ecdd1f1..091b82a 100644
--- a/lisp/init-bib.el
+++ b/lisp/init-bib.el
@@ -54,4 +54,25 @@ capitalized."
(defadvice bibtex-clean-entry (before convert-to-title-case activate)
(km/bibtex-use-title-case))
+(defun km/browse-doi (doi)
+ "Open DOI in browser.
+The link is opened using the settings of `org-doi-server-url'.
+When called interactively, DOI is taken from the text under
+point."
+ (interactive (list (km/doi-at-point)))
+ (browse-url (org-link-escape-browser (concat org-doi-server-url doi))))
+
+(defun km/doi-at-point ()
+ "Return DOI at point.
+This is a hack that uses `(thing-at-point 'url)' and then removes
+the leading 'http://'. The DOI format is not verified in any
+way."
+ (save-excursion
+ (when (equal (thing-at-point 'word) "doi")
+ (backward-word)
+ (re-search-forward "doi:[ \t\n]*"))
+ (-if-let (http-doi (thing-at-point 'url))
+ (replace-regexp-in-string "http://" "" http-doi)
+ (user-error "No DOI found at point"))))
+
(provide 'init-bib)