Skip to content

Instantly share code, notes, and snippets.

@bdarcus
Last active January 27, 2021 00:16
Show Gist options
  • Save bdarcus/e4d878d7e6841056d12645deeef48266 to your computer and use it in GitHub Desktop.
Save bdarcus/e4d878d7e6841056d12645deeef48266 to your computer and use it in GitHub Desktop.
; (start of) a completing-read (and hence selectrum) compatible frontend
; to bibtex-completion, for equivalent funtionality to helm/ivy-bibtex
;
; adapted from https://github.com/tmalsburg/helm-bibtex/issues/353#issuecomment-766844852
(require 'embark)
(require 'bibtex-completion)
(defmacro embark-bibtex-embarkify-action (action name)
"Wraps the function ACTION in another function named NAME which
extracts the key from the candidate selected in from the completion UI and
passes it to ACTION."
`(defun ,name (candidate)
(interactive "s ")
(let ((key (cdr (assoc "=key=" (assoc candidate (bibtex-completion-candidates))))))
(,action (list key)))))
(embark-bibtex-embarkify-action bibtex-completion-open-any embark-bibtex-open-any)
(embark-bibtex-embarkfiy-action bibtex-completion-open-pdf embark-bibtex-open-pdf)
(embark-bibtex-embarkify-action bibtex-completion-open-url-or-doi embark-bibtex-open-url-or-doi)
(embark-bibtex-embarkify-action bibtex-completion-insert-citation embark-bibtex-insert-citation)
(embark-bibtex-embarkify-action bibtex-completion-insert-reference embark-bibtex-insert-reference)
(embark-bibtex-embarkify-action bibtex-completion-insert-key embark-bibtex-insert-key)
(embark-bibtex-embarkify-action bibtex-completion-insert-bibtex embark-bibtex-insert-bibtex)
(embark-bibtex-embarkify-action bibtex-completion-add-PDF-attachment embark-bibtex-add-PDF-attachment)
(embark-bibtex-embarkify-action bibtex-completion-edit-notes embark-bibtex-edit-notes)
(embark-bibtex-embarkify-action bibtex-completion-show-entry embark-bibtex-show-entry)
(embark-bibtex-embarkify-action bibtex-completion-add-pdf-to-library embark-bibtex-add-pdf-to-library)
;;;###autoload
(defun embark-bibtex (bib-entry)
(interactive
(list (completing-read "Bib: " (bibtex-completion-candidates) :category 'bib)))
;; TODO Call embark-bibtex-default-action if no embark action is selected
)
(embark-define-keymap embark-bibtex-map
"Keymap for actions for bibtex."
("p" embark-bibtex-open-pdf)
("u" embark-bibtex-open-url-or-doi)
("c" embark-bibtex-insert-citation)
("r" embark-bibtex-insert-reference)
("k" embark-bibtex-insert-key)
("b" embark-bibtex-insert-bibtex)
("a" embark-bibtex-add-PDF-attachment)
("e" embark-bibtex-edit-notes)
("s" embark-bibtex-show-entry)
("l" embark-bibtex-add-pdf-to-library))
(add-to-list 'embark-keymap-alist '(bib . embark-bibtex-map))
(provide 'embark-bibtex)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment