Sort agenda entries by remaining effort by default

This might be slow and buggy, but let's keep it for now.
This commit is contained in:
dbo 2023-04-01 16:57:37 +02:00
parent 1f9e032a1a
commit 0a14f01729
Signed by: dbo
GPG Key ID: 784AA8DF0CCDF625
2 changed files with 33 additions and 4 deletions

10
init.el
View File

@ -731,6 +731,7 @@
db/org-clock-in-work-task
db/show-current-org-task
db/org-remaining-effort-of-current-item
db/org-cmp-remaining-effort
org-dblock-write:db/org-workload-report
endless/org-ispell
db/org-agenda-list-deadlines
@ -1101,10 +1102,11 @@
:init (setq org-agenda-include-diary t
org-agenda-span 1
org-agenda-insert-diary-strategy 'top-level
org-agenda-sorting-strategy '((agenda time-up priority-down effort-up category-keep)
(todo priority-down effort-up category-keep)
(tags priority-down effort-up category-keep)
(search priority-down effort-up category-keep))
org-agenda-sorting-strategy '((agenda time-up priority-down user-defined-up category-keep)
(todo priority-down user-defined-up category-keep)
(tags priority-down user-defined-up category-keep)
(search priority-down user-defined-up category-keep))
org-agenda-cmp-user-defined #'db/org-cmp-remaining-effort
org-agenda-window-setup 'current-window
org-agenda-restore-windows-after-quit t
org-agenda-compact-blocks nil

View File

@ -448,6 +448,33 @@ If no effort is specified, return nil."
(max 0 (- (org-duration-to-minutes effort)
(db/org-clocked-time-for-current-item)))))))
(defun db/org-cmp-remaining-effort (a b)
"Compare the remaining efforts of Org items A and B.
A and B are strings only, but their corresponding Org items are
accessible via the `org-hd-marker' text property."
(let* ((def (if org-agenda-sort-noeffort-is-high 32767 -1))
(ma (or (get-text-property 1 'org-marker a)
(get-text-property 1 'org-hd-marker a)))
(mb (or (get-text-property 1 'org-marker b)
(get-text-property 1 'org-hd-marker b)))
(ea (or (and (markerp ma)
(marker-buffer ma)
(org-with-point-at ma
(--if-let (db/org-remaining-effort-of-current-item)
(org-duration-to-minutes it)
0)))
def))
(eb (or (and (markerp mb)
(marker-buffer mb)
(org-with-point-at mb
(--if-let (db/org-remaining-effort-of-current-item)
(org-duration-to-minutes it)
0)))
def)))
(cond ((> ea eb) +1)
((< ea eb) -1))))
;;; Task Management