emacs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. (define-key evil-window-map (kbd "q") 'delete-window)
  82. (define-key evil-window-map (kbd "C-q") 'delete-window)
  83. ;;;; Files
  84. ;; move file backups
  85. (setq backup-directory-alist
  86. `((".*" . ,(concat user-emacs-directory "backups"))))
  87. (setq auto-save-file-name-transforms
  88. `((".*" ,(concat user-emacs-directory "backups") t)))
  89. ;; Instead save undo history under .emacs.d/undo
  90. (setq undo-tree-auto-save-history t
  91. undo-tree-history-directory-alist
  92. `(("." . ,(concat user-emacs-directory "undo"))))
  93. (unless (file-exists-p (concat user-emacs-directory "undo"))
  94. (make-directory (concat user-emacs-directory "undo")))
  95. ;; Powerline
  96. (require 'powerline)
  97. (powerline-vim-theme)
  98. ;; Recent Files
  99. (require 'recentf)
  100. (recentf-mode 1)
  101. (setq recentf-max-menu-items 25)
  102. ;; Autocomplete
  103. (require 'auto-complete)
  104. (ac-config-default)
  105. ;;(define-key ac-mode-map (kbd "TAB") 'auto-complete)
  106. (setq ac-auto-start nil)
  107. (global-set-key (kbd "<backtab>") 'ac-previous)
  108. (ac-set-trigger-key "TAB")
  109. ;; Spelling
  110. ;; TODO Mess with how I want spelling to be done. Maybe enable spelling on auto-fill mode?
  111. ;; map ]s and [s to next and previously wrong word
  112. (require 'general)
  113. (general-evil-setup)
  114. (general-nmap "]"
  115. (general-key-dispatch 'evil-change
  116. "s" 'flyspell-goto-next-error
  117. ))
  118. (general-vmap "]" 'evil-change)
  119. ;; move point to previous error
  120. ;; based on code by hatschipuh at
  121. ;; http://emacs.stackexchange.com/a/14912/2017
  122. (defun flyspell-goto-previous-error (arg)
  123. "Go to arg previous spelling error."
  124. (interactive "p")
  125. (while (not (= 0 arg))
  126. (let ((pos (point))
  127. (min (point-min)))
  128. (if (and (eq (current-buffer) flyspell-old-buffer-error)
  129. (eq pos flyspell-old-pos-error))
  130. (progn
  131. (if (= flyspell-old-pos-error min)
  132. ;; goto beginning of buffer
  133. (progn
  134. (message "Restarting from end of buffer")
  135. (goto-char (point-max)))
  136. (backward-word 1))
  137. (setq pos (point))))
  138. ;; seek the next error
  139. (while (and (> pos min)
  140. (let ((ovs (overlays-at pos))
  141. (r '()))
  142. (while (and (not r) (consp ovs))
  143. (if (flyspell-overlay-p (car ovs))
  144. (setq r t)
  145. (setq ovs (cdr ovs))))
  146. (not r)))
  147. (backward-word 1)
  148. (setq pos (point)))
  149. ;; save the current location for next invocation
  150. (setq arg (1- arg))
  151. (setq flyspell-old-pos-error pos)
  152. (setq flyspell-old-buffer-error (current-buffer))
  153. (goto-char pos)
  154. (if (= pos min)
  155. (progn
  156. (message "No more miss-spelled word!")
  157. (setq arg 0))
  158. (forward-word)))))
  159. (general-nmap "["
  160. (general-key-dispatch 'evil-change
  161. "s" 'flyspell-goto-previous-error
  162. ))
  163. (general-vmap "[" 'evil-change)
  164. ;; Relative line numbers
  165. (require 'linum-relative)
  166. (setq linum-relative-current-symbol "")
  167. (linum-mode)
  168. (linum-relative-global-mode)
  169. ;; Evil leader is Space
  170. (global-evil-leader-mode)
  171. (evil-leader/set-leader "<SPC>")
  172. ;; Leader keybinds
  173. (evil-leader/set-key
  174. "d" 'diff-buffer-with-file
  175. "u" 'undo-tree-visualize
  176. "m" 'recentf-open-files
  177. "l" 'auto-fill-mode
  178. "s" 'flyspell-mode
  179. "g" 'magit-status
  180. "M-g" 'magit-dispatch-popup)
  181. ;; TODO:
  182. ;; Go through the tutorials, skim the manuals
  183. ;; learning elisp
  184. ;; Fuzzy
  185. ;; Evil leader mode
  186. ;; Hotkey for undo tree
  187. ;; autocomplete
  188. ;; recent files
  189. ;; magit bindings
  190. (custom-set-variables
  191. ;; custom-set-variables was added by Custom.
  192. ;; If you edit it by hand, you could mess it up, so be careful.
  193. ;; Your init file should contain only one such instance.
  194. ;; If there is more than one, they won't work right.
  195. '(custom-enabled-themes (quote (wombat)))
  196. '(custom-safe-themes
  197. (quote
  198. ("14f0fbf6f7851bfa60bf1f30347003e2348bf7a1005570fd758133c87dafe08f" "4e753673a37c71b07e3026be75dc6af3efbac5ce335f3707b7d6a110ecb636a3" default)))
  199. '(inhibit-default-init t)
  200. '(inhibit-startup-buffer-menu nil)
  201. '(inhibit-startup-echo-area-message "josh")
  202. '(initial-buffer-choice t)
  203. '(initial-scratch-message "")
  204. '(package-selected-packages
  205. (quote
  206. (evil-magit linum-relative general fuzzy auto-complete evil-tabs powerline-evil zenburn-theme magit iedit evil-leader))))
  207. (custom-set-faces
  208. ;; custom-set-faces was added by Custom.
  209. ;; If you edit it by hand, you could mess it up, so be careful.
  210. ;; Your init file should contain only one such instance.
  211. ;; If there is more than one, they won't work right.
  212. )