update packages

This commit is contained in:
2025-11-25 19:52:03 +01:00
parent 14ba373378
commit dbbae92267
280 changed files with 13451 additions and 11207 deletions

View File

@@ -1,4 +1,4 @@
;;; doi-utils.el --- DOI utilities for making bibtex entries
;;; doi-utils.el --- DOI utilities for making bibtex entries -*- lexical-binding: t; -*-
;; Copyright (C) 2015-2021 John Kitchin
@@ -41,15 +41,14 @@
(declare-function bibtex-completion-edit-notes "bibtex-completion")
(declare-function org-bibtex-yank "org-bibtex")
(declare-function org-ref-possible-bibfiles "org-ref-core")
(declare-function org-ref-normalize-bibtex-completion-bibliography "org-ref-utils")
(declare-function f-ext? "f")
(declare-function f-entries "f")
(declare-function s-match "s")
(declare-function org-ref--file-ext-p "org-ref-utils")
(declare-function org-ref--directory-files "org-ref-utils")
(eval-when-compile
(require 'cl-lib))
(require 'bibtex)
(require 'dash)
(require 'json)
(require 'org) ; org-add-link-type
@@ -59,7 +58,7 @@
(require 'url-http)
(require 'url-handlers)
(require 'org-ref-utils)
(require 'hydra)
(require 'transient)
;;* Customization
(defgroup doi-utils nil
@@ -120,6 +119,35 @@ If nil use `doi-utils-get-bibtex-entry-pdf' synchronously."
:group 'doi-utils)
(defun doi-utils-pdf-filename-from-key ()
"Generate PDF filename from bibtex entry key.
This is the default function for `doi-utils-pdf-filename-function'.
Returns the bibtex entry key as the filename (without extension or path)."
(cdr (assoc "=key=" (bibtex-parse-entry))))
(defcustom doi-utils-pdf-filename-function
'doi-utils-pdf-filename-from-key
"Function to generate PDF filename from bibtex entry.
The function is called with no arguments while point is in the bibtex
entry, and should return a string to use as the PDF filename (without
the .pdf extension or directory path).
The directory path is determined separately by `bibtex-completion-library-path'.
The default function uses the bibtex entry key as the filename.
Example: To use the title field as the filename:
(setq doi-utils-pdf-filename-function
(lambda () (bibtex-autokey-get-field \"title\")))
Note: The function is responsible for ensuring the returned filename
is valid for the filesystem. Special characters in fields like title
may cause issues on some systems."
:type 'function
:group 'doi-utils)
;;* Getting pdf files from a DOI
;; The idea here is simple. When you visit http://dx.doi.org/doi or
@@ -308,7 +336,7 @@ https://onlinelibrary.wiley.com/doi/pdfdirect/10.1002/anie.201310461?download=tr
(setq p2 (replace-regexp-in-string
"^http\\(s?\\)://scitation.aip.org/" "" *doi-utils-redirect*))
(setq s (split-string p2 "/"))
(setq p1 (mapconcat 'identity (-remove-at-indices '(0 6) s) "/"))
(setq p1 (mapconcat 'identity (org-ref--remove-at-indices '(0 6) s) "/"))
(setq p3 (concat "/" (nth 0 s) (nth 1 s) "/" (nth 2 s) "/" (nth 3 s)))
(format "http://scitation.aip.org/deliver/fulltext/%s.pdf?itemId=/%s&mimeType=pdf&containerItemId=%s"
p1 p2 p3))))
@@ -334,7 +362,7 @@ https://onlinelibrary.wiley.com/doi/pdfdirect/10.1002/anie.201310461?download=tr
(defun ecs-pdf-url (*doi-utils-redirect*)
"Get url to the pdf from *DOI-UTILS-REDIRECT*."
(when (string-match "^http\\(s?\\)://jes.ecsdl.org" *doi-utils-redirect*)
(replace-regexp-in-string "\.abstract$" ".full.pdf" *doi-utils-redirect*)))
(replace-regexp-in-string "\\.abstract$" ".full.pdf" *doi-utils-redirect*)))
;; http://ecst.ecsdl.org/content/25/2/2769
;; http://ecst.ecsdl.org/content/25/2/2769.full.pdf
@@ -762,7 +790,7 @@ too. "
(doi (replace-regexp-in-string
"https?://\\(dx.\\)?.doi.org/" ""
(bibtex-autokey-get-field "doi")))
(key (cdr (assoc "=key=" (bibtex-parse-entry))))
(base-name (funcall doi-utils-pdf-filename-function))
(pdf-url)
(pdf-file))
@@ -774,7 +802,7 @@ too. "
(car bibtex-completion-library-path))
(t
(completing-read "Dir: " bibtex-completion-library-path)))
key ".pdf"))
base-name ".pdf"))
(unless doi (error "No DOI found to get a pdf for"))
@@ -834,7 +862,7 @@ checked."
(doi (replace-regexp-in-string
"https?://\\(dx.\\)?.doi.org/" ""
(bibtex-autokey-get-field "doi")))
(key (cdr (assoc "=key=" (bibtex-parse-entry))))
(base-name (funcall doi-utils-pdf-filename-function))
(pdf-url)
(pdf-file))
@@ -846,7 +874,7 @@ checked."
(car bibtex-completion-library-path))
(t
(completing-read "Dir: " bibtex-completion-library-path)))
key ".pdf"))
base-name ".pdf"))
;; now get file if needed.
(unless (file-exists-p pdf-file)
(cond
@@ -900,7 +928,7 @@ every field.")
(defun doi-utils-get-json-metadata (doi)
"Try to get json metadata for DOI. Open the DOI in a browser if we do not get it."
(if-let ((data (cdr (assoc doi doi-utils-cache))))
(if-let* ((data (cdr (assoc doi doi-utils-cache))))
;; We have the data already, so we return it.
data
(let ((url-request-method "GET")
@@ -1055,7 +1083,7 @@ MATCHING-TYPES."
fields)
(concat
,@(doi-utils-concat-prepare
(-flatten
(org-ref--flatten-list
(list (concat "@" (symbol-name name) "{,\n")
;; there seems to be some bug with mapcan,
;; so we fall back to flatten
@@ -1096,7 +1124,7 @@ MATCHING-TYPES."
(let* ((results (funcall doi-utils-metadata-function doi))
(type (plist-get results :type)))
;; (format "%s" results) ; json-data
(or (-some (lambda (g) (funcall g type results)) doi-utils-bibtex-type-generators)
(or (cl-some (lambda (g) (funcall g type results)) doi-utils-bibtex-type-generators)
(message "%s not supported yet\n%S." type results))))
;; That is just the string for the entry. To be useful, we need a function that
@@ -1171,31 +1199,31 @@ Argument BIBFILE the bibliography to use."
;; DOI raw
;; Ex: 10.1109/MALWARE.2014.6999410
((and (stringp the-active-region)
(s-match (concat "^" doi-regexp) the-active-region))
(org-ref--string-match (concat "^" doi-regexp) the-active-region))
the-active-region)
;; DOI url
;; Ex: https://doi.org/10.1109/MALWARE.2014.6999410
((and (stringp the-active-region)
(s-match (concat doi-url-prefix-regexp doi-regexp) the-active-region))
(org-ref--string-match (concat doi-url-prefix-regexp doi-regexp) the-active-region))
(replace-regexp-in-string doi-url-prefix-regexp "" the-active-region))
;; DOI url as customized
((and (stringp the-active-region)
(s-match (regexp-quote doi-utils-dx-doi-org-url) the-active-region))
(org-ref--string-match (regexp-quote doi-utils-dx-doi-org-url) the-active-region))
(replace-regexp-in-string (regexp-quote doi-utils-dx-doi-org-url) "" the-active-region))
;; Check if DOI can be found in the current kill
;; DOI raw
;; Ex: 10.1109/MALWARE.2014.6999410
((and (stringp the-current-kill)
(s-match (concat "^" doi-regexp) the-current-kill))
(org-ref--string-match (concat "^" doi-regexp) the-current-kill))
the-current-kill)
;; DOI url
;; Ex: https://doi.org/10.1109/MALWARE.2014.6999410
((and (stringp the-current-kill)
(s-match (concat doi-url-prefix-regexp doi-regexp) the-current-kill))
(org-ref--string-match (concat doi-url-prefix-regexp doi-regexp) the-current-kill))
(replace-regexp-in-string doi-url-prefix-regexp "" the-current-kill))
;; DOI url as customized
((and (stringp the-current-kill)
(s-match (regexp-quote doi-utils-dx-doi-org-url) the-current-kill))
(org-ref--string-match (regexp-quote doi-utils-dx-doi-org-url) the-current-kill))
(replace-regexp-in-string (regexp-quote doi-utils-dx-doi-org-url) "" the-current-kill))
;; otherwise, return nil
(t
@@ -1251,7 +1279,7 @@ Optional argument NODELIM see `bibtex-make-field'."
(defun plist-get-keys (plist)
"Return keys in a PLIST."
(-slice plist 0 nil 2))
(cl-loop for (key _value) on plist by #'cddr collect key))
;;;###autoload
@@ -1415,9 +1443,7 @@ May be empty if none are found."
(defun doi-utils-open-bibtex (doi)
"Search through variable `bibtex-completion-bibliography' for DOI."
(interactive "sDOI: ")
(cl-loop for f in (if (listp bibtex-completion-bibliography)
bibtex-completion-bibliography
(list bibtex-completion-bibliography))
(cl-loop for f in (org-ref-normalize-bibtex-completion-bibliography)
when (progn (find-file f)
(when (search-forward doi (point-max) t)
(bibtex-beginning-of-entry)))
@@ -1453,23 +1479,40 @@ May be empty if none are found."
(declare-function org-element-property "org-element")
(defhydra doi-link-follow (:color blue :hint nil)
"DOI actions:
"
("o" (doi-utils-open (org-element-property :path (org-element-context))) "open")
("w" (doi-utils-wos (org-element-property :path (org-element-context))) "wos")
("c" (doi-utils-wos-citing (org-element-property :path (org-element-context))) "wos citing articles")
("r" (doi-utils-wos-related (org-element-property :path (org-element-context))) "wos related articles" )
("a" (doi-utils-ads (org-element-property :path (org-element-context))) "ads")
("s" (doi-utils-google-scholar (org-element-property :path (org-element-context))) "Google Scholar")
("f" (doi-utils-crossref (org-element-property :path (org-element-context))) "CrossRef")
("p" (doi-utils-pubmed (org-element-property :path (org-element-context))) "Pubmed")
("b" (doi-utils-open-bibtex (org-element-property :path (org-element-context))) "open in bibtex")
("g" (doi-utils-add-bibtex-entry-from-doi (org-element-property :path (org-element-context))) "get bibtex entry"))
(defun doi-utils--context-doi ()
(org-element-property :path (org-element-context)))
(transient-define-prefix doi-link-follow-menu ()
"DOI actions."
[["Actions"
("o" "open" (lambda () (interactive)
(doi-utils-open (doi-utils--context-doi))))
("w" "wos" (lambda () (interactive)
(doi-utils-wos (doi-utils--context-doi))))
("c" "wos citing articles" (lambda () (interactive)
(doi-utils-wos-citing (doi-utils--context-doi))))
("r" "wos related articles" (lambda () (interactive)
(doi-utils-wos-related (doi-utils--context-doi))))
("a" "ads" (lambda () (interactive)
(doi-utils-ads (doi-utils--context-doi))))
("s" "Google Scholar" (lambda () (interactive)
(doi-utils-google-scholar (doi-utils--context-doi))))
("f" "CrossRef" (lambda () (interactive)
(doi-utils-crossref (doi-utils--context-doi))))
("p" "Pubmed" (lambda () (interactive)
(doi-utils-pubmed (doi-utils--context-doi))))
("b" "open in bibtex" (lambda () (interactive)
(doi-utils-open-bibtex (doi-utils--context-doi))))
("g" "get bibtex entry" (lambda () (interactive)
(doi-utils-add-bibtex-entry-from-doi (doi-utils--context-doi))))
("q" "quit" transient-quit-one)]])
(define-obsolete-function-alias 'doi-link-follow/body
#'doi-link-follow-menu "3.1")
(org-link-set-parameters "doi"
:follow (lambda (_) (doi-link-follow/body))
:follow (lambda (_) (doi-link-follow-menu))
:export (lambda (doi desc format)
(cond
((eq format 'html)
@@ -1639,7 +1682,7 @@ Get a list of possible matches. Choose one with completion."
nil)))
(completing-read
"Bibfile: "
(append (f-entries "." (lambda (f) (f-ext? f "bib")))
(append (org-ref--directory-files "." (lambda (f) (org-ref--file-ext-p f "bib")))
bibtex-completion-bibliography))))
(let* ((json-data (with-temp-buffer
(url-insert