init.el 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. ;;;; Startup
  2. ;(package-initialize)
  3. (setq gc-cons-threshold (* 500 100000))
  4. (setq inhibit-splash-screen t
  5. inhibit-startup-echo-area-message t
  6. initial-scratch-message ""
  7. initial-major-mode 'text-mode)
  8. (defun display-startup-echo-area-message ()
  9. (message ""))
  10. ;; Base
  11. (setq ring-bell-function 'ignore) ; Disable beep & flash
  12. (blink-cursor-mode 0)
  13. ;; No scroll bar
  14. (when (boundp 'scroll-bar-mode)
  15. (scroll-bar-mode -1))
  16. ;; Title bar displays buffer
  17. (setq frame-title-format "%b - Emacs")
  18. ;; Disable toolbar
  19. (if (fboundp 'tool-bar-mode)
  20. (tool-bar-mode -1))
  21. ;; smoother scrolling
  22. (setq scroll-margin 0
  23. scroll-conservatively 9999
  24. scroll-step 1)
  25. ;; Line settings and indicators
  26. (setq visual-line-fringe-indicators '(left-curly-arrow right-curly-arrow))
  27. (setq-default left-fringe-width nil)
  28. (setq-default indicate-empty-lines t)
  29. ;; All yes or no prompts are y or n
  30. (defalias 'yes-or-no-p 'y-or-n-p)
  31. ;; Never follow symlinks
  32. (setq vc-follow-symlinks nil)
  33. ;;; Leave the OS clipboard alone (use evil's "+ and "* instead)
  34. ; Don't copy and paste to the clipboard
  35. (setq select-enable-clipboard nil)
  36. (setq x-select-enable-clipboard nil)
  37. ; Don't save to the clipboard on exit
  38. (setq x-select-enable-clipboard-manager nil)
  39. ;; Text and Notes
  40. (setq sentence-end-double-space nil)
  41. ;; Save minibar history
  42. (savehist-mode 1)
  43. (setq savehist-additional-variables
  44. '(kill-ring search-ring regexp-search-ring))
  45. ;; Always show matching parens
  46. (show-paren-mode t)
  47. ;; Save Window layout history
  48. (winner-mode)
  49. ;; Backups (from https://stackoverflow.com/questions/151945/how-do-i-control-how-emacs-makes-backup-files/20824625#20824625)
  50. (setq version-control t ;; Use version numbers for backups.
  51. kept-new-versions 10 ;; Number of newest versions to keep.
  52. kept-old-versions 0 ;; Number of oldest versions to keep.
  53. delete-old-versions t ;; Don't ask to delete excess backup versions.
  54. backup-by-copying t) ;; Copy all files, don't rename them.
  55. (setq vc-make-backup-files t) ;; Backup versioned files
  56. ;; Default and per-save backups go here:
  57. (setq backup-directory-alist '(("" . "~/.emacs.d/backups/per-save")))
  58. (defun force-backup-of-buffer ()
  59. ;; Make a special "per session" backup at the first save of each
  60. ;; emacs session.
  61. (when (not buffer-backed-up)
  62. ;; Override the default parameters for per-session backups.
  63. (let ((backup-directory-alist '(("" . "~/.emacs.d/backups/per-session")))
  64. (kept-new-versions 3))
  65. (backup-buffer)))
  66. ;; Make a "per save" backup on each save. The first save results in
  67. ;; both a per-session and a per-save backup, to keep the numbering
  68. ;; of per-save backups consistent.
  69. (let ((buffer-backed-up nil))
  70. (backup-buffer)))
  71. (add-hook 'before-save-hook 'force-backup-of-buffer)
  72. ;; Autosave files
  73. (setq auto-save-file-name-transforms
  74. `((".*" , "~/.emacs.d/backups/auto-saves" t)))
  75. ;; remember cursor position
  76. (toggle-save-place-globally)
  77. ;; Search all buffers
  78. (defun grep-search-all-buffers (regexp)
  79. (interactive "sRegexp: ")
  80. (multi-occur-in-matching-buffers "." regexp t))
  81. ;; Tags
  82. (defvar tags-generator (expand-file-name "ctags" user-emacs-directory))
  83. ;; TODO different tags things for Windows and Linux
  84. (defun create-tags (dir-name)
  85. "Create tags file."
  86. (interactive "DDirectory: ")
  87. (shell-command
  88. (format "\"%s\" -f \"%s/TAGS\" -e -R %s"
  89. tags-generator (directory-file-name dir-name) (directory-file-name dir-name))))
  90. (add-to-list 'load-path (expand-file-name "packages" user-emacs-directory))
  91. (require 'packages)
  92. ;; Buffer-based completion
  93. (global-set-key (kbd "C-SPC") 'dabbrev-completion)
  94. (add-hook 'text-mode-hook (lambda () (setq show-trailing-whitespace t)))
  95. (add-hook 'prog-mode-hook (lambda () (setq show-trailing-whitespace t)))
  96. ;;;; System-specific configs
  97. (defun win-setup ()
  98. (add-to-list 'exec-path "C:/Program Files (x86)/Aspell/bin/")
  99. (setq ispell-program-name "aspell")
  100. ;; Add MinGW if it exists
  101. (if (file-directory-p "C:/MinGW/msys/1.0/bin")
  102. (setenv "PATH" (concat (getenv "PATH") "C:/MinGW/msys/1.0/bin")))
  103. ;; (add-to-list 'exec-path "C:/MinGW/msys/1.0/bin"))
  104. (setq tags-generator (concat tags-generator ".exe"))
  105. (defun cmd ()
  106. (interactive)
  107. (make-comint-in-buffer "cmd" nil "cmd" nil)
  108. (switch-to-buffer "*cmd*"))
  109. (setq default-directory "~/../../")
  110. (setq org-default-notes-file "~/../../Owncloud/org/organizer.org"))
  111. (defun linux-setup ()
  112. (setq org-default-notes-file "~/Owncloud/org/organizer.org"))
  113. (cond ((eq system-type 'windows-nt) (win-setup))
  114. ((eq system-type 'gnu/linux) (linux-setup))
  115. (t (message "")))
  116. ;;;; Default face customizations
  117. (set-face-attribute 'default nil :height 120 :family "Ubuntu Mono")
  118. (set-face-attribute 'evil-goggles-delete-face nil :inherit 'diff-removed)
  119. (set-face-attribute 'evil-goggles-paste-face nil :inherit 'diff-added)
  120. (set-face-attribute 'evil-goggles-undo-redo-add-face nil :inherit 'diff-added)
  121. (set-face-attribute 'evil-goggles-undo-redo-change-face nil :inherit 'diff-changed)
  122. (set-face-attribute 'evil-goggles-undo-redo-remove-face nil :inherit 'diff-removed)
  123. (set-face-attribute 'evil-goggles-yank-face nil :inherit 'diff-changed)
  124. (set-face-attribute 'linum-relative-current-face nil :inherit 'linum :background "dim gray" :foreground "white" :underline nil)
  125. (set-face-attribute 'mode-line-buffer-id-inactive nil :inherit 'mode-line-inactive)
  126. (set-face-attribute 'show-paren-match nil :background "light gray" :foreground "#d33682" :weight 'bold)
  127. (set-face-attribute 'fringe nil :background "#fafafa")
  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-variables
  134. '(custom-enabled-themes (quote (material-light))))
  135. " nil custom-file))
  136. (load custom-file)
  137. (setq gc-cons-threshold (* 800 100))