packages.el 31 KB

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