From 9b3165790436a0e3cb329a6730d2f972ece6017d Mon Sep 17 00:00:00 2001 From: mtreca Date: Mon, 1 Feb 2021 21:12:29 +0100 Subject: [PATCH 1/6] [WIP] Add embark-bibtex frontend. --- embark-bibtex.el | 150 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 embark-bibtex.el diff --git a/embark-bibtex.el b/embark-bibtex.el new file mode 100644 index 0000000..e5f9d17 --- /dev/null +++ b/embark-bibtex.el @@ -0,0 +1,150 @@ +;;; embark-bibtex.el --- A bibliography manager based on Embark + +;; Author: Maxime Tréca +;; Maintainer: Titus von der Malsburg +;; 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") (marginalia "0.2")) + +;; 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 . + +;;; 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 'marginalia) +(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 ") + (,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) + (cdr (assoc "=key=" cand))) + (bibtex-completion-candidates))) + +;;;###autoload +(defun embark-bibtex (bib-entry) + "Search BibTeX entries using `completing-read' and embark +actions." + (interactive + (list + (completing-read + "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))) + +(defun marginalia-annotate-bibtex (bib-key) + "Return completion annotations for a bibtex key." + (let ((bib-entry (bibtex-completion-get-entry bib-key))) + (concat + (marginalia--fields + ((cdr (assoc "title" bib-entry)) :width 70 :truncate 70) + ((cdr (assoc "author" bib-entry)) :width 30 :truncate 30) + ((cdr (assoc "year" bib-entry)) :width 5 :truncate 5))))) + +(add-to-list 'marginalia-annotators-light '(bibtex . marginalia-annotate-bibtex)) +(add-to-list 'marginalia-annotators-heavy '(bibtex . marginalia-annotate-bibtex)) + +(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) + +;; Local Variables: +;; byte-compile-warnings: (not cl-functions obsolete) +;; coding: utf-8 +;; indent-tabs-mode: nil +;; End: + +;;; embark-bibtex.el ends here From 77f2ccaf35ccce3e172eb151d151af8935000fab Mon Sep 17 00:00:00 2001 From: mtreca Date: Thu, 4 Feb 2021 18:51:17 +0100 Subject: [PATCH 2/6] Remove marginalia dependency --- embark-bibtex.el | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/embark-bibtex.el b/embark-bibtex.el index e5f9d17..1d3e1e5 100644 --- a/embark-bibtex.el +++ b/embark-bibtex.el @@ -5,7 +5,7 @@ ;; 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") (marginalia "0.2")) +;; (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 @@ -64,7 +64,6 @@ ;;; Code: (require 'embark) -(require 'marginalia) (require 'bibtex-completion) (defcustom embark-bibtex-default-action 'embark-bibtex-open-any @@ -94,10 +93,13 @@ passes it to ACTION." (defun embark-bibtex--get-candidates () "Return all keys from bibtex-completion-candidates." - (mapcar (lambda (cand) - (cdr (assoc "=key=" cand))) - (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) "Search BibTeX entries using `completing-read' and embark @@ -112,18 +114,6 @@ actions." (complete-with-action action (embark-bibtex--get-candidates) string predicate)))))) (apply embark-bibtex-default-action (list bib-entry))) -(defun marginalia-annotate-bibtex (bib-key) - "Return completion annotations for a bibtex key." - (let ((bib-entry (bibtex-completion-get-entry bib-key))) - (concat - (marginalia--fields - ((cdr (assoc "title" bib-entry)) :width 70 :truncate 70) - ((cdr (assoc "author" bib-entry)) :width 30 :truncate 30) - ((cdr (assoc "year" bib-entry)) :width 5 :truncate 5))))) - -(add-to-list 'marginalia-annotators-light '(bibtex . marginalia-annotate-bibtex)) -(add-to-list 'marginalia-annotators-heavy '(bibtex . marginalia-annotate-bibtex)) - (embark-define-keymap embark-bibtex-map "Keymap for actions for bibtex." ("p" embark-bibtex-open-pdf) From e477aeaa42a9c6499b6eec8ac2fcaa64b21cdab4 Mon Sep 17 00:00:00 2001 From: mtreca Date: Fri, 5 Feb 2021 15:21:11 +0100 Subject: [PATCH 3/6] Remove embark dependency. --- embark-bibtex.el | 56 +++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/embark-bibtex.el b/embark-bibtex.el index 1d3e1e5..6a35684 100644 --- a/embark-bibtex.el +++ b/embark-bibtex.el @@ -4,8 +4,7 @@ ;; Maintainer: Titus von der Malsburg ;; 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")) +;; Package-Requires: ((bibtex-completion "1.0.0") (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 @@ -63,9 +62,22 @@ ;;; Code: -(require 'embark) (require 'bibtex-completion) +(defvar embark-bibtex-map + (let ((map (make-sparse-keymap))) + (define-key map (kbd "p") 'embark-bibtex-open-pdf) + (define-key map (kbd "u") 'embark-bibtex-open-url-or-doi) + (define-key map (kbd "c") 'embark-bibtex-insert-citation) + (define-key map (kbd "r") 'embark-bibtex-insert-reference) + (define-key map (kbd "k") 'embark-bibtex-insert-key) + (define-key map (kbd "b") 'embark-bibtex-insert-bibtex) + (define-key map (kbd "a") 'embark-bibtex-add-PDF-attachment) + (define-key map (kbd "e") 'embark-bibtex-edit-notes) + (define-key map (kbd "s") 'embark-bibtex-show-entry) + (define-key map (kbd "l") 'embark-bibtex-add-pdf-to-library) + map)) + (defcustom embark-bibtex-default-action 'embark-bibtex-open-any "The default action for the `embark-bibtex` command." :group 'bibtex-completion @@ -76,7 +88,8 @@ extracts the key from the candidate selected in embark and passes it to ACTION." `(defun ,name (cand) - (interactive "s ") + (interactive + (list (embark-bibtex--read "BibTeX entries: "))) (,action (list cand)))) (embark-bibtex-embarkify-action bibtex-completion-open-any embark-bibtex-open-any) @@ -99,36 +112,25 @@ passes it to ACTION." (cdr (assoc "=key=" cand)))) (bibtex-completion-candidates))) -;; TODO Broken, use (cdr (assoc (completing-read "bib" candidates) candidates)) form +(defun embark-bibtex--read () + "Read bibtex-completion entries for completion." + (completing-read + "BibTeX entries: " + (lambda (string predicate action) + (if (eq action 'metadata) + '(metadata (category . bibtex)) + (complete-with-action action (embark-bibtex--get-candidates) string predicate))))) + ;;;###autoload (defun embark-bibtex (bib-entry) "Search BibTeX entries using `completing-read' and embark actions." (interactive - (list - (completing-read - "BibTeX entries: " - (lambda (string predicate action) - (if (eq action 'metadata) - '(metadata (category . bibtex)) - (complete-with-action action (embark-bibtex--get-candidates) string predicate)))))) + (progn + (bibtex-completion-init) + (list (cdr (assoc (embark-bibtex--read) (embark-bibtex--get-candidates)))))) (apply embark-bibtex-default-action (list bib-entry))) -(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) ;; Local Variables: From ad8f67508e2c5c8893a91c872ced4307e54704ee Mon Sep 17 00:00:00 2001 From: mtreca Date: Fri, 5 Feb 2021 20:06:05 +0100 Subject: [PATCH 4/6] Better macro. Fix action selection. --- bibtex-actions.el | 85 +++++++++++++++++++++++++++ embark-bibtex.el | 142 ---------------------------------------------- 2 files changed, 85 insertions(+), 142 deletions(-) create mode 100644 bibtex-actions.el delete mode 100644 embark-bibtex.el diff --git a/bibtex-actions.el b/bibtex-actions.el new file mode 100644 index 0000000..f5ff6a8 --- /dev/null +++ b/bibtex-actions.el @@ -0,0 +1,85 @@ +;;; bibtex-actions.el --- Bibliography manager action + +;;; Code: + +(require 'bibtex-completion) + +(defvar bibtex-actions-map + (let ((map (make-sparse-keymap))) + (define-key map (kbd "p") 'bibtex-actions-open-pdf) + (define-key map (kbd "u") 'bibtex-actions-open-url-or-doi) + (define-key map (kbd "c") 'bibtex-actions-insert-citation) + (define-key map (kbd "r") 'bibtex-actions-insert-reference) + (define-key map (kbd "k") 'bibtex-actions-insert-key) + (define-key map (kbd "b") 'bibtex-actions-insert-bibtex) + (define-key map (kbd "a") 'bibtex-actions-add-PDF-attachment) + (define-key map (kbd "e") 'bibtex-actions-edit-notes) + (define-key map (kbd "s") 'bibtex-actions-show-entry) + (define-key map (kbd "l") 'bibtex-actions-add-pdf-to-library) + map)) + +(defcustom bibtex-actions-default-action 'bibtex-actions-open-any + "The default action for the `bibtex-actions` command." + :group 'bibtex-completion + :type 'function) + +(defmacro bibtex-actions-define-action (action doc) + "Wraps the function ACTION in another function named NAME which +extracts the key from the candidate selected in embark and +passes it to ACTION." + (let* ((old-name (symbol-name action)) + (mid-name (substring old-name 17 (length old-name))) + (new-name (intern (concat "bibtex-actions" mid-name)))) + `(defun ,new-name (cand) + ,doc + (interactive + (list (cdr (assoc (bibtex-actions--read) (bibtex-actions--get-candidates))))) + (,action (list cand))))) + +(bibtex-actions-define-action bibtex-completion-open-any "") +(bibtex-actions-define-action bibtex-completion-open-pdf "") +(bibtex-actions-define-action bibtex-completion-open-url-or-doi "") +(bibtex-actions-define-action bibtex-completion-insert-citation "") +(bibtex-actions-define-action bibtex-completion-insert-reference "") +(bibtex-actions-define-action bibtex-completion-insert-key "") +(bibtex-actions-define-action bibtex-completion-insert-bibtex "") +(bibtex-actions-define-action bibtex-completion-add-PDF-attachment "") +(bibtex-actions-define-action bibtex-completion-edit-notes "") +(bibtex-actions-define-action bibtex-completion-show-entry "") +(bibtex-actions-define-action bibtex-completion-add-pdf-to-library "") + +(defun bibtex-actions--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))) + +(defun bibtex-actions--read () + "Read bibtex-completion entries for completion." + (completing-read + "BibTeX entries: " + (lambda (string predicate action) + (if (eq action 'metadata) + '(metadata (category . bibtex)) + (complete-with-action action (bibtex-actions--get-candidates) string predicate))))) + +;;;###autoload +(defun bibtex-actions (bib-entry) + "Search BibTeX entries using `completing-read' and actions." + (interactive + (progn + (bibtex-completion-init) + (list (cdr (assoc (bibtex-actions--read) (bibtex-actions--get-candidates)))))) + (apply bibtex-actions-default-action (list bib-entry))) + +(provide 'bibtex-actions) + +;; Local Variables: +;; byte-compile-warnings: (not cl-functions obsolete) +;; coding: utf-8 +;; indent-tabs-mode: nil +;; End: + +;;; bibtex-actions.el ends here diff --git a/embark-bibtex.el b/embark-bibtex.el deleted file mode 100644 index 6a35684..0000000 --- a/embark-bibtex.el +++ /dev/null @@ -1,142 +0,0 @@ -;;; embark-bibtex.el --- A bibliography manager based on Embark - -;; Author: Maxime Tréca -;; Maintainer: Titus von der Malsburg -;; URL: https://github.com/tmalsburg/embark-bibtex -;; Version: 1.0.0 -;; Package-Requires: ((bibtex-completion "1.0.0") (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 . - -;;; 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 'bibtex-completion) - -(defvar embark-bibtex-map - (let ((map (make-sparse-keymap))) - (define-key map (kbd "p") 'embark-bibtex-open-pdf) - (define-key map (kbd "u") 'embark-bibtex-open-url-or-doi) - (define-key map (kbd "c") 'embark-bibtex-insert-citation) - (define-key map (kbd "r") 'embark-bibtex-insert-reference) - (define-key map (kbd "k") 'embark-bibtex-insert-key) - (define-key map (kbd "b") 'embark-bibtex-insert-bibtex) - (define-key map (kbd "a") 'embark-bibtex-add-PDF-attachment) - (define-key map (kbd "e") 'embark-bibtex-edit-notes) - (define-key map (kbd "s") 'embark-bibtex-show-entry) - (define-key map (kbd "l") 'embark-bibtex-add-pdf-to-library) - map)) - -(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 - (list (embark-bibtex--read "BibTeX entries: "))) - (,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))) - -(defun embark-bibtex--read () - "Read bibtex-completion entries for completion." - (completing-read - "BibTeX entries: " - (lambda (string predicate action) - (if (eq action 'metadata) - '(metadata (category . bibtex)) - (complete-with-action action (embark-bibtex--get-candidates) string predicate))))) - -;;;###autoload -(defun embark-bibtex (bib-entry) - "Search BibTeX entries using `completing-read' and embark -actions." - (interactive - (progn - (bibtex-completion-init) - (list (cdr (assoc (embark-bibtex--read) (embark-bibtex--get-candidates)))))) - (apply embark-bibtex-default-action (list bib-entry))) - -(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 From 46df984f278b4eea299ba03623387c7968f8e77f Mon Sep 17 00:00:00 2001 From: mtreca Date: Sat, 6 Feb 2021 10:26:08 +0100 Subject: [PATCH 5/6] Add docstrings to bibtex actions. --- bibtex-actions.el | 63 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 52 insertions(+), 11 deletions(-) diff --git a/bibtex-actions.el b/bibtex-actions.el index f5ff6a8..bb6752c 100644 --- a/bibtex-actions.el +++ b/bibtex-actions.el @@ -36,17 +36,58 @@ passes it to ACTION." (list (cdr (assoc (bibtex-actions--read) (bibtex-actions--get-candidates))))) (,action (list cand))))) -(bibtex-actions-define-action bibtex-completion-open-any "") -(bibtex-actions-define-action bibtex-completion-open-pdf "") -(bibtex-actions-define-action bibtex-completion-open-url-or-doi "") -(bibtex-actions-define-action bibtex-completion-insert-citation "") -(bibtex-actions-define-action bibtex-completion-insert-reference "") -(bibtex-actions-define-action bibtex-completion-insert-key "") -(bibtex-actions-define-action bibtex-completion-insert-bibtex "") -(bibtex-actions-define-action bibtex-completion-add-PDF-attachment "") -(bibtex-actions-define-action bibtex-completion-edit-notes "") -(bibtex-actions-define-action bibtex-completion-show-entry "") -(bibtex-actions-define-action bibtex-completion-add-pdf-to-library "") +(bibtex-actions-define-action + bibtex-completion-open-any + "Open the PDFs associated with the BibTeX entry. +If multiple PDFs are found, ask for the one to open using +‘completion-read’. If no PDF is found, try to open a URL or DOI +in the browser instead.") + +(bibtex-actions-define-action + bibtex-completion-open-pdf + "Open the PDFs associated with the BibTeX entry. +If multiple PDFs are found, ask for the one to open using +‘completion-read’.") + +(bibtex-actions-define-action + bibtex-completion-open-url-or-doi + "Open the URL or DOI associated with a BibTeX entry in a + browser.") + +(bibtex-actions-define-action + bibtex-completion-insert-citation + "Insert citation for BibTeX entry at point.") + +(bibtex-actions-define-action + bibtex-completion-insert-reference + "Insert reference for BibTeX entry at point.") + +(bibtex-actions-define-action + bibtex-completion-insert-key + "Insert key for BibTeX entry at point.") + +(bibtex-actions-define-action + bibtex-completion-insert-bibtex + "Insert entry for BibTeX entry at point.") + +(bibtex-actions-define-action + bibtex-completion-add-PDF-attachment + "Attach the PDF of a BibTeX entry where available.") + +(bibtex-actions-define-action + bibtex-completion-edit-notes + "Open the notes associated with a BibTeX entry using + ‘bibtex-completion-edit-notes-function’.") + +(bibtex-actions-define-action + bibtex-completion-show-entry + "Show the selected entry in the relevant BibTeX file.") + +(bibtex-actions-define-action + bibtex-completion-add-pdf-to-library + "Add a PDF to the library for the selected BibTeX entry. +The PDF can be added either from an open buffer, a file, or a +URL.") (defun bibtex-actions--get-candidates () "Return all keys from bibtex-completion-candidates." From 80748e6d749e7bae74bb8c8d0d22d426eee35a3a Mon Sep 17 00:00:00 2001 From: mtreca Date: Sun, 7 Feb 2021 18:33:02 +0100 Subject: [PATCH 6/6] Add bibtex-completion--read. Remove bibtex-actions entry point. --- bibtex-actions.el | 54 +++++++++++++++++++---------------------------- 1 file changed, 22 insertions(+), 32 deletions(-) diff --git a/bibtex-actions.el b/bibtex-actions.el index bb6752c..e26732d 100644 --- a/bibtex-actions.el +++ b/bibtex-actions.el @@ -18,10 +18,27 @@ (define-key map (kbd "l") 'bibtex-actions-add-pdf-to-library) map)) -(defcustom bibtex-actions-default-action 'bibtex-actions-open-any - "The default action for the `bibtex-actions` command." - :group 'bibtex-completion - :type 'function) +(defun bibtex-actions--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))) + +(defun bibtex-actions--read () + "Read bibtex-completion entries for completion." + (bibtex-completion-init) + (completing-read + "BibTeX entries: " + (lambda (string predicate action) + (if (eq action 'metadata) + '(metadata (category . bibtex)) + (complete-with-action action (bibtex-actions--get-candidates) string predicate))))) + +(defun bibtex-completion--read () + "Select BibTeX entries in completion system." + (cdr (assoc (bibtex-actions--read) (bibtex-actions--get-candidates)))) (defmacro bibtex-actions-define-action (action doc) "Wraps the function ACTION in another function named NAME which @@ -32,8 +49,7 @@ passes it to ACTION." (new-name (intern (concat "bibtex-actions" mid-name)))) `(defun ,new-name (cand) ,doc - (interactive - (list (cdr (assoc (bibtex-actions--read) (bibtex-actions--get-candidates))))) + (interactive (list (bibtex-completion--read))) (,action (list cand))))) (bibtex-actions-define-action @@ -89,32 +105,6 @@ If multiple PDFs are found, ask for the one to open using The PDF can be added either from an open buffer, a file, or a URL.") -(defun bibtex-actions--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))) - -(defun bibtex-actions--read () - "Read bibtex-completion entries for completion." - (completing-read - "BibTeX entries: " - (lambda (string predicate action) - (if (eq action 'metadata) - '(metadata (category . bibtex)) - (complete-with-action action (bibtex-actions--get-candidates) string predicate))))) - -;;;###autoload -(defun bibtex-actions (bib-entry) - "Search BibTeX entries using `completing-read' and actions." - (interactive - (progn - (bibtex-completion-init) - (list (cdr (assoc (bibtex-actions--read) (bibtex-actions--get-candidates)))))) - (apply bibtex-actions-default-action (list bib-entry))) - (provide 'bibtex-actions) ;; Local Variables: