init.el 5.9 KB

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