1

I have a repeating habit such as:

** TODO some habit
SCHEDULED: <2020-05-22 Fri 08:00 .+1d>
:PROPERTIES:
:STYLE: habit
:CREATED:  [2020-05-08 Fri]
:LAST_REPEAT: [2020-05-21 Thu 10:07]
:END:
:LOGBOOK:
- State "DONE"       from "TODO"       [2020-05-21 Thu 10:07]
CLOCK: [2020-05-21 Thu 10:04]--[2020-05-21 Thu 10:06] =>  0:02
:END:

I coded this shortcut, where I commented out my function to clock in and out:

(defun my-org-clock-and-mark-done ()
  (interactive)
  (message "start")
  (org-back-to-heading)
  ;(my-org-clock-in-and-out nil)
  (org-shiftright)
  (message "end")
  )

The result in the *Messages buffer is:

start
Entry repeats: SCHEDULED: <2020-05-22 Fri 08:00 .+1d> 
end
Note stored
Entry repeats: SCHEDULED: <2020-05-22 Fri 08:00 .+1d> 

I suspect that Org mode has a hook that runs after my last line of code, in this case when a repeating cookie is changed, and shows that change message twice.

How can I find and disable that hook?

Update: Following the answer by phils, I added a debugger with (setq debug-on-message "Note stored") so it catches only the second occurrence. It shows these functions, neither of which I could find in the list of hooks, which I found thanks to Muihlinn's comment. The list of calls is below and has two recursive edits, which I find odd:

  org-store-log-note()
  org-add-log-note()
  recursive-edit()
  debug(error ...)
  message("%s" #("Entry repeats: SCHEDULED: ..."))
  org-store-log-note()
  org-add-log-note()
  recursive-edit()
  debug(error #("Entry repeats: SCHEDULED: ..."))
  message("%s" #("Entry repeats: SCHEDULED: ..."))
  org-auto-repeat-maybe("DONE")
  org-todo(right)
  funcall-interactively(org-todo right)
  call-interactively(org-todo)
  org-shiftright()
4
  • 2
    have you checked org-shiftright-hook?
    – Muihlinn
    May 21, 2020 at 10:33
  • 1
    M-x apropos-variable org hook describes Org's hooks.
    – Drew
    May 21, 2020 at 15:42
  • @Muihlinn org-shiftright-hook has value of nil. Besides, the extra lines appear after an additional line after org-shift-right. May 22, 2020 at 20:28
  • @Drew I belive it's M-x apropos-variable RET org hook, and it's very informative, thanks! May 22, 2020 at 20:30

2 Answers 2

1

For this particular case...

In that call to org-auto-repeat-maybe we see this:

(when org-log-repeat
  (if (or (memq 'org-add-log-note (default-value 'post-command-hook))
          (memq 'org-add-log-note post-command-hook))
      ;; We are already setup for some record.
      (when (eq org-log-repeat 'note)
        ;; Make sure we take a note, not only a time stamp.
        (setq org-log-note-how 'note))
    ;; Set up for taking a record.
    (org-add-log-setup 'state
                       (or done-word (car org-done-keywords))
                       org-last-state
                       org-log-repeat)))

Where org-log-repeat is a user option (see which).

org-add-log-setup does this:

(add-hook 'post-command-hook 'org-add-log-note 'append))

And org-add-log-note removes itself from the hook when it runs:

(defun org-add-log-note (&optional _purpose)
  "Pop up a window for taking a note, and add this note later."
  (remove-hook 'post-command-hook 'org-add-log-note)
  ...)

So if org-log-repeat is non-nil, post-command-hook will be running org-add-log-note.

3
  • This removes the second notification (with Note stored and Entry repeats...) and also the state change from being logged in the logbook drawer. Can the first happend without the second? May 25, 2020 at 13:09
  • 1
    I honestly don't know what any of this stuff is for, so I'm not in a position to recommend any changes. I'm just pointing you to the mechanisms behind it.
    – phils
    May 25, 2020 at 20:09
  • I fixed the problem with code similar to the mechanism: add another post-command-hook after calling org-shiftright, then removing it from the called function. This way, my code is the last to run and stays displayed in the mini-buffer. May 27, 2020 at 11:04
2

M-: (setq debug-on-message "Entry repeats: SCHEDULED")

The stack traces should show you what is causing each instance of that message.

See C-hig (elisp)Using Debugger for help on the debugger.

When you're done, M-: (setq debug-on-message nil)

1
  • I updated the question after running this debugger. May 22, 2020 at 20:38

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.