0

For some reason, I can't get either of these to work. I'm trying to update the statistics cookies on TODO's automatically when the file saves.

(add-hook 'after-save-hook 'org-update-statistics-cookies)
(add-hook 'after-save-hook (lambda () (org-update-statistics-cookies (current-buffer))))

Both give me the following error:

run-hooks: Wrong number of arguments: #<subr org-update-statistics-cookies>, 0
0

1 Answer 1

0

Calling org-update-statistics-cookies with the current buffer as argument is misleading but it would probably work anyway (because it would not be nil).

But if you added both functions to the hook, that would explain why you get the error: the first (wrong) addition to the hook is run even after you add the second (more-or-less correct) function to it. Both functions get to run, the second one really doing the job of updating the cookies, the first one failing with the indicated error.

Check the hook with C-h v after-save-hook and if you find the first addition there, clean it up:

(remove-hook 'after-save-hook #'org-update-statistics-cookies)

And clean up the second to just use t, not the value that current-buffer returns (which is irrelevant and misleading here):

(add-hook 'after-save-hook (lambda () (org-update-statistics-cookies t)))

See the doc string of the function with C-h v org-update-statistics-cookies.


EDIT: Actually, I'm not sure after-save-hook is the correct hook to use: it is run after the buffer is saved to its file, but the hook would then modify the buffer. But it's likely that before-save-hook is a better choice: the hook is run just before the buffer is saved, so any modifications to the buffer by the hook will also be saved.

I haven't tested however so take all this with a grain of salt.

1
  • Thank you, after-save-hook worked just fine. Commented Apr 12, 2023 at 23:11

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.