From 4ecf1e12de6c06c51058af1d2fc8da9c735b62be Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Wed, 30 Dec 2015 13:02:05 -0500 Subject: [PATCH] Add a dynamic block for generating a habit summary --- org-habit-streaks.el | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/org-habit-streaks.el b/org-habit-streaks.el index e017ddb..704fb9b 100644 --- a/org-habit-streaks.el +++ b/org-habit-streaks.el @@ -68,5 +68,29 @@ 0))) (list current-streak streaks))) +;;;###autoload +(defun org-dblock-write:habit-summary (params) + (let ((streaks (org-map-entries + (lambda () + (list (org-get-heading t t) + (let ((org-habit-streaks-preceding-days 365)) + (org-habit-streaks)))) + "STYLE=\"habit\"+TODO=\"TODO\""))) + (insert "| Habit | Best Streak | Current Streak |\n") + (insert "|-\n") + (insert (mapconcat (lambda (row) + (let ((habit (first row)) + (best-streak (first (-sort #'> (-map #'length (cdr (second row)))))) + (current-streak (car (second row)))) + (concat "| " + (mapconcat (apply-partially 'format "%s") + (list habit best-streak current-streak) + " | ") + "|"))) + streaks + "\n")) + (org-table-align))) + + (provide 'org-habit-streaks) ;;; org-habit-streaks.el ends here