-
First: thanks, again, for the work you all continue to do on this! Second: I'm trying to add back the functionality from some previous version that allowed me to add PDFs to my library using citar/bibtex-actions. I realize that functionality in turn depended on My question, now, is what the best way of adding this function to the list of actions made available via Embark. Say the function is called (use-package citar
:bind (("C-c b" . citar-insert-citation)
:map citar-map
("a" . +citar-add-pdf-to-library))
:after embark
:init
:custom
(citar-bibliography '("~/bib/apcmain.bib"))
(citar-library-paths '("~/Documents/Papers"))
(citar-notes-paths '("~/org/notebook"))
(org-cite-global-bibliography '("~/bib/apcmain.bib"))
(org-cite-insert-processor 'citar)
(org-cite-follow-processor 'citar)
(org-cite-activate-processor 'citar)
(citar-at-point-function 'embark-act)
(citar-templates
'((main . "${author editor:15} ${title:40} ${date year issued:4}")
(suffix . " ${=key= id:15} ${=type=:12} ${tags keywords:*}")
(note . "Notes on ${author editor}, ${title}")))
:config
(defvar apc-bibtex-pdf-extension ".pdf")
(defun +citar-add-pdf-to-library (keys)
"Add a PDF to the library for the first entry in KEYS.
The PDF can be added either from an open buffer, a file, or a
URL."
(interactive)
(let* ((key (car keys))
(source (char-to-string
(read-char-choice "Add pdf from [b]uffer, [f]ile, or [u]rl? " '(?b ?f ?u))))
(buffer (when (string= source "b")
(read-buffer-to-switch "Add pdf buffer: ")))
(file (when (string= source "f")
(expand-file-name (read-file-name "Add pdf file: " nil nil t))))
(url (when (string= source "u")
(read-string "Add pdf URL: ")))
(path (-flatten (list citar-library-paths)))
(path (if (cdr path)
(completing-read "Add pdf to: " path nil t)
(car path)))
(pdf (expand-file-name (completing-read "Rename pdf to: "
(--map (s-concat key it)
(-flatten apc-bibtex-pdf-extension))
nil nil key)
path)))
(cond
(buffer
(with-current-buffer buffer
(write-file pdf t)))
(file
(copy-file file pdf 1))
(url
(url-copy-file url pdf 1))))) Now, the function appears when I call
Clearly I'm missing something about how Embark works, but since at some point you had this functionality as part of |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 12 replies
-
What's your preferred UX workflow for the basic command; from the minibuffer? |
Beta Was this translation helpful? Give feedback.
-
OK, I think I figured out what was missing. This seems to work now: (use-package citar
:bind (("C-c b" . citar-insert-citation)
:map minibuffer-local-map
("M-b" . citar-insert-preset)
:map citar-map
("a" . +citar-add-pdf-to-library))
:after embark
:init
:custom
(citar-bibliography '("~/bib/apcmain.bib"))
(citar-library-paths '("~/Documents/Papers"))
(citar-notes-paths '("~/org/notebook"))
(org-cite-global-bibliography '("~/bib/apcmain.bib"))
(org-cite-insert-processor 'citar)
(org-cite-follow-processor 'citar)
(org-cite-activate-processor 'citar)
(citar-at-point-function 'embark-act)
(citar-templates
'((main . "${author editor:15} ${title:40} ${date year issued:4}")
(suffix . " ${=key= id:15} ${=type=:12} ${tags keywords:*}")
(note . "Notes on ${author editor}, ${title}")))
:config
(defvar apc-bibtex-pdf-extension ".pdf")
(defun +bibtex-add-pdf-to-library (keys)
"Add a PDF to the library for the first entry in KEYS.
The PDF can be added either from an open buffer, a file, or a
URL."
(interactive)
(let* ((key (car keys))
(source (char-to-string
(read-char-choice "Add pdf from [b]uffer, [f]ile, or [u]rl? " '(?b ?f ?u))))
(buffer (when (string= source "b")
(read-buffer-to-switch "Add pdf buffer: ")))
(file (when (string= source "f")
(expand-file-name (read-file-name "Add pdf file: " nil nil t))))
(url (when (string= source "u")
(read-string "Add pdf URL: ")))
(path (-flatten (list citar-library-paths)))
(path (if (cdr path)
(completing-read "Add pdf to: " path nil t)
(car path)))
(pdf (expand-file-name (completing-read "Rename pdf to: "
(--map (s-concat key it)
(-flatten apc-bibtex-pdf-extension))
nil nil key)
path)))
(cond
(buffer
(with-current-buffer buffer
(write-file pdf t)))
(file
(copy-file file pdf 1))
(url
(url-copy-file url pdf 1)))))
(defun +citar-add-pdf-to-library (keys-entries)
"Add PDF associated with the KEYS-ENTRIES to library.
The PDF can be added either from an open buffer, a file, or a
URL.
With prefix, rebuild the cache before offering candidates."
(interactive (list (citar-select-refs
:rebuild-cache current-prefix-arg)))
(+bibtex-add-pdf-to-library
(citar--extract-keys keys-entries))))
But I leave this open in case you have any suggestions for how to improve on what I've got so far. Thanks again! |
Beta Was this translation helpful? Give feedback.
OK, I think I figured out what was missing. This seems to work now: