packages.el 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051
  1. ;; Package installation
  2. (require 'package)
  3. ;; Create the package install directory if it doesn't exist
  4. (setq package-user-dir (format "%selpa_%s/"
  5. user-emacs-directory emacs-major-version)) ; default = ~/.emacs.d/elpa/
  6. (let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
  7. (not (gnutls-available-p))))
  8. (proto (if no-ssl "http" "https")))
  9. ;; Comment/uncomment these two lines to enable/disable MELPA and MELPA Stable as desired
  10. (add-to-list 'package-archives (cons "melpa" (concat proto "://melpa.org/packages/")) t)
  11. ;;(add-to-list 'package-archives (cons "melpa-stable" (concat proto "://stable.melpa.org/packages/")) t)
  12. (when (< emacs-major-version 24)
  13. ;; For important compatibility libraries like cl-lib
  14. (add-to-list 'package-archives '("gnu" . (concat proto "://elpa.gnu.org/packages/")))))
  15. (add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/"))
  16. (package-initialize)
  17. (setq package-enable-at-startup nil)
  18. (unless (package-installed-p 'use-package)
  19. (package-refresh-contents)
  20. (package-install 'use-package))
  21. (eval-when-compile
  22. (require 'use-package))
  23. ;;;; Required packages
  24. (setq use-package-verbose t)
  25. (use-package diminish
  26. :ensure t)
  27. (diminish 'visual-line-mode)
  28. (diminish 'abbrev-mode)
  29. (diminish 'eldoc-mode)
  30. (use-package autorevert
  31. :diminish auto-revert-mode)
  32. (use-package iedit
  33. :ensure t)
  34. (defmacro hail (p)
  35. (list 'use-package p ':ensure 't))
  36. (hail hydra)
  37. (use-package engine-mode
  38. :ensure t)
  39. (defvar evil-want-integration nil)
  40. (use-package undo-tree
  41. :ensure t
  42. :diminish undo-tree-mode
  43. :init
  44. (setq undo-tree-enable-undo-in-region nil))
  45. (use-package evil
  46. :after undo-tree
  47. :ensure t
  48. :config
  49. (evil-mode t)
  50. (setq evil-want-C-i-jump nil)
  51. (setq evil-default-state 'normal)
  52. ;; Move all elements of evil-emacs-state-modes to evil-motion-state-modes
  53. (setq evil-motion-state-modes (append evil-emacs-state-modes evil-motion-state-modes)
  54. evil-emacs-state-modes (list 'magit-popup-mode))
  55. (delete 'magit-popup-mode evil-motion-state-modes)
  56. ;; Don't echo evil's states
  57. (setq evil-insert-state-message nil
  58. evil-visual-state-message nil)
  59. ;; Little words (camelCase)
  60. (evil-define-motion evil-little-word (count)
  61. :type exclusive
  62. (let* ((case-fold-search nil)
  63. (count (if count count 1)))
  64. (while (> count 0)
  65. (forward-char)
  66. (search-forward-regexp "[_A-Z]\\|\\W" nil t)
  67. (backward-char)
  68. (decf count))))
  69. ;; Don't litter registers with whitespace
  70. (defun destroy-whitespace--evil-delete-around (func beg end type &optional reg yh)
  71. (let ((clean-string (replace-regexp-in-string "[ \t\n]" "" (buffer-substring beg end))))
  72. (if (equal "" clean-string)
  73. (apply func beg end type ?_ yh)
  74. (apply func beg end type reg yh))))
  75. (advice-add 'evil-delete :around #'destroy-whitespace--evil-delete-around)
  76. ;; eval the last sexp while in normal mode (include the character the cursor is currently on)
  77. (defun evil-eval-last-sexp ()
  78. (interactive)
  79. (evil-append 1)
  80. (eval-last-sexp nil)
  81. (evil-normal-state))
  82. ;; select recently pasted text
  83. ;; from https://emacs.stackexchange.com/a/21093
  84. (defun my/evil-select-pasted ()
  85. (interactive)
  86. (let ((start-marker (evil-get-marker ?[))
  87. (end-marker (evil-get-marker ?])))
  88. (evil-visual-select start-marker end-marker)))
  89. ;; "pull" left and right with zs and ze
  90. (defun hscroll-cursor-left ()
  91. (interactive "@")
  92. (set-window-hscroll (selected-window) (current-column)))
  93. (defun hscroll-cursor-right ()
  94. (interactive "@")
  95. (set-window-hscroll (selected-window) (- (current-column) (window-width) -1)))
  96. ;; Horizontal scrolling
  97. (setq auto-hscroll-mode 't)
  98. (setq hscroll-margin 0
  99. hscroll-step 1)
  100. (defhydra hydra-window (global-map "C-w")
  101. "window layout"
  102. ("u" winner-undo "undo")
  103. ("U" winner-redo "redo"))
  104. ;; Make K select manpage or engine-mode (m for man, g for google?)
  105. (defengine google
  106. "http://www.google.com/search?ie=utf-8&oe=utf-8&q=%s")
  107. (defhydra hydra-lookup-menu ()
  108. "Choose lookup"
  109. ("g" engine/search-google "Google" :color blue)
  110. ("m" evil-lookup "man" :color blue))
  111. (define-key evil-normal-state-map "K" 'hydra-lookup-menu/body)
  112. (define-key evil-visual-state-map "K" 'hydra-lookup-menu/body)
  113. ;; These go out here, because undefining keybinds is hard
  114. (define-key global-map "\C-j" nil)
  115. (define-key evil-normal-state-map "\C-j" 'flyspell-goto-next-error)
  116. (evil-define-key 'normal package-menu-mode-map "q" 'quit-window)
  117. (defun evil-passthrough-key (state mode key)
  118. "Use the default binding for KEY in MODE, rather than the evil-mode binding, for STATE."
  119. (evil-define-key state mode (kbd key) (evil-lookup-key mode (kbd key))))
  120. :bind (:map evil-normal-state-map
  121. ("zs" . hscroll-cursor-left)
  122. ("ze" . hscroll-cursor-right)
  123. ("[s" . flyspell-goto-previous-error)
  124. ("]s" . flyspell-goto-next-error)
  125. ("\C-k" . flyspell-goto-previous-error)
  126. ("\C-x \C-e" . evil-eval-last-sexp)
  127. ("j" . evil-next-visual-line)
  128. ("k" . evil-previous-visual-line)
  129. ("gj" . evil-next-line)
  130. ("gk" . evil-previous-line)
  131. ; :map Info-mode-map
  132. ; ("g" . nil)
  133. ; ("n" . nil)
  134. ; ("p" . nil)
  135. :map evil-window-map
  136. ("q" . delete-window)
  137. ("C-q" . delete-window)
  138. ("x" . kill-buffer-and-window)
  139. :map Buffer-menu-mode-map
  140. ("SPC" . nil)))
  141. (use-package evil-numbers
  142. :ensure t
  143. :config
  144. ;; Increment and decrement (evil-numbers)
  145. (defhydra hydra-numbers (global-map "C-x")
  146. "modify numbers"
  147. ("a" evil-numbers/inc-at-pt "increment")
  148. ("x" evil-numbers/dec-at-pt "decrement")))
  149. (use-package undohist
  150. :ensure t
  151. :config
  152. ;; Save undo history under .emacs.d/undohist
  153. (setq undohist-directory "~/.emacs.d/undohist")
  154. (unless (file-exists-p "~/.emacs.d/undohist")
  155. (make-directory "~/.emacs.d/undohist"))
  156. (undohist-initialize))
  157. (use-package powerline-evil
  158. :ensure t
  159. :config
  160. (defun powerline-center-evil-theme ()
  161. "Setup a mode-line with major, evil, and minor modes centered."
  162. (interactive)
  163. (setq-default mode-line-format
  164. '("%e"
  165. (:eval
  166. (let* ((active (powerline-selected-window-active))
  167. (mode-line-buffer-id (if active 'mode-line-buffer-id 'mode-line-buffer-id-inactive))
  168. (mode-line (if active 'mode-line 'mode-line-inactive))
  169. (face1 (if active 'powerline-active1 'powerline-inactive1))
  170. (face2 (if active 'powerline-active2 'powerline-inactive2))
  171. (separator-left (intern (format "powerline-%s-%s"
  172. (powerline-current-separator)
  173. (car powerline-default-separator-dir))))
  174. (separator-right (intern (format "powerline-%s-%s"
  175. (powerline-current-separator)
  176. (cdr powerline-default-separator-dir))))
  177. (lhs (list (powerline-raw "%*" mode-line 'l)
  178. (powerline-buffer-id mode-line-buffer-id 'l)
  179. (powerline-raw " " mode-line)
  180. (funcall separator-left mode-line face1)
  181. (powerline-narrow face1 'l)
  182. (powerline-vc face1)))
  183. (rhs (list (funcall separator-right face1 mode-line)
  184. (powerline-raw mode-line-misc-info mode-line 'r)
  185. ;(powerline-raw global-mode-string face1 'r)
  186. (powerline-raw "%2l" mode-line 'r)
  187. (powerline-raw ":" mode-line)
  188. (powerline-raw "%2c" mode-line 'r)
  189. ;(powerline-raw " ")
  190. ;(powerline-raw "%6p" mode-line 'r)
  191. (powerline-hud face2 face1)))
  192. (center (append (list (powerline-raw " " face1)
  193. (funcall separator-left face1 face2)
  194. (when (and (boundp 'erc-track-minor-mode) erc-track-minor-mode)
  195. (powerline-raw erc-modified-channels-object face2 'l))
  196. (powerline-major-mode face2 'l)
  197. (powerline-process face2)
  198. (powerline-raw " " face2))
  199. (if (split-string (format-mode-line minor-mode-alist))
  200. (append (if evil-mode
  201. (list (funcall separator-right face2 face1)
  202. (powerline-raw evil-mode-line-tag face1 'l)
  203. (powerline-raw " " face1)
  204. (funcall separator-left face1 face2)))
  205. (list (powerline-minor-modes face2 'l)
  206. (powerline-raw " " face2)
  207. (funcall separator-right face2 face1)))
  208. (list (powerline-raw evil-mode-line-tag face2)
  209. (funcall separator-right face2 face1))))))
  210. (concat (powerline-render lhs)
  211. (powerline-fill-center face1 (/ (powerline-width center) 2.0))
  212. (powerline-render center)
  213. (powerline-fill face1 (powerline-width rhs))
  214. (powerline-render rhs)))))))
  215. (defun powerline-evil-vim-theme ()
  216. "Powerline's Vim-like mode-line with evil state at the beginning."
  217. (interactive)
  218. (setq-default mode-line-format
  219. '("%e"
  220. (:eval
  221. (let* ((active (powerline-selected-window-active))
  222. (mode-line (if active 'mode-line 'mode-line-inactive))
  223. (face1 (if active 'powerline-active1 'powerline-inactive1))
  224. (face2 (if active 'powerline-active2 'powerline-inactive2))
  225. (separator-left (intern (format "powerline-%s-%s"
  226. (powerline-current-separator)
  227. (car powerline-default-separator-dir))))
  228. (separator-right (intern (format "powerline-%s-%s"
  229. (powerline-current-separator)
  230. (cdr powerline-default-separator-dir))))
  231. (lhs (list (if evil-mode
  232. (powerline-raw (powerline-evil-tag) mode-line))
  233. (powerline-buffer-id `(mode-line-buffer-id ,mode-line) 'l)
  234. (powerline-raw "[" mode-line 'l)
  235. (powerline-major-mode mode-line)
  236. (powerline-process mode-line)
  237. (powerline-raw "]" mode-line)
  238. (when (buffer-modified-p)
  239. (powerline-raw "[+]" mode-line))
  240. (when buffer-read-only
  241. (powerline-raw "[RO]" mode-line))
  242. ;; (powerline-raw (concat "[" (mode-line-eol-desc) "]") mode-line)
  243. (when (and (boundp 'which-func-mode) which-func-mode)
  244. (powerline-raw which-func-format nil 'l))
  245. (when (boundp 'erc-modified-channels-object)
  246. (powerline-raw erc-modified-channels-object face1 'l))
  247. (powerline-raw "[" mode-line 'l)
  248. (powerline-minor-modes mode-line) (powerline-raw "%n" mode-line)
  249. (powerline-raw "]" mode-line)
  250. (when (and vc-mode buffer-file-name)
  251. (let ((backend (vc-backend buffer-file-name)))
  252. (when backend
  253. (concat (powerline-raw "[" mode-line 'l)
  254. (powerline-raw (format "%s / %s" backend (vc-working-revision buffer-file-name backend)))
  255. (powerline-raw "]" mode-line)))))))
  256. (rhs (list (powerline-raw mode-line-misc-info mode-line 'r)
  257. (powerline-raw global-mode-string mode-line 'r)
  258. (powerline-raw "%l," mode-line 'l)
  259. (powerline-raw (format-mode-line '(10 "%c")))
  260. (powerline-raw (replace-regexp-in-string "%" "%%" (format-mode-line '(-3 "%p"))) mode-line 'r))))
  261. (concat (powerline-render lhs)
  262. (powerline-fill mode-line (powerline-width rhs))
  263. (powerline-render rhs)))))))
  264. (if (or (display-graphic-p) (daemonp))
  265. (powerline-center-evil-theme)
  266. (powerline-evil-vim-theme)))
  267. ; (use-package smart-mode-line
  268. ; :ensure t
  269. ; :init
  270. ; :config
  271. ; (setq sml/no-confirm-load-theme t)
  272. ; (setq sml/mule-info nil)
  273. ; (setq sml/show-frame-identification nil)
  274. ; (sml/setup))
  275. ; (use-package spaceline
  276. ; :ensure t
  277. ; :config
  278. ; (require 'spaceline-config)
  279. ; (spaceline-spacemacs-theme))
  280. ; (use-package telephone-line
  281. ; :ensure t
  282. ; :after evil-surround
  283. ; :config
  284. ; ;; These don't have any effect, surprise surprise
  285. ; (set-face-attribute 'telephone-line-evil-emacs t :inherit 'telephone-line-evil)
  286. ; (set-face-attribute 'telephone-line-evil-insert t :inherit 'telephone-line-evil)
  287. ; (set-face-attribute 'telephone-line-evil-motion t :inherit 'telephone-line-evil)
  288. ; (set-face-attribute 'telephone-line-evil-normal t :inherit 'telephone-line-evil)
  289. ; (set-face-attribute 'telephone-line-evil-operator t :inherit 'telephone-line-evil)
  290. ; (setq telephone-line-evil-use-short-tag t)
  291. ; (telephone-line-evil-config))
  292. (use-package linum-relative
  293. :ensure t
  294. :diminish linum-relative-mode
  295. :config
  296. (setq linum-relative-current-symbol "")
  297. (if (not (or (display-graphic-p) (daemonp)))
  298. (setq linum-relative-format "%3s "))
  299. (add-hook 'prog-mode-hook 'linum-relative-mode)
  300. (defun linum-update-window-scale-fix (win)
  301. "fix linum for scaled text"
  302. (set-window-margins
  303. win
  304. (ceiling (* (if (boundp 'text-scale-mode-step)
  305. (expt text-scale-mode-step
  306. text-scale-mode-amount) 1)
  307. (if (car (window-margins))
  308. (car (window-margins)) 1)
  309. ))))
  310. (advice-add #'linum-update-window
  311. :after #'linum-update-window-scale-fix))
  312. (use-package bind-map
  313. :ensure t
  314. :after evil
  315. :after evil-numbers
  316. :config
  317. (bind-map
  318. my-base-leader-map
  319. :keys ("M-m")
  320. :evil-keys ("SPC")
  321. :evil-states (normal motion visual)
  322. :bindings
  323. ("d" 'define-word-at-point
  324. "b" 'buffer-menu
  325. "f" 'treemacs-toggle
  326. "u" 'undo-tree-visualize
  327. "l" 'auto-fill-mode
  328. "s" 'flyspell-toggle-correct-mode
  329. "a" 'company-mode
  330. "g" 'magit-status
  331. "c" 'flycheck-mode
  332. "w" '(lambda () (interactive)
  333. ;; "writing" mode
  334. (variable-pitch-mode)
  335. (visual-line-mode))
  336. "p" 'my/evil-select-pasted
  337. "/" 'swiper
  338. "v" 'ivy-switch-buffer
  339. "n" 'hydra-numbers/body
  340. "m" 'evil-visual-mark-mode
  341. "1" 'eyebrowse-switch-to-window-config-1
  342. "2" 'eyebrowse-switch-to-window-config-2
  343. "3" 'eyebrowse-switch-to-window-config-3
  344. "4" 'eyebrowse-switch-to-window-config-4
  345. "5" 'eyebrowse-switch-to-window-config-5
  346. "6" 'eyebrowse-switch-to-window-config-6
  347. "7" 'eyebrowse-switch-to-window-config-7
  348. "8" 'eyebrowse-switch-to-window-config-8
  349. "9" 'eyebrowse-switch-to-window-config-9))
  350. (bind-map
  351. my-elisp-map
  352. :keys ("M-m")
  353. :evil-keys ("SPC")
  354. :major-modes (emacs-lisp-mode)
  355. :bindings
  356. ("el" 'evil-eval-last-sexp
  357. "er" 'eval-region
  358. "eb" 'eval-buffer)))
  359. (use-package treemacs
  360. :ensure t
  361. :bind (:map treemacs-mode-map
  362. ("." . treemacs-toggle-show-dotfiles)))
  363. (use-package treemacs-evil
  364. :after treemacs
  365. :ensure t)
  366. (use-package editorconfig
  367. :ensure t
  368. :diminish editorconfig-mode
  369. :config
  370. (editorconfig-mode 1))
  371. (use-package ivy
  372. :ensure t
  373. :diminish ivy-mode
  374. :config
  375. (ivy-mode)
  376. (setq ivy-use-virtual-buffers t))
  377. (use-package flx
  378. :ensure t
  379. :config
  380. (setq ivy-re-builders-alist '((t . ivy--regex-fuzzy))))
  381. (use-package company
  382. :ensure t
  383. :diminish company-mode
  384. :config
  385. (add-hook 'prog-mode-hook 'company-mode)
  386. )
  387. (use-package flycheck
  388. :ensure t
  389. :diminish flycheck-mode
  390. :config
  391. (add-hook 'prog-mode-hook 'flycheck-mode)
  392. (setq flycheck-check-syntax-automatically '(idle-change new-line save mode-enabled))
  393. (setq flycheck-checkers (delq 'emacs-lisp-checkdoc flycheck-checkers)))
  394. (use-package flycheck-pos-tip
  395. :ensure t
  396. :after flycheck
  397. :config
  398. (flycheck-pos-tip-mode))
  399. (use-package evil-surround
  400. :ensure t
  401. :config
  402. (global-evil-surround-mode 1))
  403. (use-package dtrt-indent
  404. :ensure t
  405. :config
  406. (setq global-mode-string (delq 'dtrt-indent-mode-line-info global-mode-string))
  407. (dtrt-indent-mode 1))
  408. (use-package org
  409. :commands org-mode
  410. :after bind-map
  411. :ensure t
  412. :config
  413. (setq org-log-done 'time)
  414. (defun org->odt->pdf ()
  415. "Someday I'll learn how to properly format the LaTeX to PDF output."
  416. (interactive)
  417. (org-odt-export-to-odt)
  418. (shell-command
  419. (concat
  420. "libreoffice --headless --convert-to pdf \"" (file-name-sans-extension (buffer-name)) ".odt\""
  421. " && echo Done")))
  422. (setq org-html-table-default-attributes '(:border "2" :cellspacing "0" :cellpadding "6" :rules "all" :frame "border"))
  423. (setq org-latex-minted-options
  424. '("breaklines"))
  425. (defun org-variable-toggle-latex-fragment ()
  426. "Toggle LaTeX fragment, taking into account the current zoom size of the buffer."
  427. (interactive)
  428. (if (boundp 'text-scale-mode-amount)
  429. (let ((org-format-latex-options (plist-put org-format-latex-options :scale text-scale-mode-amount)))
  430. (org-toggle-latex-fragment))
  431. (org-toggle-latex-fragment)))
  432. (face-attribute 'default :font)
  433. ;; I might experiemnt with gnuplot and notes in the future.
  434. ;; (org-babel-do-load-languages
  435. ;; 'org-babel-load-languages
  436. ;; '((gnuplot . t)))
  437. ;; (global-set-key (kbd "C-c c") 'org-capture)
  438. (bind-map
  439. my-org-map
  440. :keys ("M-m")
  441. :evil-keys ("SPC")
  442. :major-modes (org-mode)
  443. :bindings
  444. (;"ol" 'org-toggle-latex-fragment
  445. "ol" 'org-variable-toggle-latex-fragment
  446. "ot" 'org-timeline
  447. "oa" 'org-archive-subtree
  448. "od" 'org-deadline
  449. "os" 'org-schedule
  450. "op" 'org-priority
  451. "t" 'org-todo)))
  452. (use-package org-agenda
  453. :commands org-agenda org-timeline
  454. :after org
  455. :after evil
  456. :config
  457. ;; Rip org-timeline
  458. (defun org-timeline ()
  459. (interactive)
  460. (let ((org-agenda-custom-commands
  461. '(("z" "" agenda ""
  462. ((org-agenda-span 'year)
  463. ;; (org-agenda-time-grid nil)
  464. (org-agenda-show-all-dates nil)
  465. ;; (org-agenda-entry-types '(:deadline)) ;; this entry excludes :scheduled
  466. (org-deadline-warning-days 0))))))
  467. (org-agenda nil "z" 'buffer)))
  468. ;; Not sure if this can be placed in a :bind statement
  469. (evil-define-key 'motion org-agenda-mode-map (kbd "RET") '(lambda () (interactive) (org-agenda-switch-to t)))
  470. (setq org-agenda-files (quote ("~/Owncloud/org/organizer.org"))))
  471. (use-package org-preview-html
  472. :commands org-preview-html/preview
  473. :after org
  474. :ensure t)
  475. (use-package evil-ediff
  476. :ensure t
  477. :config
  478. (add-hook 'ediff-load-hook 'evil-ediff-init))
  479. (use-package rainbow-delimiters
  480. :ensure t
  481. :config
  482. (add-hook 'prog-mode-hook #'rainbow-delimiters-mode))
  483. (use-package rainbow-identifiers
  484. :ensure t
  485. :config
  486. (add-hook 'prog-mode-hook #'rainbow-identifiers-mode)
  487. (setq rainbow-identifiers-faces-to-override
  488. '(
  489. font-lock-constant-face
  490. font-lock-type-face
  491. font-lock-function-name-face
  492. font-lock-variable-name-face
  493. font-lock-keyword-face)))
  494. (use-package rainbow-mode
  495. :ensure t
  496. :diminish rainbow-mode
  497. :config
  498. (add-hook 'prog-mode-hook #'rainbow-mode))
  499. (use-package eyebrowse
  500. :ensure t
  501. :config
  502. (eyebrowse-mode t)
  503. (eyebrowse-setup-evil-keys)
  504. (setq eyebrowse-new-workspace t))
  505. (use-package material-theme
  506. :ensure t)
  507. (use-package solaire-mode
  508. :ensure t
  509. :config
  510. ;; highlight the minibuffer when it is activated
  511. (set-face-attribute 'solaire-minibuffer-face nil :inherit 'solaire-default-face :background "gainsboro")
  512. (add-hook 'minibuffer-setup-hook #'solaire-mode-in-minibuffer))
  513. (use-package evil-goggles
  514. :ensure t
  515. :diminish evil-goggles-mode
  516. :config
  517. (evil-goggles-mode)
  518. ;; optionally use diff-mode's faces; as a result, deleted text
  519. ;; will be highlighed with `diff-removed` face which is typically
  520. ;; some red color (as defined by the color theme)
  521. ;; other faces such as `diff-added` will be used for other actions
  522. (evil-goggles-use-diff-faces))
  523. (use-package shackle
  524. :ensure t
  525. :init
  526. (shackle-mode)
  527. (setq shackle-rules '(("*Python*" :align t :size 0.2)
  528. ("*Help*" :align t :size 0.4 :select t)
  529. ("\\`\\*intero:.*:repl\\*\\'" :regexp t :align t :size 0.4))))
  530. (use-package which-key
  531. :ensure t
  532. :diminish which-key-mode
  533. :config
  534. (setq which-key-idle-delay 0.5)
  535. (which-key-mode)
  536. ;(which-key-setup-minibuffer)
  537. (which-key-setup-side-window-bottom)
  538. (defvar i 1)
  539. (while (< i 10)
  540. (let ((cell (cons (cons (number-to-string i) nil) '(lambda (cs) t))))
  541. (add-to-list 'which-key-replacement-alist cell))
  542. (setq i (+ i 1)))
  543. (makunbound 'i)
  544. (which-key-add-key-based-replacements
  545. "SPC d" "Diff buffer w/ file"))
  546. ;; OS specific
  547. (use-package magit
  548. :commands magit-status
  549. :if (not (eq system-type 'windows-nt))
  550. :ensure t
  551. :defer t
  552. :diminish magit-auto-revert-mode
  553. :config
  554. (evil-magit-init))
  555. (use-package evil-magit
  556. :if (not (eq system-type 'windows-nt))
  557. :ensure t
  558. :commands evil-magit-init)
  559. (use-package multi-term
  560. :if (not (eq system-type 'windows-nt))
  561. :ensure t)
  562. (use-package esup
  563. :commands esup
  564. :ensure t)
  565. (use-package highlight-indent-guides
  566. :ensure t
  567. :init
  568. (add-hook 'prog-mode-hook 'highlight-indent-guides-mode)
  569. :config
  570. (setq highlight-indent-guides-method 'column))
  571. (use-package evil-collection
  572. :ensure t
  573. :after evil
  574. :init
  575. (setq evil-collection-setup-minibuffer t)
  576. :config
  577. (evil-collection-init))
  578. ;; global-prettify-symbols doesn't play nice on Windows
  579. (if (not (eq system-type 'windows-nt))
  580. (global-prettify-symbols-mode))
  581. (require 'prettify-custom-symbols)
  582. (use-package yasnippet
  583. :ensure t
  584. :commands yas-minor-mode
  585. :init
  586. (add-hook 'prog-mode-hook 'yas-minor-mode)
  587. :config
  588. (yas-reload-all)
  589. ;; Add yasnippet support for all company backends
  590. ;; https://github.com/syl20bnr/spacemacs/pull/179
  591. (defvar company-mode/enable-yas t
  592. "Enable yasnippet for all backends.")
  593. (defun company-mode/backend-with-yas (backend)
  594. (if (or (not company-mode/enable-yas) (and (listp backend) (member 'company-yasnippet backend)))
  595. backend
  596. (append (if (consp backend) backend (list backend))
  597. '(:with company-yasnippet))))
  598. (setq company-backends (mapcar #'company-mode/backend-with-yas company-backends)))
  599. (use-package yasnippet-snippets
  600. :ensure t
  601. :after yasnippet)
  602. (use-package gnus
  603. :ensure t
  604. :init
  605. (add-hook 'gnus-group-mode-hook 'gnus-topic-mode)
  606. (add-hook 'gnus-startup-hook
  607. '(lambda ()
  608. (define-key gnus-summary-mode-map (kbd "RET") 'gnus-summary-next-page)
  609. (cl-loop for mode in (list gnus-article-mode-map gnus-group-mode-map gnus-summary-mode-map)
  610. do (cl-loop for key in (list "RET" "G")
  611. do (evil-passthrough-key 'motion mode key)))))
  612. (add-hook 'gnus-startup-hook '(lambda () (gnus-demon-add-handler 'gnus-demon-scan-mail 5 1)))
  613. :config
  614. (setq gnus-select-method '(nntp "news.gmane.org"))
  615. (setq gnus-thread-sort-functions '(gnus-thread-sort-by-most-recent-date gnus-thread-sort-by-most-recent-number))
  616. (add-to-list 'gnus-secondary-select-methods
  617. '(nnimap "gmail"
  618. (nnimap-address "imap.gmail.com")
  619. (nnimap-server-port 993)
  620. (nnimap-stream ssl)
  621. (nnir-search-engine imap)
  622. ;; @see http://www.gnu.org/software/emacs/manual/html_node/gnus/Expiring-Mail.html
  623. ;; press 'E' to expire email
  624. (nnmail-expiry-target "nnimap+gmail:[Gmail]/Trash")
  625. (nnmail-expiry-wait 90)))
  626. (add-to-list 'gnus-secondary-select-methods
  627. '(nnimap "comcast"
  628. (nnimap-address "imap.comcast.net")
  629. (nnimap-server-port 993)
  630. (nnimap-stream ssl)
  631. (nnir-search-engine imap)
  632. (nnmail-expiry-target "nnimap+comcast:Trash")
  633. (nnmail-expiry-wait 90)))
  634. (add-hook 'gnus-topic-mode-hook
  635. '(lambda ()
  636. (setq gnus-message-archive-group '((format-time-string "sent.%Y")))
  637. (setq gnus-topic-topology '(("Gnus" visible)
  638. (("misc" visible))
  639. (("comcast" visible nil nil))
  640. (("gmail" visible nil nil))
  641. (("feeds" visible nil nil))))
  642. (gnus-topic-move-matching ".*comcast.*" "comcast")
  643. (gnus-topic-move-matching ".*gmail.*" "gmail")
  644. (gnus-topic-move-matching "gwene.*" "feeds")
  645. (setq gnus-topic-alist (mapcar 'delete-dups gnus-topic-alist)))))
  646. (use-package gnus-desktop-notify
  647. :ensure t
  648. :after gnus
  649. :config
  650. (gnus-desktop-notify-mode))
  651. (use-package dumb-jump
  652. :after evil
  653. :ensure t
  654. :bind (:map evil-normal-state-map
  655. ("zs" . hscroll-cursor-left)
  656. ("gs" . dumb-jump-go-evil-mark))
  657. :config
  658. (setq dumb-jump-selector 'ivy)
  659. (defun dumb-jump-go-evil-mark ()
  660. (interactive)
  661. (evil-set-jump)
  662. (dumb-jump-go)))
  663. (use-package evil-visual-mark-mode
  664. :after evil
  665. :ensure t)
  666. (use-package define-word
  667. :ensure t)
  668. ;;;; Optional packages
  669. (use-package flymd
  670. :defer t
  671. :config
  672. (setq flymd-close-buffer-delete-temp-files t))
  673. (use-package web-mode
  674. :defer t
  675. :config
  676. ;; 2 spaces for an indent
  677. (defun my-web-mode-hook ()
  678. "Hooks for Web mode."
  679. (setq web-mode-markup-indent-offset 2
  680. web-mode-enable-auto-closing t
  681. web-mode-enable-auto-pairing t)
  682. )
  683. (add-hook 'web-mode-hook 'my-web-mode-hook)
  684. ;; Auto-enable web-mode when opening relevent files
  685. (add-to-list 'auto-mode-alist '("\\.html\\'" . web-mode))
  686. (add-to-list 'auto-mode-alist '("\\.hbs\\'" . web-mode))
  687. (add-to-list 'auto-mode-alist '("\\.handlebars\\'" . web-mode)))
  688. (setq js-indent-level 2)
  689. (use-package tide
  690. :mode "\\.ts\\'"
  691. :config
  692. (setq typescript-indent-level 2))
  693. (use-package racket-mode
  694. :mode "\\.scm\\'"
  695. :config
  696. ;; C-w prefix in racket-REPL
  697. (add-hook 'racket-repl-mode-hook 'racket-repl-evil-hook)
  698. (defun racket-repl-evil-hook ()
  699. (define-key racket-repl-mode-map "\C-w" 'evil-window-map)
  700. (global-set-key (kbd "C-w") 'racket-repl-mode-map)))
  701. (use-package haskell-mode
  702. :ensure t
  703. :init
  704. (add-hook 'haskell-mode-hook 'haskell-indentation-mode))
  705. (use-package intero
  706. :commands intero-mode
  707. :init
  708. (add-hook 'haskell-mode-hook 'intero-mode)
  709. :config
  710. (bind-map
  711. my-haskell-map
  712. :keys ("M-m")
  713. :evil-keys ("SPC")
  714. :major-modes (haskell-mode)
  715. :bindings
  716. ("l" 'intero-repl-load
  717. "r" 'intero-repl)))
  718. (use-package emojify
  719. :defer t
  720. :config
  721. (add-hook 'after-init-hook #'global-emojify-mode))
  722. (use-package latex-preview-pane
  723. :commands latex-preview-pane-mode)
  724. (use-package slime
  725. :after bind-key
  726. :commands slime slime-mode
  727. :init
  728. (setq auto-mode-alist (cons '("\\.cl$" . common-lisp-mode) auto-mode-alist))
  729. (add-hook 'lisp-mode-hook 'slime-mode)
  730. :config
  731. (setq inferior-lisp-program "sbcl")
  732. (slime-setup)
  733. (defun evil-slime-eval-last-expression ()
  734. (interactive)
  735. (evil-append 1)
  736. (slime-eval-last-expression)
  737. (evil-normal-state))
  738. (bind-map
  739. my-slime-map
  740. :keys ("M-m")
  741. :evil-keys ("SPC")
  742. :major-modes (lisp-mode)
  743. :bindings
  744. ("el" 'evil-slime-eval-last-expression
  745. "er" 'slime-eval-region
  746. "eb" 'slime-compile-and-load-file)))
  747. (use-package slime-company
  748. :defer t
  749. :after slime)
  750. (use-package auctex
  751. :defer t)
  752. (use-package atomic-chrome
  753. :defer t
  754. :config
  755. (atomic-chrome-start-server))
  756. (use-package elpy
  757. :defer t
  758. :init
  759. (add-hook 'python-mode-hook 'elpy-enable))
  760. (use-package jedi
  761. ;; Must run `pip3 install --user jedi flake8 autopep8 virtualenv epc`
  762. :defer t
  763. :init
  764. (add-hook 'python-mode-hook 'jedi:setup))
  765. (use-package company-jedi
  766. :defer t
  767. :init
  768. (add-hook 'python-mode-hook '(lambda () (add-to-list 'company-backends 'company-jedi))))
  769. (use-package py-autopep8
  770. :defer t
  771. :config
  772. (add-hook 'elpy-mode-hook 'py-autopep8-enable-on-save))
  773. ;; List of optional packages
  774. (defvar optional-packages
  775. '(
  776. flymd
  777. web-mode
  778. tide
  779. racket-mode
  780. intero
  781. emojify
  782. latex-preview-pane
  783. slime
  784. slime-company
  785. markdown-mode
  786. auctex
  787. company-auctex
  788. atomic-chrome
  789. elpy
  790. jedi
  791. company-jedi
  792. py-autopep8
  793. ))
  794. (defvar packages-installed-this-session nil)
  795. (defun ensure-package-installed (prompt package)
  796. "Ensure a package is installed, and (optionally) ask if it isn't."
  797. (if (not (package-installed-p package))
  798. (if (or prompt (y-or-n-p (format "Package %s is missing. Install it? " package)))
  799. ;; If this is the 1st install this session, update before install
  800. (cond ((not packages-installed-this-session)
  801. (package-refresh-contents)
  802. (setq packages-installed-this-session t)
  803. (package-install package))
  804. (t (package-install package))
  805. nil)
  806. package)))
  807. (defun optional-packages-install ()
  808. "Ask to install any optional packages."
  809. (interactive)
  810. (mapcar (lambda (package) (ensure-package-installed nil package)) optional-packages))
  811. ;;;; Builtin configs
  812. (defvar gdb-many-windows t)
  813. (setq tramp-syntax (quote default))
  814. (setq prolog-program-name "swipl")
  815. (add-to-list 'auto-mode-alist '("\\.pl\\'" . prolog-mode))
  816. (bind-map
  817. my-prolog-map
  818. :keys ("M-m")
  819. :evil-keys ("SPC")
  820. :major-modes (prolog-mode)
  821. :bindings
  822. ("l" 'prolog-consult-buffer))
  823. (use-package doc-view
  824. :defer t
  825. :config
  826. (evil-define-key 'motion doc-view-mode-map
  827. (kbd "k") 'doc-view-previous-line-or-previous-page
  828. (kbd "j") 'doc-view-next-line-or-next-page
  829. (kbd "C-b") 'doc-view-previous-page
  830. (kbd "C-f") 'doc-view-next-page)
  831. )
  832. (use-package flyspell
  833. :commands flyspell-goto-previous-error flyspell-goto-next-error flyspell-toggle-correct-mode
  834. :config
  835. ;; move point to previous error
  836. ;; based on code by hatschipuh at
  837. ;; http://emacs.stackexchange.com/a/14912/2017
  838. (defun flyspell-goto-previous-error (arg)
  839. "Go to arg previous spelling error."
  840. (interactive "p")
  841. (while (not (= 0 arg))
  842. (let ((pos (point))
  843. (min (point-min)))
  844. (if (and (eq (current-buffer) flyspell-old-buffer-error)
  845. (eq pos flyspell-old-pos-error))
  846. (progn
  847. (if (= flyspell-old-pos-error min)
  848. ;; goto beginning of buffer
  849. (progn
  850. (message "Restarting from end of buffer")
  851. (goto-char (point-max)))
  852. (backward-word 1))
  853. (setq pos (point))))
  854. ;; seek the next error
  855. (while (and (> pos min)
  856. (let ((ovs (overlays-at pos))
  857. (r '()))
  858. (while (and (not r) (consp ovs))
  859. (if (flyspell-overlay-p (car ovs))
  860. (setq r t)
  861. (setq ovs (cdr ovs))))
  862. (not r)))
  863. (backward-word 1)
  864. (setq pos (point)))
  865. ;; save the current location for next invocation
  866. (setq arg (1- arg))
  867. (setq flyspell-old-pos-error pos)
  868. (setq flyspell-old-buffer-error (current-buffer))
  869. (goto-char pos)
  870. (if (= pos min)
  871. (progn
  872. (message "No more miss-spelled word!")
  873. (setq arg 0))))))
  874. (defun flyspell-toggle-correct-mode ()
  875. "Decide whether to use flyspell-mode or flyspell-prog-mode, then properly toggle."
  876. (interactive)
  877. ;; use flyspell-mode when in text buffers
  878. ;; otherwise use flyspell-prog-mode
  879. (let* ((current-mode
  880. (buffer-local-value 'major-mode (current-buffer)))
  881. (flyspell-mode-to-call
  882. (if (or (string= current-mode "text-mode") (string= current-mode "markdown-mode"))
  883. 'flyspell-mode
  884. 'flyspell-prog-mode)))
  885. ;; toggle the current flyspell mode, and
  886. ;; eval the buffer if we turned it on
  887. (if flyspell-mode
  888. (funcall 'flyspell-mode '0)
  889. (funcall flyspell-mode-to-call)
  890. (flyspell-buffer))))
  891. (add-hook 'text-mode-hook 'flyspell-mode)
  892. (add-hook 'prog-mode-hook 'flyspell-prog-mode))
  893. (use-package hideshow
  894. :config
  895. (add-hook 'prog-mode-hook
  896. 'hs-minor-mode)
  897. (add-hook 'hs-minor-mode-hook
  898. (lambda ()
  899. (diminish 'hs-minor-mode))))
  900. (use-package recentf
  901. :config
  902. (recentf-mode 1)
  903. (setq recentf-max-saved-items 200
  904. recentf-max-menu-items 15)
  905. (add-to-list 'recentf-exclude ".*.emacs\\.d/elpa.*"))
  906. (use-package dired
  907. :config
  908. (evil-define-key 'normal dired-mode-map (kbd "SPC") nil))
  909. (provide 'packages)