Drag and drop files into bibtex
I found code here dnd images into auxtex. I am using the excellent Zotra package. I modified the dnd to auctex code to allow drag and drop pdf files into bibtex. My attempt below works. It creates a bibtex “file
” field and fills it with the link to the file. However, it would be nice if I could add the following functionality: change the path of the uri to the directory citar-library-paths
, change the file-name (excl ext) to the bib-key, move the file to the new path and then sets the file
field. This will be useful when one has to manually add files to the bibtex
database (in case where the Zotero translation server doesn’t find the file. Any help or pointers to a package that works similarly would be appreciated.
(defcustom BIBTex-dnd-protocol-alist
'(("^file:///" . BIBTex-dnd-bibtex-file)
("^file://" . BIBTex-dnd-bibtex-file)
("^file:" . BIBTex-dnd-bibtex-file))
"The functions to call when a drop in a .bib file is made."
:type '(choice (repeat (cons (regexp) (function))))
:group 'bibtex)
(define-minor-mode BIBTex-dnd-mode
"Minor mode to insert the name and full path of a dropped file into the 'file' entry of a .bib file."
:lighter " DND"
(when (boundp 'dnd-protocol-alist)
(if BIBTex-dnd-mode
(set (make-local-variable 'dnd-protocol-alist)
(append BIBTex-dnd-protocol-alist 'dnd-protocol-alist))
(kill-local-variable 'dnd-protocol-alist))))
(defun BIBTex-dnd-bibtex-file (uri action)
"Insert the name and full path of a dropped file into the 'file' entry of a .bib file."
(when (equal major-mode 'bibtex-mode)
(let ((file (dnd-get-local-file-name uri t)))
(when (and file (file-regular-p file))
(bibtex-set-field "file" file )))))
You must log in or register to comment.