emacs 6.7 KB

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