Skip to content

Instantly share code, notes, and snippets.

@bdarcus
Last active Sep 11, 2022
Embed
What would you like to do?
how to create a hydra for use with citar, and org-cite "follow processor" that uses it
(require 'org-element)
(require 'pretty-hydra)
(require 'oc)
(require 'citar)
(require 'citar-org)
(declare-function 'org-cite-register-processor "ext:oc")
;; define some interactive functions for the hydra
(defun citar-hydra-open-entry ()
"A hydra interface to 'citar-open-entry'."
(interactive)
(citar--open-entry (citar-key-at-point)))
(defun citar-hydra-open-note ()
"A hydra interface to 'citar--open-note'."
(interactive)
(let* ((key (citar-key-at-point))
(entry (citar--get-entry key)))
(citar--open-note key entry)))
(defun citar-hydra-open-library-file ()
"A hydra interface to 'citar--library-file-action'."
(interactive)
(let* ((key (citar-key-at-point))
(entry (citar--get-entry key)))
(citar--library-files-action (list (cons key entry)) 'open)))
(defun citar-hydra-open ()
"A hydra interface to 'citar-open'."
(interactive)
(let* ((key (citar-key-at-point))
(entry (citar--get-entry key)))
(citar-open (list (cons key entry)))))
;; hydra definition
(pretty-hydra-define citar-hydra-menu
(:title "Reference" :color teal :quit-key "q" :idle 0.5)
("Open Related"
(("o" citar-hydra-open "files or links")
("n" citar-hydra-open-note "notes")
("e" citar-hydra-open-entry "BibTeX entry")
("f" citar-hydra-open-library-file "library files"))
"Edit"
(("i" citar-insert-edit "insert or edit")
("d" citar-org-delete-citation "delete" :color red))))
;; org-cite follow procesor definition
;;;###autoload
(defun citar-hydra-follow (datum _)
"Org-cite-follow function to use a hydra menu for citar.
DATUM is the org element."
(when (null datum) (setq datum (org-element-context)))
(if (eq 'citation-reference (org-element-type datum))
(citar-hydra-menu/body)))
;;;###autoload
(org-cite-register-processor 'citar-hydra
:follow #'citar-hydra-follow)
@bdarcus
Copy link
Author

bdarcus commented Dec 2, 2021

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment