#+TITLE: GTD & Agenda Configuration
#+PROPERTY: header-args :tangle yes

* Agenda

Basic agenda settings
#+begin_src elisp
   (setq org-deadline-warning-days 7)
   (setq org-agenda-skip-additional-timestamps-same-entry t)
   (setq org-agenda-span 'fortnight)
   (setq org-agenda-tags-column 'auto)
   (setq org-agenda-skip-scheduled-if-deadline-is-shown t)
#+end_src

Agenda files
#+begin_src elisp
  (setq org-agenda-files (list
  			(concat org-directory "/inbox.org")
  			(concat org-directory "/gtd.org")
  			(concat org-directory "/org-gtd-tasks.org")
  			)
        )

#+end_src

Better agenda views
#+begin_src elisp :tangle yes
  (use-package org-super-agenda)
#+end_src

* To-do

Basic todo
#+begin_src elisp
  (setq org-todo-keywords
          '(
            (sequence "TODO(t)" "NEXT(n)" "WAIT(w@/!)" "|" "DONE(d!)" "CNCL(c@)")
            )
          )

  (setq org-todo-keyword-faces
          '(
            ("TODO" :foreground "red" :weight bold)
            ("NEXT" :foreground "red" :weight bold)
            ("WAIT" :foreground "yellow" :weight bold)
            ("DONE" :foreground "green" :weight bold)
            ("CNCL" :foreground "blue" :weight bold)
            )
          )

  (setq org-enforce-todo-dependencies t)
  (setq org-tags-exclude-from-inheritance '("crypt" "!private"))
#+end_src

Switch entry to 'DONE' when all subentries are done
#+begin_src elisp
  (defun org-summary-todo (n-done n-not-done)
    "Switch entry to 'DONE' when all subentries are done, to 'TODO' otherwise.
  Uses N-DONE and N-NOT-DONE"
    (let (org-log-done org-log-states)   ; turn off logging
      (org-todo (if (= n-not-done 0) "DONE" "TODO")
                )
        )
    )

    ;; (add-hook 'org-after-todo-statistics-hook #'org-summary-todo)
#+end_src

* Getting Things Done (GTD)

#+begin_src elisp
  (use-package f)
  (use-package dash)
  (use-package s)
  (use-package org-edna
    :config
    (setq org-edna-use-inheritance t)
    (org-edna-mode))

  (use-package org-gtd
    :straight (org-gtd :type git :host github :repo "Trevoke/org-gtd.el")
    :demand t
    :init (setq org-gtd-update-ack "4.0.0")
    :config
    (setq org-gtd-keyword-mapping
          '((todo . "TODO")
            (next . "NEXT")
            (wait . "WAIT")
            (done . "DONE")
            (canceled . "CNCL")))
    (setq org-gtd-custom-node-paths
          (list (list "Actionable" (expand-file-name "~/memex/gtd.org") "Actions")
                (list "Legacy" (expand-file-name "~/memex/org-gtd-tasks.org") "Actions")
                (list "Projects" (expand-file-name "~/memex/gtd.org") "Projects")
                (list "Incubate" (expand-file-name "~/memex/gtd.org") "Incubate")))
    (org-gtd-mode)
    )

  (global-set-key (kbd "C-c d c") #'org-gtd-capture)
  (global-set-key (kbd "C-c d e") #'org-gtd-engage)
  (global-set-key (kbd "C-c d p") #'org-gtd-process-inbox)
  (with-eval-after-load 'org-gtd
    (define-key org-gtd-clarify-map (kbd "C-c c") #'org-gtd-organize))
#+end_src

#+begin_src elisp
  (setq org-gtd-directory org-directory)
  (setq org-gtd-organize-hooks '(org-gtd-set-area-of-focus))
  (setq org-gtd-areas-of-focus '(
  				 "Atoms"
  				 "Bits"
  				 "Cells"
  				 "Flags"
  				 "Business"
  				 "Wealth"
  				 "Learning"
  				 "Skills"
  				 "Privacy"
  				 "Archive"
  				 "Library"
  				 "Writing"
  				 "Health"
  				 "Home"
  				 "Family"
  				 "Social"
  				 "Egypt"
  				 )
    )
  (setq org-gtd-clarify-show-horizons 'right)
#+end_src

Logging
#+begin_src elisp
  (setq org-log-into-drawer "LOGBOOK")
#+end_src

Clocking work in drawer
#+begin_src elisp :tangle yes
  (setq org-clock-into-drawer t)
#+end_src

Habits
#+begin_src elisp :tangle yes
  (setq org-habit-graph-column 80)
  (setq org-habit-show-habits-only-for-today nil)
#+end_src

* Refile

org-refile targets
#+begin_src elisp
  (setq org-refile-targets '((nil :maxlevel . 9)
                             (org-agenda-files :maxlevel . 9)
                             )
        )
#+end_src

Set type of refile targets completion
#+begin_src elisp
  (setq org-outline-path-complete-in-steps nil)
#+end_src

Allow refiling to new parents created on the go after confirmation
#+begin_src elisp
  (setq org-refile-allow-creating-parent-nodes 'confirm)
#+end_src