Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Allow user to define function for PDF file name when downloading automatically from the web #1030

Open
nonducor opened this issue Sep 4, 2022 · 1 comment

Comments

@nonducor
Copy link

nonducor commented Sep 4, 2022

I suggest to extend doi-utils with a functionality that allows the user to specify a function to return the PDF file name when downloading it from the internet (in functions doi-utils-async-download-pdf and doi-utils-get-bibtex-entry-pdf).

Today this is hardcoded to be the entry's key (which happen not to work with my workflow, that uses the title).

The changes would be:

  1. Adding a new defcustom for this function (with a default for the current behaviour):
(defcustom doi-utils-get-downloaded-pdf-name
  '(lambda () (cdr (assoc "=key=" (bibtex-parse-entry))))
  "The function to create the pdf file name from the bibtex entry.
Defaults to using the `key' value as the file name."
  :type 'function
  :group 'doi-utils)
  1. Change in doi-utils-async-download-pdf to use it:
@@ -665,7 +673,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-get-downloaded-pdf-name))
           (pdf-url)
           (pdf-file))
 
@@ -677,7 +685,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"))
  1. Do the same change in doi-utils-get-bibtex-entry-pdf:
@@ -737,7 +745,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-get-downloaded-pdf-name))
           (pdf-url)
           (pdf-file))
 
@@ -749,7 +757,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

I can submit a pull request if this proposal is acceptable, or change the defcustom/variable names to make it more adequate.

@jkitchin
Copy link
Owner

jkitchin commented Sep 4, 2022

This seems reasonable. Make sure the current behavior remains the default behavior. I think you may need to modify something in how bibtex-completion finds the pdf on your end, or store that file name as a file field in the bibtex entry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants