Redo org configuration

This commit is contained in:
mokou 2020-10-06 10:58:01 +02:00
parent 76d6da531e
commit 1a0d29a743

View file

@ -58,38 +58,25 @@
(after! org (after! org
(add-to-list 'org-modules 'org-habit) (add-to-list 'org-modules 'org-habit)
(setq-default org-directory "~/code/personal/org") (setq-default org-directory "~/code/personal/org")
(setq-default org-default-notes-file "~/code/personal/org/capture.org") (setq-default org-default-notes-file "~/code/personal/org/inbox.org")
(setq-default org-todo-keywords (setq-default org-todo-keywords
(quote ((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d)") (quote ((sequence "TODO(t)" "DONE(d)" "WAITING(w@/!)"))))
(sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" "PHONE" "MEETING"))))
(setq-default org-todo-keyword-faces (setq-default org-todo-keyword-faces
(quote (("TODO" :foreground "tomato" :weight bold) (quote (("TODO" :foreground "tomato" :weight bold)
("NEXT" :foreground "royal blue" :weight bold)
("DONE" :foreground "forest green" :weight bold) ("DONE" :foreground "forest green" :weight bold)
("WAITING" :foreground "chocolate" :weight bold) ("WAITING" :foreground "chocolate" :weight bold))))
("HOLD" :foreground "orchid" :weight bold)
("CANCELLED" :foreground "yellow" :weight bold)
("MEETING" :foreground "gold" :weight bold)
("PHONE" :foreground "orange" :weight bold))))
(setq org-capture-templates (setq org-capture-templates
(quote (("t" "todo" entry (file "~/code/personal/org/capture.org") (quote (("t" "todo" entry (file "~/code/personal/org/inbox.org")
"* TODO %?\n%U\n" :clock-in t :clock-resume t) "* TODO %?\n%U\n" :clock-in t :clock-resume t)
("r" "respond" entry (file "~/code/personal/org/capture.org") ("n" "note" entry (file "~/code/personal/org/inbox.org")
"* STRT Respond to %:from on %:subject\nSCHEDULED: %t\n%U\n%a\n" :clock-in t :clock-resume t :immediate-finish t) "* %? :NOTE:\n%U\n%a\n" :clock-in t :clock-resume t))))
("n" "note" entry (file "~/code/personal/org/capture.org") (setq org-refile-targets '((nil :maxlevel . 9)
"* %? :NOTE:\n%U\n%a\n" :clock-in t :clock-resume t) (org-agenda-files :maxlevel . 9)))
("w" "org-protocol" entry (file "~/code/personal/org/capture.org")
"* TODO Review %c\n%U\n" :immediate-finish t)
("m" "meeting" entry (file "~/code/personal/org/capture.org")
"* PROJ Meeting with %? :MEETING:\n%U" :clock-in t :clock-resume t))))
(setq org-refile-targets (quote ((nil :maxlevel . 9)
(org-agenda-files :maxlevel . 9))))
(add-to-list (add-to-list
'ivy-completing-read-handlers-alist 'ivy-completing-read-handlers-alist
'(org-capture-refile . completing-read-default)) '(org-capture-refile . completing-read-default))
(org-clock-persistence-insinuate) (org-clock-persistence-insinuate)
(setq org-clock-in-switch-to-state 'cf/clock-in-to-next) (setq org-clock-in-switch-to-state 'cf/clock-in-to-next)
(setq org-drawers (quote ("PROPERTIES" "LOGBOOK")))
(setq org-clock-into-drawer t) (setq org-clock-into-drawer t)
(setq org-clock-out-remove-zero-time-clocks t) (setq org-clock-out-remove-zero-time-clocks t)
(setq org-clock-out-when-done t) (setq org-clock-out-when-done t)
@ -99,85 +86,33 @@
(setq org-agenda-dim-blocked-tasks nil) (setq org-agenda-dim-blocked-tasks nil)
(setq org-agenda-compact-blocks t) (setq org-agenda-compact-blocks t)
(setq org-agenda-custom-commands (setq org-agenda-custom-commands
(quote (("N" "Notes" tags "NOTE" (quote ((" " "Agenda"
((org-agenda-overriding-header "Notes") ((agenda "" nil)
(org-tags-match-list-sublevels t))) (tags "REFILE"
(" " "Agenda" ((org-agenda-overriding-header "Tasks to Refile")
((agenda "" nil) (org-tags-match-list-sublevels nil)))
(tags "REFILE" (tags-todo "-CANCELLED+WAITING|HOLD/!"
((org-agenda-overriding-header "Tasks to Refile") ((org-agenda-overriding-header (concat "Waiting Tasks"))
(org-tags-match-list-sublevels nil))) (org-agenda-skip-function 'cf/skip-non-tasks)
(tags-todo "-CANCELLED/!" (org-tags-match-list-sublevels nil)
((org-agenda-overriding-header "Stuck Projects") (org-agenda-todo-ignore-scheduled cf/hide-scheduled-and-waiting-next-tasks)
(org-agenda-skip-function 'cf/skip-non-stuck-projects) (org-agenda-todo-ignore-deadlines cf/hide-scheduled-and-waiting-next-tasks)))
(org-agenda-sorting-strategy (tags "-REFILE/"
'(category-keep)))) ((org-agenda-overriding-header "Tasks to Archive")
(tags-todo "-HOLD-CANCELLED/!" (org-agenda-skip-function 'cf/skip-non-archivable-tasks)
((org-agenda-overriding-header "Projects") (org-tags-match-list-sublevels nil))))
(org-agenda-skip-function 'cf/skip-non-projects) nil)))))
(org-tags-match-list-sublevels 'indented)
(org-agenda-sorting-strategy
'(category-keep))))
(tags-todo "-CANCELLED/!NEXT"
((org-agenda-overriding-header (concat "Project Next Tasks"
(if cf/hide-scheduled-and-waiting-next-tasks
""
" (including WAITING and SCHEDULED tasks)")))
(org-agenda-skip-function 'cf/skip-projects-and-habits-and-single-tasks)
(org-tags-match-list-sublevels t)
(org-agenda-todo-ignore-scheduled cf/hide-scheduled-and-waiting-next-tasks)
(org-agenda-todo-ignore-deadlines cf/hide-scheduled-and-waiting-next-tasks)
(org-agenda-todo-ignore-with-date cf/hide-scheduled-and-waiting-next-tasks)
(org-agenda-sorting-strategy
'(todo-state-down effort-up category-keep))))
(tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
((org-agenda-overriding-header (concat "Project Subtasks"
(if cf/hide-scheduled-and-waiting-next-tasks
""
" (including WAITING and SCHEDULED tasks)")))
(org-agenda-skip-function 'cf/skip-non-project-tasks)
(org-agenda-todo-ignore-scheduled cf/hide-scheduled-and-waiting-next-tasks)
(org-agenda-todo-ignore-deadlines cf/hide-scheduled-and-waiting-next-tasks)
(org-agenda-todo-ignore-with-date cf/hide-scheduled-and-waiting-next-tasks)
(org-agenda-sorting-strategy
'(category-keep))))
(tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
((org-agenda-overriding-header (concat "Standalone Tasks"
(if cf/hide-scheduled-and-waiting-next-tasks
""
" (including WAITING and SCHEDULED tasks)")))
(org-agenda-skip-function 'cf/skip-project-tasks)
(org-agenda-todo-ignore-scheduled cf/hide-scheduled-and-waiting-next-tasks)
(org-agenda-todo-ignore-deadlines cf/hide-scheduled-and-waiting-next-tasks)
(org-agenda-todo-ignore-with-date cf/hide-scheduled-and-waiting-next-tasks)
(org-agenda-sorting-strategy
'(category-keep))))
(tags-todo "-CANCELLED+WAITING|HOLD/!"
((org-agenda-overriding-header (concat "Waiting and Postponed Tasks"
(if cf/hide-scheduled-and-waiting-next-tasks
""
" (including WAITING and SCHEDULED tasks)")))
(org-agenda-skip-function 'cf/skip-non-tasks)
(org-tags-match-list-sublevels nil)
(org-agenda-todo-ignore-scheduled cf/hide-scheduled-and-waiting-next-tasks)
(org-agenda-todo-ignore-deadlines cf/hide-scheduled-and-waiting-next-tasks)))
(tags "-REFILE/"
((org-agenda-overriding-header "Tasks to Archive")
(org-agenda-skip-function 'cf/skip-non-archivable-tasks)
(org-tags-match-list-sublevels nil))))
nil)))))
(map! :map global-map :leader "a" 'org-agenda) (map! :map global-map :leader "a" 'org-agenda)
(defvar cf/hide-scheduled-and-waiting-next-tasks t)
(defun cf/clock-in-to-next (kw) (defun cf/clock-in-to-next (kw)
(when (not (and (boundp 'org-capture-mode) org-capture-mode)) (when (not (and (boundp 'org-capture-mode) org-capture-mode))
(cond (cond
((and (member (org-get-todo-state) (list "TODO")) ((and (member (org-get-todo-state) (list "WAITING"))
(cf/is-task-p)) (cf/is-task-p))
"NEXT")
((and (member (org-get-todo-state) (list "NEXT"))
(cf/is-project-p))
"TODO")))) "TODO"))))
(defun cf/find-project-task () (defun cf/find-project-task ()
@ -220,97 +155,6 @@
(setq has-subtask t)))) (setq has-subtask t))))
(and is-a-task (not has-subtask))))) (and is-a-task (not has-subtask)))))
(defun cf/is-project-subtree-p ()
(let ((task (save-excursion (org-back-to-heading 'invisible-ok)
(point))))
(save-excursion
(cf/find-project-task)
(if (equal (point) task)
nil
t))))
(defun cf/is-subproject-p ()
(let ((is-subproject)
(is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
(save-excursion
(while (and (not is-subproject) (org-up-heading-safe))
(when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
(setq is-subproject t))))
(and is-a-task is-subproject)))
(defun cf/list-sublevels-for-projects-indented ()
(if (marker-buffer org-agenda-restrict-begin)
(setq org-tags-match-list-sublevels 'indented)
(setq org-tags-match-list-sublevels nil))
nil)
(defun cf/list-sublevels-for-projects ()
(if (marker-buffer org-agenda-restrict-begin)
(setq org-tags-match-list-sublevels t)
(setq org-tags-match-list-sublevels nil))
nil)
(defvar cf/hide-scheduled-and-waiting-next-tasks t)
(defun cf/toggle-next-task-display ()
(interactive)
(setq cf/hide-scheduled-and-waiting-next-tasks (not cf/hide-scheduled-and-waiting-next-tasks))
(when (equal major-mode 'org-agenda-mode)
(org-agenda-redo))
(message "%s WAITING and SCHEDULED NEXT Tasks" (if cf/hide-scheduled-and-waiting-next-tasks "Hide" "Show")))
(defun cf/skip-stuck-projects ()
(save-restriction
(widen)
(let ((next-headline (save-excursion (or (outline-next-heading) (point-max)))))
(if (cf/is-project-p)
(let* ((subtree-end (save-excursion (org-end-of-subtree t)))
(has-next ))
(save-excursion
(forward-line 1)
(while (and (not has-next) (< (point) subtree-end) (re-search-forward "^\\*+ NEXT " subtree-end t))
(unless (member "WAITING" (org-get-tags-at))
(setq has-next t))))
(if has-next
nil
next-headline)) ; a stuck project, has subtasks but no next task
nil))))
(defun cf/skip-non-stuck-projects ()
;; (cf/list-sublevels-for-projects-indented)
(save-restriction
(widen)
(let ((next-headline (save-excursion (or (outline-next-heading) (point-max)))))
(if (cf/is-project-p)
(let* ((subtree-end (save-excursion (org-end-of-subtree t)))
(has-next ))
(save-excursion
(forward-line 1)
(while (and (not has-next) (< (point) subtree-end) (re-search-forward "^\\*+ NEXT " subtree-end t))
(unless (member "WAITING" (org-get-tags-at))
(setq has-next t))))
(if has-next
next-headline
nil)) ; a stuck project, has subtasks but no next task
next-headline))))
(defun cf/skip-non-projects ()
;; (cf/list-sublevels-for-projects-indented)
(if (save-excursion (cf/skip-non-stuck-projects))
(save-restriction
(widen)
(let ((subtree-end (save-excursion (org-end-of-subtree t))))
(cond
((cf/is-project-p)
nil)
((and (cf/is-project-subtree-p) (not (cf/is-task-p)))
nil)
(t
subtree-end))))
(save-excursion (org-end-of-subtree t))))
(defun cf/skip-non-tasks () (defun cf/skip-non-tasks ()
(save-restriction (save-restriction
(widen) (widen)
@ -321,108 +165,6 @@
(t (t
next-headline))))) next-headline)))))
(defun cf/skip-project-trees-and-habits ()
(save-restriction
(widen)
(let ((subtree-end (save-excursion (org-end-of-subtree t))))
(cond
((cf/is-project-p)
subtree-end)
((org-is-habit-p)
subtree-end)
(t
nil)))))
(defun cf/skip-projects-and-habits-and-single-tasks ()
(save-restriction
(widen)
(let ((next-headline (save-excursion (or (outline-next-heading) (point-max)))))
(cond
((org-is-habit-p)
next-headline)
((and cf/hide-scheduled-and-waiting-next-tasks
(member "WAITING" (org-get-tags-at)))
next-headline)
((cf/is-project-p)
next-headline)
((and (cf/is-task-p) (not (cf/is-project-subtree-p)))
next-headline)
(t
nil)))))
(defun cf/skip-project-tasks-maybe ()
(save-restriction
(widen)
(let* ((subtree-end (save-excursion (org-end-of-subtree t)))
(next-headline (save-excursion (or (outline-next-heading) (point-max))))
(limit-to-project (marker-buffer org-agenda-restrict-begin)))
(cond
((cf/is-project-p)
next-headline)
((org-is-habit-p)
subtree-end)
((and (not limit-to-project)
(cf/is-project-subtree-p))
subtree-end)
((and limit-to-project
(cf/is-project-subtree-p)
(member (org-get-todo-state) (list "NEXT")))
subtree-end)
(t
nil)))))
(defun cf/skip-project-tasks ()
(save-restriction
(widen)
(let* ((subtree-end (save-excursion (org-end-of-subtree t))))
(cond
((cf/is-project-p)
subtree-end)
((org-is-habit-p)
subtree-end)
((cf/is-project-subtree-p)
subtree-end)
(t
nil)))))
(defun cf/skip-non-project-tasks ()
(save-restriction
(widen)
(let* ((subtree-end (save-excursion (org-end-of-subtree t)))
(next-headline (save-excursion (or (outline-next-heading) (point-max)))))
(cond
((cf/is-project-p)
next-headline)
((org-is-habit-p)
subtree-end)
((and (cf/is-project-subtree-p)
(member (org-get-todo-state) (list "NEXT")))
subtree-end)
((not (cf/is-project-subtree-p))
subtree-end)
(t
nil)))))
(defun cf/skip-projects-and-habits ()
(save-restriction
(widen)
(let ((subtree-end (save-excursion (org-end-of-subtree t))))
(cond
((cf/is-project-p)
subtree-end)
((org-is-habit-p)
subtree-end)
(t
nil)))))
(defun cf/skip-non-subprojects ()
(let ((next-headline (save-excursion (outline-next-heading))))
(if (cf/is-subproject-p)
nil
next-headline)))
(defun cf/skip-non-archivable-tasks () (defun cf/skip-non-archivable-tasks ()
(save-restriction (save-restriction
(widen) (widen)