emacs 6.9 KB

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