init.el 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. ;; .emacs --- Emacs customizations
  2. ;;; Commentary:
  3. ;;
  4. ;; My Emacs customizations. Is there more to say?
  5. ;;
  6. ;; Packages:
  7. ;;
  8. ;; ac-emoji
  9. ;; ace-window
  10. ;; company
  11. ;; emms
  12. ;; emms-player
  13. ;; emojify
  14. ;; flycheck
  15. ;; helm
  16. ;; highlight-parentheses
  17. ;; image+
  18. ;; magit
  19. ;; markdown-mode
  20. ;; mic-paren
  21. ;; modalka-mode
  22. ;; multiple-cursors
  23. ;; nlinum
  24. ;; org-plus
  25. ;; projectile-mode
  26. ;;; Code:
  27. (let ((minver "24.1"))
  28. (when (version< emacs-version minver)
  29. (error "Your Emacs is too old -- this config requires v%s or higher" minver)))
  30. (setq gc-cons-threshold (* 511 1024 1024))
  31. (setq gc-cons-percentage 0.5)
  32. (run-with-idle-timer 5 t #'garbage-collect)
  33. (when (>= emacs-major-version 24)
  34. (require 'package)
  35. (setq-default
  36. package-archives
  37. '(("gnu" . "https://elpa.gnu.org/packages/")
  38. ("melpa" . "https://melpa.org/packages/")
  39. ("org" . "https://orgmode.org/elpa/")))
  40. (package-initialize))
  41. ;;; Enable debug during loading.
  42. ;; (setq debug-on-error t)
  43. (defvar emacs-cache-folder "~/.cache/emacs/"
  44. "Cache folder is everything we do not want to track together
  45. with the configuration files.")
  46. (if (not (file-directory-p emacs-cache-folder))
  47. (make-directory emacs-cache-folder t))
  48. ;; General Modifications
  49. (setq inhibit-splash-screen t)
  50. (menu-bar-mode -1)
  51. (tool-bar-mode -1)
  52. ;; (scroll-bar-mode -1)
  53. (column-number-mode 1)
  54. (set-frame-font "DejaVu Sans Mono")
  55. (setq-default tab-width 2)
  56. (global-auto-revert-mode t)
  57. (setq confirm-kill-emacs #'y-or-n-p) ;Asks if you wish to leave emacs
  58. (setq-default org-src-fontify-natively t) ;syntax highlighting in org-modesource blocks
  59. (setq browse-url-browser-function 'eww-browse-url)
  60. (setq visible-bell nil)
  61. (setq fill-column 80)
  62. (setq echo-keystrokes 0.1)
  63. ;;; Show matching parenthesis
  64. (show-paren-mode 1)
  65. ;;; By default, there’s a small delay before showing a matching parenthesis. Set
  66. ;;; it to 0 to deactivate.
  67. (setq show-paren-delay 0)
  68. (setq show-paren-when-point-inside-paren t)
  69. (setq-default ftp-program "sftp")
  70. (setq-default vs-display-status nil)
  71. (setq tab-always-indent 'complete)
  72. (setq initial-scratch-message "")
  73. ;; indetn
  74. ;; You may need to get rid of the -default on the indent ones
  75. (setq-default js-indent-level 2)
  76. (setq-default js2-indent-level 2)
  77. (setq-default js2-basic-offset 2)
  78. (setq-default js2-strict-trailing-comma-warning nil) ;I don't care about commas
  79. (setq-default typescript-indent-level 2)
  80. (setq-default indent-tabs-mode nil)
  81. (setq-default jsx-indent-level 2)
  82. (setq-default css-indent-offset 2)
  83. (setq backup-by-copying t ; don't clobber symlinks
  84. backup-directory-alist
  85. '(("." . "~/.backups")) ; don't litter my fs tree
  86. delete-old-versions t
  87. kept-new-versions 6
  88. kept-old-versions 2
  89. version-control t) ; use versioned backups
  90. (add-hook 'minibuffer-exit-hook
  91. '(lambda ()
  92. (let ((buffer "*Completions*"))
  93. (and (get-buffer buffer)
  94. (kill-buffer buffer)))))
  95. ;; For some reason I think this loads images faster
  96. (setq imagemagick-enabled-types t)
  97. ;; Removes trailing whitespace before saving.
  98. (add-hook 'before-save-hook (lambda ()
  99. (delete-trailing-whitespace)))
  100. ;; Thou shall use 2 spaces indenting
  101. ;; (setq typescript-indent-level 2)
  102. ;; Enable a line at the 80 character column for certain modes
  103. (setq fci-rule-column 80)
  104. ;; Enable some good modes when editing source files
  105. ;; (add-hook 'hl-line-mode-hook
  106. ;; (lambda ()
  107. ;; (set-face-background 'hl-line "#c1dde6")
  108. ;; (set-face-attribute 'region nil :background "LightSkyBlue1")))
  109. (add-hook 'prog-mode-hook
  110. (lambda ()
  111. (smartparens-mode 1)
  112. (flycheck-mode 1)
  113. (hl-line-mode 1)))
  114. (add-hook 'haskell-mode-hook
  115. (lambda ()
  116. (flycheck-mode -1)))
  117. (add-hook 'html-mode-hook
  118. (lambda ()
  119. (flycheck-mode 1)
  120. (flyspell-mode -1)
  121. (hl-line-mode 1)))
  122. (add-hook 'image-mode-hook 'imagex-sticky-mode)
  123. ;; Lets not forget the text modes!
  124. (add-hook 'text-mode-hook
  125. (lambda ()
  126. ;; (column-enforce-mode 1)
  127. ;; (nlinum-mode 1)
  128. ;; (modalka-mode 1)
  129. (auto-fill-mode 1)
  130. (flyspell-mode 1)
  131. (hl-line-mode 1)))
  132. (add-hook 'markdown-mode-hook
  133. (lambda ()
  134. ;; (column-enforce-mode 1)
  135. (auto-fill-mode 1)
  136. ;; (nlinum-mode 1)
  137. ;; (modalka-mode 1)
  138. (flyspell-mode 1)
  139. (hl-line-mode 1)))
  140. (defun org-table-copy-down-no-inc (&optional arg)
  141. "Copy the previous cell's value without incrementing.
  142. ARG is needed for `kill-word'."
  143. (interactive "p")
  144. (kill-word arg)
  145. (yank)
  146. (org-return)
  147. (org-table-blank-field)
  148. (yank)
  149. (org-table-align))
  150. (use-package org
  151. :bind (:map org-mode-map
  152. ("C-S-<down>" . org-table-copy-down-no-inc)))
  153. ;; (use-package org-journal
  154. ;; :init
  155. ;; (setq-default org-journal-dir "~/personal/journal"))
  156. (add-hook 'latex-mode-hook
  157. (lambda ()
  158. (fci-mode 1)
  159. ;; (nlinum-mode 1)
  160. (flycheck-mode 1)
  161. (column-enforce-mode 1)
  162. (auto-fill-mode 1)
  163. (flyspell-mode 1)))
  164. (add-hook 'erc-mode-hook
  165. (lambda ()
  166. (erc-notify-mode 1)
  167. (flyspell-mode 1)))
  168. ;; Enable M-RET to add another comment line. This is mainly for typing long
  169. ;; explainations that take more than 1 line. For example, this comment...
  170. ;; Note: Since the other languages I use have things like /* */, they don't
  171. ;; need this feature.
  172. (add-hook 'emacs-lisp-mode-hook
  173. '(lambda () (local-set-key (kbd "M-RET") 'comment-indent-new-line)))
  174. (add-hook 'common-lisp-mode-hook
  175. '(lambda () (local-set-key (kbd "M-RET") 'comment-indent-new-line)))
  176. (add-hook 'lisp-mode-hook
  177. '(lambda () (local-set-key (kbd "M-RET") 'comment-indent-new-line)))
  178. (add-hook 'sh-mode-hook
  179. '(lambda () (local-set-key (kbd "M-RET") 'comment-indent-new-line)))
  180. (add-hook 'R-mode-hook
  181. '(lambda () (local-set-key (kbd "M-RET") 'comment-indent-new-line)))
  182. ;; Make backtab go backwards for links, like any normal person would want it
  183. (add-hook 'eww-mode-hook
  184. '(lambda ()
  185. (local-set-key (kbd "<backtab>") 'shr-previous-link)
  186. (local-set-key (kbd "&") 'eww-external-browser-seamonkey)))
  187. (defvar mode-line-cleaner-alist
  188. `((smartparens-mode . " ()")
  189. (eldoc-mode . "")
  190. (abbrev-mode . "")
  191. (undo-tree-mode . " U")
  192. (ivy-mode . " Ɩ")
  193. (flycheck-mode . " ✔")
  194. (flyspell-mode . " s✔")
  195. ;; Major modes
  196. (lisp-interaction-mode . "λ")
  197. (emacs-lisp-mode . "Eλ")
  198. (eshell-mode . "ξ")
  199. (haskell-mode . "Hλ")
  200. (purescript-mode . "PS")
  201. (clojurescript-mode . "CLJS")
  202. (clojure-mode . "Cλ")
  203. (javascript-mode . "JS")
  204. (racket-mode . "Rλ")
  205. (erc-mode . "Ɛ")
  206. (calc-mode . "π")))
  207. (defun clean-mode-line ()
  208. (interactive)
  209. (dolist (cleaner mode-line-cleaner-alist)
  210. (let* ((mode (car cleaner))
  211. (mode-str (cdr cleaner))
  212. (old-mode-str (cdr (assq mode minor-mode-alist))))
  213. (when old-mode-str
  214. (setcar old-mode-str mode-str))
  215. ;; major mode
  216. (when (eq mode major-mode)
  217. (setq mode-name mode-str)))))
  218. (add-hook 'after-change-major-mode-hook 'clean-mode-line)
  219. ;; Personal Keybindings
  220. (global-set-key (kbd "C-x o") 'ace-window)
  221. (global-set-key (kbd "M-c") 'comment-region)
  222. (global-set-key (kbd "M-C") 'capitalize-word)
  223. (global-set-key (kbd "M-u") 'uncomment-region)
  224. (global-set-key (kbd "M-U") 'upcase-word)
  225. (global-set-key (kbd "C-x &") 'calendar)
  226. (global-set-key (kbd "M-g c") 'avy-goto-char)
  227. (global-set-key (kbd "M-g M-c") 'avy-goto-char)
  228. (global-set-key (kbd "M-g t") 'avy-goto-char-2)
  229. (global-set-key (kbd "M-g M-t") 'avy-goto-char-2)
  230. (global-set-key (kbd "M-g l") 'avy-goto-char-in-line)
  231. (global-set-key (kbd "M-g M-l") 'avy-goto-char-in-line)
  232. (global-set-key (kbd "M-g c") 'iy-go-to-char)
  233. (global-set-key (kbd "M-g C") 'iy-go-to-char-backward)
  234. (global-set-key (kbd "M-g ;") 'iy-go-to-or-up-to-continue)
  235. (global-set-key (kbd "M-g :") 'iy-go-to-or-up-to-continue-backward)
  236. (global-set-key (kbd "M-g f") 'avy-goto-line)
  237. (global-set-key (kbd "M-g M-f") 'avy-goto-line)
  238. (global-set-key (kbd "M-g w") 'avy-goto-word-1)
  239. (global-set-key (kbd "M-g M-w") 'avy-goto-word-1)
  240. ;; (global-set-key (kbd "M-G G") 'magit-status)
  241. ;; (global-set-key (kbd "C-|") 'pop-global-mark) ;return to last cursor position
  242. (global-set-key (kbd "C-x B") 'list-buffers)
  243. (global-set-key (kbd "C-x C-b") 'ido-switch-buffer)
  244. (global-set-key (kbd "C-x b") 'ido-switch-buffer)
  245. (global-set-key (kbd "M-o") 'ace-window)
  246. (global-set-key (kbd "M-h") 'ido-switch-buffer)
  247. (global-set-key (kbd "M-k") 'ido-kill-buffer)
  248. (add-hook 'org-mode-hook
  249. '(lambda () (local-set-key (kbd "M-h") 'ido-switch-buffer)))
  250. ;; replace `compose-mail' keybinding
  251. (global-unset-key (kbd "C-x m"))
  252. (global-set-key (kbd "C-x m m") 'compose-mail)
  253. ;; C-x M for Multicursor or Music (for emms controls)
  254. ;; Notice for the music controls, previous and next are upper case!
  255. (global-set-key (kbd "C-x m d") 'mc/mark-all-dwim) ;d for dwim
  256. (global-set-key (kbd "C-x m l") 'mc/mark-next-lines) ;l for lines
  257. (global-set-key (kbd "C-x m a") 'mc/mark-all-like-this) ;a for all
  258. (global-set-key (kbd "C-x m n") 'mc/mark-next-like-this) ;n for next
  259. (global-set-key (kbd "C-x m m") 'mc/mark-more-like-this-extended) ;m for more
  260. (global-set-key (kbd "C-x M p") 'emms-pause) ;p for pause
  261. (global-set-key (kbd "C-x M P") 'emms-previous) ;P for previous
  262. (global-set-key (kbd "C-x M N") 'emms-next) ;N for next
  263. (global-set-key (kbd "C-x M s") 'emms-show) ;s for show
  264. (global-set-key (kbd "C-x M f") 'emms-play-file) ;play (f)ile
  265. (global-set-key (kbd "C-x M D") 'emms-play-directory) ;play (D)irectory
  266. (global-set-key (kbd "C-x M v") 'emms-playlist-mode-go) ;(v)iew playlist
  267. (global-set-key (kbd "C-x E a") 'emojify-apropos-emoji) ; For easy emoji finding
  268. ;; (global-set-key (kbd "M-d") 'forward-delete-word-no-kill-ring)
  269. ;; (global-set-key (kbd "M-<backspace>") 'backward-delete-word-no-kill-ring)
  270. (global-set-key (kbd "M-D") 'kill-word)
  271. (global-set-key (kbd "M-S-<backspace>") 'backward-kill-word)
  272. (global-set-key (kbd "M-<SPC>") 'mark-sexp)
  273. (global-set-key (kbd "M-g m") 'magit-status)
  274. ;; (global-set-key (kbd "C-m") 'replace-char)
  275. (global-set-key (kbd "C-x C-l") 'display-line-numbers-mode)
  276. (global-set-key (kbd "C-x p w") 'pwd)
  277. (global-set-key (kbd "<home>") 'beginning-of-buffer)
  278. (global-set-key (kbd "<end>") 'end-of-buffer)
  279. (use-package emojify
  280. :hook ((text-mode . emojify-mode)
  281. (org-mode . emojify-mode)
  282. (markdown-mode . emojify-mode)
  283. (erc-mode . emojify-mode)))
  284. ;; (use-package ledger-mode
  285. ;; :bind
  286. ;; (("C-c C-e" . ledger-jentry)
  287. ;; :map ledger-mode-map
  288. ;; ("C-c C-j" . ledger-run-command))
  289. ;; :init
  290. ;; (add-to-list 'auto-mode-alist '("\\.dat\\'" . hledger-mode))
  291. ;; (setq-default hledger-currency-string "$"
  292. ;; hledger-jfile "~/personal/money/finances/2020.dat"))
  293. (use-package ivy
  294. :bind
  295. ("C-s" . swiper-isearch)
  296. ("C-r" . swiper-isearch-backward)
  297. ("C-c C-r" . ivy-resume)
  298. ("C-x C-f" . counsel-find-file)
  299. ("C-x b" . counsel-switch-buffer)
  300. ("C-x C-b" . counsel-switch-buffer)
  301. ("M-x" . counsel-M-x)
  302. ("M-y" . 'counsel-yank-pop)
  303. ("<f1> f" . counsel-describe-function)
  304. ("<f1> v" . counsel-describe-variable)
  305. ("<f1> l" . 'counsel-find-library)
  306. ("<f1> a" . 'counsel-apropos)
  307. ("<f2> i" . 'counsel-info-lookup-symbol)
  308. ("<f2> u" . 'counsel-unicode-char)
  309. ("<f2> j" . 'counsel-set-variable)
  310. ("C-c v" . 'ivy-push-view)
  311. ("C-c V" . 'ivy-pop-view)
  312. ("C-x p g" . 'counsel-git-grep)
  313. ("C-x p f" . counsel-git) ;this is basically projectile-find-file
  314. :config
  315. (ivy-mode 1)
  316. (setq ivy-use-virtual-buffers t
  317. enable-recursive-minibuffers t)
  318. (define-key ivy-minibuffer-map (kbd "<return>") 'ivy-alt-done))
  319. (use-package flx)
  320. ;;; Others
  321. (setq-default ispell-program-name "/usr/pkg/bin/aspell")
  322. (use-package slime-autoloads
  323. :config
  324. (setq-default inferior-lisp-program "/usr/local/bin/sbcl"))
  325. (use-package slime
  326. :config
  327. (slime-setup)
  328. (setq slime-contribs '(slime-fancy)))
  329. (slime-setup '(slime-company))
  330. ;; eshell
  331. ;; Run "alias sudo 'eshell/sudo $*'" sudo to work right
  332. (use-package em-tramp
  333. :init
  334. (setq-default eshell-prefer-lisp-functions t
  335. eshell-prefer-lisp-variables t
  336. password-cache t ; enable password caching
  337. password-cache-expiry 300 ; for 5 minutes (time in secs)
  338. tramp-histfile-override "/dev/null"))
  339. ;;; Email
  340. ;;; setup for use with mbsync in maildir format
  341. (defun kev-mark-as-disposed-and-read (&optional number data)
  342. (interactive)
  343. (wl-summary-dispose)
  344. (wl-summary-mark-as-read))
  345. (defun kev-mark-as-disposed-and-read-region (beg end)
  346. (interactive "r")
  347. (wl-summary-dispose-region beg end)
  348. (wl-summary-mark-as-read-region beg end))
  349. (setq user-mail-address "kevin.bloom@posteo.net"
  350. smtpmail-smtp-user "kevin.bloom@posteo.net"
  351. smtpmail-local-domain "posteo.de"
  352. smtpmail-default-smtp-server "posteo.de"
  353. smtpmail-smtp-server "posteo.de"
  354. smtpmail-smtp-service 587
  355. smtpmail-stream-type 'starttls
  356. message-send-mail-function 'smtpmail-send-it)
  357. (use-package elmo
  358. :config
  359. (elmo-search-register-engine
  360. 'mairix 'local-file
  361. :prog "mairix"
  362. :args '(pattern)
  363. :charset 'utf-8)
  364. (setq elmo-search-default-engine 'mairix
  365. elmo-passwd-storage-type 'auth-source))
  366. (use-package wl
  367. :bind
  368. (:map wl-summary-mode-map
  369. ("d" . kev-mark-as-disposed-and-read)
  370. ("r d" . kev-mark-as-disposed-and-read-region))
  371. :hook
  372. (wl-folder-check-entity-hook wl-folder-open-all)
  373. :config
  374. (setq wl-quicksearch-folder "[]"
  375. wl-summary-line-format "%n%T%P %Y/%M/%D (%W) %h:%m %t%[%25(%c %f%) %] %s"
  376. wl-summary-width 150
  377. wl-message-ignored-field-list '("^.*:")
  378. wl-message-visible-field-list '("^To:"
  379. "^Cc:"
  380. "^From:"
  381. "^Subject:"
  382. "^Date:"
  383. "^Content-Disposition:")
  384. wl-message-sort-field-list '("^From:"
  385. "^Subject:"
  386. "^Date:"
  387. "^To:"
  388. "^Cc:"
  389. "^Content-Disposition:")
  390. wl-fcc "./Users/kev/Maildir/posteo/sent/" ;prefixing with '.' means maildir
  391. wl-fcc-force-as-read t
  392. wl-smtp-posting-server "posteo.de"
  393. wl-smtp-posting-port 587
  394. wl-smtp-connection-type 'starttls
  395. wl-smtp-authenticate-type "plain"
  396. wl-smtp-posting-user "kevin.bloom@posteo.net"))
  397. (custom-set-variables
  398. ;; custom-set-variables was added by Custom.
  399. ;; If you edit it by hand, you could mess it up, so be careful.
  400. ;; Your init file should contain only one such instance.
  401. ;; If there is more than one, they won't work right.
  402. '(custom-enabled-themes '(gruvbox-dark-soft))
  403. '(custom-safe-themes
  404. '("72ed8b6bffe0bfa8d097810649fd57d2b598deef47c992920aef8b5d9599eefe" "2ff9ac386eac4dffd77a33e93b0c8236bb376c5a5df62e36d4bfa821d56e4e20" default))
  405. '(package-selected-packages
  406. '(gruvbox-theme janet-mode lua-mode flycheck smartparens company-emojify company-ledger emojify slime slime-company ace-window avy counsel flx ivy magit multiple-cursors smex swiper use-package)))
  407. (custom-set-faces
  408. ;; custom-set-faces was added by Custom.
  409. ;; If you edit it by hand, you could mess it up, so be careful.
  410. ;; Your init file should contain only one such instance.
  411. ;; If there is more than one, they won't work right.
  412. )