1

Q: Which function does org-mode use to log a note with a TODO state change?

Background

org-mode provides the option of adding a note when tracking TODO state changes. That's great.

However, org is also cavalier about changing my window configuration when it adds notes (i.e., it temporarily changes the frame to a two-window layout), which is infuriating.

I've resolved the issue in a different setting when dealing with capture templates by tracking down the offending function (org-capture-place-template) and commenting out the offending line that changes my window configuration.

Problem

I cannot find the analogous function for dealing with todo state changes. The org source code is sometimes rather baroque, and I've gone through the source for org-todo without finding the relevant call. I suspect it's the same problem with a hard-coded change to the window configuration that I need to comment out.

So: what function does org use to log the NOTE with a TODO state change?

2
  • Looks like it adds org-add-log-note to post-command-hook within org-add-log-setup from org-todo.
    – wasamasa
    Sep 9, 2016 at 16:56
  • @wasamasa: yes, that was definitely the one, thank you. Please post it as an answer so I can accept it. For what it's worth, commenting out the (delete-other-windows) line resolves the window-spamming problem.
    – Dan
    Sep 9, 2016 at 17:00

2 Answers 2

1

I've dug into Org a few times before, so how hard could this possibly be? Well, the location is somewhat unusual. If you follow along the sources of org-todo, you can see some comments about state changes to the TODO:

(when (and now-done-p org-log-done)
  ;; It is now done, and it was not done before
  (org-add-planning-info 'closed (org-current-effective-time))
  (if (and (not dolog) (eq 'note org-log-done))
      (org-add-log-setup 'done org-state this 'findpos 'note)))

According to its docstring, org-add-log-setup adds a helper function to post-command-hook:

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

From this one can assume that org-add-log-note is the one we're looking for.

1
  • Thanks for tracking it down. I indeed missed it when scanning through the code. In my half-hearted defense, it's buried pretty deeply around the function's 200th line with cryptic comments.
    – Dan
    Sep 9, 2016 at 19:45
0

If somebody stumbles on this in the search for preventing window config change when changing TODO state (org-todo), I found it in (org-fast-todo-selection).

As I struggled to change this, here is how I did it:

  1. Find out where (org-fast-todo-selection) is
  • M-x helpful-callable (or C-h f)
  • Search for org-fast-todo-selection
  • In the help find 'Defined in' in the Source Code section
  1. Go to the definition and copy the code

  2. Save the function to your init code (like in ~/.emacs)

  3. Rename it
    I use my/org-fast-todo-selection

  4. Alter the malicious code

  • Comment out (delete-other-windows)
  • ;;(delete-other-windows)
  1. Replace the original function
    (advice-add 'org-fast-todo-selection :override #'my/org-fast-todo-selection)

Now our version of (org-fast-todo-selection) without the window alteration. Bliss.

1
  • (org-agenda-get-restriction-and-command) for when opening the agenda. Dec 3, 2023 at 20:28

Your Answer

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

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