init.el 4.8 KB

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