Improving org-ref cite links with tooltips
Posted November 23, 2015 at 07:03 AM | categories: orgmode, orgref, emacs | tags:
Org-ref uses timers to give you messages about the cite link at point. I am not so crazy about the timer, there is always a (short) delay, and I have had trouble debugging timers in the past, and you have to put the point on the link. Since I wrote that code, I have learned some new things about Emacs, including dynamic tooltips. This will allow me to use the mouse to see what a cite link refers to. While reading documents, I am more likely to use a mouse than when typing a document, and getting a tooltip by hovering sounds like a good idea.
Here, we explore using dynamic tooltips on cite links. The idea is pretty simple, we tie into font-lock to add a function to the :help-echo property of a cite link. The function will go to point, and compute the citation string at point, which will be displayed as a tooltip when the mouse hovers over the citation.
Font-lock allows you to specify a function that sets match-data and that can have other side-effects, e.g. setting text properties. Org-ref has a regexp that defines cite links, which we use here, and a function that gets the citation string at point. We just go to the mouse position, and get that string, wrapped in a save-excursion macro so that point does not actually move. Then, we add the function to font-lock keywords, and we are done!
Here are some papers we wrote on using org-mode kitchin-2015-examp,kitchin-2015-data-surfac-scien and some other references in my bibliography zou-2014-cobal-embed,zlotea-2014-nanoal and one final example zhu-2015.
Here is the short code required to do this. You can see the tooltips in action here: https://www.youtube.com/watch?v=ifSmlId2rk0
(defun org-ref-match-next-cite-link (&optional limit) (when (re-search-forward org-ref-cite-re limit t) (add-text-properties (match-beginning 0) (match-end 0) (list 'help-echo (lambda (window object position) (save-excursion (goto-char position) (let ((s (org-ref-get-citation-string-at-point))) (with-temp-buffer (insert s) (fill-paragraph) (buffer-string))))))))) ; do this for this buffer (font-lock-add-keywords nil '((org-ref-match-next-cite-link (0 'org-ref-cite-face t))) t) (font-lock-fontify-buffer) ;; do this for every org file (add-hook 'org-mode-hook (lambda () (font-lock-add-keywords nil '((org-ref-match-next-cite-link (0 'org-ref-cite-face t))) t)))
Bibliography
- [kitchin-2015-data-surfac-scien] "John Kitchin", Data Sharing in Surface Science, "Surface Science ", (0), - (2015). link. doi.
- [kitchin-2015-examp] Kitchin, Examples of Effective Data Sharing in Scientific Publishing, ACS Catalysis, 5(6), 3894-3899 (2015). link. doi.
- [zhu-2015] Yinlong Zhu, Wei Zhou, Zhi-Gang Chen, Yubo Chen, , Chao Su, Moses Tad\'e & Zongping Shao, \ceSrNb_0.1Co_0.7Fe_0.2 O_3-$\delta$ Perovskite As a Next-Generation Electrocatalyst for Oxygen Evolution in Alkaline Solution, Angew. Chem. Int. Ed., 54(13), 3897-3901 (2015). link. doi.
- [zlotea-2014-nanoal] Zlotea, Morfin, Nguyen, Nguyen, , Nelayah, Ricolleau, Latroche & Piccolo, Nanoalloying Bulk-Immiscible Iridium and Palladium Inhibits Hydride Formation and Promotes Catalytic Performances, Nanoscale, 6(17), 9955 (2014). link. doi.
- [zou-2014-cobal-embed] Zou, Huang, Goswami, , Silva, Sathe, Mikmekov\'a, ska & Asefa, Cobalt-Embedded Nitrogen-Rich Carbon Nanotubes Efficiently Catalyze Hydrogen Evolution Reaction At All pH Values, Angewandte Chemie, , 4461-4465 (2014). link. doi.
Copyright (C) 2015 by John Kitchin. See the License for information about copying.
Org-mode version = 8.2.10