 (use-package org-capture
   :bind (("M-c" . org-capture))
   :commands org-capture
-  :config
-  (ar/csetq org-capture-templates
-            '(("t" "Todo" entry (file+headline "~/stuff/active/agenda.org" "INBOX")
-               "* TODO %?\n" :prepend t))))
+  :custom
+  (org-capture-templates
+   '(("t" "Todo" entry (file+headline "~/stuff/active/agenda.org" "INBOX")
+      "* TODO %?\n" :prepend t))))

    (ar/csetq org-crypt-key nil)))

(use-package org-agenda
  :bind (("M-a" . ar/org-agenda-toggle)
         :map org-agenda-mode-map
         ;; I prefer my M-m global key bind.
         ("M-m" . nil)
         ;; Use org-return instead, to follow links.
         ("<RET>" . org-return)
         ;; C-n/C-p for can be used for granular movement.
         ;; Use n/p for faster movement between items
         ("n" . org-agenda-next-item)
         ("p" . org-agenda-previous-item)
         ("g" . org-agenda-redo)
         ("s" . ar/org-agenda-schedule-dwim)
         ("M-<up>" . ar/org-agenda-item-move-up)
         ("M-<down>" . ar/org-agenda-item-move-down)
         ("1"  . ar/org-agenda-item-to-top))
  :commands (org-agenda
             ar/org-agenda-toggle)
  :custom
  (org-default-priority ?C) ;; Ensures unset tasks have low priority.
  (org-fontify-done-headline t)
  (org-agenda-block-separator ?\u2015)

  ;; Display all unscheduled todos in same buffer as agenda.
  ;; https://blog.aaronbieber.com//2016/09/24/an-agenda-for-life-with-org-mode.html
  (org-agenda-custom-commands

    (ar/org-headline-to-top)
    (switch-to-buffer (other-buffer (current-buffer) 1))
    (org-agenda-redo))

  ;; From https://blog.aaronbieber.com/2016/09/25/agenda-interactions-primer.html
  (defun ar/org-agenda-capture (&optional vanilla)
    "Capture a task in agenda mode, using the date at point.

If VANILLA is non-nil, run the standard `org-capture'."
    (interactive "P")
    (if vanilla
        (org-capture)
      (let ((org-overriding-default-time (org-get-cursor-date)))
        (org-capture nil "t"))))

  (defun ar/org-agenda-next-header ()
    "Jump to the next header in an agenda series."
    (interactive)
    (ar/org-agenda--goto-header))

  (defun ar/org-agenda-previous-header ()
    "Jump to the previous header in an agenda series."
    (interactive)
    (ar/org-agenda--goto-header t))

  (defun ar/org-agenda--goto-header (&optional backwards)
    "Find the next agenda series header forwards or BACKWARDS."
    (let ((pos (save-excursion
                 (goto-char (if backwards
                                (line-beginning-position)
                              (line-end-position)))
                 (let* ((find-func (if backwards
                                       'previous-single-property-change
                                     'next-single-property-change))
                        (end-func (if backwards
                                      'max
                                    'min))
                        (all-pos-raw (list (funcall find-func (point) 'org-agenda-structural-header)
                                           (funcall find-func (point) 'org-agenda-date-header)))
                        (all-pos (cl-remove-if-not 'numberp all-pos-raw))
                        (prop-pos (if all-pos (apply end-func all-pos) nil)))
                   prop-pos))))
      (if pos (goto-char pos))
      (if backwards (goto-char (line-beginning-position)))))

  (defun ar/org-agenda-toggle (&optional arg)
    "Toggles between agenda using my custom command and org file."
