Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add embark-bibtex frontend. #355

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 140 additions & 0 deletions embark-bibtex.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
;;; embark-bibtex.el --- A bibliography manager based on Embark

;; Author: Maxime Tréca <[email protected]>
;; Maintainer: Titus von der Malsburg <[email protected]>
;; URL: https://github.com/tmalsburg/embark-bibtex
;; Version: 1.0.0
;; Package-Requires: ((bibtex-completion "1.0.0") (embark "0.10")
;; (cl-lib "0.5"))

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; A BibTeX bibliography manager based on built-in completion, embark
;; completion actions and the bibtex-completion backend.
;;
;; Key features:
;; - Quick access to your bibliography from within Emacs
;; - Tightly integrated workflows
;; - Provides instant search results as you type
;; - Powerful search expressions
;; - Open the PDFs, URLs, or DOIs associated with an entry
;; - Insert LaTeX cite commands, Ebib links, or Pandoc citations,
;; BibTeX entries, or plain text references at point, attach PDFs to
;; emails
;; - Attach notes to publications
;;
;; Install:
;;
;; Put this file in a directory included in your load path or
;; install embark-bibtex from MELPA (preferred). Then add the
;; following in your Emacs startup file:
;;
;; (require 'embark-bibtex)
;;
;; Alternatively, you can use autoload:
;;
;; (autoload 'embark-bibtex "embark-bibtex" "" t)
;;
;; Requirements are parsebib, embark, s, dash, and f. The easiest way
;; to install these packages is through MELPA.
;;
;; Let embark-bibtex know where it can find your bibliography by
;; setting the variable `bibtex-completion-bibliography'. See the
;; manual for more details:
;;
;; https://github.com/tmalsburg/helm-bibtex/blob/master/README.embark-bibtex.org
;;
;; Usage:
;;
;; Do M-x embark-bibtex and start typing a search query when prompted.

;;; Code:

(require 'embark)
(require 'bibtex-completion)

(defcustom embark-bibtex-default-action 'embark-bibtex-open-any
"The default action for the `embark-bibtex` command."
:group 'bibtex-completion
:type 'function)

(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 embark and
passes it to ACTION."
`(defun ,name (cand)
(interactive "s ")
mtreca marked this conversation as resolved.
Show resolved Hide resolved
(,action (list cand))))

(embark-bibtex-embarkify-action bibtex-completion-open-any embark-bibtex-open-any)
(embark-bibtex-embarkify-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)

(defun embark-bibtex--get-candidates ()
"Return all keys from bibtex-completion-candidates."
(mapcar
(lambda (cand)
(cons (bibtex-completion-format-entry cand (1- (frame-width)))
(cdr (assoc "=key=" cand))))
(bibtex-completion-candidates)))

;; TODO Broken, use (cdr (assoc (completing-read "bib" candidates) candidates)) form
;;;###autoload
(defun embark-bibtex (bib-entry)

This comment was marked as outdated.

"Search BibTeX entries using `completing-read' and embark
actions."
(interactive
(list
(completing-read
mtreca marked this conversation as resolved.
Show resolved Hide resolved
"BibTeX entries: "
(lambda (string predicate action)
(if (eq action 'metadata)
'(metadata (category . bibtex))
(complete-with-action action (embark-bibtex--get-candidates) string predicate))))))
(apply embark-bibtex-default-action (list bib-entry)))

(embark-define-keymap embark-bibtex-map
mtreca marked this conversation as resolved.
Show resolved Hide resolved
"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))
Copy link

@minad minad Feb 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. At this point, this line is the only dependency with Embark. Remove it and the Embark dependency. This line can be written in the user config instead in order to make the keymap available to embark.

Copy link

@bdarcus bdarcus Feb 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in the end, the idea for a user who has selectrum setup as their completion framework, is they just install this package (or, ideally at some point, just bibtex-completion), and install and configure embark to use the keybindings, and so associate the bibtex-completion commands with the selected candidates?


(provide 'embark-bibtex)

;; Local Variables:
;; byte-compile-warnings: (not cl-functions obsolete)
;; coding: utf-8
;; indent-tabs-mode: nil
;; End:

;;; embark-bibtex.el ends here