summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Herklotz <git@yannherklotz.com>2022-11-27 12:08:11 +0000
committerYann Herklotz <git@yannherklotz.com>2022-11-27 12:08:11 +0000
commitad161b70c317cc766c6ec42064cb6410136c7905 (patch)
tree56b914aabe00e6526e7ba1cdd5aeb9a3ab4da732
parent3cc9791003364c338cc6d219c5f144210aa76bef (diff)
downloadymh-emacs-ad161b70c317cc766c6ec42064cb6410136c7905.tar.gz
ymh-emacs-ad161b70c317cc766c6ec42064cb6410136c7905.zip
Take more configuration into packages
-rw-r--r--init.el261
-rw-r--r--ymh-emacs/ymh-common.el53
-rw-r--r--ymh-emacs/ymh-diary.el30
-rw-r--r--ymh-emacs/ymh-ebib.el113
4 files changed, 285 insertions, 172 deletions
diff --git a/init.el b/init.el
index 0092091..54ad984 100644
--- a/init.el
+++ b/init.el
@@ -5,35 +5,6 @@
(setq gc-cons-threshold (* 1024 1024 1024))
-(defun ymhg/prev-window ()
- "Go to the previous window using `other-window'."
- (interactive)
- (other-window -1))
-
-(defun ymhg/reset-coq-windows ()
- "Resets the Goal and Response windows."
- (interactive)
- (other-frame 1)
- (delete-other-windows)
- (split-window-below)
- (switch-to-buffer "*goals*")
- (other-window 1)
- (switch-to-buffer "*response*")
- (other-frame 1))
-
-(defun ymhg/pass (query)
- "Return the password as a string from QUERY."
- (s-trim (shell-command-to-string (concat "pass show " query))))
-
-(defun ymhg/apply-theme (appearance)
- "Load theme, taking current system APPEARANCE into consideration."
- (mapc #'disable-theme custom-enabled-themes)
- (pcase appearance
- ;;('light (load-theme 'modus-operandi t))
- ;;('dark (load-theme 'modus-vivendi t))
- ('light (load-theme 'ef-spring t))
- ('dark (load-theme 'ef-autumn t))))
-
(global-set-key (kbd "M-u") #'upcase-dwim)
(global-set-key (kbd "M-l") #'downcase-dwim)
(global-set-key (kbd "M-c") #'capitalize-dwim)
@@ -42,7 +13,7 @@
(global-set-key (kbd "C-.") #'other-window)
(global-set-key (kbd "C-,") #'ymhg/prev-window)
(global-set-key (kbd "C-\\") #'undo-only)
-(global-set-key (kbd "M-SPC") (lambda () (interactive)(insert " ")))
+(global-set-key (kbd "M-SPC") (lambda () (interactive) (insert " ")))
(global-set-key (kbd "C-c l") #'org-store-link)
(global-set-key (kbd "C-c c") #'org-capture)
@@ -62,41 +33,6 @@
(set-register ?p (cons 'file "~/Dropbox/org/projects.org"))
(set-register ?c (cons 'file (format-time-string "~/Dropbox/org/%Y-%m.org")))
-(defadvice load-theme
- (before theme-dont-propagate activate)
- (mapc #'disable-theme custom-enabled-themes))
-
-(defun diary-schedule (y1 m1 d1 y2 m2 d2 dayname)
- "Entry applies if date is between dates on DAYNAME.
- Order of the parameters is M1, D1, Y1, M2, D2, Y2 if
- `european-calendar-style' is nil, and D1, M1, Y1, D2, M2, Y2 if
- `european-calendar-style' is t. Entry does not apply on a history."
- (let ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
- (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
- (d (calendar-absolute-from-gregorian date)))
- (if (and
- (<= date1 d)
- (<= d date2)
- (= (calendar-day-of-week date) dayname)
- ;;(not (calendar-check-holidays date))
- )
- entry)))
-
-(defun diary-last-day-of-month (date)
- "Return `t` if DATE is the last day of the month."
- (let* ((day (calendar-extract-day date))
- (month (calendar-extract-month date))
- (year (calendar-extract-year date))
- (last-day-of-month
- (calendar-last-day-of-month month year)))
- (= day last-day-of-month)))
-
-(defun ymhg/electric-space ()
- (interactive)
- (if (looking-back (sentence-end))
- (insert "%\n")
- (self-insert-command 1)))
-
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
@@ -113,11 +49,18 @@
(straight-use-package 'use-package)
+(use-package ymh-common
+ :straight nil
+ :load-path "ymh-emacs")
+
(use-package emacs
:straight nil
:init
+ (setq gnus-init-file (concat user-emacs-directory "gnus.el"))
+
(setq-default fill-column 80)
+ (setq use-short-answers t)
(setq inhibit-startup-message t)
(setq confirm-nonexistent-file-or-buffer nil)
(setq ring-bell-function 'ignore)
@@ -134,8 +77,6 @@
(setq face-remapping-alist '((proof-locked-face . region)))
- (fset 'yes-or-no-p 'y-or-n-p)
-
(defvar --backup-directory)
(setq --backup-directory (concat user-emacs-directory "backups"))
(if (not (file-exists-p --backup-directory))
@@ -176,24 +117,33 @@
(tool-bar-mode -1)
(scroll-bar-mode -1)
+ ;; Enable those
+ (dolist (c '(overwrite-mode narrow-to-region narrow-to-page upcase-region downcase-region))
+ (put c 'disabled nil))
+
(set-face-attribute 'default nil :font "Iosevka YMHG Medium-12")
(setq auto-mode-alist
(append
(list ;;'("\\.\\(vcf\\|gpg\\)\\'" . sensitive-minor-mode)
+ '("\\.v\\'" . coq-mode)
'("\\.sv\\'" . verilog-mode)
'("\\.mkiv\\'" . context-mode)
'("\\.mkii\\'" . context-mode)
'("\\.mkxl\\'" . context-mode))
auto-mode-alist))
+
;; Mac configuration
(when (eq system-type 'darwin)
(progn (setq mac-right-option-modifier 'none
mac-command-modifier 'meta
mac-option-modifier nil)
-
(add-hook 'ns-system-appearance-change-functions #'ymhg/apply-theme))))
+(use-package ymh-diary
+ :straight nil
+ :load-path "ymh-emacs")
+
(use-package shr
:straight nil
:init
@@ -344,8 +294,7 @@ https://yannherklotz.com"))
(use-package ef-themes
:config
- (load-theme 'ef-autumn t)
- )
+ (load-theme 'ef-dark t))
(use-package modus-themes
:config
@@ -604,7 +553,9 @@ https://yannherklotz.com"))
(interactive (notmuch-interactive-region))
(if (member "deleted" (notmuch-search-get-tags))
(notmuch-search-tag (list "-deleted"))
- (notmuch-search-tag (list "+deleted" "-unread") beg end)))
+ (progn
+ (notmuch-search-tag (list "+deleted" "-unread") beg end)
+ (notmuch-search-next-thread))))
(defun ymhg/notmuch ()
"Delete a message."
@@ -621,7 +572,9 @@ https://yannherklotz.com"))
(interactive (notmuch-interactive-region))
(if (member "deleted" (notmuch-show-get-tags))
(notmuch-show-tag (list "-deleted"))
- (notmuch-show-tag (list "+deleted" "-unread") beg end)))
+ (progn
+ (notmuch-show-tag (list "+deleted" "-unread") beg end)
+ (notmuch-show-next-thread))))
(setq notmuch-archive-tags '("-inbox" "-unread" "+archive"))
(setq-default notmuch-search-oldest-first nil)
@@ -638,6 +591,8 @@ https://yannherklotz.com"))
(:name "drafts" :query "tag:draft" :key "d")
(:name "mailbox" :query "date:last_month..this_month and (tag:mailbox and tag:inbox) and not tag:deleted and not tag:sent" :key "m")
(:name "imperial" :query "date:last_month..this_month and (tag:imperial and tag:inbox) and not tag:deleted and not tag:sent" :key "i")
+ (:name "mailbox-archive" :query "date:last_month..this_month and (tag:mailbox and tag:archive) and not tag:deleted and not tag:sent" :key "a")
+ (:name "imperial-archive" :query "date:last_month..this_month and (tag:imperial and tag:archive) and not tag:deleted and not tag:sent" :key "b")
(:name "all recent" :query "date:last_month..this_month" :key "r")))
(setq notmuch-fcc-dirs
@@ -676,106 +631,13 @@ https://yannherklotz.com"))
(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)
-
- (define-key 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 ieee-pdf-url (doi)
- "Retrieve a DOI pdf from the IEEE."
- (when (string-match "\\.\\([0-9]*\\)$" doi)
- (let ((doi-bit (match-string 1 doi)))
- (concat "https://ieeexplore.ieee.org/stampPDF/getPDF.jsp?tp=&arnumber=" doi-bit "&ref="))))
-
- (defun springer-pdf-url (doi)
- "Retrieve a DOI pdf from the Springer."
- (concat "https://link.springer.com/content/pdf/" doi ".pdf"))
-
- (defun arxiv-pdf-url (epr)
- (concat "https://arxiv.org/pdf/" epr ".pdf"))
-
- (defun download-pdf-from-doi (key &optional doi publisher eprint journal organization url)
- "Download pdf from doi with KEY name."
- (let ((pub (or publisher ""))
- (epr (or eprint ""))
- (jour (or journal ""))
- (org (or organization ""))
- (link (or url "")))
- (url-copy-file (cond
- ((not doi) link)
- ((or (string-match "ACM" (s-upcase pub))
- (string-match "association for computing machinery" (s-downcase pub)))
- (acm-pdf-url doi))
- ((string-match "arxiv" (s-downcase pub))
- (arxiv-pdf-url epr))
- ((or (string-match "IEEE" (s-upcase pub))
- (string-match "IEEE" (s-upcase jour))
- (string-match "IEEE" (s-upcase org)))
- (ieee-pdf-url doi))
- ((string-match "springer" (s-downcase pub))
- (springer-pdf-url doi))
- (t (sci-hub-pdf-url doi)))
- (concat (car ebib-file-search-dirs) "/" key ".pdf"))))
-
- (defun download-pdf-from-link (link key)
- (url-copy-file link
- (concat (car ebib-file-search-dirs) "/" key ".pdf")))
-
- (defun download-pdf-from-downloads (key)
- (copy-file (concat "~/Downloads/" key ".pdf")
- (concat (car ebib-file-search-dirs) "/" key ".pdf") t))
-
- (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))
- (eprinttype (ebib-get-field-value "eprinttype" key ebib--cur-db 'noerror 'unbraced 'xref))
- (eprint (ebib-get-field-value "eprint" key ebib--cur-db 'noerror 'unbraced 'xref))
- (journal (ebib-get-field-value "journal" key ebib--cur-db 'noerror 'unbraced 'xref))
- (journaltitle (ebib-get-field-value "journaltitle" key ebib--cur-db 'noerror 'unbraced 'xref))
- (organization (ebib-get-field-value "organization" key ebib--cur-db 'noerror 'unbraced 'xref))
- (url (ebib-get-field-value "url" key ebib--cur-db 'noerror 'unbraced 'xref)))
- (unless key
- (error "[Ebib] No key assigned to entry"))
- (download-pdf-from-doi key doi (or publisher eprinttype) eprint (or journal journaltitle) organization url)))
-
- (defun ebib-check-file ()
- "Download a PDF for the current entry."
- (interactive)
- (let ((key (ebib--get-key-at-point)))
- (unless (file-exists-p (concat (car ebib-file-search-dirs) "/" key ".pdf"))
- (error "[Ebib] No PDF found."))
- t)))
+ (remove-hook 'ebib-notes-new-note-hook #'org-narrow-to-subtree))
+
+(use-package ymh-ebib
+ :straight nil
+ :load-path "ymh-emacs"
+ :config
+ (define-key ebib-index-mode-map "D" #'ymh-ebib-download-pdf-from-doi))
(use-package spell-fu
:hook text-mode
@@ -876,6 +738,61 @@ https://yannherklotz.com"))
" "
#'ymhg/electric-space)))
+(use-package ox-hugo)
+(use-package ox-gfm)
+
+(use-package smartparens-config
+ :straight smartparens
+ :defer nil
+ :config
+ (smartparens-global-mode)
+ (add-hook 'minibuffer-setup-hook #'turn-on-smartparens-strict-mode)
+
+ (define-key smartparens-mode-map (kbd "C-M-f") #'sp-forward-sexp)
+ (define-key smartparens-mode-map (kbd "C-M-b") #'sp-backward-sexp)
+
+ (define-key smartparens-mode-map (kbd "C-M-d") #'sp-down-sexp)
+ (define-key smartparens-mode-map (kbd "C-M-a") #'sp-backward-down-sexp)
+ (define-key smartparens-mode-map (kbd "C-S-d") #'sp-beginning-of-sexp)
+ (define-key smartparens-mode-map (kbd "C-S-a") #'sp-end-of-sexp)
+
+ (define-key smartparens-mode-map (kbd "C-M-e") #'sp-up-sexp)
+ (define-key smartparens-mode-map (kbd "C-M-u") #'sp-backward-up-sexp)
+ (define-key smartparens-mode-map (kbd "C-M-t") #'sp-transpose-sexp)
+
+ (define-key smartparens-mode-map (kbd "C-M-n") #'sp-forward-hybrid-sexp)
+ (define-key smartparens-mode-map (kbd "C-M-p") #'sp-backward-hybrid-sexp)
+
+ (define-key smartparens-mode-map (kbd "C-M-k") #'sp-kill-sexp)
+ (define-key smartparens-mode-map (kbd "C-M-w") #'sp-copy-sexp)
+
+ (define-key smartparens-mode-map (kbd "C-<right>") #'sp-forward-slurp-sexp)
+ (define-key smartparens-mode-map (kbd "C-<left>") #'sp-forward-barf-sexp)
+ (define-key smartparens-mode-map (kbd "C-M-<left>") #'sp-backward-slurp-sexp)
+ (define-key smartparens-mode-map (kbd "C-M-<right>") #'sp-backward-barf-sexp)
+
+ (define-key smartparens-mode-map (kbd "M-D") #'sp-splice-sexp)
+
+ (define-key smartparens-mode-map (kbd "C-]") #'sp-select-next-thing-exchange)
+ (define-key smartparens-mode-map (kbd "C-<left_bracket>") #'sp-select-previous-thing)
+ (define-key smartparens-mode-map (kbd "C-M-]") #'sp-select-next-thing)
+
+ (define-key smartparens-mode-map (kbd "M-F") #'sp-forward-symbol)
+ (define-key smartparens-mode-map (kbd "M-B") #'sp-backward-symbol)
+
+ (define-key smartparens-mode-map (kbd "C-\"") #'sp-change-inner)
+ (define-key smartparens-mode-map (kbd "M-i") #'sp-change-enclosing)
+
+ (bind-key "C-c f" (lambda () (interactive) (sp-beginning-of-sexp 2)) smartparens-mode-map)
+ (bind-key "C-c b" (lambda () (interactive) (sp-beginning-of-sexp -2)) smartparens-mode-map)
+
+ (bind-key ";" #'sp-comment emacs-lisp-mode-map)
+
+ (bind-key [remap c-electric-backspace] #'sp-backward-delete-char smartparens-strict-mode-map)
+
+ (sp-with-modes 'org-mode
+ (sp-local-pair "=" "=" :wrap "C-=")))
+
(setq gc-cons-threshold (* 1024 1024 10))
(setq custom-file (concat user-emacs-directory "custom.el"))
diff --git a/ymh-emacs/ymh-common.el b/ymh-emacs/ymh-common.el
new file mode 100644
index 0000000..005f39b
--- /dev/null
+++ b/ymh-emacs/ymh-common.el
@@ -0,0 +1,53 @@
+;;; ymh-common.el --- Some common functions -*- lexical-binding: t; -*-
+
+;; Author: Yann Herklotz <git@yannherklotz.com>
+;; Package-Requires: ((emacs "24.3"))
+
+;;; Commentary:
+
+;; This file contains some common code.
+
+;;; Code:
+
+(defun ymhg/prev-window ()
+ "Go to the previous window using `other-window'."
+ (interactive)
+ (other-window -1))
+
+(defun ymhg/reset-coq-windows ()
+ "Resets the Goal and Response windows."
+ (interactive)
+ (other-frame 1)
+ (delete-other-windows)
+ (split-window-below)
+ (switch-to-buffer "*goals*")
+ (other-window 1)
+ (switch-to-buffer "*response*")
+ (other-frame 1))
+
+(defun ymhg/pass (query)
+ "Return the password as a string from QUERY."
+ (s-trim (shell-command-to-string (concat "pass show " query))))
+
+(defun ymhg/apply-theme (appearance)
+ "Load theme, taking current system APPEARANCE into consideration."
+ (mapc #'disable-theme custom-enabled-themes)
+ (pcase appearance
+ ;;('light (load-theme 'modus-operandi t))
+ ;;('dark (load-theme 'modus-vivendi t))
+ ('light (load-theme 'ef-spring t))
+ ('dark (load-theme 'ef-dark t))))
+
+(defadvice load-theme
+ (before theme-dont-propagate activate)
+ (mapc #'disable-theme custom-enabled-themes))
+
+(defun ymhg/electric-space ()
+ (interactive)
+ (if (looking-back (sentence-end))
+ (insert "%\n")
+ (self-insert-command 1)))
+
+(provide 'ymh-common)
+
+;;; ymh-common.el ends here
diff --git a/ymh-emacs/ymh-diary.el b/ymh-emacs/ymh-diary.el
index 9654971..343d331 100644
--- a/ymh-emacs/ymh-diary.el
+++ b/ymh-emacs/ymh-diary.el
@@ -1,5 +1,8 @@
;;; ymh-diary.el --- Extensions to the Emacs Diary -*- lexical-binding: t; -*-
+;; Author: Yann Herklotz <git@yannherklotz.com>
+;; Package-Requires: ((emacs "24.3"))
+
;;; Commentary:
;; This file contains extensions to the built-in Emacs Diary. Mainly, it adds a
@@ -7,4 +10,31 @@
;;; Code:
+(defun ymh-diary-schedule (y1 m1 d1 y2 m2 d2 dayname)
+ "Entry applies if date is between dates on DAYNAME.
+ Order of the parameters is M1, D1, Y1, M2, D2, Y2 if
+ `european-calendar-style' is nil, and D1, M1, Y1, D2, M2, Y2 if
+ `european-calendar-style' is t. Entry does not apply on a history."
+ (let ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
+ (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
+ (d (calendar-absolute-from-gregorian date)))
+ (if (and
+ (<= date1 d)
+ (<= d date2)
+ (= (calendar-day-of-week date) dayname)
+ ;;(not (calendar-check-holidays date))
+ )
+ entry)))
+
+(defun ymh-diary-last-day-of-month (date)
+ "Return `t` if DATE is the last day of the month."
+ (let* ((day (calendar-extract-day date))
+ (month (calendar-extract-month date))
+ (year (calendar-extract-year date))
+ (last-day-of-month
+ (calendar-last-day-of-month month year)))
+ (= day last-day-of-month)))
+
+(provide 'ymh-diary)
+
;;; ymh-diary.el ends here
diff --git a/ymh-emacs/ymh-ebib.el b/ymh-emacs/ymh-ebib.el
new file mode 100644
index 0000000..38cc9c0
--- /dev/null
+++ b/ymh-emacs/ymh-ebib.el
@@ -0,0 +1,113 @@
+;;; ymh-ebib.el --- Extensions to the Ebib package -*- lexical-binding: t; -*-
+
+;; Author: Yann Herklotz <git@yannherklotz.com>
+;; Package-Requires: ((emacs "26.1") (ebib "2.0"))
+
+;;; Commentary:
+
+;; This file contains extensions to ebib.
+
+;;; Code:
+
+(require 'ebib)
+
+(defun ymh-ebib-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 ymh-ebib-acm-pdf-url (doi)
+ "Retrieve a DOI pdf from the ACM."
+ (concat "https://dl.acm.org/doi/pdf/" doi))
+
+(defun ymh-ebib-ieee-pdf-url (doi)
+ "Retrieve a DOI pdf from the IEEE."
+ (when (string-match "\\.\\([0-9]*\\)$" doi)
+ (let ((doi-bit (match-string 1 doi)))
+ (concat "https://ieeexplore.ieee.org/stampPDF/getPDF.jsp?tp=&arnumber=" doi-bit "&ref="))))
+
+(defun ymh-ebib-springer-pdf-url (doi)
+ "Retrieve a DOI pdf from the Springer."
+ (concat "https://link.springer.com/content/pdf/" doi ".pdf"))
+
+(defun ymh-ebib-arxiv-pdf-url (epr)
+ (concat "https://arxiv.org/pdf/" epr ".pdf"))
+
+(defun ymh-ebib--download-pdf-from-doi (key &optional doi publisher eprint journal organization url)
+ "Download pdf from doi with KEY name."
+ (let ((pub (or publisher ""))
+ (epr (or eprint ""))
+ (jour (or journal ""))
+ (org (or organization ""))
+ (link (or url "")))
+ (url-copy-file (cond
+ ((not doi) link)
+ ((or (string-match "ACM" (s-upcase pub))
+ (string-match "association for computing machinery" (s-downcase pub)))
+ (ymh-ebib-acm-pdf-url doi))
+ ((string-match "arxiv" (s-downcase pub))
+ (ymh-ebib-arxiv-pdf-url epr))
+ ((or (string-match "IEEE" (s-upcase pub))
+ (string-match "IEEE" (s-upcase jour))
+ (string-match "IEEE" (s-upcase org)))
+ (ymh-ebib-ieee-pdf-url doi))
+ ((string-match "springer" (s-downcase pub))
+ (ymh-ebib-springer-pdf-url doi))
+ (t (ymh-ebib-sci-hub-pdf-url doi)))
+ (concat (car ebib-file-search-dirs) "/" key ".pdf"))))
+
+(defun ymh-ebib-download-pdf-from-link (link key)
+ (url-copy-file link
+ (concat (car ebib-file-search-dirs) "/" key ".pdf")))
+
+(defun ymh-ebib-download-pdf-from-downloads (key)
+ (copy-file (concat "~/Downloads/" key ".pdf")
+ (concat (car ebib-file-search-dirs) "/" key ".pdf") t))
+
+(defun ymh-ebib-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 ymh-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))
+ (eprinttype (ebib-get-field-value "eprinttype" key ebib--cur-db 'noerror 'unbraced 'xref))
+ (eprint (ebib-get-field-value "eprint" key ebib--cur-db 'noerror 'unbraced 'xref))
+ (journal (ebib-get-field-value "journal" key ebib--cur-db 'noerror 'unbraced 'xref))
+ (journaltitle (ebib-get-field-value "journaltitle" key ebib--cur-db 'noerror 'unbraced 'xref))
+ (organization (ebib-get-field-value "organization" key ebib--cur-db 'noerror 'unbraced 'xref))
+ (url (ebib-get-field-value "url" key ebib--cur-db 'noerror 'unbraced 'xref)))
+ (unless key
+ (error "[Ebib] No key assigned to entry"))
+ (ymh-ebib--download-pdf-from-doi key doi (or publisher eprinttype) eprint (or journal journaltitle) organization url)))
+
+(defun ymh-ebib-ebib-check-file ()
+ "Download a PDF for the current entry."
+ (interactive)
+ (let ((key (ebib--get-key-at-point)))
+ (unless (file-exists-p (concat (car ebib-file-search-dirs) "/" key ".pdf"))
+ (error "[Ebib] No PDF found."))
+ t))
+
+(provide 'ymh-ebib)
+
+;;; ymh-ebib.el ends here