 ;  :defer 3)
 
 (use-package helm
-	:init
-		(setq helm-split-window-in-side-p        t
-			helm-apropos-fuzzy-match              t
-			helm-bookmark-show-location           t
-			helm-buffers-fuzzy-matching           t
-			helm-completion-in-region-fuzzy-match t
-			helm-ff-search-library-in-sexp        t
-			helm-file-cache-fuzzy-match           t
-			helm-imenu-fuzzy-match                t
-			helm-locate-fuzzy-match               nil          ; not useful
-			helm-mode-fuzzy-match                 t
-			helm-move-to-line-cycle-in-source     t
-			helm-M-x-fuzzy-match                  t
-			helm-quick-update                     nil          ; ui flashing occurs
-			helm-recentf-fuzzy-match              t
-			helm-semantic-fuzzy-match             t
-			helm-input-idle-delay                 0.1
-			helm-idle-delay                       0.0
-			helm-buffer-max-length                40
-			helm-scroll-amount                    8)
-		;; set the sources for helm-for-files
-		(setq helm-for-files-preferred-list '(
-			helm-source-recentf
-			helm-source-buffers-list
-			helm-source-files-in-current-dir
-			helm-source-locate))
-	:config
-		(define-key helm-map [escape] 'helm-keyboard-quit)
-	:bind
-		("M-x" . helm-M-x)
-		("C-x b" . helm-mini)
-		("<f2>"   . helm-mini)
-		("<f3>" . helm-for-files)
-		("<S-f3>" . dired-jump)
-		("<f4> a" . helm-apropos)
-		("<f4> j" . helm-all-mark-ring)
-		("<f4> i" . helm-info-at-point)
-		("<f4> k" . helm-show-kill-ring)
-		("<f4> m" . helm-man-woman)
-		("<f4> p" . helm-list-elisp-packages-no-fetch)
-		("<f4> x" . helm-top)
-		("<f4> l" . helm-locate)
-		("<f4> <f4>" . helm-resume)
-	:defer 2
-	)
+  :init
+  (progn
+    (setq helm-split-window-in-side-p           t
+          helm-split-window-default-side        'other
+          helm-apropos-fuzzy-match              t
+          helm-bookmark-show-location           t
+          helm-buffers-fuzzy-matching           t
+          helm-completion-in-region-fuzzy-match t
+                                        ; helm-ff-search-library-in-sexp        t
+          helm-file-cache-fuzzy-match           t
+          helm-imenu-fuzzy-match                t
+          helm-locate-fuzzy-match               nil          ; not useful
+          helm-mode-fuzzy-match                 t
+          helm-move-to-line-cycle-in-source     t
+          helm-M-x-fuzzy-match                  t
+          helm-quick-update                     nil          ; ui flashing occurs
+          helm-recentf-fuzzy-match              t
+          helm-semantic-fuzzy-match             t
+          helm-input-idle-delay                 0.1
+          helm-idle-delay                       0.0
+          helm-buffer-max-length                40
+          helm-candidate-number-limit           200
+          helm-scroll-amount                    8
+          ;; set the sources for helm-for-files
+          helm-for-files-preferred-list '( helm-source-recentf
+                                           helm-source-buffers-list
+                                           helm-source-files-in-current-dir
+                                           helm-source-locate )))
+  :config
+  (progn
+    (define-key helm-map [escape] 'helm-keyboard-quit))
+
+  :bind
+  (("M-x"       . helm-M-x)
+   ("C-x b"     . helm-mini)
+   ("<f2>"      . helm-mini)
+   ("<f3>"      . helm-for-files)
+   ("<S-f3>"    . dired-jump)
+   ("<f4> a"    . helm-apropos)
+   ("<f4> j"    . helm-all-mark-ring)
+   ("<f4> i"    . helm-info-at-point)
+   ("<f4> k"    . helm-show-kill-ring)
+   ("<f4> m"    . helm-man-woman)
+   ("<f4> p"    . helm-list-elisp-packages-no-fetch)
+   ("<f4> x"    . helm-top)
+   ("<f4> l"    . helm-locate)
+   ("<f4> <f4>" . helm-resume))
+  :defer 2)
 
 (use-package projectile
-	:init
-		(setq projectile-completion-system 'helm)
-		(setq projectile-enable-caching t)
-		(setq projectile-use-git-grep t)
-		(setq projectile-mode-line '(:eval (format " [%s]" (projectile-project-name))))
-	:config
-		(use-package helm-projectile
-			:config
-				(helm-projectile-on)
-				(setq projectile-switch-project-action 'helm-for-files)
-			)
-		(use-package ag)
-		(use-package helm-ag)
-		(use-package grep)
-		(setq helm-for-files-preferred-list '(
-			helm-source-projectile-files-list
-			helm-source-projectile-recentf-list
-			helm-source-recentf
-			helm-source-buffers-list
-			helm-source-projectile-projects
-			helm-source-files-in-current-dir
-			helm-source-locate))
-		(projectile-global-mode 1)
-	:defer 3
-	:bind
-		("<f5>" . helm-projectile-find-other-file)
-		("<f7> <f7>" . helm-projectile-switch-project)
-		("<f7> c" . projectile-compile-project)
-		("<f7> o" . projectile-multi-occur)
-		("<f7> u" . projectile-invalidate-cache)
-		("<f7> k" . projectile-kill-buffers)
-		("<f7> f" . helm-projectile-ag)
-	)
-
-(defun update-all-tags ( )
-	(interactive)
-	(let ((current-prefix-arg 4)) (call-interactively 'helm-gtags-update-tags)))
+  :init
+  (progn
+    (setq projectile-completion-system 'helm
+          projectile-use-git-grep t
+          projectile-mode-line '(:eval (format " [%s]" (projectile-project-name)))
+          projectile-enable-caching t))
+  :config
+  (progn
+    (use-package helm-projectile
+      :config
+      (progn
+        (helm-projectile-on)
+        (setq projectile-switch-project-action 'helm-for-files)))
+    (use-package ag)
+    (use-package helm-ag)
+    (use-package grep)
+    (setq helm-for-files-preferred-list '( helm-source-projectile-files-list
+                                           helm-source-projectile-recentf-list
+                                           helm-source-recentf
+                                           helm-source-buffers-list
+                                           helm-source-projectile-projects
+                                           helm-source-files-in-current-dir
+                                           helm-source-locate))
+    (projectile-global-mode 1))
+  :bind
+  (("<f5>"      . helm-projectile-find-other-file)
+   ("<f7> <f7>" . helm-projectile-switch-project)
+   ("<f7> c"    . projectile-compile-project)
+   ("<f7> o"    . projectile-multi-occur)
+   ("<f7> u"    . projectile-invalidate-cache)
+   ("<f7> k"    . projectile-kill-buffers)
+   ("<f7> f"    . helm-projectile-ag))
+  :defer 3)
+
+(defun me:update-all-tags ( )
+  (interactive)
+  (let ((current-prefix-arg 4)) (call-interactively 'helm-gtags-update-tags)))
 
 (use-package helm-gtags
-	:init
-		(setq helm-gtags-auto-update t)
-		(setq helm-gtags-use-input-at-cursor t)
-		(setq helm-gtags-ignore-case t)
-	:config
-		(add-hook 'dired-mode-hook 'helm-gtags-mode)
-		(add-hook 'eshell-mode-hook 'helm-gtags-mode)
-		(add-hook 'c-mode-hook 'helm-gtags-mode)
-		(add-hook 'c++-mode-hook 'helm-gtags-mode)
-		(add-hook 'asm-mode-hook 'helm-gtags-mode)
-	:bind
-		("<f6> <f6>" . helm-gtags-dwim)
-		("<f6> d" . helm-gtags-find-tag)
-		("<f6> r" . helm-gtags-find-rtag)
-		("<f6> u" . update-all-tags )
-		("<f6> m" . helm-semantic-or-imenu)
-	:diminish helm-gtags-mode)
+  :init
+  (progn
+    (setq helm-gtags-auto-update t
+          helm-gtags-use-input-at-cursor t
+          helm-gtags-ignore-case t))
+  :config
+  (progn
+    (add-hook 'dired-mode-hook 'helm-gtags-mode)
+    (add-hook 'eshell-mode-hook 'helm-gtags-mode)
+    (add-hook 'c-mode-hook 'helm-gtags-mode)
+    (add-hook 'c++-mode-hook 'helm-gtags-mode)
+    (add-hook 'asm-mode-hook 'helm-gtags-mode))
+  :bind
+  (("<f6> <f6>" . helm-gtags-dwim)
+   ("<f6> d"    . helm-gtags-find-tag)
+   ("<f6> r"    . helm-gtags-find-rtag)
+   ("<f6> u"    . me:update-all-tags )
+   ("<f6> m"    . helm-semantic-or-imenu))
+  :diminish helm-gtags-mode)
 
 (use-package markdown-mode
-	:mode
-		("\\.markdown\\'" . markdown-mode)
-		("\\.md\\'" . markdown-mode)
-	)
+  :mode
+  (("\\.markdown\\'" . markdown-mode)
+   ("\\.md\\'" . markdown-mode)))
 
 (use-package cmake-mode
-	:init
-		(setq cmake-tab-width 3)
-	:mode
-		("CMakeLists\\.txt\\'" . cmake-mode)
-		("\\.cmake\\'" . cmake-mode)
-	)
+  :init
+  (progn
+    (setq cmake-tab-width 3))
+  :mode
+  (("CMakeLists\\.txt\\'" . cmake-mode)
+   ("\\.cmake\\'" . cmake-mode)))
 
 (use-package smart-tabs-mode
-	:config
-		(smart-tabs-insinuate 'c 'c++)
-	)
+  :config
+  (progn
+    (smart-tabs-insinuate 'c 'c++)))
 
 (use-package cc-mode
-	:init
-		(setq show-paren-mode 0)
-		(setq c-default-style "ellemtel")                           ; similar to allman style
-		(setq c-electric-pound-behavior (quote (alignleft)))        ; cpp directives aligned to left
-
-   :config
-	(add-hook 'c-mode-common-hook
-		(lambda ()
-			(setq c-basic-offset 3)))
-	(add-hook 'c++-mode-hook
-		(lambda ()
-			(c-set-offset 'innamespace [0])))                        ; no indentation in namespace
-
-	:mode
-		("\\.c\\'" . cc-mode)
-		("\\.cpp\\'" . c++-mode)
-		("\\.cxx\\'" . c++-mode)
-		("\\.h\\'" . c++-mode)
-		("\\.hpp\\'" . c++-mode)
-	)
+  :init
+  (progn
+    (setq c-default-style "ellemtel"                           ; similar to allman style
+          c-electric-pound-behavior (quote (alignleft))        ; cpp directives aligned to left
+          show-paren-mode 0))
+
+  :config
+  (progn
+    (add-hook 'c-mode-common-hook
+              (lambda ()
+                (setq c-basic-offset 3)))
+    (add-hook 'c++-mode-hook
+              (lambda ()
+                (c-set-offset 'innamespace [0]))))                       ; no indentation in namespace
+  :mode
+  (("\\.c\\'"   . cc-mode)
+   ("\\.cpp\\'" . c++-mode)
+   ("\\.cxx\\'" . c++-mode)
+   ("\\.h\\'"   . c++-mode)
+   ("\\.hpp\\'" . c++-mode)))
 
 (use-package python-mode
-	:config
-		(smart-tabs-advice py-indent-line py-indent-offset)
-		(smart-tabs-advice py-newline-and-indent py-indent-offset)
-		(smart-tabs-advice py-indent-region py-indent-offset)
-		(add-hook 'python-mode-hook 'guess-style-guess-tabs-mode)
-		(add-hook 'python-mode-hook
-			(lambda ()
-				(semantic-mode t)
-				(setq tab-width 4)))
-	:defer 3)
+  :config
+  (progn
+    (smart-tabs-advice py-indent-line py-indent-offset)
+    (smart-tabs-advice py-newline-and-indent py-indent-offset)
+    (smart-tabs-advice py-indent-region py-indent-offset)
+    (add-hook 'python-mode-hook
+      (lambda ()
+        (semantic-mode t)
+        (setq tab-width 4)))
+    (add-hook 'python-mode-hook 'guess-style-guess-tabs-mode))
+  :defer 3)
 
 (use-package git-gutter
-	:config
-		(global-git-gutter-mode t)
-	:defer 3
-	:diminish git-gutter-mode)
+  :config
+  (progn
+    (global-git-gutter-mode t))
+  :defer 3
+  :diminish git-gutter-mode)
 
 (use-package deft
-	:init
-		(setq deft-directory "~/Dropbox/Notes")
-		(setq deft-recursive t)
-		(setq deft-use-filter-string-for-filename t)
-		(setq deft-file-naming-rules '((nospace . "_")
-												 (noslash . "_")
-												 (case-fn . downcase)))
-		(setq deft-text-mode 'markdown-mode)
-		; first extension in list seems to be used for new files.  Not sure
-		; what deft-default-extesion does
-		(setq deft-default-extension "md")
-		(setq deft-extensions '("md" "txt" "text" "markdown" "mmd" "org"))
-		; deft auto-save interferes with whitespace-butler, so disable
-		(setq deft-auto-save-interval 0)
-
-	:bind
-		("<f4> n" . deft)
-
-	:config
-	(add-hook 'deft-mode-hook
-		(lambda ()
-			(define-key deft-mode-map (kbd "<C-return>") 'deft-new-file)
-			(define-key deft-mode-map (kbd "<C-backspace>") 'deft-filter-clear)))
-	)
+  :init
+  (progn
+    (setq deft-directory "~/Dropbox/Notes"
+          deft-recursive t
+          deft-use-filter-string-for-filename t
+          deft-file-naming-rules '((nospace . "_")
+                                   (noslash . "_")
+                                   (case-fn . downcase))
+          deft-text-mode 'markdown-mode
+          ; first extension in list seems to be used for new files.  Not sure
+          ; what deft-default-extesion does
+          deft-default-extension "md"
+          deft-extensions '("md" "txt" "text" "markdown" "mmd" "org")
+                                        ; deft auto-save interferes with whitespace-butler, so disable
+          deft-auto-save-interval 0))
+
+
+  :config
+  (progn
+    (add-hook 'deft-mode-hook
+              (lambda ()
+                (define-key deft-mode-map (kbd "<C-return>") 'deft-new-file)
+                (define-key deft-mode-map (kbd "<C-backspace>") 'deft-filter-clear))))
+  :bind
+  ("<f4> n" . deft))
 
 (use-package company
-	:config
-		(add-hook 'after-init-hook 'global-company-mode)
-	:diminish company-mode
-	)
+  :config
+  (progn
+    (add-hook 'after-init-hook 'global-company-mode))
+  :diminish company-mode)
 
 ; enable code folding (evil has bindings)
 (use-package hideshow
   :config
-		(add-hook 'c-mode-common-hook   'hs-minor-mode)
-		(add-hook 'c++-mode-hook        'hs-minor-mode)
-		(add-hook 'emacs-lisp-mode-hook 'hs-minor-mode)
-		(add-hook 'sh-mode-hook         'hs-minor-mode)
-		(add-hook 'python-mode-hook     'hs-minor-mode)
-	:diminish hs-minor-mode
-	)
+  (progn
+    (add-hook 'c-mode-common-hook   'hs-minor-mode)
+    (add-hook 'c++-mode-hook        'hs-minor-mode)
+    (add-hook 'emacs-lisp-mode-hook 'hs-minor-mode)
+    (add-hook 'sh-mode-hook         'hs-minor-mode)
+    (add-hook 'python-mode-hook     'hs-minor-mode))
+  :diminish hs-minor-mode)
 
 
 ;broken due to changes in helm
 ;(use-package helm-company
-;	:requires company
-;	:requires helm)
-
-
-(defun use-evil-selection-register ()
-	(interactive)
-	(evil-execute-macro 1 "\"*"))
-
-(defun use-evil-clipboard-register ()
-	(interactive)
-	(evil-execute-macro 1 "\"+"))
-
-
-(defun me/evil-shift-left-visual ()
+;   :requires company
+;   :requires helm)
+
+
+(defun me:use-evil-selection-register ()
+  (interactive)
+  (evil-execute-macro 1 "\"*"))
+
+(defun me:use-evil-clipboard-register ()
+  (interactive)
+  (evil-execute-macro 1 "\"+"))
+
+
+(defun me:evil-shift-left-visual ()
   (interactive)
   (evil-shift-left (region-beginning) (region-end))
   (evil-normal-state)
   (evil-visual-restore))
 
-(defun me/evil-shift-right-visual ()
+(defun me:evil-shift-right-visual ()
   (interactive)
   (evil-shift-right (region-beginning) (region-end))
   (evil-normal-state)


;; N.B. evil-mode must be enabled after global-evil-leader-mode
(use-package evil
	:init
		(setq evil-shift-width 3)
		(setq-default evil-symbol-word-search t)
		(setq evil-search-module 'evil-search)
	:config
		(use-package evil-args)
		(use-package evil-textobj-anyblock)
		(use-package evil-commentary
		  :config (evil-commentary-mode)
		  :diminish evil-commentary-mode)
		(use-package evil-leader
			:init
				(setq evil-leader/in-all-states 1)
			:config
				(global-evil-leader-mode t)
				(evil-leader/set-leader "<SPC>")
				(evil-leader/set-key
					";" 'evil-jump-forward
					"," 'evil-jump-backward
					"w" 'save-buffer
					"x" 'kill-buffer
					"e" 'pp-eval-last-sexp
					"v"  'exchange-point-and-mark
					"c" 'use-evil-clipboard-register
					"s" 'use-evil-selection-register
					"a" 'align
					)
			)  ; evil-leader
		(use-package powerline-evil
			:config
				(powerline-default-theme)
				(display-time-mode t)
			)
		; use SPC prefix before motion to see helpers
		(use-package evil-easymotion
			:config
			(evilem-default-keybindings "SPC"))
		(evil-set-initial-state 'git-rebase-mode 'emacs)
		(evil-set-initial-state 'deft-mode 'insert)
		(evil-set-initial-state 'magit-branch-manager-mode 'emacs)
		; note evil-set-initial-state didn't work for this mode
		(add-hook 'with-editor-mode-hook 'evil-insert-state)
		(define-key evil-inner-text-objects-map "a" 'evil-inner-arg)
		(define-key evil-outer-text-objects-map "a" 'evil-outer-arg)
		(define-key evil-inner-text-objects-map "b" 'evil-textobj-anyblock-inner-block)
		(define-key evil-outer-text-objects-map "b" 'evil-textobj-anyblock-a-block)
		(define-key evil-normal-state-map (kbd "j") 'evil-next-visual-line)
		(define-key evil-normal-state-map (kbd "k") 'evil-previous-visual-line)
		; buffer swapping, next/previous
		(define-key evil-normal-state-map (kbd "<RET>") 'switch-to-previous-buffer)
		; esc key (from WikEmacs)
		(define-key evil-normal-state-map [escape] 'keyboard-quit)
		(define-key evil-visual-state-map [escape] 'keyboard-quit)
		; scroll keeping cursor in place
		(define-key evil-normal-state-map (kbd "C-j")
			(lambda () (interactive)  (evil-scroll-line-down 1) (evil-next-visual-line 0)))
		(define-key evil-normal-state-map (kbd "C-k")
			(lambda () (interactive) (evil-scroll-line-up 1) (evil-previous-visual-line 0)))
		; Overload shifts so that they don't lose the selection
		(define-key evil-visual-state-map (kbd ">") 'me/evil-shift-right-visual)
		(define-key evil-visual-state-map (kbd "<") 'me/evil-shift-left-visual)
		(define-key evil-visual-state-map [tab] 'me/evil-shift-right-visual)
		(define-key evil-visual-state-map [S-tab] 'me/evil-shift-left-visual)
		(evil-mode 1)
	) ; evil


(use-package diminish
	:config
		(diminish 'undo-tree-mode)
	)

(use-package ws-butler
	:config
	(ws-butler-global-mode t)
	:defer 3
	)

(use-package shell-pop
	:init
		(setq shell-pop-internal-mode "ansi-term")
		(setq shell-pop-term-shell "/bin/bash")
		(setq shell-pop-window-size 40)
		(setq shell-pop-window-position "top")
		(setq shell-pop-universal-key "<f8>")
	:bind
		("<f8>" . shell-pop)
	)

(use-package guide-key
	:defer 3
	:init
	(setq guide-key/guide-key-sequence '(
		"<SPC>" "C-x" "C-h" "C-w" "C-c"
		"<f4>" "<f6>" "<f7>" "z" "g" ))
	:config
		(guide-key-mode 1)
	:diminish guide-key-mode)

(use-package magit
	:init
	:config
	; get out of magit blame mode
		(define-key magit-blame-mode-map (kbd "<f7> b") 'magit-blame-quit)
	; keep me accidently hitting k key due to evil habits
	; this should suffice until magit mapping is figured out
		(define-key magit-mode-map (kbd "<DEL>") 'magit-delete-thing)
		(define-key magit-mode-map "k" nil)
	:bind
		("<f7> g" . magit-status)
		("<f7> b" . magit-blame)
		("<f7> a" . magit-run-git-gui-blame)
	:defer t)


(require 'package)

(setq package-archives '(("melpa" . "http://melpa.milkbox.net/packages/")
                         ("org"   . "http://orgmode.org/elpa/")
                         ("gnu"   . "http://elpa.gnu.org/packages/")))

(package-initialize)

(when (not package-archive-contents)
  (package-refresh-contents))

(when (not (package-installed-p 'use-package ))
  (package-install 'use-package))

(eval-when-compile
  (require 'use-package))
(require 'diminish)                ;; if you use :diminish
(require 'bind-key)                ;; if you use any :bind variant
(setq use-package-always-ensure t
      use-package-minimum-reported-time 0.03
      use-package-verbose t)

;; configure the chrome
(set-default-font "DejaVu Sans Mono 9")
