Thanks for the bug report, I can confirm this is happening. I encountered a similar bug where org-agenda-prepare-buffers was causing the same issue when the file hadn't been saved to disk, and I agree that the solution looks good. I've formatted this into a patch and attached it. Might be worth considering too if this is happening anywhere else too, since this is the second time it has come up. On 5/11/21 6:07 AM, mail@kisaragi-hiu.com wrote: > * Reproduction > > 1. emacs -Q > 2. C-x C-f /tmp/new.org RET > 3. Type anything > 4. Type C-u C-c # (C-u org-update-statistics-cookies) to try to update all statistics cookies in the buffer > 5. Notice the "Non-existent agenda file /tmp/new.org." error. > > This doesn't happen if the file already exists. > > I first saw this reported in this reddit thread: https://www.reddit.com/r/orgmode/comments/n9g1yf/is_this_a_bug_with_orgupdatestatisticcookies/ (u/flyin1501 is me) > > * Expectation > > All statistics cookies in the buffer are updated no matter if the buffer's associated file is already created or not. > > * Why this is happening > > - `org-update-statistics-cookies` (C-c #) uses `org-map-entries` to update all cookies. > - `org-map-entries` uses `org-agenda-prepare-buffers` to prepare the file when SCOPE is nil. Excerpt: > > (if (not scope) > (progn > (org-agenda-prepare-buffers > (and buffer-file-name (list buffer-file-name))) > (setq res > (org-scan-tags > func matcher org--matcher-tags-todo-only start-level))) > > - This function complains if the file does not exist, causing the error. > > * Solution (IMO) > > `org-map-entries` is quite complex because of its matching and scoping features; `org-update-statistics-cookies` only updates the current buffer and should use `org-map-region` instead. IMO it should go from > > (if all > (progn > (org-update-checkbox-count 'all) > (org-map-entries 'org-update-parent-todo-statistics)) > > to: > > (if all > (progn > (org-update-checkbox-count 'all) > (org-map-region 'org-update-parent-todo-statistics (point-min) (point-max))) >