Advertisement
Guest User

Untitled

a guest
Mar 31st, 2015
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. (defun org-todo-score (&optional ignore)
  2. "Compute the score of an Org-mode task.
  3. Age gradually decreases the value given to a task. After 28
  4. days, its score is zero.
  5. Effort should act as a multiplier on the value."
  6. 1)
  7.  
  8. (defvar org-categories-pending-hashmap nil)
  9. (defvar org-categories-completed-hashmap nil)
  10.  
  11. (defun org-compute-category-totals ()
  12. (interactive)
  13. (setq org-categories-pending-hashmap (make-hash-table :test 'equal)
  14. org-categories-completed-hashmap (make-hash-table :test 'equal))
  15. (dolist (file '("todo.txt" "archive.txt"))
  16. (with-current-buffer
  17. (find-file-noselect (expand-file-name file "~/Documents/Tasks"))
  18. (save-excursion
  19. (goto-char (point-min))
  20. (while (not (eobp))
  21. (outline-next-heading)
  22. (let* ((state (org-get-todo-state))
  23. (category
  24. (or (org-entry-get (point) "ARCHIVE_CATEGORY" t)
  25. (org-entry-get (point) "CATEGORY" t)))
  26. (hashmap
  27. (cond
  28. ((string= state "TODO") org-categories-pending-hashmap)
  29. ((string= state "DONE") org-categories-completed-hashmap)))
  30. (value (and hashmap (gethash category hashmap 0))))
  31. (if hashmap
  32. (puthash category (+ value (org-todo-score)) hashmap))))))))
  33.  
  34. (defun org-category-total (category)
  35. ;; A category's final score is the sum of all open tasks (which raises the
  36. ;; value), subtracted by the sum of all closed tasks. Thus, a category with
  37. ;; a higher score deserves more attention (it has been neglected or has not
  38. ;; seen much activity), while a category with a low score deserves less.
  39. ;;
  40. ;; Note that this score is affected by several heuristics. See
  41. ;; `org-todo-score'.
  42. (unless org-categories-pending-hashmap
  43. (org-compute-category-totals))
  44. (- (gethash category org-categories-pending-hashmap 0)
  45. (gethash category org-categories-completed-hashmap 0)))
  46.  
  47. (defun org-cmp-category-totals (a b)
  48. (let ((cat-a (get-text-property 1 'org-category a))
  49. (cat-b (get-text-property 1 'org-category b)))
  50. (if (> (org-category-total cat-a)
  51. (org-category-total cat-b))
  52. 1
  53. -1)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement