summaryrefslogtreecommitdiffstats
path: root/ymh-emacs
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 /ymh-emacs
parent3cc9791003364c338cc6d219c5f144210aa76bef (diff)
downloadymh-emacs-ad161b70c317cc766c6ec42064cb6410136c7905.tar.gz
ymh-emacs-ad161b70c317cc766c6ec42064cb6410136c7905.zip
Take more configuration into packages
Diffstat (limited to 'ymh-emacs')
-rw-r--r--ymh-emacs/ymh-common.el53
-rw-r--r--ymh-emacs/ymh-diary.el30
-rw-r--r--ymh-emacs/ymh-ebib.el113
3 files changed, 196 insertions, 0 deletions
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