packages.el 32 KB

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