packages.el 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008
  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" 'diff-buffer-with-file
  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. "1" 'eyebrowse-switch-to-window-config-1
  340. "2" 'eyebrowse-switch-to-window-config-2
  341. "3" 'eyebrowse-switch-to-window-config-3
  342. "4" 'eyebrowse-switch-to-window-config-4
  343. "5" 'eyebrowse-switch-to-window-config-5
  344. "6" 'eyebrowse-switch-to-window-config-6
  345. "7" 'eyebrowse-switch-to-window-config-7
  346. "8" 'eyebrowse-switch-to-window-config-8
  347. "9" 'eyebrowse-switch-to-window-config-9))
  348. (bind-map
  349. my-elisp-map
  350. :keys ("M-m")
  351. :evil-keys ("SPC")
  352. :major-modes (emacs-lisp-mode)
  353. :bindings
  354. ("el" 'evil-eval-last-sexp
  355. "er" 'eval-region
  356. "eb" 'eval-buffer)))
  357. (use-package treemacs
  358. :ensure t
  359. :bind (:map treemacs-mode-map
  360. ("." . treemacs-toggle-show-dotfiles)))
  361. (use-package treemacs-evil
  362. :after treemacs
  363. :ensure t)
  364. (use-package editorconfig
  365. :ensure t
  366. :diminish editorconfig-mode
  367. :config
  368. (editorconfig-mode 1))
  369. (use-package ivy
  370. :ensure t
  371. :diminish ivy-mode
  372. :config
  373. (ivy-mode)
  374. (setq ivy-use-virtual-buffers t))
  375. (use-package flx
  376. :ensure t
  377. :config
  378. (setq ivy-re-builders-alist '((t . ivy--regex-fuzzy))))
  379. (use-package company
  380. :ensure t
  381. :diminish company-mode
  382. :config
  383. (add-hook 'prog-mode-hook 'company-mode)
  384. )
  385. (use-package flycheck
  386. :ensure t
  387. :diminish flycheck-mode
  388. :config
  389. (add-hook 'prog-mode-hook 'flycheck-mode)
  390. (setq flycheck-check-syntax-automatically '(idle-change new-line save mode-enabled))
  391. (setq flycheck-checkers (delq 'emacs-lisp-checkdoc flycheck-checkers)))
  392. (use-package flycheck-pos-tip
  393. :ensure t
  394. :after flycheck
  395. :config
  396. (flycheck-pos-tip-mode))
  397. (use-package evil-surround
  398. :ensure t
  399. :config
  400. (global-evil-surround-mode 1))
  401. (use-package dtrt-indent
  402. :ensure t
  403. :config
  404. (setq global-mode-string (delq 'dtrt-indent-mode-line-info global-mode-string))
  405. (dtrt-indent-mode 1))
  406. (use-package org
  407. :commands org-mode
  408. :after bind-map
  409. :ensure t
  410. :config
  411. (setq org-log-done 'time)
  412. (defun org->odt->pdf ()
  413. "Someday I'll learn how to properly format the LaTeX to PDF output."
  414. (interactive)
  415. (org-odt-export-to-odt)
  416. (shell-command
  417. (concat
  418. "libreoffice --headless --convert-to pdf \"" (file-name-sans-extension (buffer-name)) ".odt\""
  419. " && echo Done")))
  420. (setq org-html-table-default-attributes '(:border "2" :cellspacing "0" :cellpadding "6" :rules "all" :frame "border"))
  421. (setq org-latex-minted-options
  422. '("breaklines"))
  423. (defun org-variable-toggle-latex-fragment ()
  424. "Toggle LaTeX fragment, taking into account the current zoom size of the buffer."
  425. (interactive)
  426. (if (boundp 'text-scale-mode-amount)
  427. (let ((org-format-latex-options (plist-put org-format-latex-options :scale text-scale-mode-amount)))
  428. (org-toggle-latex-fragment))
  429. (org-toggle-latex-fragment)))
  430. (face-attribute 'default :font)
  431. ;; I might experiemnt with gnuplot and notes in the future.
  432. ;; (org-babel-do-load-languages
  433. ;; 'org-babel-load-languages
  434. ;; '((gnuplot . t)))
  435. ;; (global-set-key (kbd "C-c c") 'org-capture)
  436. (bind-map
  437. my-org-map
  438. :keys ("M-m")
  439. :evil-keys ("SPC")
  440. :major-modes (org-mode)
  441. :bindings
  442. (;"ol" 'org-toggle-latex-fragment
  443. "ol" 'org-variable-toggle-latex-fragment
  444. "ot" 'org-timeline
  445. "oa" 'org-archive-subtree
  446. "od" 'org-deadline
  447. "os" 'org-schedule
  448. "op" 'org-priority
  449. "t" 'org-todo)))
  450. (use-package org-agenda
  451. :commands org-agenda org-timeline
  452. :after org
  453. :after evil
  454. :config
  455. ;; Rip org-timeline
  456. (defun org-timeline ()
  457. (interactive)
  458. (let ((org-agenda-custom-commands
  459. '(("z" "" agenda ""
  460. ((org-agenda-span 'year)
  461. ;; (org-agenda-time-grid nil)
  462. (org-agenda-show-all-dates nil)
  463. ;; (org-agenda-entry-types '(:deadline)) ;; this entry excludes :scheduled
  464. (org-deadline-warning-days 0))))))
  465. (org-agenda nil "z" 'buffer)))
  466. ;; Not sure if this can be placed in a :bind statement
  467. (evil-define-key 'motion org-agenda-mode-map (kbd "RET") '(lambda () (interactive) (org-agenda-switch-to t)))
  468. (setq org-agenda-files (quote ("~/Owncloud/org/organizer.org"))))
  469. (use-package org-preview-html
  470. :commands org-preview-html/preview
  471. :after org
  472. :ensure t)
  473. (use-package evil-ediff
  474. :ensure t
  475. :config
  476. (add-hook 'ediff-load-hook 'evil-ediff-init))
  477. (use-package rainbow-delimiters
  478. :ensure t
  479. :config
  480. (add-hook 'prog-mode-hook #'rainbow-delimiters-mode))
  481. (use-package rainbow-identifiers
  482. :ensure t
  483. :config
  484. (add-hook 'prog-mode-hook #'rainbow-identifiers-mode)
  485. (setq rainbow-identifiers-faces-to-override
  486. '(
  487. font-lock-constant-face
  488. font-lock-type-face
  489. font-lock-function-name-face
  490. font-lock-variable-name-face
  491. font-lock-keyword-face)))
  492. (use-package rainbow-mode
  493. :ensure t
  494. :diminish rainbow-mode
  495. :config
  496. (add-hook 'prog-mode-hook #'rainbow-mode))
  497. (use-package eyebrowse
  498. :ensure t
  499. :config
  500. (eyebrowse-mode t)
  501. (eyebrowse-setup-evil-keys)
  502. (setq eyebrowse-new-workspace t))
  503. (use-package material-theme
  504. :ensure t)
  505. (use-package solaire-mode
  506. :ensure t
  507. :config
  508. ;; highlight the minibuffer when it is activated
  509. (set-face-attribute 'solaire-minibuffer-face nil :inherit 'solaire-default-face :background "gainsboro")
  510. (add-hook 'minibuffer-setup-hook #'solaire-mode-in-minibuffer))
  511. (use-package evil-goggles
  512. :ensure t
  513. :diminish evil-goggles-mode
  514. :config
  515. (evil-goggles-mode)
  516. ;; optionally use diff-mode's faces; as a result, deleted text
  517. ;; will be highlighed with `diff-removed` face which is typically
  518. ;; some red color (as defined by the color theme)
  519. ;; other faces such as `diff-added` will be used for other actions
  520. (evil-goggles-use-diff-faces))
  521. (use-package shackle
  522. :ensure t
  523. :init
  524. (shackle-mode)
  525. (setq shackle-rules '(("*Python*" :align t :size 0.2)
  526. ("*Help*" :align t :size 0.4 :select t)
  527. ("\\`\\*intero:.*:repl\\*\\'" :regexp t :align t :size 0.4))))
  528. (use-package which-key
  529. :ensure t
  530. :diminish which-key-mode
  531. :config
  532. (setq which-key-idle-delay 0.5)
  533. (which-key-mode)
  534. ;(which-key-setup-minibuffer)
  535. (which-key-setup-side-window-bottom)
  536. (defvar i 1)
  537. (while (< i 10)
  538. (let ((cell (cons (cons (number-to-string i) nil) '(lambda (cs) t))))
  539. (add-to-list 'which-key-replacement-alist cell))
  540. (setq i (+ i 1)))
  541. (makunbound 'i)
  542. (which-key-add-key-based-replacements
  543. "SPC d" "Diff buffer w/ file"))
  544. ;; OS specific
  545. (use-package magit
  546. :commands magit-status
  547. :if (not (eq system-type 'windows-nt))
  548. :ensure t
  549. :defer t
  550. :diminish magit-auto-revert-mode
  551. :config
  552. (evil-magit-init))
  553. (use-package evil-magit
  554. :if (not (eq system-type 'windows-nt))
  555. :ensure t
  556. :commands evil-magit-init)
  557. (use-package multi-term
  558. :if (not (eq system-type 'windows-nt))
  559. :ensure t)
  560. (use-package esup
  561. :commands esup
  562. :ensure t)
  563. (use-package highlight-indent-guides
  564. :ensure t
  565. :init
  566. (add-hook 'prog-mode-hook 'highlight-indent-guides-mode)
  567. :config
  568. (setq highlight-indent-guides-method 'column))
  569. (use-package evil-collection
  570. :ensure t
  571. :after evil
  572. :init
  573. (setq evil-collection-setup-minibuffer t)
  574. :config
  575. (evil-collection-init))
  576. ;; global-prettify-symbols doesn't play nice on Windows
  577. (if (not (eq system-type 'windows-nt))
  578. (global-prettify-symbols-mode))
  579. (require 'prettify-custom-symbols)
  580. (use-package yasnippet
  581. :ensure t
  582. :commands yas-minor-mode
  583. :init
  584. (add-hook 'prog-mode-hook 'yas-minor-mode)
  585. :config
  586. (yas-reload-all)
  587. ;; Add yasnippet support for all company backends
  588. ;; https://github.com/syl20bnr/spacemacs/pull/179
  589. (defvar company-mode/enable-yas t
  590. "Enable yasnippet for all backends.")
  591. (defun company-mode/backend-with-yas (backend)
  592. (if (or (not company-mode/enable-yas) (and (listp backend) (member 'company-yasnippet backend)))
  593. backend
  594. (append (if (consp backend) backend (list backend))
  595. '(:with company-yasnippet))))
  596. (setq company-backends (mapcar #'company-mode/backend-with-yas company-backends)))
  597. (use-package yasnippet-snippets
  598. :ensure t
  599. :after yasnippet)
  600. (use-package gnus
  601. :ensure t
  602. :init
  603. (add-hook 'gnus-group-mode-hook 'gnus-topic-mode)
  604. (add-hook 'gnus-startup-hook
  605. '(lambda () (cl-loop for mode in (list gnus-article-mode-map gnus-group-mode-map gnus-summary-mode-map)
  606. do (cl-loop for key in (list "RET" "G")
  607. do (evil-passthrough-key 'motion mode key)))))
  608. (add-hook 'gnus-startup-hook '(lambda () (gnus-demon-add-handler 'gnus-demon-scan-mail 5 1)))
  609. :config
  610. (setq gnus-select-method '(nntp "news.gmane.org"))
  611. (setq gnus-thread-sort-functions '(gnus-thread-sort-by-most-recent-date gnus-thread-sort-by-most-recent-number))
  612. (add-to-list 'gnus-secondary-select-methods
  613. '(nnimap "gmail"
  614. (nnimap-address "imap.gmail.com")
  615. (nnimap-server-port 993)
  616. (nnimap-stream ssl)
  617. (nnir-search-engine imap)
  618. ;; @see http://www.gnu.org/software/emacs/manual/html_node/gnus/Expiring-Mail.html
  619. ;; press 'E' to expire email
  620. (nnmail-expiry-target "nnimap+gmail:[Gmail]/Trash")
  621. (nnmail-expiry-wait 90)))
  622. (add-to-list 'gnus-secondary-select-methods
  623. '(nnimap "comcast"
  624. (nnimap-address "imap.comcast.net")
  625. (nnimap-server-port 993)
  626. (nnimap-stream ssl)
  627. (nnir-search-engine imap)
  628. (nnmail-expiry-target "nnimap+comcast:Trash")
  629. (nnmail-expiry-wait 90)))
  630. (add-hook 'gnus-topic-mode-hook
  631. '(lambda ()
  632. (setq gnus-message-archive-group '((format-time-string "sent.%Y")))
  633. (setq gnus-topic-topology '(("Gnus" visible)
  634. (("misc" visible))
  635. (("comcast" visible nil nil))
  636. (("gmail" visible nil nil))
  637. (("feeds" visible nil nil))))
  638. (gnus-topic-move-matching ".*comcast.*" "comcast")
  639. (gnus-topic-move-matching ".*gmail.*" "gmail")
  640. (gnus-topic-move-matching "gwene.*" "feeds")
  641. (setq gnus-topic-alist (mapcar 'delete-dups gnus-topic-alist)))))
  642. (use-package gnus-desktop-notify
  643. :ensure t
  644. :after gnus
  645. :config
  646. (gnus-desktop-notify-mode))
  647. (use-package dumb-jump
  648. :after evil
  649. :ensure t
  650. :bind (:map evil-normal-state-map
  651. ("zs" . hscroll-cursor-left)
  652. ("gs" . dumb-jump-go-evil-mark))
  653. :config
  654. (setq dumb-jump-selector 'ivy)
  655. (defun dumb-jump-go-evil-mark ()
  656. (interactive)
  657. (evil-set-jump)
  658. (dumb-jump-go)))
  659. ;;;; Optional packages
  660. (use-package flymd
  661. :defer t
  662. :config
  663. (setq flymd-close-buffer-delete-temp-files t))
  664. (use-package web-mode
  665. :defer t
  666. :config
  667. ;; 2 spaces for an indent
  668. (defun my-web-mode-hook ()
  669. "Hooks for Web mode."
  670. (setq web-mode-markup-indent-offset 2
  671. web-mode-enable-auto-closing t
  672. web-mode-enable-auto-pairing t)
  673. )
  674. (add-hook 'web-mode-hook 'my-web-mode-hook)
  675. ;; Auto-enable web-mode when opening relevent files
  676. (add-to-list 'auto-mode-alist '("\\.html\\'" . web-mode))
  677. (add-to-list 'auto-mode-alist '("\\.hbs\\'" . web-mode))
  678. (add-to-list 'auto-mode-alist '("\\.handlebars\\'" . web-mode)))
  679. (setq js-indent-level 2)
  680. (use-package tide
  681. :mode "\\.ts\\'"
  682. :config
  683. (setq typescript-indent-level 2))
  684. (use-package racket-mode
  685. :mode "\\.scm\\'"
  686. :config
  687. ;; C-w prefix in racket-REPL
  688. (add-hook 'racket-repl-mode-hook 'racket-repl-evil-hook)
  689. (defun racket-repl-evil-hook ()
  690. (define-key racket-repl-mode-map "\C-w" 'evil-window-map)
  691. (global-set-key (kbd "C-w") 'racket-repl-mode-map)))
  692. (use-package intero
  693. :commands intero-mode
  694. :config
  695. (add-hook 'haskell-mode-hook 'intero-mode)
  696. (bind-map
  697. my-haskell-map
  698. :keys ("M-m")
  699. :evil-keys ("SPC")
  700. :major-modes (haskell-mode)
  701. :bindings
  702. ("l" 'intero-repl-load
  703. "r" 'intero-repl)))
  704. (use-package emojify
  705. :defer t
  706. :config
  707. (add-hook 'after-init-hook #'global-emojify-mode))
  708. (use-package latex-preview-pane
  709. :commands latex-preview-pane-mode)
  710. (use-package slime
  711. :after bind-key
  712. :commands slime slime-mode
  713. :init
  714. (setq auto-mode-alist (cons '("\\.cl$" . common-lisp-mode) auto-mode-alist))
  715. (add-hook 'lisp-mode-hook 'slime-mode)
  716. :config
  717. (setq inferior-lisp-program "sbcl")
  718. (slime-setup)
  719. (defun evil-slime-eval-last-expression ()
  720. (interactive)
  721. (evil-append 1)
  722. (slime-eval-last-expression)
  723. (evil-normal-state))
  724. (bind-map
  725. my-slime-map
  726. :keys ("M-m")
  727. :evil-keys ("SPC")
  728. :major-modes (lisp-mode)
  729. :bindings
  730. ("el" 'evil-slime-eval-last-expression
  731. "er" 'slime-eval-region
  732. "eb" 'slime-compile-and-load-file)))
  733. (use-package slime-company
  734. :defer t
  735. :after slime)
  736. (use-package auctex
  737. :defer t)
  738. (use-package atomic-chrome
  739. :defer t
  740. :config
  741. (atomic-chrome-start-server))
  742. ;; List of optional packages
  743. (defvar optional-packages
  744. '(
  745. flymd
  746. web-mode
  747. tide
  748. racket-mode
  749. intero
  750. emojify
  751. latex-preview-pane
  752. slime
  753. slime-company
  754. markdown-mode
  755. auctex
  756. company-auctex
  757. atomic-chrome
  758. ))
  759. (defvar packages-installed-this-session nil)
  760. (defun ensure-package-installed (prompt package)
  761. "Ensure a package is installed, and (optionally) ask if it isn't."
  762. (if (not (package-installed-p package))
  763. (if (or prompt (y-or-n-p (format "Package %s is missing. Install it? " package)))
  764. ;; If this is the 1st install this session, update before install
  765. (cond ((not packages-installed-this-session)
  766. (package-refresh-contents)
  767. (setq packages-installed-this-session t)
  768. (package-install package))
  769. (t (package-install package))
  770. nil)
  771. package)))
  772. (defun optional-packages-install ()
  773. "Ask to install any optional packages."
  774. (interactive)
  775. (mapcar (lambda (package) (ensure-package-installed nil package)) optional-packages))
  776. ;;;; Builtin configs
  777. (defvar gdb-many-windows t)
  778. (setq tramp-syntax (quote default))
  779. (setq prolog-program-name "swipl")
  780. (add-to-list 'auto-mode-alist '("\\.pl\\'" . prolog-mode))
  781. (bind-map
  782. my-prolog-map
  783. :keys ("M-m")
  784. :evil-keys ("SPC")
  785. :major-modes (prolog-mode)
  786. :bindings
  787. ("l" 'prolog-consult-buffer))
  788. (use-package doc-view
  789. :defer t
  790. :config
  791. (evil-define-key 'motion doc-view-mode-map
  792. (kbd "k") 'doc-view-previous-line-or-previous-page
  793. (kbd "j") 'doc-view-next-line-or-next-page
  794. (kbd "C-b") 'doc-view-previous-page
  795. (kbd "C-f") 'doc-view-next-page)
  796. )
  797. (use-package flyspell
  798. :commands flyspell-goto-previous-error flyspell-goto-next-error flyspell-toggle-correct-mode
  799. :config
  800. ;; move point to previous error
  801. ;; based on code by hatschipuh at
  802. ;; http://emacs.stackexchange.com/a/14912/2017
  803. (defun flyspell-goto-previous-error (arg)
  804. "Go to arg previous spelling error."
  805. (interactive "p")
  806. (while (not (= 0 arg))
  807. (let ((pos (point))
  808. (min (point-min)))
  809. (if (and (eq (current-buffer) flyspell-old-buffer-error)
  810. (eq pos flyspell-old-pos-error))
  811. (progn
  812. (if (= flyspell-old-pos-error min)
  813. ;; goto beginning of buffer
  814. (progn
  815. (message "Restarting from end of buffer")
  816. (goto-char (point-max)))
  817. (backward-word 1))
  818. (setq pos (point))))
  819. ;; seek the next error
  820. (while (and (> pos min)
  821. (let ((ovs (overlays-at pos))
  822. (r '()))
  823. (while (and (not r) (consp ovs))
  824. (if (flyspell-overlay-p (car ovs))
  825. (setq r t)
  826. (setq ovs (cdr ovs))))
  827. (not r)))
  828. (backward-word 1)
  829. (setq pos (point)))
  830. ;; save the current location for next invocation
  831. (setq arg (1- arg))
  832. (setq flyspell-old-pos-error pos)
  833. (setq flyspell-old-buffer-error (current-buffer))
  834. (goto-char pos)
  835. (if (= pos min)
  836. (progn
  837. (message "No more miss-spelled word!")
  838. (setq arg 0))))))
  839. (defun flyspell-toggle-correct-mode ()
  840. "Decide whether to use flyspell-mode or flyspell-prog-mode, then properly toggle."
  841. (interactive)
  842. ;; use flyspell-mode when in text buffers
  843. ;; otherwise use flyspell-prog-mode
  844. (let* ((current-mode
  845. (buffer-local-value 'major-mode (current-buffer)))
  846. (flyspell-mode-to-call
  847. (if (or (string= current-mode "text-mode") (string= current-mode "markdown-mode"))
  848. 'flyspell-mode
  849. 'flyspell-prog-mode)))
  850. ;; toggle the current flyspell mode, and
  851. ;; eval the buffer if we turned it on
  852. (if flyspell-mode
  853. (funcall 'flyspell-mode '0)
  854. (funcall flyspell-mode-to-call)
  855. (flyspell-buffer))))
  856. (add-hook 'text-mode-hook 'flyspell-mode)
  857. (add-hook 'prog-mode-hook 'flyspell-prog-mode))
  858. (use-package hideshow
  859. :config
  860. (add-hook 'prog-mode-hook
  861. 'hs-minor-mode)
  862. (add-hook 'hs-minor-mode-hook
  863. (lambda ()
  864. (diminish 'hs-minor-mode))))
  865. (use-package recentf
  866. :config
  867. (recentf-mode 1)
  868. (setq recentf-max-saved-items 200
  869. recentf-max-menu-items 15)
  870. (add-to-list 'recentf-exclude ".*.emacs\\.d/elpa.*"))
  871. (use-package dired
  872. :bind (:map dired-mode-map
  873. ("SPC" . nil)))
  874. (provide 'packages)