ml729 / org-habit-stats

Stats and visuals for Emacs org-mode habits
GNU General Public License v3.0
63 stars 4 forks source link

feature request: org-habit-stats-review function #4

Open ParetoOptimalDev opened 10 months ago

ParetoOptimalDev commented 10 months ago

I think an easy way to implement this would be:

The agenda you can get with just:

(let ((org-agenda-sticky t) ;; avoid clobbering users org-agenda in use
        (org-agenda-custom-commands 
         '(("H" "Habits" tags-todo "STYLE=\"habit\""
            ((org-agenda-overriding-header "*Habits Review*")
             (org-agenda-sorting-strategy
              '(todo-state-down effort-up category-keep)))))))
  (org-agenda nil "H"))

I'm not quite sure how to make a minor (err major?) mode to then use that agenda as I describe above.

Here is elisp code that demonstrates what I mean and works though:

(defun next-habit-and-show-stats ()
  (interactive)
  (if (progn (next-line) (eobp))
      (goto-char (point-min)))
  (org-agenda-next-item 1)
  (org-habit-stats-view-habit-at-point-agenda))

(defun review-habits ()
  (interactive)
  (let ((org-agenda-sticky t) 
          (org-agenda-custom-commands 
           '(("H" "Habits" tags-todo "STYLE=\"habit\"" 
              ((org-agenda-overriding-header "*Habits Review*") 
               (org-agenda-sorting-strategy
                '(todo-state-down effort-up category-keep)))))))
      (org-agenda nil "H")
      (next-habit-and-show-stats))
  (with-current-buffer "*Org Agenda(H:STYLE=\"habit\")*"
    (next-habit-and-show-stats)))
ParetoOptimalDev commented 10 months ago

Here is something that basically adds "next" habit functionality from the org-habit-stats-mode buffer. I'm out of time but was meaning to make a function called "org-habit-stats-review" that opens the first habit.

This is all very hacky and likely not the best way, but hopefully it's a good starting point.

Code:

(define-minor-mode habits-review-mode
  "Mode for reviewing habits."
  :lighter " Review"
  :keymap (let ((map (make-sparse-keymap)))
            (define-key map (kbd "n") 'next-habit-and-show-stats)
            map)
  (init-habits-agenda-buffer)
  (defun next-habit-and-show-stats ()
    (interactive)
    (init-habits-agenda-buffer)
    (with-current-buffer "*Org Agenda(H:STYLE=\"habit\")*"
      (if (progn (forward-line) (eobp))
      (goto-char (point-min)))
      (org-agenda-next-item 1)
      (org-habit-stats-view-habit-at-point-agenda)))

  (defun init-habits-agenda-buffer ()
    (unless (get-buffer "*Org Agenda(H:STYLE=\"habit\")*")
      (let ((org-agenda-sticky t) 
            (org-agenda-custom-commands 
             '(("H" "Habits" tags-todo "STYLE=\"habit\"" 
        ((org-agenda-overriding-header "*Habits Review*") 
         (org-agenda-sorting-strategy
          '(todo-state-down effort-up category-keep)))))))
    (org-agenda nil "H")
    (next-habit-and-show-stats))))
  )

(add-hook 'org-habit-stats-mode-hook 'habits-review-mode)