org-mode links meet hydra
Posted February 22, 2015 at 07:06 PM | categories: hydra, orgmode, emacs | tags:
I have played with a lot of options to give org-mode links extra functionality. Here are a few of the ideas I have looked at so far.
- Enabling right clicks on links
- A home made minibuffer menu in org-ref
- A helm buffer in org-ref
Here, I want to explore a hydra menu for a link. The idea is pretty simple, we need functions that do something with the link at point, and a hydra interface to call them. This turned out to be a little tricky. I could not get the path from the link in the link lambda function, and we need a way to pass the path to the function. I use a global variable for that. I wish there was another way to do that, but this does actually work. We illustrate it here with a more functional doi link.
(defun doi-crossref () "Search DOI in CrossRef." (interactive) (browse-url (format "http://search.crossref.org/?q=%s" *doi-hydra-path*))) (defun doi-google-scholar () "Google scholar the doi." (interactive) (browse-url (format "http://scholar.google.com/scholar?q=%s" *doi-hydra-path*))) (defun doi-pubmed () "Pubmed the doi." (interactive) (browse-url (format "http://www.ncbi.nlm.nih.gov/pubmed/?term=%s" (url-hexify-string *doi-hydra-path*)))) (defhydra doi-hydra () "org-ref" ("c" doi-crossref "Crossref") ("g" doi-google-scholar "Google Scholar") ("p" doi-pubmed "Pubmed")) (org-add-link-type "doi" (lambda (path) (setq *doi-hydra-path* path) (doi-hydra/body)))
lambda | (path) | (setq doi-hydra-path path) | (doi-hydra/body) |
Now for a test, 10.1021/jp047349j.
It works fine, when you click on a link, you get a minibuffer menu with context hints, and pressing any other key than is defined simply cancels the command.
Copyright (C) 2015 by John Kitchin. See the License for information about copying.
Org-mode version = 8.2.10