Last active
April 16, 2024 09:27
-
-
Save tmalsburg/c4e8c9bc9a94a7f9faea21f1c7b2cd0f to your computer and use it in GitHub Desktop.
An Emacs command that takes the DOI in the clipboard and inserts the corresponding BibTeX entry at point.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require 'url-http) | |
(defun insert-bibtex-from-doi () | |
(interactive) | |
(let* ((doi (string-trim (gui-get-primary-selection))) | |
(url (if (string-prefix-p "https://doi.org/" doi) | |
doi | |
(concat "https://doi.org/" doi))) | |
(url-request-method "GET") | |
(url-mime-accept-string "application/x-bibtex")) | |
(insert | |
(with-current-buffer (url-retrieve-synchronously url t) | |
(goto-char (point-min)) | |
(while (not (looking-at "\n")) | |
(forward-line 1)) | |
(let ((string (buffer-substring-no-properties (point) (point-max)))) | |
(kill-buffer) | |
(decode-coding-string (string-trim string) 'utf-8)))) | |
(bibtex-clean-entry t))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Take a look at https://github.com/mpedramfar/zotra