 ;; shrink minibuffer window automatically when remove some lines of text from the minibuffer
 (setq resize-mini-windows t)
 
+(transient-mark-mode t)
+
++
+;;; Whitespace
+
+(defun sanityinc/no-trailing-whitespace ()
+  "Turn off display of trailing whitespace in this buffer."
+  (setq show-trailing-whitespace nil))
+
 ;; But don't show trailing whitespace in SQLi, inf-ruby etc.
-(add-hook 'comint-mode-hook
-          (lambda () (setq show-trailing-whitespace nil)))
-
-(transient-mark-mode t)
+(dolist (hook '(special-mode-hook
+                eww-mode
+                term-mode-hook
+                comint-mode-hook
+                compilation-mode-hook
+                twittering-mode-hook
+                minibuffer-setup-hook))
+  (add-hook hook #'sanityinc/no-trailing-whitespace))
+
+
+(require-package 'whitespace-cleanup-mode)
+(global-whitespace-cleanup-mode t)
+
++
+;;; Newline behaviour
 
 (define-key global-map (kbd "RET") 'newline-and-indent)
+(defun sanityinc/newline-at-end-of-line ()
+  "Move to end of line, enter a newline, and reindent."
+  (interactive)
+  (move-end-of-line 1)
+  (newline-and-indent))
+
+(global-set-key (kbd "S-<return>") 'sanityinc/newline-at-end-of-line)
+
++
+
+(when (eval-when-compile (string< "24.3.1" emacs-version))
+  ;; https://github.com/purcell/emacs.d/issues/138
+  (after-load 'subword
+    (diminish 'subword-mode)))
+
++
+
+(when (fboundp 'global-prettify-symbols-mode)
+  (global-prettify-symbols-mode))
+
++
+(require-package 'undo-tree)
+(global-undo-tree-mode)
+(diminish 'undo-tree-mode)
+
++
+(require-package 'highlight-symbol)
+(dolist (hook '(prog-mode-hook html-mode-hook css-mode-hook))
+  (add-hook hook 'highlight-symbol-mode)
+  ;; (add-hook hook 'highlight-symbol-nav-mode)
+  )
+(eval-after-load 'highlight-symbol
+  '(diminish 'highlight-symbol-mode))
 
 ;;----------------------------------------------------------------------------
 ;; Zap *up* to char is a more sensible default

      )
  )


(require-package 'guide-key)
(setq guide-key/guide-key-sequence '("C-x r" "C-x 4" "C-x 5" "C-c ;" "C-c ; f" "C-c ' f" "C-x n"))

;; Use evil-mode (strongly recommended) will make this file much smaller!

(require-package 'unfill)
(require-package 'whole-line-or-region)

(when (fboundp 'electric-pair-mode)
  (electric-pair-mode))

;;----------------------------------------------------------------------------
;; Some basic preferences
