From 9cf17c973f889621e2cd6452bcfe3b20d36a072f Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Fri, 29 Jan 2021 17:11:55 +0100 Subject: [PATCH] Show sum of daily efforts directly in the agenda Now that column view does not show effort sums any longer, we need another means to show daily efforts. It turns out that this can be accomplished easily using two simple functions and `org-agenda-finalize-hook`. This is taken from https://emacs.stackexchange.com/questions/21380/show-sum-of-efforts-for-a-day-in-org-agenda-day-title#21902. --- init.el | 4 ++++ site-lisp/db-org.el | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/init.el b/init.el index fb0fa60..f43ec89 100644 --- a/init.el +++ b/init.el @@ -720,6 +720,7 @@ db/org-agenda-list-deadlines db/org-agenda-skip-tag hydra-org-agenda-view/body + db/org-agenda-insert-efforts org-babel-execute:hy db/org-timestamp-difference db/org-capture-code-snippet @@ -1013,6 +1014,9 @@ org-agenda-search-headline-for-time nil org-agenda-search-view-always-boolean t + ;; Show daily efforts directly in the agenda + org-agenda-finalize-hook '(db/org-agenda-insert-efforts) + org-agenda-clock-consistency-checks '(:max-duration 9999999 :min-duration 0 diff --git a/site-lisp/db-org.el b/site-lisp/db-org.el index 33fb5cf..ecf8457 100644 --- a/site-lisp/db-org.el +++ b/site-lisp/db-org.el @@ -181,6 +181,40 @@ _y_: ?y? year _q_: quit _L__l__c_: ?l? (org-agenda-redo))) ("q" (message "Abort") :exit t)) +;; Show sum of daily efforts in agenda, the following two functions are from +;; anpandey, +;; cf. https://emacs.stackexchange.com/questions/21380/show-sum-of-efforts-for-a-day-in-org-agenda-day-title#21902 + +(defun db/org-agenda-calculate-efforts (limit) + "Sum efforts of scheduled entries up to LIMIT in the agenda buffer." + (let (total) + (save-excursion + (while (< (point) limit) + (when (member (org-get-at-bol 'type) '("scheduled" "past-scheduled")) + (push (org-entry-get (org-get-at-bol 'org-hd-marker) "Effort") total)) + (forward-line))) + (org-duration-from-minutes + (cl-reduce #'+ + (mapcar #'org-duration-to-minutes + (cl-remove-if-not 'identity total)))))) + +(defun db/org-agenda-insert-efforts () + "Insert efforts for each day into the agenda buffer. + +Add this function to `org-agenda-finalize-hook'." + (save-excursion + (let (pos) + (while (setq pos (text-property-any + (point) (point-max) 'org-agenda-date-header t)) + (goto-char pos) + (end-of-line) + (insert-and-inherit + (concat " (" + (db/org-agenda-calculate-efforts + (next-single-property-change (point) 'day)) + ")")) + (forward-line))))) + ;;; Capturing