Skip to content

Commit

Permalink
Add: [Save / checkpoint] Many new features wrt org-agenda
Browse files Browse the repository at this point in the history
  • Loading branch information
Musa Al-hassy committed May 3, 2024
1 parent 6072c41 commit de4fb8e
Show file tree
Hide file tree
Showing 2 changed files with 249 additions and 32 deletions.
137 changes: 121 additions & 16 deletions init.el
Original file line number Diff line number Diff line change
Expand Up @@ -1705,7 +1705,7 @@ fonts (‒̀ᴗ‒́)و"
(use-package org-fancy-priorities

:hook (org-mode . org-fancy-priorities-mode)
:custom (org-fancy-priorities-list '("High" "MID" "LOW")) ;; "OPTIONAL"
:custom (org-fancy-priorities-list '("MUST DO" "MID" "LOW")) ;; "OPTIONAL"
;; Let's use the β€œEisenhower map of priority”…
;; :custom (org-fancy-priorities-list '("Urgent and Important" ;; Do now!
;; "Not Urgent But Important" ;; Do schedule this.
Expand Down Expand Up @@ -1929,7 +1929,7 @@ fonts (‒̀ᴗ‒́)و"
(add-to-list 'org-src-lang-modes '("plantuml" . fundamental))

;; Record a note on what was accomplished when clocking out of an item.
(setq org-log-note-clock-out t)
(setq org-log-note-clock-out nil) ;; I break tasks down & use C-c C-z, so no need for this anymore.

(setq confirm-kill-emacs 'yes-or-no-p)

Expand Down Expand Up @@ -2155,18 +2155,30 @@ Example uses:
(flet ((org-read-date (&rest rest) (current-time)))
(call-interactively 'org-agenda-schedule))))))

;; Relevant function is β€œC-c C-z”.
;;
;; In Org-Agenda, β€œl” to see top-level clocked in/out logs.
;; On a given item, press β€œL” to see its note logs.
;;
;; Or, just β€œv L” to see all logged notes in the agenda view.
;;
(setq org-log-note-headings '((done . "CLOSING NOTE %t")
(state . "State %-12s from %-12S %t")
(note . "Note taken on %t")
;; (reschedule . "Rescheduled from %S on %t") ;; Default
(note . "%t")
;; (reschedule . "Rescheduled from %S on %t") ;; Default
(reschedule . "Schedule changed on %t: %S -> %s")
(delschedule . "Not scheduled, was %S on %t")
(redeadline . "Deadline changed on %t: %S -> %s")
;; (redeadline . "New deadline from %S on %t") ;; Default
;; (redeadline . "New deadline from %S on %t") ;; Default
(deldeadline . "Removed deadline, was %S on %t")
(refile . "Refiled on %t")
(clock-out . "")))


;; Remove the β€œ\\\n” added to the end of notes.
(advice-add 'org-store-log-note :after
(cl-defun remove-\\ (&rest _) (org-narrow-to-subtree) (replace-in-buffer "\\\\\\\\\n" "") (widen)))

;; Start each agenda item with β€˜β—‹β€™, then show me it's %timestamp and how many
;; times it's been re-%scheduled.
(setq org-agenda-prefix-format " β—‹ %?-12t%-6e%s ")
Expand Down Expand Up @@ -2230,23 +2242,23 @@ Example uses:
(defun my/special-ON_STARTED-property-hook ()
"When a task enters STARTED/DONE state, execute the code in its ON_STARTED/ON_DONE property."
(save-excursion
;; yet another property support
(when (equal (org-get-todo-state) "TODO")
;; yet another property support
(when (equal (org-get-todo-state) "TODO")
;; Instead of ignore-errors, it should only evaluate the string /if/ it is present.
(ignore-errors (eval (car (read-from-string (eval (org-entry-get (point) "ON_TODO")))))))

;; yet another property support
(when (equal (org-get-todo-state) "STARTED")
;; yet another property support
(when (equal (org-get-todo-state) "STARTED")
;; Instead of ignore-errors, it should only evaluate the string /if/ it is present.
(ignore-errors (eval (car (read-from-string (eval (org-entry-get (point) "ON_STARTED")))))))

;; yet another property support
(when (equal (org-get-todo-state) "DONE")
;; yet another property support
(when (equal (org-get-todo-state) "DONE")
;; Instead of ignore-errors, it should only evaluate the string /if/ it is present.
(ignore-errors (eval (car (read-from-string (eval (org-entry-get (point) "ON_DONE")))))))

;; yet another property support
(when (equal "t" (org-entry-get (point) "TEMPORARILY_TREAT_SUBTREES_AS_CHECKBOXES"))
;; yet another property support -- AXE?
(when (equal "t" (org-entry-get (point) "TEMPORARILY_TREAT_SUBTREES_AS_CHECKBOXES"))
(when (equal (org-get-todo-state) "TODO")
(let ((current-prefix-arg :random-theme)) (my/toggle-theme))
(org-narrow-to-subtree)
Expand All @@ -2265,10 +2277,103 @@ Example uses:
(org-mode-restart))))))

;; β€œC-c a t” β‡’ List all (non-recurring non-someday) todos sorted by state, priority, effort
;; β€œC-c a a” β‡’ Daily agenda view, followed by unscheduled open loops
;;
;; Query Language :: https://orgmode.org/manual/Matching-tags-and-properties.html
;; For general-purpose SQL-like queries against all Org entries, consider using org-ql: https://github.com/alphapapa/org-ql
;; For example, to find all entries that have any timestamp in a given period.
;; Another example: Suppose you know that there is a β€œsrc” block you're looking for in your notes, but
;; you're not sure which entry it is in, you can use org-ql to find all entries that contain a β€œsrc” block.
;; Moreover, you can refine the query by considering only a specific time window, if the entry has any timestamp at all.

;; You can even use org-ql in org-agenda-custom-commands! See https://github.com/alphapapa/org-ql/blob/master/examples.org#stuck-projects-block-agenda
;; or, even, better: https://www.reddit.com/r/emacs/comments/cnrt2d/comment/ewtqez8/
;; That is, you can write SQL-like queries for your agenda, if you prefer.
;; Moreover, one could use org-ql-agenda as an alternative implementation of org-agenda,
;; but their are pros/cons to both, neither is strictly better: org-ql has better queries, org-agenda has different features (such as weekly view). ⟡ This might not be true anymore.
;; MA: I may switch to org-ql since org-ql-block is about 80% faster than org-agenda!
;; MA: Actually, no thanks: I dislike that my agenda is broken down my projects, I like the usual timebased grid ordering of org-agenda.
;; β‡’ This is the only blocker, if I can fix it, then I'd be happy to use org-ql / org-super-agenda.
;; β‡’ Note: Any use of org-ql in org-agenda-custom-commands actually recreates the agenda buffer from scratch: It's not what you get by calling classic org-agenda!
;; See: https://www.reddit.com/r/emacs/comments/cnrt2d/comment/ewhf0zj/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button
;; i.e., see org-super-agenda
(setq org-agenda-custom-commands
'(("t" "My list of all TODO entries" tags-todo "-recurring-someday"
'(("t" "My list of all TODO entries" tags-todo "-recurring-someday+LEVEL=2"
((org-agenda-overriding-header "\nTODOs sorted by state, priority, effort")
(org-agenda-sorting-strategy '(todo-state-down priority-down effort-up))))))
(org-agenda-sorting-strategy '(todo-state-down priority-down effort-up))
(org-super-agenda-groups (progn (org-super-agenda-mode t) '(
(:name "Important" :and (:priority "A" :not (:todo ("DONE" "CANCELED"))))
(:name "Process your Inbox" :tag "inbox")
(:name "Approved" :todo "APPROVED")
(:name "Started" :todo "STARTED")
(:name "Waiting" :todo "WAITING")
(:name "Low Priority" :priority "C" :tag "maybe"))))))
("w" "WAITING Tasks"
((tags "todo=\"WAITING\"+LEVEL=2")))
;; To see EVERYTHING I've done, just press β€œC-c a a v w l” and it will activate logbook mode.
;;
;; This is a helpful view:
;; As the week moves along, I know what I have left to do
;; and can choose to /not/ do low-priority tasks, or to
;; act as a motivator for me to work faster or focus better, etc.
("a" "Daily Agenda; Productivity β‰ˆ β™―DONE / β™―TASKS"
(;; TODO: MAYBE MOVE DOWN: (tags-todo "inbox" ((org-agenda-prefix-format " %?-12t% s") (org-agenda-overriding-header "\nProcess your Inbox\n")))
(agenda "" ((org-agenda-span 'day) (org-agenda-overriding-header (progn (org-super-agenda-mode -1) "Please focus on π’ͺπ“ƒπ“π“Ž these tasks for the day!"))))
;; Show me deadline items grouped together
(agenda nil
((org-agenda-entry-types '(:deadline))
(org-agenda-format-date "")
(org-deadline-warning-days 7)
(org-agenda-show-all-dates nil) ;; Only show if there are actually entries
(org-agenda-skip-function
'(org-agenda-skip-entry-if 'notregexp "\\* NEXT"))
(org-agenda-overriding-header "\nDeadlines")))
;; What I've left to do is all incomplete tasks scheduled within the next 5-𝓃 days, where 𝓃 is the numeral of the current week day.
;; ;; Mon=1, β‹―, Thu=4, β‹―
(tags (with-today
;; Add 1 to include tasks scheduled for today.
(format "-recurring-TODO=\"DONE\"+SCHEDULED>=\"<-%sd>\"+SCHEDULED<=\"<+%sd>\"" (1+ it) it))
((org-agenda-overriding-header "What I have left to do this week")))
;; Press E to toggle seeing ~5 lines of each entry; might be helpful for rescheduling or doing a task sooner.
;; https://emacs.stackexchange.com/questions/41468/show-notes-in-org-mode-agenda
;;
;; What I've done so far is all tasks closed in the past 𝓃-days, where 𝓃 is the numeral of the current week day.
;; ;; Mon=1, β‹―, Thu=4, β‹―
(tags (with-today (format
;; NOTE: AND β€œ&” bindings tigher than OR β€œ|”.
;; TODO [LOW PRIORITY]: The second clause, on WAITING, should reference this week. E.g., state entered this week.
"-recurring&LEVEL=2&TODO=\"DONE\"&CLOSED>=\"<-%sd>\"|-recurring&LEVEL=2&TODO=\"WAITING\"" it))
((org-agenda-overriding-header "What I've done so far this week")))
;; Section on what I β€œCompleted Today”. Not useful now in my life since I do 1 or do large non-recuring tasks per day.
;; (tags "CLOSED>=\"<today>\"" ((org-agenda-overriding-header "\nCompleted today\n")))
(tags "-Someday+todo=\"STARTED\""
((org-agenda-overriding-header "Please 𝒓𝒆𝒅𝒖𝒄𝒆 the number of (unscheduled) open loops")
(org-agenda-skip-function '(org-agenda-skip-entry-if 'scheduled))))
))))

(defmacro with-today (&rest body)
"Evaluate BODY which may mention `it' to refer to the numeral denoting today"
`(-let [it (calendar-day-of-week (calendar-current-date))] ,@body))

(with-today it)

(setq org-agenda-span 'day)

(defun replace-in-buffer (regexp replacement)
"Perform a regexp replace in the entire buffer."
(save-excursion
(goto-char (point-min))
(while (re-search-forward regexp nil t)
)

;; Press β€œ?” on a leading headline star to see other speed commands.
;;
;; Press β€œd” to mark a task as DONE without logging any meta-data
(add-to-list 'org-speed-commands (cons "d"
(cl-defun my/mark-as-DONE-without-logging-meta-data ()
(org-narrow-to-subtree)
(replace-in-buffer (concat "\\(^\\*+ \\)" org-todo-regexp "?") "\\1DONE") (widen)
(message "Nicely π‘‘π‘œπ‘›π‘’!"))))

(cl-defmacro my/work-links (type url &optional (export-display '(format "%s-%s" type label)))
"Given a link of TYPE with a URL, produce the correct org-link.
Expand Down Expand Up @@ -2326,7 +2431,7 @@ Usage:
(interactive "p")
(-let [org-capture-templates
;; I'm using omega π“Œ as a placeholder; i.e., a gensym-like key.
`(("π“Œ" ,,name entry (file+headline ,,org-default-notes-file ,,location) ,,template))]
`(("π“Œ" ,,name entry (file+headline ,,org-default-notes-file ,,location) ,,template :clock-in t :clock-keep t))]
(org-capture (list prefix) "π“Œ")
(unless (> prefix 1) (rename-buffer ,name)))))

Expand Down
Loading

0 comments on commit de4fb8e

Please sign in to comment.