packages.el 32 KB

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