emacs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. ;; Disable beep & flash
  2. (setq ring-bell-function 'ignore)
  3. ;; All yes or no prompts are y or n
  4. (defalias 'yes-or-no-p 'y-or-n-p)
  5. ;; Never follow symlinks
  6. (setq vc-follow-symlinks nil)
  7. ;; Leave the OS clipboard alone (use evil's "+ and "* instead)
  8. (setq x-select-enable-clipboard nil)
  9. ;; Text and Notes
  10. (setq sentence-end-double-space nil)
  11. ;; Save minibar history
  12. (savehist-mode 1)
  13. (setq savehist-additional-variables '(kill-ring search-ring regexp-search-ring))
  14. ;; system-specific configs
  15. (cond ((eq system-type 'windows-nt) (win-setup))
  16. ((eq system-type 'gnu/linux) (linux-setup))
  17. (t (message "")))
  18. (defun win-setup ()
  19. (add-to-list 'exec-path "C:/Program Files (x86)/Aspell/bin/")
  20. (setq ispell-program-name "aspell"))
  21. (defun linux-setup ()
  22. ;; linux specific things
  23. )
  24. ;;;; Packages
  25. ;; Package installation
  26. (require 'package)
  27. (add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/"))
  28. (add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/"))
  29. (add-to-list 'package-archives '("melpa-stable" . "http://stable.melpa.org/packages/"))
  30. (setq package-enable-at-startup nil)
  31. (package-initialize)
  32. ;; Function to ensure every package in installed, and ask if it isn't.
  33. (defun ensure-package-installed (&rest packages)
  34. (mapcar
  35. (lambda (package)
  36. (if (package-installed-p package)
  37. nil
  38. (if (y-or-n-p (format "Package %s is missing. Install it? " package))
  39. (package-install package)
  40. package)))
  41. packages))
  42. ;; Make sure to have downloaded archive description.
  43. (or (file-exists-p package-user-dir)
  44. (package-refresh-contents))
  45. ;; Activate installed packages
  46. (package-initialize)
  47. ;; Check that all packages are installed
  48. (ensure-package-installed
  49. 'iedit
  50. 'magit
  51. 'undo-tree
  52. 'evil
  53. 'evil-leader
  54. 'evil-tabs
  55. 'powerline-evil
  56. 'zenburn-theme
  57. 'auto-complete
  58. 'fuzzy
  59. 'general
  60. 'relative-line-numbers
  61. )
  62. ;;;; Evil
  63. ;; Evil leader is Space
  64. (global-evil-leader-mode)
  65. (evil-leader/set-leader "<SPC>")
  66. ;; Evil tabs
  67. (global-evil-tabs-mode t)
  68. ;; Default to evil mode
  69. (evil-mode t)
  70. ;; Leader keybinds
  71. (evil-leader/set-key
  72. "u" 'undo-tree-visualize
  73. "m" 'recentf-open-files
  74. "l" 'auto-fill-mode
  75. "s" 'flyspell-mode)
  76. ;; Move all elements of evil-emacs-state-modes to evil-motion-state-modes
  77. (setq evil-motion-state-modes (append evil-emacs-state-modes evil-motion-state-modes))
  78. (setq evil-emacs-state-modes nil)
  79. ;; Delete info bindings for evil to take over
  80. (define-key Info-mode-map "g" nil)
  81. (define-key Info-mode-map "n" nil)
  82. (define-key Info-mode-map "p" nil)
  83. ;;;; Files
  84. ;; Disable file backup
  85. (setq make-backup-files nil)
  86. ;; Instead save undo history under .emacs.d/undo
  87. (setq undo-tree-auto-save-history t
  88. undo-tree-history-directory-alist
  89. `(("." . ,(concat user-emacs-directory "undo"))))
  90. (unless (file-exists-p (concat user-emacs-directory "undo"))
  91. (make-directory (concat user-emacs-directory "undo")))
  92. ;; Powerline
  93. (require 'powerline)
  94. (powerline-vim-theme)
  95. ;; Recent Files
  96. (require 'recentf)
  97. (recentf-mode 1)
  98. (setq recentf-max-menu-items 25)
  99. ;; Autocomplete
  100. (require 'auto-complete)
  101. (ac-config-default)
  102. (define-key ac-mode-map (kbd "TAB") 'auto-complete)
  103. (setq ac-auto-start nil)
  104. (global-set-key (kbd "<backtab>") 'ac-previous)
  105. ;; Spelling
  106. ;; TODO Mess with how I want spelling to be done. Maybe enable spelling on auto-fill mode?
  107. ;; map ]s and [s to next and previously wrong word
  108. (require 'general)
  109. (general-evil-setup)
  110. (general-nmap "]"
  111. (general-key-dispatch 'evil-change
  112. "s" 'flyspell-goto-next-error
  113. ))
  114. (general-vmap "]" 'evil-change)
  115. ;; move point to previous error
  116. ;; based on code by hatschipuh at
  117. ;; http://emacs.stackexchange.com/a/14912/2017
  118. (defun flyspell-goto-previous-error (arg)
  119. "Go to arg previous spelling error."
  120. (interactive "p")
  121. (while (not (= 0 arg))
  122. (let ((pos (point))
  123. (min (point-min)))
  124. (if (and (eq (current-buffer) flyspell-old-buffer-error)
  125. (eq pos flyspell-old-pos-error))
  126. (progn
  127. (if (= flyspell-old-pos-error min)
  128. ;; goto beginning of buffer
  129. (progn
  130. (message "Restarting from end of buffer")
  131. (goto-char (point-max)))
  132. (backward-word 1))
  133. (setq pos (point))))
  134. ;; seek the next error
  135. (while (and (> pos min)
  136. (let ((ovs (overlays-at pos))
  137. (r '()))
  138. (while (and (not r) (consp ovs))
  139. (if (flyspell-overlay-p (car ovs))
  140. (setq r t)
  141. (setq ovs (cdr ovs))))
  142. (not r)))
  143. (backward-word 1)
  144. (setq pos (point)))
  145. ;; save the current location for next invocation
  146. (setq arg (1- arg))
  147. (setq flyspell-old-pos-error pos)
  148. (setq flyspell-old-buffer-error (current-buffer))
  149. (goto-char pos)
  150. (if (= pos min)
  151. (progn
  152. (message "No more miss-spelled word!")
  153. (setq arg 0))
  154. (forward-word)))))
  155. (general-nmap "["
  156. (general-key-dispatch 'evil-change
  157. "s" 'flyspell-goto-previous-error
  158. ))
  159. (general-vmap "[" 'evil-change)
  160. ;; Relative line numbers
  161. (require 'relative-line-numbers)
  162. (global-relative-line-numbers-mode)
  163. ;; TODO:
  164. ;; Go through the tutorials, skim the manuals
  165. ;; learning elisp
  166. ;; Fuzzy
  167. ;; Evil leader mode
  168. ;; Hotkey for undo tree
  169. ;; autocomplete
  170. ;; recent files
  171. ;; magit bindings
  172. (custom-set-variables
  173. ;; custom-set-variables was added by Custom.
  174. ;; If you edit it by hand, you could mess it up, so be careful.
  175. ;; Your init file should contain only one such instance.
  176. ;; If there is more than one, they won't work right.
  177. '(custom-enabled-themes (quote (zenburn)))
  178. '(custom-safe-themes
  179. (quote
  180. ("14f0fbf6f7851bfa60bf1f30347003e2348bf7a1005570fd758133c87dafe08f" "4e753673a37c71b07e3026be75dc6af3efbac5ce335f3707b7d6a110ecb636a3" default)))
  181. '(inhibit-default-init t)
  182. '(inhibit-startup-buffer-menu nil)
  183. '(inhibit-startup-echo-area-message "josh")
  184. '(initial-buffer-choice t)
  185. '(initial-scratch-message "")
  186. '(package-selected-packages
  187. (quote
  188. (relative-line-numbers general fuzzy auto-complete evil-tabs powerline-evil zenburn-theme magit iedit evil-leader))))
  189. (custom-set-faces
  190. ;; custom-set-faces was added by Custom.
  191. ;; If you edit it by hand, you could mess it up, so be careful.
  192. ;; Your init file should contain only one such instance.
  193. ;; If there is more than one, they won't work right.
  194. )