From d4f47d380cc976e6257a10d415811b6e5fde61d2 Mon Sep 17 00:00:00 2001
From: Feng Shu <tumashu@163.com>
Date: Fri, 23 Aug 2019 10:41:13 +0800
Subject: [PATCH] Add org-agenda-show-indirect variable.

* etc/ORG-NEWS (New variable: ~org-agenda-show-indirect~): Add variable news.
* lisp/org-agenda.el (org-agenda-show-indirect): New variable.
(org-agenda-show-and-scroll-up): Using org-agenda-show-indirect.
---
 etc/ORG-NEWS       |  4 ++++
 lisp/org-agenda.el | 12 ++++++++++++
 2 files changed, 16 insertions(+)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 089f62995..0bc3f6f9a 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -415,6 +415,10 @@ leave unfolded subtrees unfolded.
 I.e. treat the whole file as if it was a subtree.
 
 *** Respect narrowing when agenda command is restricted to buffer
+*** New variable: ~org-agenda-show-indirect~
+
+This variable let ~org-agenda-show-and-scroll-up~ show current item in
+indirect buffer.
 
 * Version 9.2
 ** Incompatible changes
diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index c446f155e..67689d058 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -1031,6 +1031,13 @@ current item's tree, in an indirect buffer."
   :version "24.1"
   :type 'boolean)
 
+(defcustom org-agenda-show-indirect nil
+  "Non-nil means `org-agenda-show-and-scroll-up' displays only the
+current item's tree, in an indirect buffer."
+  :group 'org-agenda
+  :version "26.4"
+  :type 'boolean)
+
 (defcustom org-agenda-show-outline-path t
   "Non-nil means show outline path in echo area after line motion."
   :group 'org-agenda-startup
@@ -8744,6 +8751,11 @@ fold drawers."
 	  (ignore-errors (scroll-up)))
       (org-agenda-goto t)
       (org-show-entry)
+      (when org-agenda-show-indirect
+	(let ((org-indirect-buffer-display 'current-window))
+	  (org-tree-to-indirect-buffer)
+	  ;; hide indirect buffer in ibuffer
+	  (rename-buffer (concat " " (buffer-name)))))
       (if arg (org-cycle-hide-drawers 'children)
 	(org-with-wide-buffer
 	 (narrow-to-region (org-entry-beginning-position)
-- 
2.22.0

