emacs 6.3 KB

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