On 2026-01-31 09:41, Ihor Radchenko wrote:
>> Calling ‘org-update-statistics-cookies’ with a prefix argument (‘C-u
>> C-c #’) and point anywhere in the checklist correctly updates the
>> cookies (‘[0/3]’ and ‘[0/2]’, respectively), but calling it outside
>> produces incorrect ones (‘[0/1]’ and ‘[0/0]’, respectively).
>> --8<--
> 
> Not outside list, but outside the heading containing the cookie.

Yes, sorry about the ambiguity.

> Fixed, on main.
> https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=0efcbc617

Thanks, works for me!

I noticed something unrelated to this bug, but since it’s in the same
area I thought I’d hijack the thread.  If you call
‘org-update-statistics-cookies’ with a prefix argument on the
following buffer the cookies will update correctly, but not if you’re
narrowed to one of the top-level subtrees:

* Test [0/2]
** TODO Subtask
** TODO Subtask
* Test [0/0]
** TODO Subtask
** TODO Subtask

Attached is a simple fix that calls ‘org-update-checkbox-count’ with
an appropriate symbol when the buffer is narrowed.

Best,

-- 
Jacob S. Gordon
[email protected]
Please don’t send me HTML emails or MS Office/Apple iWork documents.
https://useplaintext.email/#etiquette
https://www.fsf.org/campaigns/opendocument
From 1f4228676391e5303f0648a924d94c82214c2306 Mon Sep 17 00:00:00 2001
From: "Jacob S. Gordon" <[email protected]>
Date: Sat, 31 Jan 2026 16:20:00 -0500
Subject: [PATCH v1] org-update-statistics-cookies: Respect narrowing

* lisp/org.el (org-update-statistics-cookies): When narrowed and
called with a prefix argument, only update cookies in the accessible
portion of the buffer.
* etc/ORG-NEWS (Important announcements and breaking changes):
Announce change.
---
 etc/ORG-NEWS | 6 ++++++
 lisp/org.el  | 3 ++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 966eafab4..6a0605dd2 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -174,6 +174,12 @@ Previously, =1=, =2=, and =3= would insert priorities =A=, =B=, and
 insert ~org-priority-highest~, ~org-priority-default~, and
 ~org-priority-lowest~, respectively.
 
+*** Updating statistics cookies now respects narrowing
+
+When narrowed, calling ~org-update-statistics-cookies~ with a prefix
+argument will now only touch cookies in the accessible portion of the
+buffer.
+
 ** New features
 
 # We list the most important features, and the features that may
diff --git a/lisp/org.el b/lisp/org.el
index 172b5c559..92e71a2b2 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -10021,7 +10021,8 @@ (defun org-update-statistics-cookies (all)
   (interactive "P")
   (if all
       (progn
-	(org-update-checkbox-count 'all)
+	(org-update-checkbox-count
+	 (if (buffer-narrowed-p) 'narrow 'all))
 	(org-map-region 'org-update-parent-todo-statistics
                         (point-min) (point-max)))
     (if (not (org-at-heading-p))

base-commit: 0efcbc617cd8e7a284fada9eaf03716d1d4c2f51
-- 
Jacob S. Gordon
[email protected]
Please don’t send me HTML emails or MS Office/Apple iWork documents.
https://useplaintext.email/#etiquette
https://www.fsf.org/campaigns/opendocument

Reply via email to