emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@posteo.net>
To: Patrick Nicodemus <gadget142@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: Treat habits as ordinary tasks
Date: Wed, 10 Jul 2024 19:17:48 +0000	[thread overview]
Message-ID: <87v81d5a5f.fsf@localhost> (raw)
In-Reply-To: <CADZEZBbEu8wz36aF6dnH-FweTiZSryPKKOoCQQpM9x4YoCn-Eg@mail.gmail.com>

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>


      reply	other threads:[~2024-07-10 19:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-09  2:50 Treat habits as ordinary tasks Patrick Nicodemus
2024-07-10 19:17 ` Ihor Radchenko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87v81d5a5f.fsf@localhost \
    --to=yantar92@posteo.net \
    --cc=emacs-orgmode@gnu.org \
    --cc=gadget142@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).