Ihor Radchenko <yanta...@gmail.com> writes: >> To reproduce this curious behavior, you only need this configuration: > > Confirmed. > > Something inside `org-todo' call in the hook triggers recursive-edit > that, in turn, triggers premature call to post-command-hook containing > note saving function.
I was wrong. Your bug has little to do with recursive edits. It is related to the fact that log notes rely on global variables to save the information about the note and record it in `post-command-hook'. What is happening is that `org-add-log-setup' is first called for the child heading and then called for the parent heading in `org-after-todo-statistics-hook'. The second call overwrites the global note state. Later, after Emacs finish executing the user command, `org-store-log-note' is called, but it only sees the overwritten log state - the one for the most recent call to `org-add-log-setup' (parent heading). Thus only parent heading gets the actual note record. We can solve the issue in multiple ways: 1. We may force recording the previous note (if any) at the beginning of `org-add-log-setup'. 2. We may alter `org-add-log-setup' to record the note using recursive edit. This way, every log note will be recorded immediately upon request. 3. We may maintain a log queue and record multiple logs one-by-one in post-command-hook. I personally like option 2, but I am not sure about side effects. -- Ihor Radchenko, 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