packages.el 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083
  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. (use-package evil-magit
  558. :if (not (eq system-type 'windows-nt))
  559. :ensure t
  560. :commands evil-magit-init)
  561. (use-package multi-term
  562. :if (not (eq system-type 'windows-nt))
  563. :ensure t)
  564. (use-package esup
  565. :commands esup
  566. :ensure t)
  567. (use-package highlight-indent-guides
  568. :ensure t
  569. :init
  570. (add-hook 'prog-mode-hook 'highlight-indent-guides-mode)
  571. :config
  572. (setq highlight-indent-guides-method 'column))
  573. (use-package evil-collection
  574. :ensure t
  575. :after evil
  576. :init
  577. (setq evil-collection-setup-minibuffer t)
  578. :config
  579. (evil-collection-init))
  580. ;; global-prettify-symbols doesn't play nice on Windows
  581. (if (not (eq system-type 'windows-nt))
  582. (global-prettify-symbols-mode))
  583. (require 'prettify-custom-symbols)
  584. (use-package yasnippet
  585. :ensure t
  586. :commands yas-minor-mode
  587. :init
  588. (add-hook 'prog-mode-hook 'yas-minor-mode)
  589. :config
  590. (yas-reload-all)
  591. ;; Add yasnippet support for all company backends
  592. ;; https://github.com/syl20bnr/spacemacs/pull/179
  593. (defvar company-mode/enable-yas t
  594. "Enable yasnippet for all backends.")
  595. (defun company-mode/backend-with-yas (backend)
  596. (if (or (not company-mode/enable-yas) (and (listp backend) (member 'company-yasnippet backend)))
  597. backend
  598. (append (if (consp backend) backend (list backend))
  599. '(:with company-yasnippet))))
  600. (setq company-backends (mapcar #'company-mode/backend-with-yas company-backends)))
  601. (use-package yasnippet-snippets
  602. :ensure t
  603. :after yasnippet)
  604. (use-package gnus
  605. :ensure t
  606. :init
  607. (add-hook 'gnus-group-mode-hook 'gnus-topic-mode)
  608. (add-hook 'gnus-startup-hook
  609. '(lambda ()
  610. (define-key gnus-summary-mode-map (kbd "RET") 'gnus-summary-next-page)
  611. (cl-loop for mode in (list gnus-article-mode-map gnus-group-mode-map gnus-summary-mode-map)
  612. do (cl-loop for key in (list "RET" "G")
  613. do (evil-passthrough-key 'motion mode key)))))
  614. (add-hook 'gnus-startup-hook '(lambda () (gnus-demon-add-handler 'gnus-demon-scan-mail 5 1)))
  615. :config
  616. (setq gnus-select-method '(nntp "news.gmane.org"))
  617. (setq gnus-thread-sort-functions '(gnus-thread-sort-by-most-recent-date gnus-thread-sort-by-most-recent-number))
  618. (add-to-list 'gnus-secondary-select-methods
  619. '(nnimap "gmail"
  620. (nnimap-address "imap.gmail.com")
  621. (nnimap-server-port 993)
  622. (nnimap-stream ssl)
  623. (nnir-search-engine imap)
  624. ;; @see http://www.gnu.org/software/emacs/manual/html_node/gnus/Expiring-Mail.html
  625. ;; press 'E' to expire email
  626. (nnmail-expiry-target "nnimap+gmail:[Gmail]/Trash")
  627. (nnmail-expiry-wait 90)))
  628. (add-to-list 'gnus-secondary-select-methods
  629. '(nnimap "comcast"
  630. (nnimap-address "imap.comcast.net")
  631. (nnimap-server-port 993)
  632. (nnimap-stream ssl)
  633. (nnir-search-engine imap)
  634. (nnmail-expiry-target "nnimap+comcast:Trash")
  635. (nnmail-expiry-wait 90)))
  636. (add-hook 'gnus-topic-mode-hook
  637. '(lambda ()
  638. (setq gnus-message-archive-group '((format-time-string "sent.%Y")))
  639. (setq gnus-topic-topology '(("Gnus" visible)
  640. (("misc" visible))
  641. (("comcast" visible nil nil))
  642. (("gmail" visible nil nil))
  643. (("feeds" visible nil nil))))
  644. (gnus-topic-move-matching ".*comcast.*" "comcast")
  645. (gnus-topic-move-matching ".*gmail.*" "gmail")
  646. (gnus-topic-move-matching "gwene.*" "feeds")
  647. (setq gnus-topic-alist (mapcar 'delete-dups gnus-topic-alist)))))
  648. (use-package gnus-desktop-notify
  649. :ensure t
  650. :after gnus
  651. :config
  652. (gnus-desktop-notify-mode))
  653. (use-package dumb-jump
  654. :after evil
  655. :ensure t
  656. :bind (:map evil-normal-state-map
  657. ("zs" . hscroll-cursor-left)
  658. ("gs" . dumb-jump-go-evil-mark))
  659. :config
  660. (setq dumb-jump-selector 'ivy)
  661. (defun dumb-jump-go-evil-mark ()
  662. (interactive)
  663. (evil-set-jump)
  664. (dumb-jump-go)))
  665. (use-package evil-visual-mark-mode
  666. :after evil
  667. :ensure t)
  668. (use-package define-word
  669. :ensure t)
  670. (use-package calfw
  671. :commands cfw:open-org-calendar
  672. :ensure t)
  673. (use-package calfw-org
  674. :ensure t
  675. )
  676. (use-package helpful
  677. :ensure t
  678. :bind (("C-h f" . helpful-callable)
  679. ("C-h v" . helpful-variable)
  680. ("C-h k" . helpful-key)))
  681. ;;;; Optional packages
  682. (use-package flymd
  683. :defer t
  684. :config
  685. (setq flymd-close-buffer-delete-temp-files t))
  686. (use-package web-mode
  687. :defer t
  688. :config
  689. ;; 2 spaces for an indent
  690. (defun my-web-mode-hook ()
  691. "Hooks for Web mode."
  692. (setq web-mode-markup-indent-offset 2
  693. web-mode-enable-auto-closing t
  694. web-mode-enable-auto-pairing t)
  695. )
  696. (add-hook 'web-mode-hook 'my-web-mode-hook)
  697. ;; Auto-enable web-mode when opening relevent files
  698. (add-to-list 'auto-mode-alist '("\\.html\\'" . web-mode))
  699. (add-to-list 'auto-mode-alist '("\\.hbs\\'" . web-mode))
  700. (add-to-list 'auto-mode-alist '("\\.handlebars\\'" . web-mode)))
  701. (setq js-indent-level 2)
  702. (use-package tide
  703. :mode "\\.ts\\'"
  704. :config
  705. (setq typescript-indent-level 2))
  706. (use-package racket-mode
  707. :mode "\\.scm\\'"
  708. :config
  709. ;; C-w prefix in racket-REPL
  710. (add-hook 'racket-repl-mode-hook 'racket-repl-evil-hook)
  711. (defun racket-repl-evil-hook ()
  712. (define-key racket-repl-mode-map "\C-w" 'evil-window-map)
  713. (global-set-key (kbd "C-w") 'racket-repl-mode-map)))
  714. (use-package haskell-mode
  715. :ensure t
  716. :init
  717. (add-hook 'haskell-mode-hook 'haskell-indentation-mode))
  718. (use-package intero
  719. :commands intero-mode
  720. :init
  721. (add-hook 'haskell-mode-hook 'intero-mode)
  722. :config
  723. (bind-map
  724. my-haskell-map
  725. :keys ("M-m")
  726. :evil-keys ("SPC")
  727. :major-modes (haskell-mode)
  728. :bindings
  729. ("l" 'intero-repl-load
  730. "r" 'intero-repl)))
  731. (use-package emojify
  732. :defer t
  733. :config
  734. (add-hook 'after-init-hook #'global-emojify-mode))
  735. (use-package latex-preview-pane
  736. :commands latex-preview-pane-mode)
  737. (use-package slime
  738. :after bind-key
  739. :commands slime slime-mode
  740. :init
  741. (setq auto-mode-alist (cons '("\\.cl$" . common-lisp-mode) auto-mode-alist))
  742. (add-hook 'lisp-mode-hook 'slime-mode)
  743. :config
  744. (setq inferior-lisp-program "sbcl")
  745. (slime-setup)
  746. (defun evil-slime-eval-last-expression ()
  747. (interactive)
  748. (evil-append 1)
  749. (slime-eval-last-expression)
  750. (evil-normal-state))
  751. (bind-map
  752. my-slime-map
  753. :keys ("M-m")
  754. :evil-keys ("SPC")
  755. :major-modes (lisp-mode)
  756. :bindings
  757. ("el" 'evil-slime-eval-last-expression
  758. "er" 'slime-eval-region
  759. "eb" 'slime-compile-and-load-file)))
  760. (use-package slime-company
  761. :defer t
  762. :after slime)
  763. (use-package auctex
  764. :defer t)
  765. (use-package atomic-chrome
  766. :defer t
  767. :config
  768. (atomic-chrome-start-server))
  769. (use-package elpy
  770. :defer t
  771. :init
  772. (add-hook 'python-mode-hook 'elpy-enable))
  773. (use-package jedi
  774. ;; Must run `pip3 install --user jedi flake8 autopep8 virtualenv epc`
  775. :defer t
  776. :init
  777. (add-hook 'python-mode-hook 'jedi:setup))
  778. (use-package company-jedi
  779. :defer t
  780. :init
  781. (add-hook 'python-mode-hook '(lambda () (add-to-list 'company-backends 'company-jedi))))
  782. (use-package py-autopep8
  783. :defer t
  784. :config
  785. (add-hook 'elpy-mode-hook 'py-autopep8-enable-on-save))
  786. (use-package rust-mode
  787. :defer t)
  788. (use-package flycheck-rust
  789. :defer t
  790. :after rust-mode
  791. :init
  792. (with-eval-after-load 'rust-mode
  793. (add-hook 'flycheck-mode-hook #'flycheck-rust-setup)))
  794. ;; List of optional packages
  795. (defvar optional-packages
  796. '(
  797. flymd
  798. web-mode
  799. tide
  800. racket-mode
  801. intero
  802. emojify
  803. latex-preview-pane
  804. slime
  805. slime-company
  806. markdown-mode
  807. auctex
  808. company-auctex
  809. atomic-chrome
  810. elpy
  811. jedi
  812. company-jedi
  813. py-autopep8
  814. ))
  815. (defvar packages-installed-this-session nil)
  816. (defun ensure-package-installed (prompt package)
  817. "Ensure a package is installed, and (optionally) ask if it isn't."
  818. (if (not (package-installed-p package))
  819. (if (or prompt (y-or-n-p (format "Package %s is missing. Install it? " package)))
  820. ;; If this is the 1st install this session, update before install
  821. (cond ((not packages-installed-this-session)
  822. (package-refresh-contents)
  823. (setq packages-installed-this-session t)
  824. (package-install package))
  825. (t (package-install package))
  826. nil)
  827. package)))
  828. (defun optional-packages-install ()
  829. "Ask to install any optional packages."
  830. (interactive)
  831. (mapcar (lambda (package) (ensure-package-installed nil package)) optional-packages))
  832. ;;;; Builtin configs
  833. (defvar gdb-many-windows t)
  834. (setq tramp-syntax (quote default))
  835. (use-package flymake
  836. :config
  837. (use-package flymake-php
  838. :init
  839. (add-hook 'php-mode-hook 'flymake-php-load)))
  840. (setq prolog-program-name "swipl")
  841. (add-to-list 'auto-mode-alist '("\\.pl\\'" . prolog-mode))
  842. (bind-map
  843. my-prolog-map
  844. :keys ("M-m")
  845. :evil-keys ("SPC")
  846. :major-modes (prolog-mode)
  847. :bindings
  848. ("l" 'prolog-consult-buffer))
  849. (use-package doc-view
  850. :defer t
  851. :config
  852. (evil-define-key 'motion doc-view-mode-map
  853. (kbd "k") 'doc-view-previous-line-or-previous-page
  854. (kbd "j") 'doc-view-next-line-or-next-page
  855. (kbd "C-b") 'doc-view-previous-page
  856. (kbd "C-f") 'doc-view-next-page)
  857. )
  858. (use-package flyspell
  859. :commands flyspell-goto-previous-error flyspell-goto-next-error flyspell-toggle-correct-mode
  860. :config
  861. ;; move point to previous error
  862. ;; based on code by hatschipuh at
  863. ;; http://emacs.stackexchange.com/a/14912/2017
  864. (defun flyspell-goto-previous-error (arg)
  865. "Go to arg previous spelling error."
  866. (interactive "p")
  867. (while (not (= 0 arg))
  868. (let ((pos (point))
  869. (min (point-min)))
  870. (if (and (eq (current-buffer) flyspell-old-buffer-error)
  871. (eq pos flyspell-old-pos-error))
  872. (progn
  873. (if (= flyspell-old-pos-error min)
  874. ;; goto beginning of buffer
  875. (progn
  876. (message "Restarting from end of buffer")
  877. (goto-char (point-max)))
  878. (backward-word 1))
  879. (setq pos (point))))
  880. ;; seek the next error
  881. (while (and (> pos min)
  882. (let ((ovs (overlays-at pos))
  883. (r '()))
  884. (while (and (not r) (consp ovs))
  885. (if (flyspell-overlay-p (car ovs))
  886. (setq r t)
  887. (setq ovs (cdr ovs))))
  888. (not r)))
  889. (backward-word 1)
  890. (setq pos (point)))
  891. ;; save the current location for next invocation
  892. (setq arg (1- arg))
  893. (setq flyspell-old-pos-error pos)
  894. (setq flyspell-old-buffer-error (current-buffer))
  895. (goto-char pos)
  896. (if (= pos min)
  897. (progn
  898. (message "No more miss-spelled word!")
  899. (setq arg 0))))))
  900. (defun flyspell-toggle-correct-mode ()
  901. "Decide whether to use flyspell-mode or flyspell-prog-mode, then properly toggle."
  902. (interactive)
  903. ;; use flyspell-mode when in text buffers
  904. ;; otherwise use flyspell-prog-mode
  905. (let* ((current-mode
  906. (buffer-local-value 'major-mode (current-buffer)))
  907. (flyspell-mode-to-call
  908. (if (or (string= current-mode "text-mode") (string= current-mode "markdown-mode"))
  909. 'flyspell-mode
  910. 'flyspell-prog-mode)))
  911. ;; toggle the current flyspell mode, and
  912. ;; eval the buffer if we turned it on
  913. (if flyspell-mode
  914. (funcall 'flyspell-mode '0)
  915. (funcall flyspell-mode-to-call)
  916. (flyspell-buffer))))
  917. (add-hook 'text-mode-hook 'flyspell-mode)
  918. (add-hook 'prog-mode-hook 'flyspell-prog-mode))
  919. (use-package hideshow
  920. :config
  921. (add-hook 'prog-mode-hook
  922. 'hs-minor-mode)
  923. (add-hook 'hs-minor-mode-hook
  924. (lambda ()
  925. (diminish 'hs-minor-mode))))
  926. (use-package recentf
  927. :config
  928. (recentf-mode 1)
  929. (setq recentf-max-saved-items 200
  930. recentf-max-menu-items 15)
  931. (add-to-list 'recentf-exclude ".*.emacs\\.d/elpa.*"))
  932. (use-package dired
  933. :config
  934. (evil-define-key 'normal dired-mode-map (kbd "SPC") nil))
  935. (provide 'packages)