0

what I want to achieve

Say a ++2d habit not accomplished yesterday, I don't want it shown in today's agenda view but shown in tomorrow's and 2 days after tomorrow's and so forth.

what I tried

(defun my/several-day-habit-and-not-due-today ()
  "only work for today's habit list"
  (interactive)
  (let ((time (my/floor-time-to-date (org-time-string-to-time (org-entry-get nil "SCHEDULED"))))
        (repeater (org-get-repeat)))
    (string-match "\\([.+]\\)?\\(\\+[0-9]+\\)\\([hdwmy]\\)" repeater)
    (let ((repeater-type (match-string 1 repeater))
          (day (string-to-number (match-string 2 repeater)))
          (what (match-string 3 repeater))
          (today (my/floor-time-to-date)))
      (when (and (equal what "d")
                 (< day 5))
        (while (time-less-p time today)
          (setq time (time-add time (* day 60 60 24))))
        (time-less-p today time)))))

(defun my/org-is-habit-p (&optional pom)
  "Is the task at POM or point a habit?"
  (and (string= "habit" (org-entry-get (or pom (point)) "STYLE" t))
       (not (my/several-day-habit-and-not-due-today)) ;will show in ordinary agenda
       ))

(advice-add 'org-is-habit-p :override 'my/org-is-habit-p)

This way filtered it out as a habit, but it will show as a normal entry in agnda view.

any idea how I can filter it out in today's agenda view?

1 Answer 1

0

I don't use org-habit so I can not provide a full answer, but it looks like you can use a org-agenda-before-sorting-filter-function function for this. Read its docstring to see how it works.

Then make up some predicate expression that checks if a line is one of your particular org-habits and replace it in the appropriate place in the following code block:

(defun org-agenda-yesterday-habit-filter (line)
  ;; (pp line)
  (if (and (= (print (time-to-days (org-time-from-absolute (org-find-text-property-in-string 'date line))))
              (print (org-today)))
           "replace this string with some predicate expression that returns t for your habit")
      nil
    line))

(setq org-agenda-before-sorting-filter-function 'org-agenda-yesterday-habit-filter)

You could uncomment the pp expression to look at the string object in the *Messages* buffer. Also, the if could be replaced by a unless but I leave it in this form here for clarity.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.