Hey everyone,
In light of some recent [discussion]/[bugs] around narrowing, here’s
one I’ve been encountering. Often I’m narrowed to a tree in larger
files, and when I try to follow with indirect buffers in an agenda
view, sometimes the wrong heading is chosen.
To reproduce:
1. ‘emacs -Q’ / ‘make repro’
2. Use the following setting (if ‘nil’, it will widen first and
there’s no issue):
(setopt org-agenda-follow-indirect t)
3. Add this to the list of agenda files:
* Heading 1
** TODO Task 1
* Heading 2
** TODO Task 2
3. Execute ‘org-todo-list’ (‘M-x org-agenda t’) and enable
‘org-agenda-follow-mode’ (‘F’). You should see both TODOs, and
moving over them with the point should display each in an indirect
buffer in another window.
4. Go back to the file, narrow to one of the headings, e.g. ‘Heading
1’ with ‘org-narrow-to-subtree’ (‘C-x n s’), and go back to the
TODO list.
5. Moving over ‘Task 1’ will correctly show it in an indirect buffer,
but ‘Task 2’ will also show ‘Task 1’! Classic unwidened behaviour.
Patch #1: Fixes this by widening first and saving the restriction.
Patch #2: While fixing #1 I noticed that ‘org-indirect-buffer-display’
is unconditionally let-bound to ‘other-window’ in
‘org-agenda-do-context-action’, ignoring the user choice. I traced
this back to ‘db5478108’ and [this bug], and confirmed that it’s still
fixed. This patch removes it, but I could also imagine people wanting
to have different behaviour when following vs. calling
‘tree-to-indirect-buffer’ directly.
Patch #3: ‘org-agenda-tree-to-indirect-buffer’ really just calls
‘org-tree-to-indirect-buffer’, but has an over-simplified description
of the universal-prefix argument in the docstring. I tried to improve
it.
Thanks,
[discussion]<https://list.orgmode.org/[email protected]/>
[bugs]<https://list.orgmode.org/[email protected]/>
[this bug]
<https://list.orgmode.org/orgmode/[email protected]/>
--
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 404d0590644048d5aed17080e233fec617dc24b2 Mon Sep 17 00:00:00 2001
From: "Jacob S. Gordon" <[email protected]>
Date: Wed, 27 May 2026 16:20:00 -0400
Subject: [PATCH v1 1/3] ; 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 | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 62f9c0c3b..ebc5525d7 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -9729,8 +9729,12 @@ (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
+ (when (or (< pos (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)
base-commit: a7f36181e682df7b93ba5cc4ba1c9728b10d6fc2
--
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 6190c34d0fdabc00a18285d042338a2e642fbf6e Mon Sep 17 00:00:00 2001
From: "Jacob S. Gordon" <[email protected]>
Date: Wed, 27 May 2026 16:21:00 -0400
Subject: [PATCH v1 2/3] org-agenda: Respect org-indirect-buffer-display when
following
* lisp/org-agenda.el (org-agenda-do-context-action): Don't override
'org-indirect-buffer-display'.
---
lisp/org-agenda.el | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index ebc5525d7..90e215219 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -9247,8 +9247,7 @@ (defun org-agenda-do-context-action ()
(when (and (markerp m) (marker-buffer m))
(and org-agenda-follow-mode
(if org-agenda-follow-indirect
- (let ((org-indirect-buffer-display 'other-window))
- (org-agenda-tree-to-indirect-buffer nil))
+ (org-agenda-tree-to-indirect-buffer nil)
(org-agenda-show)))
(and org-agenda-show-outline-path
(org-with-point-at m (org-display-outline-path org-agenda-show-outline-path))))))
--
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 f6086b0ab0cf443ce4f8fbdbd89734d642d3368d Mon Sep 17 00:00:00 2001
From: "Jacob S. Gordon" <[email protected]>
Date: Wed, 27 May 2026 16:22:00 -0400
Subject: [PATCH v1 3/3] ; org-agenda: Improve docstring of
org-agenda-tree-to-indirect-buffer
* lisp/org-agenda.el (org-agenda-tree-to-indirect-buffer): Clarify
behavior of the universal prefix argument.
---
lisp/org-agenda.el | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 90e215219..3b48aecd2 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -9715,11 +9715,15 @@ (defun org-agenda-tree-to-indirect-buffer (arg)
This calls the command `org-tree-to-indirect-buffer' from the original buffer.
With a numerical prefix ARG, go up to this level and then take that tree.
-With a negative numeric ARG, go up by this number of levels.
+If ARG is negative, go up by that number of levels.
-With a `\\[universal-argument]' prefix, make a separate frame for this tree, \
-i.e. don't use
-the dedicated frame."
+When called with a `\\[universal-argument]' prefix or \
+`org-indirect-buffer-display' is `new-frame',
+keep the previous indirect buffer so that you can work with several at
+once Also, if `org-indirect-buffer-display' is `dedicated-frame', the
+`\\[universal-argument]' prefix requests a new frame instead of reusing \
+the dedicated one.
+See `org-tree-to-indirect-buffer'."
(interactive "P" org-agenda-mode)
(org-agenda-check-no-diary)
(let* ((marker (or (org-get-at-bol 'org-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