emacs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. 'evil-magit
  54. 'undo-tree
  55. 'evil
  56. 'evil-leader
  57. 'evil-tabs
  58. 'powerline-evil
  59. 'zenburn-theme
  60. 'auto-complete
  61. 'fuzzy
  62. 'general
  63. 'linum-relative
  64. )
  65. ;;;; Evil
  66. (setq evil-want-C-i-jump nil)
  67. ;; Evil tabs
  68. (global-evil-tabs-mode t)
  69. ;; Default to evil mode
  70. (evil-mode t)
  71. ;; Move all elements of evil-emacs-state-modes to evil-motion-state-modes
  72. (setq evil-motion-state-modes (append evil-emacs-state-modes evil-motion-state-modes))
  73. (setq evil-emacs-state-modes nil)
  74. ;; Delete info bindings for evil to take over
  75. (define-key Info-mode-map "g" nil)
  76. (define-key Info-mode-map "n" nil)
  77. (define-key Info-mode-map "p" nil)
  78. ;;;; Files
  79. ;; move file backups
  80. (setq backup-directory-alist
  81. `((".*" . ,(concat user-emacs-directory "backups"))))
  82. (setq auto-save-file-name-transforms
  83. `((".*" ,(concat user-emacs-directory "backups") t)))
  84. ;; Instead save undo history under .emacs.d/undo
  85. (setq undo-tree-auto-save-history t
  86. undo-tree-history-directory-alist
  87. `(("." . ,(concat user-emacs-directory "undo"))))
  88. (unless (file-exists-p (concat user-emacs-directory "undo"))
  89. (make-directory (concat user-emacs-directory "undo")))
  90. ;; Powerline
  91. (require 'powerline)
  92. (powerline-vim-theme)
  93. ;; Recent Files
  94. (require 'recentf)
  95. (recentf-mode 1)
  96. (setq recentf-max-menu-items 25)
  97. ;; Autocomplete
  98. (require 'auto-complete)
  99. (ac-config-default)
  100. ;;(define-key ac-mode-map (kbd "TAB") 'auto-complete)
  101. (setq ac-auto-start nil)
  102. (global-set-key (kbd "<backtab>") 'ac-previous)
  103. (ac-set-trigger-key "TAB")
  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 'linum-relative)
  161. (setq linum-relative-current-symbol "")
  162. (linum-mode)
  163. (linum-relative-global-mode)
  164. ;; Magit
  165. (require 'magit)
  166. (require 'evil-magit)
  167. (global-magit-file-mode)
  168. ;; Evil leader is Space
  169. (global-evil-leader-mode)
  170. (evil-leader/set-leader "<SPC>")
  171. ;; Leader keybinds
  172. (evil-leader/set-key
  173. "d" 'diff-buffer-with-file
  174. "u" 'undo-tree-visualize
  175. "m" 'recentf-open-files
  176. "l" 'auto-fill-mode
  177. "s" 'flyspell-mode
  178. "g" 'magit-status
  179. "M-g" 'magit-dispatch-popup)
  180. ;; TODO:
  181. ;; Go through the tutorials, skim the manuals
  182. ;; learning elisp
  183. ;; Fuzzy
  184. ;; Evil leader mode
  185. ;; Hotkey for undo tree
  186. ;; autocomplete
  187. ;; recent files
  188. ;; magit bindings
  189. (custom-set-variables
  190. ;; custom-set-variables 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. '(custom-enabled-themes (quote (zenburn)))
  195. '(custom-safe-themes
  196. (quote
  197. ("14f0fbf6f7851bfa60bf1f30347003e2348bf7a1005570fd758133c87dafe08f" "4e753673a37c71b07e3026be75dc6af3efbac5ce335f3707b7d6a110ecb636a3" default)))
  198. '(inhibit-default-init t)
  199. '(inhibit-startup-buffer-menu nil)
  200. '(inhibit-startup-echo-area-message "josh")
  201. '(initial-buffer-choice t)
  202. '(initial-scratch-message "")
  203. '(package-selected-packages
  204. (quote
  205. (evil-magit linum-relative general fuzzy auto-complete evil-tabs powerline-evil zenburn-theme magit iedit evil-leader))))
  206. (custom-set-faces
  207. ;; custom-set-faces was added by Custom.
  208. ;; If you edit it by hand, you could mess it up, so be careful.
  209. ;; Your init file should contain only one such instance.
  210. ;; If there is more than one, they won't work right.
  211. )