Add function to automatically append bibtex from search to end of specific library file
ashiklom opened this issue · comments
Often, as I'm reading another paper or doing other work, I want to be able to quickly do a reference search (e.g. crossref-lookup
) and add the bibtex entries of the results to the end of my library.bib
file. It would be nice to do this in one go, without having to select the target buffer each time, and, perhaps more importantly, to know that the entry will always be placed at the end of the buffer (rather than wherever my cursor was last, which is often in the middle of a bibtex entry).
I wrote a custom function to do this that looks like this (where ans/reference-bibfile
is my default, system-wide library.bib
, but this could be a configurable setting within the package. Also, note that I call org-ref-clean-bibtex-entry
from the org-ref
package, which formats my citation key and does a few other tweaks):
(general-def
:states 'emacs
:keymaps 'biblio-selection-mode-map
"I" 'ans/biblio-selection-insert-end-of-bibfile)
(defun ans/biblio--selection-insert-at-end-of-bibfile-callback (bibtex entry)
"Add BIBTEX (from ENTRY) to end of library.bib file."
(with-current-buffer (find-file-noselect ans/reference-bibfile)
(goto-char (point-max))
(insert bibtex)
(org-ref-clean-bibtex-entry))
(message "Inserted bibtex entry for %S."
(biblio--prepare-title (biblio-alist-get 'title entry))))
(defun ans/biblio-selection-insert-end-of-bibfile ()
"Insert BibTeX of current entry at the end of my library.bib file."
(interactive)
(biblio--selection-forward-bibtex #'ans/biblio--selection-insert-at-end-of-bibfile-callback))
...but it might be nice if something like this was part of the core functionality.
This looks very nice; thanks, and sorry for the delay.
I think it would work well as a separately-distributed plugin, though I'd be fine with having it in core, too :) Some suggestions / questions:
ans/reference-bibfile
could be a defcustom; I'm not entirely sure which:safe
predicate to give it.- How much does
org-ref-clean-bibtex-entry
do thatbiblio-format-bibtex
doesn't do? - We could add an appropriate hook to make it easy for users of
org-ref
to callorg-ref-clean-bibtex-entry
, while not adding a dependency on that.
No worries about the delay -- we're all busy people, and thanks for developing and maintaining such an awesome tool!
I'm not sure my Elisp is strong enough yet for me to be confident in my ability to develop a full plugin, but maybe someday. In the meantime, perhaps you could just link to this issue from the bottom of your README as an example of a custom action?
Based on my limited understanding, yes, I think reference-bibfile
could be a defcustom
, though I've never made one of those myself since I prefer to configure everything via setq
in my .emacs
.
I like the idea of customizing it via a hook. It may even be possible to replicate this functionality with just pre-
and post-
"insert into bibtex" hooks, such that the pre-
hook moves the point to the end of the file and the post-
hook runs the formatter.
As I recall, I went with org-ref
's formatting because it fixes the indentation, removes non-ascii characters, and formats the bibtex key. It may well be that biblio
does some or all of those things too -- possibly, in a better way -- but I haven't done the appropriate research 😉
No worries about the delay -- we're all busy people, and thanks for developing and maintaining such an awesome tool!
Thanks :)
I'm not sure my Elisp is strong enough yet for me to be confident in my ability to develop a full plugin, but maybe someday.
You should try :) it's fun, and it's very easy.
M-x auto-insert in an empty .el file will interactively help you with the basic format. You can also copy one of the existing backends for inspiration. For the defcustom, you can draw inspiration from the existing defcustoms in biblio.el (defining a veariable with defcustom makes it easy to discover, and you can still set its value with setq
)
In the meantime, perhaps you could just link to this issue from the bottom of your README as an example of a custom action?
Sure; can you make a PR for that? Maybe a new "Community extensions" section?
I like the idea of customizing it via a hook. It may even be possible to replicate this functionality with just
pre-
andpost-
"insert into bibtex" hooks
You'd still need to say which file to write to, I think.
Any update on this? :)
Sorry for the delay! I opened a documentation PR (#29) -- that should be sufficient to close this. Unfortunately, I don't think I have the bandwidth to try to integrate this more intelligently into the core package or make an extension.
Thanks very much. I will review this PR in ~1 week, I expect :)