On 2026-02-01 06:39, Ihor Radchenko wrote:
> That makes sense, but please also update the docstring to explicitly
> reflect the new behavior. Respecting narrowing is not consistent
> across Org commands, so respecting narrowing is not a given.

Makes sense, done in v2 attached.

Thanks,

-- 
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 817bd91f2a8e1763643d2dd28959cabaa77a991a Mon Sep 17 00:00:00 2001
From: "Jacob S. Gordon" <[email protected]>
Date: Mon, 2 Feb 2026 16:20:00 -0500
Subject: [PATCH v2] org-update-statistics-cookies: Respect narrowing

* etc/ORG-NEWS (Important announcements and breaking changes):
Announce change.
* lisp/org.el (org-update-statistics-cookies): Only update cookies
in the accessible portion of the buffer when called with a prefix
argument.
---
 etc/ORG-NEWS | 5 +++++
 lisp/org.el  | 8 +++++---
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 966eafab4..72152e15a 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -174,6 +174,11 @@ Previously, =1=, =2=, and =3= would insert priorities =A=, =B=, and
 insert ~org-priority-highest~, ~org-priority-default~, and
 ~org-priority-lowest~, respectively.
 
+*** Update of statistics cookies now respects narrowing
+
+Calling ~org-update-statistics-cookies~ with a prefix argument will
+now only update 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..ef02e657e 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -10016,12 +10016,14 @@ (defun org-entry-blocked-p ()
 (defun org-update-statistics-cookies (all)
   "Update the statistics cookie, either from TODO or from checkboxes.
 This should be called with the cursor in a line with a statistics
-cookie.  When called with a \\[universal-argument] prefix, update
-all statistics cookies in the buffer."
+cookie.  When called with a \\[universal-argument] prefix, update all
+statistics cookies in the accessible portion of the buffer, i.e.,
+respect narrowing."
   (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: 53c28d27d07d7338267eb217d161fdffb71b7796
-- 
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