emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: mail@kisaragi-hiu.com
To: emacs-orgmode@gnu.org
Subject: [bug] C-u org-update-statitics-cookies errors out with "Non-existent agenda file" if current file isn't saved
Date: Tue, 11 May 2021 10:07:28 +0000	[thread overview]
Message-ID: <670485e3bc62d5fde5f32fd60d2af6f3@kisaragi-hiu.com> (raw)

* 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)))


             reply	other threads:[~2021-05-11 10:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-11 10:07 mail [this message]
2021-05-11 11:12 ` [bug] C-u org-update-statitics-cookies errors out with "Non-existent agenda file" if current file isn't saved Nick Savage
2021-05-16 12:23   ` Bastien
2021-05-16 19:49   ` Bastien

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=670485e3bc62d5fde5f32fd60d2af6f3@kisaragi-hiu.com \
    --to=mail@kisaragi-hiu.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).