init.el 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. ;; Backups (from https://stackoverflow.com/questions/151945/how-do-i-control-how-emacs-makes-backup-files/20824625#20824625)
  41. (setq version-control t ;; Use version numbers for backups.
  42. kept-new-versions 10 ;; Number of newest versions to keep.
  43. kept-old-versions 0 ;; Number of oldest versions to keep.
  44. delete-old-versions t ;; Don't ask to delete excess backup versions.
  45. backup-by-copying t) ;; Copy all files, don't rename them.
  46. (setq vc-make-backup-files t) ;; Backup versioned files
  47. ;; Default and per-save backups go here:
  48. (setq backup-directory-alist '(("" . "~/.emacs.d/backups/per-save")))
  49. (defun force-backup-of-buffer ()
  50. ;; Make a special "per session" backup at the first save of each
  51. ;; emacs session.
  52. (when (not buffer-backed-up)
  53. ;; Override the default parameters for per-session backups.
  54. (let ((backup-directory-alist '(("" . "~/.emacs.d/backups/per-session")))
  55. (kept-new-versions 3))
  56. (backup-buffer)))
  57. ;; Make a "per save" backup on each save. The first save results in
  58. ;; both a per-session and a per-save backup, to keep the numbering
  59. ;; of per-save backups consistent.
  60. (let ((buffer-backed-up nil))
  61. (backup-buffer)))
  62. (add-hook 'before-save-hook 'force-backup-of-buffer)
  63. ;; Autosave files
  64. (setq auto-save-file-name-transforms
  65. `((".*" , "~/.emacs.d/backups/auto-saves" t)))
  66. ;; remember cursor position
  67. (toggle-save-place-globally)
  68. ;; Search all buffers
  69. (defun grep-search-all-buffers (regexp)
  70. (interactive "sRegexp: ")
  71. (multi-occur-in-matching-buffers "." regexp t))
  72. ;;; Spelling
  73. ;; map ]s and [s to next and previously wrong word
  74. ;; move point to previous error
  75. ;; based on code by hatschipuh at
  76. ;; http://emacs.stackexchange.com/a/14912/2017
  77. (defun flyspell-goto-previous-error (arg)
  78. "Go to arg previous spelling error."
  79. (interactive "p")
  80. (while (not (= 0 arg))
  81. (let ((pos (point))
  82. (min (point-min)))
  83. (if (and (eq (current-buffer) flyspell-old-buffer-error)
  84. (eq pos flyspell-old-pos-error))
  85. (progn
  86. (if (= flyspell-old-pos-error min)
  87. ;; goto beginning of buffer
  88. (progn
  89. (message "Restarting from end of buffer")
  90. (goto-char (point-max)))
  91. (backward-word 1))
  92. (setq pos (point))))
  93. ;; seek the next error
  94. (while (and (> pos min)
  95. (let ((ovs (overlays-at pos))
  96. (r '()))
  97. (while (and (not r) (consp ovs))
  98. (if (flyspell-overlay-p (car ovs))
  99. (setq r t)
  100. (setq ovs (cdr ovs))))
  101. (not r)))
  102. (backward-word 1)
  103. (setq pos (point)))
  104. ;; save the current location for next invocation
  105. (setq arg (1- arg))
  106. (setq flyspell-old-pos-error pos)
  107. (setq flyspell-old-buffer-error (current-buffer))
  108. (goto-char pos)
  109. (if (= pos min)
  110. (progn
  111. (message "No more miss-spelled word!")
  112. (setq arg 0))
  113. ))))
  114. (add-to-list 'load-path (expand-file-name "packages" user-emacs-directory))
  115. (require 'packages)
  116. ;;;; System-specific configs
  117. (defun win-setup ()
  118. (add-to-list 'exec-path "C:/Program Files (x86)/Aspell/bin/")
  119. (setq ispell-program-name "aspell")
  120. (defun cmd ()
  121. (interactive)
  122. (make-comint-in-buffer "cmd" nil "cmd" nil)
  123. (switch-to-buffer "*cmd*")))
  124. (defun linux-setup ())
  125. (cond ((eq system-type 'windows-nt) (win-setup))
  126. ((eq system-type 'gnu/linux) (linux-setup))
  127. (t (message "")))
  128. ;;;; Custom
  129. (defconst custom-file (expand-file-name "custom.el" user-emacs-directory))
  130. ;; if no custom file exists, write a default one
  131. (unless (file-exists-p custom-file)
  132. (write-region "(custom-set-faces
  133. ;; custom-set-faces was added by Custom.
  134. ;; If you edit it by hand, you could mess it up, so be careful.
  135. ;; Your init file should contain only one such instance.
  136. ;; If there is more than one, they won't work right.
  137. '(powerline-evil-normal-face ((t (:background \"#859900\")))))
  138. (custom-set-variables
  139. ;; custom-set-variables was added by Custom.
  140. ;; If you edit it by hand, you could mess it up, so be careful.
  141. ;; Your init file should contain only one such instance.
  142. ;; If there is more than one, they won't work right.
  143. '(custom-enabled-themes (quote (monokai)))
  144. '(custom-safe-themes
  145. (quote
  146. (\"c7a9a68bd07e38620a5508fef62ec079d274475c8f92d75ed0c33c45fbe306bc\" default))))
  147. " nil custom-file))
  148. (load custom-file)