On 2026-06-07 09:05, Ihor Radchenko wrote:
> The reason I added that let-binding, is to preserve existing behavior.
> Without let-binding, that patch would risk more breaking changes.
> The let-binding also makes sure that the window behavior is the same
> regardless of the value of `org-agenda-follow-indirect'.
> If you want to avoid that let-binding, having a dedicated customization
> would make more sense.

Alright, I’ll leave it be then. Perhaps it should be stated somewhere
that ‘org-indirect-buffer-display’ is ignored when following in
agendas.

>> +    (save-restriction
>> +      (when (or (< pos (point-min))
>> +                (> pos (point-max)))
>> +        (widen))
>> +      (goto-char pos)
>> +      (org-tree-to-indirect-buffer arg)))))
> 
> Nitpick: (unless (<= (point-min) pos (point-max)) ...)
> would be more compact.

Done in v2.

-- 
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 11434afc24ebee39c67082f93fe3da66ca3f0f76 Mon Sep 17 00:00:00 2001
From: "Jacob S. Gordon" <[email protected]>
Date: Wed, 24 Jun 2026 04:20:00 -0400
Subject: [PATCH v2] ; org-agenda: Ensure the correct tree is chosen for
 indirect buffers

* lisp/org-agenda.el (org-agenda-tree-to-indirect-buffer): Widen the
buffer before jumping to inaccessible trees, and preserve
restrictions.
---
 lisp/org-agenda.el | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index b6acbce52..e3b862e3f 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -9738,8 +9738,10 @@ (defun org-agenda-tree-to-indirect-buffer (arg)
 	 (pos (marker-position marker)))
     (with-current-buffer buffer
       (save-excursion
-	(goto-char pos)
-	(org-tree-to-indirect-buffer arg))))
+	(save-restriction
+	  (unless (<= (point-min) pos (point-max)) (widen))
+	  (goto-char pos)
+	  (org-tree-to-indirect-buffer arg)))))
   (setq org-agenda-last-indirect-buffer org-last-indirect-buffer))
 
 (defvar org-last-heading-marker (make-marker)
-- 
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