I like to move through past days in org-agenda and see every task I logged done on that day. In order to do this, I wrote a function (my/archive-repeating-task) that checks if a task repeats and, if so, captures a copy of the task with today's date to an archive buffer. I use another function (my/org-done-task) to call this function as well as mark the task as done. Here are the two functions and the simple capture template:

(defun my/archive-repeating-task ()
  ;; check if repeating task
  (if (org-get-repeat)   
    ;; copy task without todo state text                  
    (let ((copied-header (substring (org-get-heading) 5 nil)))
      ;; go to archive capture template and 
      ;; insert heading to be logged to archive (capture "r")
      (org-capture nil "r")
      (insert "DONE " copied-header)
      ;; add scheduling information to reflect task done today
      (newline 1)
      (let ((current-prefix-arg '(16)))
        (insert "CLOSED: ")
        (call-interactively 'org-time-stamp-inactive)
        (insert " SCHEDULED: ")
        (call-interactively 'org-time-stamp))
      ;; finalize capture template

(defun my/org-done-task ()
   (my/archive-repeating-task) ;; check if repeating, copy to archive if so
   (org-todo "DONE")) ;; mark task as done

(setq org-capture-templates
      '(("r" "Archive Repeats" entry (file+headline "~/org/archive.org" "Repeating Tasks")
         "* %?"))

The functions do what they are meant to do in my current set-up (emacs 26.3 build 1, org-mode 9.3.6); however, there is one weird behavior that I have not been able to figure out.

In vanilla emacs, after marking a repeating task as done (org-todo "DONE"), a message appears in the echo area reflecting the newly scheduled date of the repeating task. For example, marking a repeating tasks due today (Sunday 2020-04-26) done produces the following message:

Entry repeats: SCHEDULED: <2020-04-27 Mon ++1d>

This message does not appear if a non-repeating task is marked done (what you would expect).

If I run my/org-done-task on a repeating task, an "entry repeats" message appears. If I subsequently run this function on a non-repeating task, I get the most recent "entry repeats" message again in the echo area. This message appears even through the task is not rescheduled. I have tried adding (message nil) everywhere to locate the issue, but nothing seems to make the message stop. Restarting emacs gets rid of the message for non-repeating tasks but only if I don't run the function on a repeating task first.

So, the core of the issue is that running the function on a repeating task means that same "entry repeats" message will be shown anytime a non-repeating task is marked done. The message does change, however, when the function is run on a different repeating task.

To reproduce the behavior, run my/org-done-task first on task 1 and then on task 2:

* TODO Task 1 Repeating
  SCHEDULED: <2020-04-26 Sun ++1d>

* TODO Task 2 Non-repeating
  SCHEDULED: <2020-04-26 Sun>

I have the following in my init file:

(setq org-log-done 'note)
(setq org-log-into-drawer t)

The message appears only after the state change has been logged in the LOGBOOK under the task. (There is a slight delay between marking the task as done and when the state change appears in the LOGBOOK.)

I have scoured the org source file, but I'm coming up empty handed. This is more an annoyance than anything as the function does what it's meant to do, but now I'm curious why the "entry repeats" message seems to get stuck on the repeating task that was most recently marked done. Anyone have any suggestions?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.