this post was submitted on 18 Oct 2023
1 points (100.0% liked)

Emacs

314 readers
2 users here now

A community for the timeless and infinitely powerful editor. Want to see what Emacs is capable of?!

Get Emacs

Rules

  1. Posts should be emacs related
  2. Be kind please
  3. Yes, we already know: Google results for "emacs" and "vi" link to each other. We good.

Emacs Resources

Emacs Tutorials

Useful Emacs configuration files and distributions

Quick pain-saver tip

founded 1 year ago
MODERATORS
 

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 are viewing a single comment's thread
view the rest of the comments
[–] _viz_@alien.top 1 points 1 year ago (1 children)

You're looking for rename-file function. For finding out the key of the current entry, you can use bibtex-parse-entry making sure point is on @XXX line.

[–] Motor_Mouth_@alien.top 1 points 1 year ago

Thanks - will check these out.