Transient org cite follow processor - emacs-citar/citar GitHub Wiki

Possible idea for enhancement that just occurred to me, that isn't possible with embark (IUC), but may be here: the menu should indicate whether a command will return results, much like the minibuffer indicators. Basically, it would color-code the keys. I don't know how to implement that ATM, but please add it if you do.

Digging a bit more, not sure the above would work. But another idea: the transient could also enable setting the local citation style or command.

image

If you would rather not use embark-act in the buffer, and prefer hydra or transient, here's how you can create such a processor; this example using transient (though the screenshot above is using pretty-hydra).


;;; citar-menu.el --- transient menu for citar -*- lexical-binding: t; -*-
;;
;;; Code:
(require 'org-element)
(require 'transient)
(require 'citar)
(require 'citar-org)

;; First, create at-point functions for the key commands.
;; A hydra would use the same functions.

(defun citar-menu-open-entry ()
  "An at-point interface to 'citar-open-entry'."
  (interactive)
  (citar--open-entry (citar-key-at-point)))

(defun citar-menu-open-notes ()
    "An at-point interface to 'citar-open-notes'."
  (interactive)
  (let ((key (citar-key-at-point)))
    (citar-open-notes (list key))))

(defun citar-menu-open-files ()
  "An at-point interface to 'citar-open-files'."
  (interactive)
  (let ((key (citar-key-at-point)))
    (citar-open-files (list key))))

(defun citar-menu-open ()
    "An at-point interface to 'citar-open'."
  (interactive)
  (let ((key (citar-key-at-point)))
    (citar-open (list key))))

;; Next, create the transient menu definition.

(transient-define-prefix citar-menu-transient ()
  ["Reference(s)\n"
   ["Open"
    ("f" "library files" citar-menu-open-files)
    ("e" "BibTeX entry" citar-menu-open-entry)
    ("n" "notes" citar-menu-open-notes)
    ("o" "files or links" citar-menu-open)]

   ["Edit"
    ("i" "Insert or edit" citar-insert-edit)
    ("d" "Delete key/citation" citar-org-delete-citation)]])

;; Finally, create and register the org-cite processor.

(defun citar-menu-transient-follow (&optional datum _)
  "Follow function to use a transient menu for citar.
DATUM is the org element."
  (interactive)
  (when (null datum) (setq datum (org-element-context)))
  (if (eq 'citation-reference (org-element-type datum))
      (citar-menu-transient)))

;;;###autoload
(org-cite-register-processor 'citar-transient
  :follow #'citar-menu-transient-follow)

(provide 'citar-menu)
;;; citar-menu.el ends here