emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Treat habits as ordinary tasks
@ 2024-07-09  2:50 Patrick Nicodemus
  2024-07-10 19:17 ` Ihor Radchenko
  0 siblings, 1 reply; 2+ messages in thread
From: Patrick Nicodemus @ 2024-07-09  2:50 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 787 bytes --]

Any task which is a habit is listed in a special portion of the agenda for
consistency tracking. This is useful and convenient. However, this
apparently conflicts with scheduling the habit for a certain time. For
example, if I want to go for a run on Tuesday at 5pm, I would like to have
the option to schedule my running habit for 5pm on Tuesday and have it
appear in the agenda at that position.

Ideally I would like to toggle the features of the habit module on and off,
so that in the agenda view, habits are treated either as normal tasks at a
particular time, or they appear in the consistency tracker window rather
than the schedule. Is there a way to accomplish this?

Note that I don't want to filter (remove) the habits from the agenda. I am
familiar with this functionality.

[-- Attachment #2: Type: text/html, Size: 876 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Treat habits as ordinary tasks
  2024-07-09  2:50 Treat habits as ordinary tasks Patrick Nicodemus
@ 2024-07-10 19:17 ` Ihor Radchenko
  0 siblings, 0 replies; 2+ messages in thread
From: Ihor Radchenko @ 2024-07-10 19:17 UTC (permalink / raw)
  To: Patrick Nicodemus; +Cc: emacs-orgmode

Patrick Nicodemus <gadget142@gmail.com> writes:

> Any task which is a habit is listed in a special portion of the agenda for
> consistency tracking. This is useful and convenient. However, this
> apparently conflicts with scheduling the habit for a certain time. For
> example, if I want to go for a run on Tuesday at 5pm, I would like to have
> the option to schedule my running habit for 5pm on Tuesday and have it
> appear in the agenda at that position.
>
> Ideally I would like to toggle the features of the habit module on and off,
> so that in the agenda view, habits are treated either as normal tasks at a
> particular time, or they appear in the consistency tracker window rather
> than the schedule. Is there a way to accomplish this?
>
> Note that I don't want to filter (remove) the habits from the agenda. I am
> familiar with this functionality.

This is no built-in way to toggle this, but I can give you pointers how
to achieve what you want.

The reason why habits are grouped together is the default value of
`org-agenda-sorting-strategy':

org-agenda-sorting-strategy is a variable defined in ‘org-agenda-sort.el’.

Its value is
((agenda habit-down time-up urgency-down category-keep)
 (todo urgency-down category-keep) (tags urgency-down category-keep)
 (search category-keep))

As you can see, for "agenda" blocks, the first sorting key is
"habit-down" causing all habits go after non-habits.

To get the habits sorted by time (I assume that you are looking for your
habits to appear in the time grid), you need to remove "habit-down" from
the sorting strategy.

You can write a small helper command to do this:

(defvar my/org-agenda-sorting-strategy-pre nil
  "Previous value of `org-agenda-sorting-strategy'.")
(defun my/org-agenda-toggle-habit-grouping ()
  "Toggle grouping of habits in agendas.
Does not work when custom agenda command defines local sorting strategy."
  (interactive)
  (org-agenda-check-type t 'agenda)
  (if my/org-agenda-sorting-strategy-pre
      (progn
	(setq org-agenda-sorting-strategy my/org-agenda-sorting-strategy-pre)
        (setq my/org-agenda-sorting-strategy-pre nil)
        (org-agenda-redo)
        (message "Habit grouping ON"))
    (let ((old-strategy (alist-get 'agenda org-agenda-sorting-strategy)))
      (if (not (or (memq 'habit-up old-strategy) (memq 'habit-down old-strategy)))
	  (user-error "Habits are not grouped in agendas: %S" old-strategy)
	(setq my/org-agenda-sorting-strategy-pre (copy-alist org-agenda-sorting-strategy))
        (setf (alist-get 'agenda org-agenda-sorting-strategy) (delete 'habit-up (delete 'habit-down old-strategy)))
        (org-agenda-redo)
        (message "Habit grouping OFF")))))

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-07-10 19:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-09  2:50 Treat habits as ordinary tasks Patrick Nicodemus
2024-07-10 19:17 ` Ihor Radchenko

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).