Skip to content

Instantly share code, notes, and snippets.

@bdarcus
Last active December 21, 2022 15:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bdarcus/09dff264a75ae78330d8ee1a1ee5e1b2 to your computer and use it in GitHub Desktop.
Save bdarcus/09dff264a75ae78330d8ee1a1ee5e1b2 to your computer and use it in GitHub Desktop.
how to create a hydra for use with citar, and org-cite "follow processor" that uses it
;;; citar-hydra.el --- hydra menu for citar -*- lexical-binding: t; -*-
(require 'org-element)
(require 'pretty-hydra)
(require 'oc)
(require 'citar)
(require 'citar-org)
(declare-function 'org-cite-register-processor "ext:oc")
(declare-function 'citar--library-file-action "ext:citar")
(declare-function 'citar-open-note "ext:citar")
(declare-function 'citar-get-entry "ext:citar")
;; 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)
(citar--bibliography-files)))
(defun citar-hydra-open-note ()
"A hydra interface to 'citar-open-notes'."
(interactive)
(let ((key (citar-key-at-point)))
(citar-open-notes (list key))))
(defun citar-hydra-open-library-file ()
"A hydra interface to 'citar--library-file-action'."
(interactive)
(let ((key (citar-key-at-point)))
(citar--library-file-action key 'open)))
(defun citar-hydra-open ()
"A hydra interface to 'citar-open'."
(interactive)
(let ((key (citar-key-at-point)))
(citar-open (list key))))
;; 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)
;;; citar-hydra.el ends here
@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