 
 ;;;; Navigation START
 
-(add-hook 'emacs-startup-hook
-          (lambda ()
-            (use-package isearch
-              :commands (isearch-forward isearch-backward)
-              :defer 5
-              :preface
-              (provide 'isearch)
-              :config
-              (use-package char-fold)
-
-              (vsetq search-default-mode #'char-fold-to-regexp)
-
-              ;; Prepopulate isearch with selectionn.
-              ;; From http://www.reddit.com/r/emacs/comments/2amn1v/isearch_selected_text
-              (defadvice isearch-mode (around isearch-mode-default-string
-                                              (forward &optional regexp op-fun recursive-edit word-p) activate)
-                "Enable isearch to start with current selection."
-                (if (and transient-mark-mode mark-active (not (eq (mark) (point))))
-                    (progn
-                      (isearch-update-ring (buffer-substring-no-properties (mark) (point)))
-                      (deactivate-mark)
-                      ad-do-it
-                      (if (not forward)
-                          (isearch-repeat-backward)
-                        (goto-char (mark))
-                        (isearch-repeat-forward)))
-                  ad-do-it)))
-
-            ;; From http://endlessparentheses.com/emacs-narrow-or-widen-dwim.html
-            (defun ar/narrow-or-widen-dwim (p)
-              "Widen if buffer is narrowed, narrow-dwim otherwise.
+(add-hook! 'emacs-startup-hook
+           (use-package isearch
+             :commands (isearch-forward isearch-backward)
+             :defer 5
+             :preface
+             (provide 'isearch)
+             :config
+             (use-package char-fold)
+
+             (vsetq search-default-mode #'char-fold-to-regexp)
+
+             ;; Prepopulate isearch with selectionn.
+             ;; From http://www.reddit.com/r/emacs/comments/2amn1v/isearch_selected_text
+             (defadvice isearch-mode (around isearch-mode-default-string
+                                             (forward &optional regexp op-fun recursive-edit word-p) activate)
+               "Enable isearch to start with current selection."
+               (if (and transient-mark-mode mark-active (not (eq (mark) (point))))
+                   (progn
+                     (isearch-update-ring (buffer-substring-no-properties (mark) (point)))
+                     (deactivate-mark)
+                     ad-do-it
+                     (if (not forward)
+                         (isearch-repeat-backward)
+                       (goto-char (mark))
+                       (isearch-repeat-forward)))
+                 ad-do-it)))
+
+           ;; From http://endlessparentheses.com/emacs-narrow-or-widen-dwim.html
+           (defun ar/narrow-or-widen-dwim (p)
+             "Widen if buffer is narrowed, narrow-dwim otherwise.
 Dwim means: region, org-src-block, org-subtree, or defun,
 whichever applies first. Narrowing to org-src-block actually
 calls `org-edit-src-code'.
 
 With prefix P, don't widen, just narrow even if buffer is
 already narrowed."
-              (interactive "P")
-              (declare (interactive-only))
-              (cond ((and (buffer-narrowed-p) (not p)) (widen))
-                    ((region-active-p)
-                     (narrow-to-region (region-beginning) (region-end)))
-                    ((derived-mode-p 'org-mode)
-                     ;; `org-edit-src-code' is not a real narrowing
-                     ;; command. Remove this first conditional if you
-                     ;; don't want it.
-                     (cond ((ignore-errors (org-edit-src-code))
-                            (delete-other-windows))
-                           ((ignore-errors (org-narrow-to-block) t))
-                           (t (org-narrow-to-subtree))))
-                    ((derived-mode-p 'latex-mode)
-                     (LaTeX-narrow-to-environment))
-                    (t (narrow-to-defun))))
-
-            (bind-key "C-x n n" #'ar/narrow-or-widen-dwim)))
+             (interactive "P")
+             (declare (interactive-only))
+             (cond ((and (buffer-narrowed-p) (not p)) (widen))
+                   ((region-active-p)
+                    (narrow-to-region (region-beginning) (region-end)))
+                   ((derived-mode-p 'org-mode)
+                    ;; `org-edit-src-code' is not a real narrowing
+                    ;; command. Remove this first conditional if you
+                    ;; don't want it.
+                    (cond ((ignore-errors (org-edit-src-code))
+                           (delete-other-windows))
+                          ((ignore-errors (org-narrow-to-block) t))
+                          (t (org-narrow-to-subtree))))
+                   ((derived-mode-p 'latex-mode)
+                    (LaTeX-narrow-to-environment))
+                   (t (narrow-to-defun))))
+
+           (bind-key "C-x n n" #'ar/narrow-or-widen-dwim))
 
 (use-package swiper
   :ensure t

  :bind (("M-<up>" . drag-stuff-up)
         ("M-<down>" . drag-stuff-down)))

(add-hook 'emacs-startup-hook
          (lambda ()
            ;; Remember history of things across launches (ie. kill ring).
            ;; From https://www.wisdomandwonder.com/wp-content/uploads/2014/03/C3F.html
            (use-package savehist
              :defer 2
              :config
              (vsetq savehist-file "~/.emacs.d/savehist")
              (vsetq savehist-save-minibuffer-history t)
              (vsetq history-length 1000)
              (vsetq savehist-additional-variables
                     '(kill-ring
                       search-ring
                       regexp-search-ring))
              (savehist-mode +1))
            (use-package whitespace
              :defer 5
              ;; Automatically remove whitespace on saving.
              :hook ((before-save . whitespace-cleanup)
                     (prog-mode . whitespace-mode))
              :config
              ;; When nil, fill-column is used instead.
              (vsetq whitespace-line-column nil)
              ;; Highlight empty lines, TABs, blanks at beginning/end, lines
              ;; longer than fill-column, and trailing blanks.
              (vsetq whitespace-style '(face empty tabs lines-tail trailing))
              (vsetq show-trailing-whitespace t)
              (set-face-attribute 'whitespace-line nil
                                  :foreground "DarkOrange1"
                                  :background "default"))
            (use-package smartparens
              :ensure t
              :defer 0.01
              ;; Add to minibuffer also.
              :hook ((minibuffer-setup . smartparens-mode)
                     (prog-mode . smartparens-strict-mode)
                     (eshell-mode . smartparens-strict-mode))
              :config
              (require 'smartparens-config)
              (require 'smartparens-html)
              (require 'smartparens-python)

              (defun ar/kill-region-advice-fun (orig-fun &rest r)
                "Advice function around `kill-region' (ORIG-FUN and R)."
                (if (or (null (nth 2 r)) ;; Consider kill-line (C-k).
                        mark-active)
                    (apply orig-fun r)
                  ;; Kill entire line.
                  (let ((last-command (lambda ())) ;; Override last command to avoid appending to kill ring.
                        (offset (- (point)
                                   (line-beginning-position))))
                    (apply orig-fun (list (line-beginning-position)
                                          (line-end-position)
                                          nil))
                    (delete-char 1)
                    (forward-char (min offset
                                       (- (line-end-position)
                                          (line-beginning-position)))))))

              (advice-add 'kill-region
                          :around
                          'ar/kill-region-advice-fun)

              ;; I prefer keeping C-w to DWIM kill, provided by
              ;; `ar/kill-region-advice-fun'. Removing remap.
              ;;   (define-key smartparens-strict-mode-map [remap kill-region] nil)

              (defun ar/smartparens-wrap-square-bracket (arg)
                "[] equivalent of `paredit-wrap-round'."
                (interactive "P")
                (save-excursion
                  (unless (sp-point-in-symbol)
                    (backward-char))
                  (sp-wrap-with-pair "["))
                (insert " "))

              :bind (:map smartparens-strict-mode-map
                          ([remap kill-region] . kill-region)
                          ("C-c <right>" . sp-forward-slurp-sexp)
                          ("C-c <left>" . sp-forward-barf-sexp)
                          ("M-[" . sp-rewrap-sexp)
                          :map smartparens-mode-map
                          ("M-]" . ar/smartparens-wrap-square-bracket)))))


(use-package region-bindings-mode

      (insert (replace-regexp-in-string "^[^ ]*:" "" candidate))
      (indent-for-tab-command))
    (let ((helm-source-do-ag (helm-build-async-source "Silver Searcher inserter"
                               :init 'helm-ag--do-ag-set-command
                               :candidates-process 'helm-ag--do-ag-candidate-process
                               :action 'ar/insert-candidate
                               :nohighlight t
                               :requires-pattern 3
                               :candidate-number-limit 9999
                               :keymap helm-do-ag-map)))
      (call-interactively #'ar/helm-ag)))

  (defun ar/helm-ag (arg)
