init.el 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. ;;;; Startup
  2. (setq inhibit-splash-screen t
  3. inhibit-startup-echo-area-message t
  4. initial-scratch-message "" ; I like things empty.
  5. initial-major-mode 'text-mode) ; I'm usually not writing elisp.
  6. ;; Base
  7. (setq ring-bell-function 'ignore) ; Disable beep & flash
  8. (blink-cursor-mode 0)
  9. ;; No scroll bar
  10. (when (boundp 'scroll-bar-mode)
  11. (scroll-bar-mode -1))
  12. ;; Disable toolbar
  13. (when (display-graphic-p)
  14. (tool-bar-mode -1))
  15. ;; smoother scrolling
  16. (setq scroll-margin 0
  17. scroll-conservatively 9999
  18. scroll-step 1)
  19. ;; Line settings and indicators
  20. (setq visual-line-fringe-indicators '(left-curly-arrow right-curly-arrow))
  21. (setq-default left-fringe-width nil)
  22. (setq-default indicate-empty-lines t)
  23. ;; All yes or no prompts are y or n
  24. (defalias 'yes-or-no-p 'y-or-n-p)
  25. ;; Never follow symlinks
  26. (setq vc-follow-symlinks nil)
  27. ;;; Leave the OS clipboard alone (use evil's "+ and "* instead)
  28. ; Don't copy and paste to the clipboard
  29. (setq select-enable-clipboard nil)
  30. (setq x-select-enable-clipboard nil)
  31. ; Don't save to the clipboard on exit
  32. (setq x-select-enable-clipboard-manager nil)
  33. ;; Text and Notes
  34. (setq sentence-end-double-space nil)
  35. ;; Save minibar history
  36. (savehist-mode 1)
  37. (setq savehist-additional-variables '(kill-ring search-ring regexp-search-ring))
  38. ;; Always show matching parens
  39. (show-paren-mode t)
  40. ;; Save Window layout history
  41. (winner-mode)
  42. ;; Backups (from https://stackoverflow.com/questions/151945/how-do-i-control-how-emacs-makes-backup-files/20824625#20824625)
  43. (setq version-control t ;; Use version numbers for backups.
  44. kept-new-versions 10 ;; Number of newest versions to keep.
  45. kept-old-versions 0 ;; Number of oldest versions to keep.
  46. delete-old-versions t ;; Don't ask to delete excess backup versions.
  47. backup-by-copying t) ;; Copy all files, don't rename them.
  48. (setq vc-make-backup-files t) ;; Backup versioned files
  49. ;; Default and per-save backups go here:
  50. (setq backup-directory-alist '(("" . "~/.emacs.d/backups/per-save")))
  51. (defun force-backup-of-buffer ()
  52. ;; Make a special "per session" backup at the first save of each
  53. ;; emacs session.
  54. (when (not buffer-backed-up)
  55. ;; Override the default parameters for per-session backups.
  56. (let ((backup-directory-alist '(("" . "~/.emacs.d/backups/per-session")))
  57. (kept-new-versions 3))
  58. (backup-buffer)))
  59. ;; Make a "per save" backup on each save. The first save results in
  60. ;; both a per-session and a per-save backup, to keep the numbering
  61. ;; of per-save backups consistent.
  62. (let ((buffer-backed-up nil))
  63. (backup-buffer)))
  64. (add-hook 'before-save-hook 'force-backup-of-buffer)
  65. ;; Autosave files
  66. (setq auto-save-file-name-transforms
  67. `((".*" , "~/.emacs.d/backups/auto-saves" t)))
  68. ;; remember cursor position
  69. (toggle-save-place-globally)
  70. ;; Search all buffers
  71. (defun grep-search-all-buffers (regexp)
  72. (interactive "sRegexp: ")
  73. (multi-occur-in-matching-buffers "." regexp t))
  74. ;;; Spelling
  75. ;; map ]s and [s to next and previously wrong word
  76. ;; move point to previous error
  77. ;; based on code by hatschipuh at
  78. ;; http://emacs.stackexchange.com/a/14912/2017
  79. (defun flyspell-goto-previous-error (arg)
  80. "Go to arg previous spelling error."
  81. (interactive "p")
  82. (while (not (= 0 arg))
  83. (let ((pos (point))
  84. (min (point-min)))
  85. (if (and (eq (current-buffer) flyspell-old-buffer-error)
  86. (eq pos flyspell-old-pos-error))
  87. (progn
  88. (if (= flyspell-old-pos-error min)
  89. ;; goto beginning of buffer
  90. (progn
  91. (message "Restarting from end of buffer")
  92. (goto-char (point-max)))
  93. (backward-word 1))
  94. (setq pos (point))))
  95. ;; seek the next error
  96. (while (and (> pos min)
  97. (let ((ovs (overlays-at pos))
  98. (r '()))
  99. (while (and (not r) (consp ovs))
  100. (if (flyspell-overlay-p (car ovs))
  101. (setq r t)
  102. (setq ovs (cdr ovs))))
  103. (not r)))
  104. (backward-word 1)
  105. (setq pos (point)))
  106. ;; save the current location for next invocation
  107. (setq arg (1- arg))
  108. (setq flyspell-old-pos-error pos)
  109. (setq flyspell-old-buffer-error (current-buffer))
  110. (goto-char pos)
  111. (if (= pos min)
  112. (progn
  113. (message "No more miss-spelled word!")
  114. (setq arg 0))
  115. ))))
  116. (add-to-list 'load-path (expand-file-name "packages" user-emacs-directory))
  117. (require 'packages)
  118. ;;;; System-specific configs
  119. (defun win-setup ()
  120. (add-to-list 'exec-path "C:/Program Files (x86)/Aspell/bin/")
  121. (setq ispell-program-name "aspell")
  122. (if (file-directory-p "C:/MinGW/msys/1.0/bin")
  123. (add-to-list 'exec-path "C:/MinGW/msys/1.0/bin"))
  124. (defun cmd ()
  125. (interactive)
  126. (make-comint-in-buffer "cmd" nil "cmd" nil)
  127. (switch-to-buffer "*cmd*")))
  128. (defun linux-setup ())
  129. (cond ((eq system-type 'windows-nt) (win-setup))
  130. ((eq system-type 'gnu/linux) (linux-setup))
  131. (t (message "")))
  132. ;;;; Custom
  133. (defconst custom-file (expand-file-name "custom.el" user-emacs-directory))
  134. ;; if no custom file exists, write a default one
  135. (unless (file-exists-p custom-file)
  136. (write-region "(custom-set-faces
  137. ;; custom-set-faces was added by Custom.
  138. ;; If you edit it by hand, you could mess it up, so be careful.
  139. ;; Your init file should contain only one such instance.
  140. ;; If there is more than one, they won't work right.
  141. '(powerline-evil-normal-face ((t (:background \"#859900\")))))
  142. (custom-set-variables
  143. ;; custom-set-variables was added by Custom.
  144. ;; If you edit it by hand, you could mess it up, so be careful.
  145. ;; Your init file should contain only one such instance.
  146. ;; If there is more than one, they won't work right.
  147. '(custom-enabled-themes (quote (monokai)))
  148. '(custom-safe-themes
  149. (quote
  150. (\"c7a9a68bd07e38620a5508fef62ec079d274475c8f92d75ed0c33c45fbe306bc\" default))))
  151. " nil custom-file))
  152. (load custom-file)