-(require 'package)
-;; Add the original Emacs Lisp Package Archive
-(add-to-list 'package-archives
-             '("elpa" . "http://tromey.com/elpa/"))
-;; Add the user-contributed repository
-(add-to-list 'package-archives
-             '("marmalade" . "http://marmalade-repo.org/packages/"))
+;;
+;; Load emacs 24's package system. Add MELPA repository.
+;;
+
+;; Added by Package.el.  This must come before configurations of
+;; installed packages.  Don't delete this line.  If you don't want it,
+;; just comment it out by adding a semicolon to the start of the line.
 (package-initialize)
 
-;;
-;; whitespace and indentation stuff
+(when (>= emacs-major-version 24)
+  (require 'package)
+  (add-to-list
+   'package-archives
+   '("melpa" . "http://melpa.milkbox.net/packages/")
+   t))
+
+(eval-when-compile
+    (require 'use-package))
+(setq use-package-always-ensure t)
+
+;;
+;; Package config
+;;
+
+(use-package tabbar
+    :bind (
+        ("M-<left>" . tabbar-backward-tab)
+        ("M-<right>" . tabbar-forward-tab)
+    )
+    :config
+    (defun my-tabbar-buffer-groups () ;; customize to show all normal files in one group
+        "Returns the name of the tab group names the current buffer belongs to.
+        There are two groups: Emacs buffers (those whose name starts with '*', plus
+        dired buffers), and the rest.  This works at least with Emacs v24.2 using
+        tabbar.el v1.7."
+    (list (cond ((string-equal "*" (substring (buffer-name) 0 1)) "emacs")
+               ((eq major-mode 'dired-mode) "emacs")
+               (t "user"))))
+    (setq tabbar-buffer-groups-function 'my-tabbar-buffer-groups)
+    (tabbar-mode)
+)
+
+(use-package nlinum
+    :config
+    (global-nlinum-mode)
+)
+
+(use-package afternoon-theme
+    :config
+    ;; use t to avoid safety prompt each time
+    (load-theme 'afternoon t)
+)
+
+;;
+;; General settings
+;;
+
+;; require a single blank line at the end of each file
+(setq-default require-final-newline t)
+(setq-default delete-trailing-lines nil)
+;; don't create backup files and clutter
+(setq auto-save-default nil)
+(setq-default make-backup-files nil)
+;; set the cursor type
+;(setq-default cursor-type '(bar . 1))
+(setq-default cursor-type 'box)
+;; cursor blink never times out
+(setq-default blink-cursor-blinks 0)
+;; add handles to resize windows
+(setq-default window-divider-default-places t)
+(window-divider-mode +1)
+;; add column number (row, column) and buffer size to status bars
+(column-number-mode)
+(size-indication-mode)
+;; buffer boundary indicators
+(setq-default indicate-buffer-boundaries '((up . right) (down . right)))
+
+(global-set-key (kbd "S-C-<left>") 'shrink-window-horizontally)
+(global-set-key (kbd "S-C-<right>") 'enlarge-window-horizontally)
+(global-set-key (kbd "S-C-<down>") 'shrink-window)
+(global-set-key (kbd "S-C-<up>") 'enlarge-window)
+
+;; move between windows using S-arrow
+(when (fboundp 'windmove-default-keybindings)
+      (windmove-default-keybindings))
+
+;;
+;; Whitespace and indentation stuff
 ;;
 
 (defvar my-indent 4 "My indentation offset.")

 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(inhibit-startup-screen t))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.

    (interactive)
    ; if current column is at beginning of line or not on a tab stop
    ; or if the previous character is "\t"
    (if (or (bolp) (/= 0 (% (current-column) my-indent))
            (string= (string (char-before)) "\t")
    )

    ;then
        (delete-backward-char 1)
    ;else
        ; we are on a non-zero tabstop, compute the previous tabstop
        (setq last-tabstop (- (current-column) my-indent))
        ; if there are only spaces and/or tabs between the cursor and last tabstop
        (if (and (string-match "[ \t]*" (thing-at-point 'line t) last-tabstop)
                 (>= (match-end 0) (current-column))
            )
        ;then
