123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449 |
- ;; Always revert files, i.e. reload them to buffers if emacs notices
- ;; them changing by e.g. an external program.
- (global-auto-revert-mode 1)
- ;; Global keys for using Org-mode
- ;; Read the tutorial at http://orgmode.org/worg/org-tutorials/orgtutorial_dto.html
- ;; Load the MELPA package library
- (require 'package)
- (add-to-list 'package-archives '("melpa"
- . "https://melpa.org/packages/") t)
- (package-initialize)
- (setq mail-user-agent 'gnus-user-agent)
- ;; Constants
- (setq keepass-folder "~/Syncthing/keepass/"
- bibliography-folder "~/Syncthing/bibliography/")
- ;; BBDB settings
- (require 'bbdb)
- (setq bbdb-file (concat keepass-folder "bbdb"))
- (bbdb-initialize 'gnus 'message)
- (bbdb-mua-auto-update-init 'gnus 'message)
- ;; Display BBDB in popup window
- (setq bbdb-mua-pop-up t)
- (setq bbdb-mua-pop-up-window-size 3)
- ;; Look for existing contact, interactively prompt to create
- (setq bbdb-mua-update-interactive-p '(query . create))
- ;; Nyan-mode.
- (require 'nyan-mode)
- (nyan-mode 1)
- (nyan-start-animation)
- ;; Install sox in termux to play music and uncomment below.
- ;; (defun nyan-start-music ()
- ;; (interactive)
- ;; (unless nyan-music-process
- ;; (setq nyan-music-process (start-process-shell-command "nyan-music" "nyan-music" (concat "play " +nyan-music+ " repeat 9001")))))
- ;; Company (complete anything) mode
- (require 'company)
- (add-hook 'latex-mode-hook 'company-mode)
- (setq company-tooltip-align-annotations 1
- company-minimum-prefix-length 3
- company-idle-delay 0.0)
- ;; SLIME + company (For Common LISP)
- (require 'slime)
- (setq inferior-lisp-program "clisp")
- (slime-setup '(slime-company))
- (slime-setup '(slime-fancy))
- ;; Geiser-Chez (For Chez Scheme), start with M-x run-geiser
- (require 'geiser-chez)
- ;; Don't use text color when rendering html using shr (links ok)
- (setq shr-use-colors nil)
- ;; Avoids GPG password input entry issue in emacs termux
- ;; ALSO: you must edist .gnupeg/gpg-agent.conf and add "allow-emacs-pinentry"
- (setq epg-pinentry-mode 'loopback)
- ;; Expand region see https://github.com/magnars/expand-region.el
- (require 'expand-region)
- (global-set-key (kbd "<f11>") 'er/expand-region)
- (delete-selection-mode 1)
- ;; Smartparens
- (require 'smartparens-config)
- (add-hook 'lisp-mode-hook 'show-paren-mode)
- (add-hook 'lisp-mode-hook 'smartparens-mode)
- (add-hook 'latex-mode-hook 'show-paren-mode)
- (add-hook 'latex-mode-hook 'smartparens-mode)
- (add-hook 'markdown-mode-hook 'smartparens-mode)
- ;; Make new buffers split the window vertically instead of horizontally
- (setq split-height-threshold 10)
- (setq split-width-threshold 80)
- ;; Winner mode: C-c ← and C-c → for going between used window configurations
- (winner-mode 1)
- ;; Word wrap
- (setq-default word-wrap t)
- ;; Unfill paragraph. E.g. when needing to copy to an external program.
- (defun unfill-paragraph ()
- "Takes a multi-line paragraph and makes it into a single line of text."
- (interactive)
- (let ((fill-column (point-max)))
- (fill-paragraph nil)))
- ;; Handy key definition: alt-Q (alt+shift+q)
- (define-key global-map "\M-Q" 'unfill-paragraph)
- ;; Windmove
- (windmove-default-keybindings)
- (setq org-replace-disputed-keys t) ; This must be loaded before org-mode
- (require 'org)
- (define-key global-map "\C-cl" 'org-store-link)
- (define-key global-map "\C-ca" 'org-agenda)
- (setq org-log-done 'time)
- ;; The below is so that PDF-files or others can be opened with \C-o in org-mode
- ;; It makes xdg-open work in eshell. See
- ;; https://askubuntu.com/questions/646631/emacs-doesnot-work-with-xdg-open
- ;; and
- ;; https://emacs.stackexchange.com/questions/19344/why-does-xdg-open-not-work-in-eshell
- ;; WARNING: it might break other things. Some have mentioned gnuplot.
- (setq process-connection-type nil)
- ;; Make org open links using xdg-open (for termux e.g.)
- (setq browse-url-generic-program
- (executable-find "xdg-open")
- browse-url-browser-function 'browse-url-generic)
- ;; Allow refiling to level 9 branches with C-c C-w
- (setq org-refile-targets '((org-agenda-files :maxlevel . 9)))
- ;; In calendar.org refilling C-c C-w will put to beginning of list instead of end
- (setq org-reverse-note-order '(("calendar.org" . t)))
- ;; Show e.g. Work/Research/LUT/self-improvement instead of just self-improvement
- (setq org-refile-use-outline-path t)
- ;; Show done recurring tasks in org-mode log (agenda, then press l)
- (setq org-agenda-log-mode-items '(closed clock state))
- (setq org-clock-idle-time 15)
- ;; Let the agenda always show 3 days in advance instead of the current week
- (setq org-agenda-start-on-weekday 1) ; nil means current day
- (setq org-agenda-span 7)
- ;; Make sure org-latex uses the OT1 font encoding instead of OT. The
- ;; latter has licensing issues in Parabola GNU/Linux. If the defaults
- ;; of "org-latex-default-packages-alist" should ever change, then run
- ;; "M-x apropos RET org-latex-default-packages-alist" and read them
- ;; from there. Also, to preview a LaTeX formula when using X, run C-c
- ;; C-x C-l.
- (with-eval-after-load 'org
- (setq org-latex-default-packages-alist
- '(("AUTO" "inputenc" t)
- ("OT1" "fontenc" t)
- ("" "fixltx2e" nil)
- ("" "graphicx" t)
- ("" "longtable" nil)
- ("" "float" nil)
- ("" "wrapfig" nil)
- ("" "rotating" nil)
- ("normalem" "ulem" t)
- ("" "amsmath" t)
- ("" "textcomp" t)
- ("" "marvosym" t)
- ("" "wasysym" t)
- ("" "amssymb" t)
- ("" "hyperref" nil)
- "\\tolerance=1000")
- )
- )
- ;; Make the formulas larger when previewing:
- ;;(with-eval-after-load 'org
- ;; (setq org-format-latex-options (plist-put org-format-latex-options :scale 1.5))
- ;; )
- ;; Load emacs speaks statistics
- ;;(add-to-list 'load-path "/usr/share/emacs/site-lisp/ess")
- ;;(require 'ess-site)
- ;; Allow executing "GNU calc" code blocks in org-mode
- (org-babel-do-load-languages
- 'org-babel-load-languages
- '((calc . t)
- (octave . t)
- (R . t)
- (python . t)
- (shell . t)))
- ;; Make the keyboard sortcut "< s TAB" create a code block that also
- ;; exports the results when exporting.
- (add-to-list 'org-structure-template-alist
- '("s" "#+BEGIN_SRC ? :exports both\n\n#+END_SRC"))
- ;; Add syntax highlighting in code blocks
- (setq org-src-fontify-natively t)
- ;; Use tab to indent inside code blocks
- (setq org-src-tab-acts-natively t)
- ;; Tell emacs to opem .m-files in the Octave-mode
- (add-to-list 'auto-mode-alist '("\\.m\\'" . octave-mode))
- ;; Firstly, make C-x C-m always compile. Secondly make the compilation
- ;; always run "make -k", unless a prefix argument has been given,
- ;; e.g. C-u C-x C-m.
- (global-set-key "\C-x\C-m" 'compile)
- (setq compilation-read-command nil
- compilation-scroll-output t)
- ;; Tell emacs to use the current emacs cursor position for pasting,
- ;; instead of first moving to the mouse cursor position and then
- ;; pasting.
- (setq mouse-yank-at-point t)
- ;; Tell emacs to align at equal sign in bibtex files. Do the aligning
- ;; ourself with C-c C-q.
- (setq bibtex-align-at-equal-sign t)
- ;; Reftex
- (require 'reftex)
- (add-hook 'latex-mode-hook 'turn-on-reftex)
- ;; Set same TODO list for all. Individually it should be:
- ;;#+SEQ_TODO: TODO(t) WAIT(w!/!) MEET(m) | DONE(d) CANCELLED(c@)
- (setq calendar-file (concat keepass-folder "calendar.org"))
- (setq org-todo-keywords
- '((sequence "TODO(t)" "WAIT(w!/!)" "MEET(m)" "IDEA(i)" "|" "DONE(d)" "CANCELLED(c@)")))
- (setq org-todo-keyword-faces
- '(("MEET" . (:foreground "#486f66" :background "#f4bbce" :weight ultra-bold))))
- ;; Define custom org-capture templates
- ;; see http://cachestocaches.com/2016/9/my-workflow-org-agenda/
- (setq org-capture-templates
- '(("t" "todo" entry (file+headline calendar-file "Unclassified")
- "* TODO %? %A")
- ("m" "Meeting" entry (file+headline calendar-file "Unclassified")
- "* MEET %? %A")))
- ;; Use the C-c c key globally to create an org-item from the context
- (define-key global-map "\C-cc" 'org-capture)
- ;; org-agenda files, can be directories (doesn't look at subdirs) or files
- (setq org-agenda-files (list calendar-file))
- ;; Remove unnecessary " calendar: " from each entry on the left.
- (setq org-agenda-prefix-format
- '((agenda . " %i %?-12t% s") ; default: " %i %-12:c%?-12t% s"
- (todo . " %i %-12:c")
- (tags . " %i %-12:c")
- (search . " %i %-12:c")))
- (setq org-agenda-remove-tags t)
- ;; Never use tabs, always use spaces for indenting
- (setq indent-tabs-mode nil)
- ;; Use 2 spaces when indenting CSS, JS and shell instead of the default 4
- (setq css-indent-offset 2)
- (setq js-indent-level 2)
- (setq sh-indentation 2)
- ;; Helm-Bibtex
- ;; See https://github.com/tmalsburg/helm-bibtex
- (autoload 'helm-bibtex "helm-bibtex" "" t)
- (setq bibtex-completion-bibliography (list (concat bibliography-folder "references.bib"))) ; needs (list ...) for new org-ref to work
- (setq bibtex-completion-library-path (list (concat bibliography-folder "bibtex-pdfs/"))) ; needs (list ...) for new org-ref to work
- (setq bibtex-completion-pdf-field "File")
- (setq bibtex-completion-notes-path (concat bibliography-folder "notes.org"))
- (setq bibtex-completion-additional-search-fields '(keywords tags))
- (setq bibtex-completion-pdf-symbol "⌘")
- (setq bibtex-completion-notes-symbol "✎")
- ;; Requires a newer version of bibtex-completion!
- (setq bibtex-completion-pdf-extension '(".pdf" ".djvu"))
- (setq while-no-input-ignore-events '())
- ;; See this also:
- ;; https://github.com/tmalsburg/helm-bibtex#create-a-bibtex-file-containing-only-specific-entries
- (require 'helm)
- (global-set-key (kbd "<f12>") 'helm-command-prefix) ;; use <apps> for the menu button in other OS's, or for example <f12> for Termux and see its wiki for showing this button on its interface. Also <X86Launch1> works in Mate desktop, but not terminals.
- (define-key helm-command-map "b" 'helm-bibtex)
- (define-key helm-command-map "B" 'helm-bibtex-with-local-bibliography)
- (define-key helm-command-map "n" 'helm-bibtex-with-notes)
- (define-key helm-command-map (kbd "<f12>") 'helm-resume)
- (require 'org-ref-helm)
- (setq org-ref-insert-link-function 'org-ref-insert-link-hydra/body
- org-ref-insert-cite-function 'org-ref-cite-insert-helm
- org-ref-insert-label-function 'org-ref-insert-label-link
- org-ref-insert-ref-function 'org-ref-insert-ref-link
- org-ref-cite-onclick-function (lambda (_) (org-ref-citation-hydra/body)))
- (define-key helm-command-map "c" org-ref-insert-cite-function)
- (define-key helm-command-map "r" org-ref-insert-ref-function)
- (define-key helm-command-map "l" org-ref-insert-label-function)
- (define-key helm-command-map "p" 'org-ref-open-pdf-at-point)
- ;; sort helm-bibtex in the same order as the bib file
- (eval-after-load "helm-bibtex"
- '(advice-add 'bibtex-completion-candidates
- :filter-return 'reverse))
- (require 'doi-utils)
- (setq org-ref-pdf-directory (car bibtex-completion-library-path)) ; needs a string. Just take the first item in the list.
- (require 'org-ref-isbn)
- (require 'org-ref-pubmed)
- (require 'org-ref-arxiv)
- (require 'x2bib)
- ;; Open pdf's as org-mode does (see above).
- (setq bibtex-completion-pdf-open-function 'org-open-file)
- ;; Journal abbreviations
- (add-to-list 'org-ref-bibtex-journal-abbreviations
- '("IUMJ" "Indiana University Mathematics Journal" "Indiana Univ. Math. J."))
- ;; Sci-hub
- (defun sci-hub-pdf-url (doi)
- "Get url to the pdf from SCI-HUB"
- (setq *doi-utils-pdf-url* (concat "https://sci-hub.st/" doi) ;captcha
- *doi-utils-waiting* t
- )
- ;; try to find PDF url (if it exists)
- (url-retrieve (concat "https://sci-hub.st/" doi)
- (lambda (status)
- (goto-char (point-min))
- (while (search-forward-regexp "\\(https://\\|//sci-hub.st/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 doi-utils-get-bibtex-entry-pdf (&optional arg)
- "Download pdf for entry at point if the pdf does not already exist locally.
- The entry must have a doi. The pdf will be saved to
- `org-ref-pdf-directory', by the name %s.pdf where %s is the
- bibtex label. Files will not be overwritten. The pdf will be
- checked to make sure it is a pdf, and not some html failure
- page. You must have permission to access the pdf. We open the pdf
- at the end if `doi-utils-open-pdf-after-download' is non-nil.
- With one prefix ARG, directly get the pdf from a file (through
- `read-file-name') instead of looking up a DOI. With a double
- prefix ARG, directly get the pdf from an open buffer (through
- `read-buffer-to-switch') instead. These two alternative methods
- work even if the entry has no DOI, and the pdf file is not
- checked."
- (interactive "P")
- (save-excursion
- (bibtex-beginning-of-entry)
- (let ( ;; get doi, removing http://dx.doi.org/ if it is there.
- (doi (replace-regexp-in-string
- "https?://\\(dx.\\)?.doi.org/" ""
- (bibtex-autokey-get-field "doi")))
- (key (cdr (assoc "=key=" (bibtex-parse-entry))))
- (pdf-url)
- (pdf-file))
- (setq pdf-file (concat
- (if org-ref-pdf-directory
- (file-name-as-directory org-ref-pdf-directory)
- (read-directory-name "PDF directory: " "."))
- key ".pdf"))
- ;; now get file if needed.
- (unless (file-exists-p pdf-file)
- (cond
- ((and (not arg)
- doi
- (if (doi-utils-get-pdf-url doi)
- (setq pdf-url (doi-utils-get-pdf-url doi))
- (setq pdf-url "https://www.sciencedirect.com/science/article/")))
- (url-copy-file pdf-url pdf-file)
- ;; now check if we got a pdf
- (if (org-ref-pdf-p pdf-file)
- (message "%s saved" pdf-file)
- (delete-file pdf-file)
- ;; sci-hub fallback option
- (setq pdf-url (sci-hub-pdf-url doi))
- (url-copy-file pdf-url pdf-file)
- ;; now check if we got a pdf
- (if (org-ref-pdf-p pdf-file)
- (message "%s saved" pdf-file)
- (delete-file pdf-file)
- (message "No pdf was downloaded.") ; SH captcha
- (browse-url pdf-url))))
- ;; End of sci-hub fallback option
- ((equal arg '(4))
- (copy-file (expand-file-name (read-file-name "Pdf file: " nil nil t))
- pdf-file))
- ((equal arg '(16))
- (with-current-buffer (read-buffer-to-switch "Pdf buffer: ")
- (write-file pdf-file)))
- (t
- (message "We don't have a recipe for this journal.")))
- (when (and doi-utils-open-pdf-after-download (file-exists-p pdf-file))
- (org-open-file pdf-file))))))
- ;; Asymptote mode
- ;; if "asy" is not on path, use:
- ;;(add-to-list 'load-path "ASYDIR")
- ;; for compiling with C-c C-c
- (autoload 'asy-mode "asy-mode.el" "Asymptote major mode." t)
- (autoload 'lasy-mode "asy-mode.el" "hybrid Asymptote/Latex major mode." t)
- (autoload 'asy-insinuate-latex "asy-mode.el" "Asymptote insinuate LaTeX." t)
- (add-to-list 'auto-mode-alist '("\\.asy$" . asy-mode))
- ;; Set color theme (generated using M-x customize-theme)
- (custom-set-variables
- ;; custom-set-variables was added by Custom.
- ;; If you edit it by hand, you could mess it up, so be careful.
- ;; Your init file should contain only one such instance.
- ;; If there is more than one, they won't work right.
- '(ansi-color-faces-vector
- [default default default italic underline success warning error])
- '(custom-enabled-themes (quote (dracula)))
- '(custom-safe-themes
- (quote
- ("fe1c13d75398b1c8fd7fdd1241a55c286b86c3e4ce513c4292d01383de152cb7" default)))
- '(org-file-apps
- (quote
- ((auto-mode . emacs)
- ("\\.mm\\'" . default)
- ("\\.x?html?\\'" . default)
- ("\\.pdf\\'" . "xdg-open %s")
- ("\\.djvu\\'" . "xdg-open %s"))))
- '(org-ref-clean-bibtex-entry-hook
- (quote
- (org-ref-bibtex-format-url-if-doi orcb-key-comma orcb-& orcb-% org-ref-title-case-article orcb-clean-year orcb-key orcb-clean-doi orcb-clean-pages orcb-check-journal org-ref-sort-bibtex-entry)))
- '(package-selected-packages
- (quote
- (auth-source-xoauth2 oauth2 bbdb geiser-chez geiser graphviz-dot-mode slime-company slime company smartparens expand-region nyan-mode helm-bibtex helm dracula-theme suomalainen-kalenteri dash bibtex-completion org-ref magit markdown-mode))))
- ;; Set markdown-command to run pandoc
- (setq markdown-command "pandoc")
- ;; Use HTML5 and UTF-8 for markdown export to html
- (eval-after-load "markdown-mode"
- '(defalias 'markdown-add-xhtml-header-and-footer 'as/markdown-add-xhtml-header-and-footer))
- (defun as/markdown-add-xhtml-header-and-footer (title)
- "Wrap XHTML header and footer with given TITLE around current buffer."
- (goto-char (point-min))
- (insert "<!DOCTYPE html5>\n"
- "<html>\n"
- "<head>\n<title>")
- (insert title)
- (insert "</title>\n")
- (insert "<meta charset=\"utf-8\" />\n")
- (when (> (length markdown-css-paths) 0)
- (insert (mapconcat 'markdown-stylesheet-link-string markdown-css-paths "\n")))
- (insert "\n</head>\n\n"
- "<body>\n\n")
- (goto-char (point-max))
- (insert "\n"
- "</body>\n"
- "</html>\n"))
- ;; Emacs-magit
- (require 'magit)
- ;; Make C-x g show the magit status
- (define-key global-map "\C-xg" 'magit-status)
|