 ;; UTF-8 as default encoding
 (set-language-environment "UTF-8")
 
+;; Do the packaging dance
 (require 'package)
 (package-initialize)
-
-;; MELPA
 (add-to-list 'package-archives
   '("melpa-stable" . "http://melpa-stable.milkbox.net/packages/") t)
-
-;; appearance
-(add-to-list 'custom-theme-load-path "~/.emacs.d/vendor/emacs-color-theme-solarized")
-(load-theme 'solarized t)
+(package-refresh-contents)
+
+;; Solarized theme
+(if (not (package-installed-p 'color-theme-sanityinc-solarized))
+    (progn
+      (package-install 'color-theme-sanityinc-solarized)))
+(load-theme 'sanityinc-solarized-dark t)
 
 (define-key global-map (kbd "C-+") 'text-scale-increase)
 (define-key global-map (kbd "C--") 'text-scale-decrease)

(global-set-key (kbd "C-c C-c M-x") 'execute-extended-command)
(setq smex-show-unbound-commands t)

;; https://github.com/kjhealy/emacs-starter-kit/blob/master/starter-kit-bindings.org
;; When you have an active region that spans multiple lines, the following will add a cursor to each line:
(global-set-key (kbd "C-S-c C-S-c") 'mc/edit-lines)
(global-set-key (kbd "C-S-c C-e") 'mc/edit-ends-of-lines)
(global-set-key (kbd "C-S-c C-a") 'mc/edit-beginnings-of-lines)
;; When you want to add multiple cursors not based on continuous lines, but based on keywords in the buffer, use:
(global-set-key (kbd "C->") 'mc/mark-next-like-this)
(global-set-key (kbd "C-<") 'mc/mark-previous-like-this)
(global-set-key (kbd "C-c C-<") 'mc/mark-all-like-this)

(global-linum-mode 1)
(column-number-mode 1)

;; Commenting
(global-set-key "\C-c;"      'comment-region)
(global-set-key "\C-c:"      'uncomment-region)

;; Kill whitespace
(add-hook 'before-save-hook 'delete-trailing-whitespace)

;; Add new lines automatically
(setq next-line-add-newlines t)

;; Faster redrawing
(setq redisplay-dont-pause nil)

;; Tabs (no)
(setq-default indent-tabs-mode nil)

;; Auto fill mode
;; (add-hook 'text-mode-hook 'turn-on-auto-fill)
(add-hook 'tex-mode-hook 'turn-on-auto-fill)
(add-hook 'markdown-mode-hook 'turn-on-auto-fill)

;; Flycheck
(if (not (package-installed-p 'flycheck))
    (progn
      (package-install 'flycheck)))
(add-hook 'after-init-hook #'global-flycheck-mode)

;; Better Meta
(if (not (package-installed-p 'smex))
    (progn
      (package-install 'smex)))
(setq mac-option-modifier 'meta)
(global-set-key (kbd "M-x") 'smex)
(global-set-key (kbd "C-x C-m") 'smex)
