Compare commits

...

3 Commits

Author SHA1 Message Date
Daniel - 866f652c4b
Fix nil display in agenda when remaining effort is not set
Just return the empty string instead.
2023-04-01 17:01:00 +02:00
Daniel - 0a14f01729
Sort agenda entries by remaining effort by default
This might be slow and buggy, but let's keep it for now.
2023-04-01 16:57:37 +02:00
Daniel - 1f9e032a1a
Display remaining effort in Org agenda by default
Note that sorting is wrong now, this needs to be fixed later.
2023-04-01 16:50:30 +02:00
2 changed files with 53 additions and 17 deletions

19
init.el
View File

@ -730,6 +730,8 @@
db/org-clock-in-home-task
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
@ -1100,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
@ -1156,10 +1159,10 @@
"")
org-agenda-prefix-format
'((agenda . "%11s%?-12t%-4e ")
(todo . "%-8c%-4e ")
(tags . "%-8c%-4e ")
(search . "%-8c%-4e "))
'((agenda . "%11s%?-12t%-4(db/org-remaining-effort-of-current-item) ")
(todo . "%-8c%-4(db/org-remaining-effort-of-current-item) ")
(tags . "%-8c%-4(db/org-remaining-effort-of-current-item) ")
(search . "%-8c%-4(db/org-remaining-effort-of-current-item) "))
org-agenda-custom-commands
`(("A" "Main Agenda"

View File

@ -204,7 +204,9 @@ shown because they are due)."
'("scheduled" "past-scheduled" "timestamp" "deadline" "block"))
(let ((item-id (org-with-point-at (org-get-at-bol 'org-hd-marker) (org-id-get-create))))
(unless (member item-id already-seen)
(push (org-entry-get (org-get-at-bol 'org-hd-marker) "Effort") total)
(push (org-with-point-at (org-get-at-bol 'org-hd-marker)
(db/org-remaining-effort-of-current-item))
total)
(push item-id already-seen))))
(forward-line))))
(org-duration-from-minutes
@ -425,21 +427,52 @@ is clocked in."
The remaining effort is computed as the planned effort minus the
already clocked time. If this result is negative, return zero.
If no effort is specified, return nil."
If no effort is specified, return an empty string."
(if (derived-mode-p 'org-agenda-mode)
;; XXX: is this the right way to do it?
(org-agenda-with-point-at-orig-entry
nil (db/org-remaining-effort-of-current-item))
(if-let ((hd-marker (org-get-at-bol 'org-hd-marker)))
;; `org-hd-marker' is set, there is some Org item that corresponds to
;; this line. Get the remaining effort from there.
(org-with-point-at hd-marker
(db/org-remaining-effort-of-current-item))
;; We are at some special item in the Org agenda (e.g. some diary
;; entry), just show nothing.
"")
(unless (derived-mode-p 'org-mode)
(user-error "Not in Org mode buffer, aborting"))
(when-let ((effort (org-entry-get (point) "Effort")))
(org-duration-from-minutes
(max 0 (- (org-duration-to-minutes effort)
(db/org-clocked-time-for-current-item)))))))
(if-let ((effort (org-entry-get (point) "Effort")))
(org-duration-from-minutes
(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
(org-duration-to-minutes ; this is inefficient
(db/org-remaining-effort-of-current-item))))
def))
(eb (or (and (markerp mb)
(marker-buffer mb)
(org-with-point-at mb
(org-duration-to-minutes
(db/org-remaining-effort-of-current-item))))
def)))
(cond ((> ea eb) +1)
((< ea eb) -1))))
;;; Task Management