;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; helper for building agenda file lists
(defun load-org-agenda-files-recursively (dir) "Find all directories in DIR."
    (unless (file-directory-p dir) (error "Not a directory `%s'" dir))
    (unless (equal (directory-files dir nil org-agenda-file-regexp t) nil)
      (add-to-list 'org-agenda-files dir)
    )
    (dolist (file (directory-files dir nil nil t))
        (unless (member file '("." ".."))
            (let ((file (concat dir file "/")))
                (when (file-directory-p file)
                    (load-org-agenda-files-recursively file)
                )
            )
        )
    )
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Set some org agendas/dashboards
(setq org-agenda-todo-ignore-scheduled 'all)
(setq org-agenda-sorting-strategy 
    '(
      (agenda habit-down time-up scheduled-down priority-down category-keep)
      (todo habit-up time-down scheduled-down deadline-down todo-state-down priority-down alpha-up)
      (tags priority-down category-keep)
      (search category-keep)
     )
)

(setq org-agenda-custom-commands
      '(
          ("P" "Personal"
              (
                  (agenda "" (
                      (org-agenda-overriding-header "PERSONAL Agenda")
                      (org-agenda-files (list "~/org/_todo.org"
                                              "~/org/_index.org"
                                              "~/org/health/_health.org"
                                              "~/org/health/health_houdini.org"
                                              "~/org/health/health_mike.org"))
                      (load-org-agenda-files-recursively "~/org/culinary")
                      (load-org-agenda-files-recursively "~/org/gaz")
                      (load-org-agenda-files-recursively "~/org/photography")
                      (load-org-agenda-files-recursively "~/org/reading")
                  ))
                  (alltodo "*" (
                      (org-agenda-overriding-header "PERSONAL To Do List")
                      (org-agenda-files (list "~/org/_todo.org"
                                              "~/org/_index.org"
                                              "~/org/health/_health.org"
                                              "~/org/health/health_houdini.org"
                                              "~/org/health/health_mike.org"))
                      (load-org-agenda-files-recursively "~/org/culinary")
                      (load-org-agenda-files-recursively "~/org/gaz")
                      (load-org-agenda-files-recursively "~/org/photography")
                      (load-org-agenda-files-recursively "~/org/reading")
                  ))
               )
          )
          ("G" . "Gaming")
          ("Gd" "Destiny"
              (
                  (agenda "" (
                      (org-agenda-start-on-weekday 2)
                      (org-agenda-overriding-header "DESTINY Agenda")
                      (org-agenda-files (list "~/org/games_destiny.org"))
                  ))
                  (tags-todo "-crafting-STYLE=\"habit\"" (
                      (org-agenda-overriding-header "DESTINY To Do List")
                      (org-agenda-files (list "~/org/games_destiny.org"))
                  ))
                  (tags-todo "+crafting+weaponleveling" (
                      (org-agenda-overriding-header "DESTINY Weapon Leveling")
                      (org-agenda-files (list "~/org/games_destiny.org"))
                  ))
                  (tags-todo "+crafting+resonance" (
                      (org-agenda-overriding-header "DESTINY Weapon Shaping")
                      (org-agenda-files (list "~/org/games_destiny.org"))
                  ))
                  (tags-todo "+crafting+weaponupgrade" (
                      (org-agenda-overriding-header "DESTINY Weapon Upgrades")
                      (org-agenda-files (list "~/org/games_destiny.org"))
                  ))
               )
           )
        )
)