0

I try to automatically refresh statistics cookies while changing buffer to org buffer, saving buffer, showing agenda and refreshing agenda.

I know it's possible to update entire file by calling org-update-statistics-cookies with prefix.

Any ideas?

  • 1
    I presume you are changing state manually, so the cookie is not updated? If you change the state of e.g. a checkboxed list item with C-c C-c, the cookie gets updated automatically and you don't have to run a manual update. Similarly using C-c C-t (or the fast-todo-selection keys) to change a TODO item state, will update the cookie automatically. – NickD Jul 30 at 19:11
0

This did the trick.

(defun jarfar/org-update-all-statistics-cookies ()
   "Update all statistics cookies in org buffer."
   (when (string-equal major-mode "org-mode")
     (org-update-statistics-cookies t)))

(add-hook 'buffer-list-update-hook 'jarfar/org-update-all-statistics-cookies)

(advice-add 'save-buffer :before (lambda (&rest args) (jarfar/org-update-all-statistics-cookies)))


EDIT Sadly this messes things up.

When cookies get updated the file is market as modified even if there were no change, so it cause constant problems with unsaved changes. It's better to refresh cookies manually.

| improve this answer | |

Your Answer

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

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