From f0f9bee1e39846461003b1ce268037b885b2a1d2 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Sat, 19 Nov 2022 00:37:56 +0000 Subject: Refining the changes --- init.el | 384 ++++++++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 301 insertions(+), 83 deletions(-) (limited to 'init.el') diff --git a/init.el b/init.el index 6e05f1f..6f5df08 100644 --- a/init.el +++ b/init.el @@ -23,17 +23,43 @@ (setq-default bidi-paragraph-direction 'left-to-right) (if (version<= "27.1" emacs-version) (setq bidi-inhibit-bpa t)) +;; Set up dictionaries +(setq ispell-dictionary "british") + +(setq read-extended-command-predicate + #'command-completion-default-include-p) + +(setq enable-recursive-minibuffers t) + +(setq auto-mode-alist + (append + (list ;;'("\\.\\(vcf\\|gpg\\)\\'" . sensitive-minor-mode) + '("\\.sv\\'" . verilog-mode) + '("\\.mkiv\\'" . context-mode) + '("\\.mkii\\'" . context-mode) + '("\\.mkxl\\'" . context-mode)) + auto-mode-alist)) (setq face-remapping-alist '((proof-locked-face . region))) (fset 'yes-or-no-p 'y-or-n-p) +;; Mac configuration (when (eq system-type 'darwin) - (setq mac-right-option-modifier 'none - mac-option-key-is-meta nil - mac-command-key-is-meta t - mac-command-modifier 'meta - mac-option-modifier nil)) + (progn (setq mac-right-option-modifier 'none + mac-command-modifier 'meta + mac-option-modifier nil) + + (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)))) + + (add-hook 'ns-system-appearance-change-functions #'ymhg/apply-theme))) (defun prev-window () (interactive) @@ -50,6 +76,10 @@ (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)))) + (global-set-key (kbd "M-u") #'upcase-dwim) (global-set-key (kbd "M-l") #'downcase-dwim) (global-set-key (kbd "M-c") #'capitalize-dwim) @@ -92,6 +122,11 @@ (define-prefix-command 'ymh-map) (global-set-key (kbd "C-c y") 'ymh-map) (define-key ymh-map (kbd "o") #'ymhg/reset-coq-windows) +(define-key ymh-map (kbd "c") #'calendar) +(define-key ymh-map (kbd "C-l") #'org-agenda-open-link) +(define-key ymh-map (kbd "C-p") #'org-previous-link) +(define-key ymh-map (kbd "C-n") #'org-next-link) +;;(define-key y-map (kbd "C-g") #'org-zettelkasten-goto-id) (setq browse-url-handlers '(("wikipedia\\.org" . eww-browse-url) @@ -115,12 +150,6 @@ (setq message-send-mail-function 'message-send-mail-with-sendmail) (setq message-fill-column 80) -(use-package sendmail - :config - (if (eq system-type 'darwin) - (setq sendmail-program "/usr/local/bin/msmtp") - (setq sendmail-program "/usr/bin/msmtp"))) - (setq message-signature "Yann Herklotz Imperial College London https://yannherklotz.com") @@ -174,9 +203,93 @@ https://yannherklotz.com") (straight-use-package 'use-package) +(use-package flyspell + :straight nil + :config + (unbind-key "C-." flyspell-mode-map) + (unbind-key "C-," flyspell-mode-map) + (setq flyspell-mouse-map (make-sparse-keymap))) + +(use-package calc-forms + :straight nil + :config + (add-to-list 'math-tzone-names '("AOE" 12 0)) + (add-to-list 'math-tzone-names '("IST" (float -55 -1) 0))) + +(use-package calendar + :straight nil + :config + (setq calendar-mark-diary-entries-flag t) + (setq calendar-mark-holidays-flag t) + (setq calendar-mode-line-format nil) + (setq calendar-time-display-form + '(24-hours ":" minutes + (when time-zone + (format "(%s)" time-zone)))) + (setq calendar-week-start-day 1) ; Monday + (setq calendar-date-style 'iso) + (setq calendar-date-display-form calendar-iso-date-display-form) + (setq calendar-time-zone-style 'numeric) ; Emacs 28.1 + (add-hook 'calendar-today-visible-hook #'calendar-mark-today) + (remove-hook 'calendar-mode-hook #'org--setup-calendar-bindings) + (let ((map calendar-mode-map)) + (define-key map (kbd "s") #'calendar-sunrise-sunset) + (define-key map (kbd "l") #'lunar-phases) + (define-key map (kbd "i") nil) ; Org sets this, much to my chagrin (see `remove-hook' above) + (define-key map (kbd "i a") #'diary-insert-anniversary-entry) + (define-key map (kbd "i c") #'diary-insert-cyclic-entry) + (define-key map (kbd "i d") #'diary-insert-entry) ; for current "day" + (define-key map (kbd "i m") #'diary-insert-monthly-entry) + (define-key map (kbd "i w") #'diary-insert-weekly-entry) + (define-key map (kbd "i y") #'diary-insert-yearly-entry) + (define-key map (kbd "M-n") #'calendar-forward-month) + (define-key map (kbd "M-p") #'calendar-backward-month))) + +(use-package cal-dst + :straight nil + :config + (setq calendar-standard-time-zone-name "+0000") + (setq calendar-daylight-time-zone-name "+0100")) + +(use-package diary-lib + :straight nil + :config + (setq diary-file "~/Dropbox/org/diary") + (setq diary-date-forms diary-iso-date-forms) + (setq diary-comment-start ";;") + (setq diary-comment-end "") + (setq diary-nonmarking-symbol "!") + (setq diary-show-holidays-flag t) + (setq diary-display-function #'diary-fancy-display) ; better than its alternative + (setq diary-header-line-format nil) + (setq diary-list-include-blanks nil) + (setq diary-number-of-entries 2) + (setq diary-mail-days 2) + (setq diary-abbreviated-year-flag nil) + ;;(add-hook 'diary-list-entries-hook #'diary-fix-timezone t) + (add-hook 'diary-list-entries-hook #'diary-sort-entries t) + (add-hook 'diary-list-entries-hook 'diary-include-other-diary-files) + (add-hook 'diary-mark-entries-hook 'diary-mark-included-diary-files)) + +(use-package appt + :straight nil + :config + (setq appt-display-diary nil) + (setq appt-disp-window-function #'appt-disp-window) + (setq appt-display-mode-line t) + (setq appt-display-interval 3) + (setq appt-audible nil) + (setq appt-warning-time-regexp "appt \\([0-9]+\\)") + (setq appt-message-warning-time 15) + (run-at-time 10 nil #'appt-activate 1)) + +(use-package savehist + :straight nil + :init + (savehist-mode)) + (use-package ef-themes :config - (load-theme 'ef-autumn t)) (use-package pass @@ -317,61 +430,6 @@ https://yannherklotz.com") :straight nil :after org) -(use-package calendar - :straight nil - :config - (setq calendar-mark-diary-entries-flag t) - (setq calendar-mark-holidays-flag t) - (setq calendar-mode-line-format nil) - (setq calendar-time-display-form - '(24-hours ":" minutes - (when time-zone - (format "(%s)" time-zone)))) - (setq calendar-week-start-day 1) ; Monday - (setq calendar-date-style 'iso) - (setq calendar-date-display-form calendar-iso-date-display-form) - (setq calendar-time-zone-style 'numeric) ; Emacs 28.1 - (add-hook 'calendar-today-visible-hook #'calendar-mark-today) - (remove-hook 'calendar-mode-hook #'org--setup-calendar-bindings) - (let ((map calendar-mode-map)) - (define-key map (kbd "s") #'calendar-sunrise-sunset) - (define-key map (kbd "l") #'lunar-phases) - (define-key map (kbd "i") nil) ; Org sets this, much to my chagrin (see `remove-hook' above) - (define-key map (kbd "i a") #'diary-insert-anniversary-entry) - (define-key map (kbd "i c") #'diary-insert-cyclic-entry) - (define-key map (kbd "i d") #'diary-insert-entry) ; for current "day" - (define-key map (kbd "i m") #'diary-insert-monthly-entry) - (define-key map (kbd "i w") #'diary-insert-weekly-entry) - (define-key map (kbd "i y") #'diary-insert-yearly-entry) - (define-key map (kbd "M-n") #'calendar-forward-month) - (define-key map (kbd "M-p") #'calendar-backward-month))) - -(use-package cal-dst - :straight nil - :config - (setq calendar-standard-time-zone-name "+0000") - (setq calendar-daylight-time-zone-name "+0100")) - -(use-package diary-lib - :straight nil - :config - (setq diary-file "~/Dropbox/org/diary") - (setq diary-date-forms diary-iso-date-forms) - (setq diary-comment-start ";;") - (setq diary-comment-end "") - (setq diary-nonmarking-symbol "!") - (setq diary-show-holidays-flag t) - (setq diary-display-function #'diary-fancy-display) ; better than its alternative - (setq diary-header-line-format nil) - (setq diary-list-include-blanks nil) - (setq diary-number-of-entries 2) - (setq diary-mail-days 2) - (setq diary-abbreviated-year-flag nil) - ;;(add-hook 'diary-list-entries-hook #'diary-fix-timezone t) - (add-hook 'diary-list-entries-hook #'diary-sort-entries t) - (add-hook 'diary-list-entries-hook 'diary-include-other-diary-files) - (add-hook 'diary-mark-entries-hook 'diary-mark-included-diary-files)) - (use-package org-crypt :straight nil :after org @@ -387,18 +445,6 @@ https://yannherklotz.com") (setq org-id-link-to-org-use-id 'use-existing) (setq org-id-track-globally t)) -(use-package appt - :straight nil - :config - (setq appt-display-diary nil) - (setq appt-disp-window-function #'appt-disp-window) - (setq appt-display-mode-line t) - (setq appt-display-interval 3) - (setq appt-audible nil) - (setq appt-warning-time-regexp "appt \\([0-9]+\\)") - (setq appt-message-warning-time 15) - (run-at-time 10 nil #'appt-activate 1)) - (use-package org-transclusion :after org :config @@ -444,6 +490,25 @@ https://yannherklotz.com") ;;(define-key coq-mode-map (kbd "C-c TAB") #'smie-indent-line) ) +(use-package alectryon + :hook (coq-mode . alectryon-mode) + :config + (when (eq system-type 'darwin) + (setq alectryon-executable "/nix/store/bvlk3hyrjdgl0sg93rrdr2z71hgza0m9-python3.9-alectryon-1.4.0/bin/alectryon")) + (map! :map alectryon-mode-map + "C-c u t" #'alectryon-toggle + "C-c u p" #'ymhg/alectryon-preview) + (defun ymhg/alectryon-preview () + "Display an HTML preview of the current buffer." + (interactive) + (let* ((html-fname (make-temp-file "alectryon" nil ".html")) + (args `("-r" "5" "-" ,html-fname))) + (apply #'call-process-region nil nil "rst2html5" nil nil nil args) + (message "Compilation complete") + (browse-url html-fname)))) + +(use-package rst) + (use-package boogie-friends :config (setq flycheck-dafny-executable (executable-find "dafny")) @@ -460,10 +525,11 @@ https://yannherklotz.com") :init (vertico-mode)) -(use-package savehist - :straight nil - :init - (savehist-mode)) +(use-package sendmail + :config + (if (eq system-type 'darwin) + (setq sendmail-program "/usr/local/bin/msmtp") + (setq sendmail-program "/usr/bin/msmtp"))) (use-package notmuch :config @@ -517,6 +583,158 @@ https://yannherklotz.com") (use-package ol-notmuch) +(use-package ebib + :bind (("C-c y b" . ebib)) + :init + (defun ymhg/ebib-create-identifier (key _) key) + (setq ebib-preload-bib-files '("~/Dropbox/bibliography/references.bib") + ebib-notes-default-file "~/Dropbox/bibliography/notes.org" + ebib-notes-template "* %T\n:PROPERTIES:\n%K\n:NOTER_DOCUMENT: papers/%k.pdf\n:END:\n%%?\n" + ebib-keywords (expand-file-name "~/Dropbox/bibliography/keywords.txt") + ebib-reading-list-file "~/Dropbox/bibliography/reading_list.org" + ebib-notes-storage 'multiple-notes-per-file) + :config + (add-to-list 'ebib-notes-template-specifiers '(?k . ymhg/ebib-create-identifier)) + (add-to-list 'ebib-file-search-dirs "~/Dropbox/bibliography/papers") + (if (eq system-type 'darwin) + (add-to-list 'ebib-file-associations '("pdf" . "open")) + (add-to-list 'ebib-file-associations '("pdf" . nil))) + (add-to-list 'ebib-citation-commands '(org-mode (("ref" "[cite:@%(%K%,)]")))) + (add-to-list 'ebib-citation-commands '(context-mode (("cite" "\\cite[%(%K%,)]") + ("authoryear" "\\cite[authoryear][%(%K%,)]") + ("authoryears" "\\cite[authoryears][%(%K%,)]") + ("entry" "\\cite[entry][%(%K%,)]") + ("author" "\\cite[author][%(%K%,)]")))) + + (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))) + +(use-package spell-fu + :config + (add-hook 'spell-fu-mode-hook + (lambda () + (spell-fu-dictionary-add (spell-fu-get-ispell-dictionary "en_GB")) + (spell-fu-dictionary-add (spell-fu-get-ispell-dictionary "de_DE")) + (spell-fu-dictionary-add (spell-fu-get-ispell-dictionary "fr_FR")) + (spell-fu-dictionary-add + (spell-fu-get-personal-dictionary "fr-personal" "~/.aspell.en_GB.pws")) + (spell-fu-dictionary-add + (spell-fu-get-personal-dictionary "de-personal" "~/.aspell.de_DE.pws")) + (spell-fu-dictionary-add + (spell-fu-get-personal-dictionary "fr-personal" "~/.aspell.fr_FR.pws"))))) + +(use-package ledger-mode) + +(use-package geiser + :config + ;;(unbind-key "C-." geiser-mode-map) + (unbind-key "C-." geiser-repl-mode-map)) + +(use-package geiser-chicken + :config + (setq geiser-chicken-binary "chicken-csi")) + (setq gc-cons-threshold (* 1024 1024 10)) (custom-set-variables -- cgit