init.el 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. ;;;; Startup
  2. ;(package-initialize)
  3. (setq inhibit-splash-screen t
  4. inhibit-startup-echo-area-message t
  5. initial-scratch-message ""
  6. initial-major-mode 'text-mode)
  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
  39. '(kill-ring search-ring regexp-search-ring))
  40. ;; Always show matching parens
  41. (show-paren-mode t)
  42. ;; Save Window layout history
  43. (winner-mode)
  44. ;; Backups (from https://stackoverflow.com/questions/151945/how-do-i-control-how-emacs-makes-backup-files/20824625#20824625)
  45. (setq version-control t ;; Use version numbers for backups.
  46. kept-new-versions 10 ;; Number of newest versions to keep.
  47. kept-old-versions 0 ;; Number of oldest versions to keep.
  48. delete-old-versions t ;; Don't ask to delete excess backup versions.
  49. backup-by-copying t) ;; Copy all files, don't rename them.
  50. (setq vc-make-backup-files t) ;; Backup versioned files
  51. ;; Default and per-save backups go here:
  52. (setq backup-directory-alist '(("" . "~/.emacs.d/backups/per-save")))
  53. (defun force-backup-of-buffer ()
  54. ;; Make a special "per session" backup at the first save of each
  55. ;; emacs session.
  56. (when (not buffer-backed-up)
  57. ;; Override the default parameters for per-session backups.
  58. (let ((backup-directory-alist '(("" . "~/.emacs.d/backups/per-session")))
  59. (kept-new-versions 3))
  60. (backup-buffer)))
  61. ;; Make a "per save" backup on each save. The first save results in
  62. ;; both a per-session and a per-save backup, to keep the numbering
  63. ;; of per-save backups consistent.
  64. (let ((buffer-backed-up nil))
  65. (backup-buffer)))
  66. (add-hook 'before-save-hook 'force-backup-of-buffer)
  67. ;; Autosave files
  68. (setq auto-save-file-name-transforms
  69. `((".*" , "~/.emacs.d/backups/auto-saves" t)))
  70. ;; remember cursor position
  71. (toggle-save-place-globally)
  72. ;; Search all buffers
  73. (defun grep-search-all-buffers (regexp)
  74. (interactive "sRegexp: ")
  75. (multi-occur-in-matching-buffers "." regexp t))
  76. ;; Tags
  77. (defun create-tags (dir-name)
  78. "Create tags file."
  79. (interactive "DDirectory: ")
  80. (shell-command
  81. (format "\"%s\" -f TAGS -e -R %s"
  82. tags-generator (directory-file-name dir-name))))
  83. (add-to-list 'load-path (expand-file-name "packages" user-emacs-directory))
  84. (require 'packages)
  85. ;; Buffer-based completion
  86. (global-set-key (kbd "C-SPC") 'dabbrev-completion)
  87. ;;;; System-specific configs
  88. (defun win-setup ()
  89. (add-to-list 'exec-path "C:/Program Files (x86)/Aspell/bin/")
  90. (setq ispell-program-name "aspell")
  91. ;; Add MinGW if it exists
  92. (if (file-directory-p "C:/MinGW/msys/1.0/bin")
  93. (setenv "PATH" (concat (getenv "PATH") "C:/MinGW/msys/1.0/bin")))
  94. ;; (add-to-list 'exec-path "C:/MinGW/msys/1.0/bin"))
  95. ;; Add tags
  96. (setq tags-generator (expand-file-name "ctags.exe" user-emacs-directory))
  97. (defun cmd ()
  98. (interactive)
  99. (make-comint-in-buffer "cmd" nil "cmd" nil)
  100. (switch-to-buffer "*cmd*")))
  101. (defun linux-setup ()
  102. (setq tage-generator "ctags"))
  103. (cond ((eq system-type 'windows-nt) (win-setup))
  104. ((eq system-type 'gnu/linux) (linux-setup))
  105. (t (message "")))
  106. ;;;; Custom
  107. (defconst custom-file (expand-file-name "custom.el" user-emacs-directory))
  108. ;; if no custom file exists, write a default one
  109. (unless (file-exists-p custom-file)
  110. (write-region "(custom-set-faces
  111. ;; custom-set-faces was added by Custom.
  112. ;; If you edit it by hand, you could mess it up, so be careful.
  113. ;; Your init file should contain only one such instance.
  114. ;; If there is more than one, they won't work right.
  115. '(powerline-evil-normal-face ((t (:background \"#859900\")))))
  116. (custom-set-variables
  117. ;; custom-set-variables was added by Custom.
  118. ;; If you edit it by hand, you could mess it up, so be careful.
  119. ;; Your init file should contain only one such instance.
  120. ;; If there is more than one, they won't work right.
  121. '(custom-enabled-themes (quote (monokai)))
  122. '(custom-safe-themes
  123. (quote
  124. (\"c7a9a68bd07e38620a5508fef62ec079d274475c8f92d75ed0c33c45fbe306bc\" default))))
  125. " nil custom-file))
  126. (load custom-file)