From 12613a23e4880a2aa79b899b3dac94dd585e0f9f Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Thu, 30 Jun 2022 11:14:06 +0100 Subject: Add downloader for pdfs --- doom/config.org | 111 ++++++++++++++++++++++++++++++++++---------------- zsh/.zsh/function.zsh | 4 ++ 2 files changed, 80 insertions(+), 35 deletions(-) diff --git a/doom/config.org b/doom/config.org index 972a747..2c51f9e 100644 --- a/doom/config.org +++ b/doom/config.org @@ -569,7 +569,9 @@ TeX-run-command nil t :help "Run ConTeXt")) TeX-command-list)) (map! :map ConTeXt-mode-map "C-c ]" #'ebib-insert-citation)) +#+end_src +#+begin_src emacs-lisp ;; Bibtex stuff (use-package! ebib :bind (("C-c y b" . ebib)) @@ -595,8 +597,62 @@ (advice-add 'bibtex-generate-autokey :around (lambda (orig-func &rest args) (replace-regexp-in-string ":" "" (apply orig-func args)))) - (remove-hook 'ebib-notes-new-note-hook #'org-narrow-to-subtree)) + (remove-hook 'ebib-notes-new-note-hook #'org-narrow-to-subtree) + + (map! :map ebib-index-mode-map + "D" #'ebib-download-pdf-from-doi)) + +(defun sci-hub-pdf-url (doi) + "Get url to the pdf from SCI-HUB using DOI." + (setq *doi-utils-pdf-url* (concat "https://sci-hub.hkvisa.net/" doi) ;captcha + ,*doi-utils-waiting* t + ) + ;; try to find PDF url (if it exists) + (url-retrieve (concat "https://sci-hub.hkvisa.net/" doi) + (lambda (_) + (goto-char (point-min)) + (while (search-forward-regexp + "\\(https:\\|sci-hub.hkvisa.net/downloads\\).+download=true'" nil t) + (let ((foundurl (match-string 0))) + (message foundurl) + (if (string-match "https:" foundurl) + (setq *doi-utils-pdf-url* foundurl) + (setq *doi-utils-pdf-url* (concat "https:" foundurl)))) + (setq *doi-utils-waiting* nil)))) + (while *doi-utils-waiting* (sleep-for 0.1)) + (replace-regexp-in-string "\\\\" "" *doi-utils-pdf-url*)) + +(defun acm-pdf-url (doi) + "Retrieve a DOI pdf from the ACM." + (concat "https://dl.acm.org/doi/pdf/" doi)) + +(defun download-pdf-from-doi (doi key &optional publisher) + "Download pdf from doi with KEY name." + (let ((pub (or publisher ""))) + (url-copy-file (cond + ((or (string-match "ACM" pub) + (string-match "Association for Computing Machinery" pub)) + (acm-pdf-url doi)) + (t (sci-hub-pdf-url doi))) + (concat "~/Dropbox/bibliography/papers/" key ".pdf")))) +(defun get-bib-from-doi (doi) + "Get the bibtex from DOI." + (shell-command (concat "curl -L -H \"Accept: application/x-bibtex; charset=utf-8\" " + "https://doi.org/" doi))) + +(defun ebib-download-pdf-from-doi () + "Download a PDF for the current entry." + (interactive) + (let* ((key (ebib--get-key-at-point)) + (doi (ebib-get-field-value "doi" key ebib--cur-db 'noerror 'unbraced 'xref)) + (publisher (ebib-get-field-value "publisher" key ebib--cur-db 'noerror 'unbraced 'xref))) + (unless (and key doi) + (error "[Ebib] No DOI found in doi field")) + (download-pdf-from-doi doi key publisher))) +#+end_src + +#+begin_src emacs-lisp ;; Set up dictionaries (setq ispell-dictionary "british") @@ -631,15 +687,13 @@ coq-compile-quick 'no-quick) (after! company-mode - (setq company-idle-delay 1)) + (setq company-idle-delay 1 + company-coq-disabled-features '(prettify-symbols hello company-defaults spinner compile-command))) ;; Removes performance problems with opening coq files. (after! core-editor (add-to-list 'doom-detect-indentation-excluded-modes 'coq-mode)) -(setq coq-may-use-prettify nil - company-coq-prettify-symbols nil) - (use-package! smartparens :config (map! :map smartparens-mode-map @@ -725,36 +779,6 @@ (use-package! ox-hugo :after ox) -(defun sci-hub-pdf-url (doi) - "Get url to the pdf from SCI-HUB using DOI." - (setq *doi-utils-pdf-url* (concat "https://sci-hub.do/" doi) ;captcha - ,*doi-utils-waiting* t - ) - ;; try to find PDF url (if it exists) - (url-retrieve (concat "https://sci-hub.do/" doi) - (lambda (_) - (goto-char (point-min)) - (while (search-forward-regexp - "\\(https://\\|//sci-hub.do/downloads\\).+download=true'" nil t) - (let ((foundurl (match-string 0))) - (message foundurl) - (if (string-match "https:" foundurl) - (setq *doi-utils-pdf-url* foundurl) - (setq *doi-utils-pdf-url* (concat "https:" foundurl)))) - (setq *doi-utils-waiting* nil)))) - (while *doi-utils-waiting* (sleep-for 0.1)) - ,*doi-utils-pdf-url*) - -(defun download-pdf-from-doi (doi key) - "Download pdf from doi with KEY name." - (url-copy-file (sci-hub-pdf-url doi) - (concat "~/Dropbox/bibliography/papers/" key ".pdf"))) - -(defun get-bib-from-doi (doi) - "Get the bibtex from DOI." - (shell-command (concat "curl -L -H \"Accept: application/x-bibtex; charset=utf-8\" " - "https://doi.org/" doi))) - (use-package alert :custom (alert-default-style 'osx-notifier)) @@ -866,8 +890,11 @@ https://yannherklotz.com") ;; Must be in the :init section of use-package such that the mode gets ;; enabled right away. Note that this forces loading the package. (marginalia-mode)) +#+end_src +** Embark +#+begin_src emacs-lisp (use-package! embark :bind (("C-;" . embark-act)) @@ -887,7 +914,11 @@ https://yannherklotz.com") ;; auto-updating embark collect buffer :hook (embark-collect-mode . consult-preview-at-point-mode)) +#+end_src + +** Consult +#+begin_src emacs-lisp ;; Example configuration for Consult (use-package! consult ;; Replace bindings. Lazily loaded due by `use-package'. @@ -965,7 +996,11 @@ https://yannherklotz.com") (lambda () (when-let (project (project-current)) (car (project-roots project)))))) +#+end_src +** Scheme + +#+begin_src emacs-lisp (use-package! geiser-chicken :config (setq geiser-chicken-binary "chicken-csi")) @@ -974,7 +1009,11 @@ https://yannherklotz.com") :init (map! :map geiser-mode-map "C-." nil) (map! :map geiser-repl-mode-map "C-." nil)) +#+end_src + +** Emacs +#+begin_src emacs-lisp (use-package! emacs :init ;; Add prompt indicator to `completing-read-multiple'. @@ -1066,3 +1105,5 @@ https://yannherklotz.com") ;; ;;(use-package! agda2-mode) #+end_src + +* diff --git a/zsh/.zsh/function.zsh b/zsh/.zsh/function.zsh index 809471e..6fa8bd0 100644 --- a/zsh/.zsh/function.zsh +++ b/zsh/.zsh/function.zsh @@ -28,3 +28,7 @@ wal-tile-l() { feh --bg-fill "$(< "${HOME}/.cache/wal/wal")" $HOME/.local/bin/betterlock -u "$(< "${HOME}/.cache/wal/wal")" } + +latestqr() { + ls -aS $HOME/Desktop | tail -n1 | tr \\n \\0 | xargs -0 -I% zbarimg --raw -q $HOME/Desktop/% +} -- cgit