emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Add org-agenda-show-indirect variable
@ 2019-08-23  2:53 tumashu
  2019-09-01 14:28 ` Adam Porter
  0 siblings, 1 reply; 4+ messages in thread
From: tumashu @ 2019-08-23  2:53 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 1 bytes --]



[-- Attachment #1.2: Type: text/html, Size: 86 bytes --]

[-- Attachment #2: 0001-Add-org-agenda-show-indirect-variable.patch --]
[-- Type: application/octet-stream, Size: 2060 bytes --]

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Add org-agenda-show-indirect variable
  2019-08-23  2:53 [PATCH] Add org-agenda-show-indirect variable tumashu
@ 2019-09-01 14:28 ` Adam Porter
  2019-09-02  0:59   ` tumashu
  0 siblings, 1 reply; 4+ messages in thread
From: Adam Porter @ 2019-09-01 14:28 UTC (permalink / raw)
  To: emacs-orgmode

tumashu <tumashu@163.com> writes:

> +      (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)))))

1.  That does not affect only ibuffer, but most any code that lists
buffers.

2.  Please don't hide indirect buffers this way.  The user won't be able
to switch back to it without enabling the display of hidden buffers.
That will be unexpected, and many users wouldn't even know that such a
thing can be done.  So if the user was working in that indirect buffer,
how will he get back to it?

Also, indirect buffers are not automatically cleaned up; according to
the manual, if their base buffer is killed, they merely cannot be made
active again, so hiding them is not a good idea.

3.  What if such an indirect buffer already exists?  i.e. what if the
user activates the command more than once?  It would be good to avoid
creating multiple indirect buffers pointing to the same subtree.

4.  You could give the indirect buffer a useful name, which would also
make it possible to reuse indirect buffers if the user activates the
command more than once.  For example, I use this code in my config:

#+BEGIN_SRC elisp
(defun ap/org-tree-to-indirect-buffer (&optional arg)
  "Create indirect buffer and narrow it to current subtree.
The buffer is named after the subtree heading, with the filename
appended.  If a buffer by that name already exists, it is
selected instead of creating a new buffer."
  (interactive "P")
  (let* ((new-buffer-p)
         (buffer-name
          (let* ((level (org-outline-level))
                 (heading-string (org-link-display-format
                                  (org-get-heading t t))))
            (concat heading-string "::" (buffer-name))))
         (new-buffer
          (or (get-buffer buffer-name)
              (prog1 (condition-case nil
                         (make-indirect-buffer (current-buffer)
                                               buffer-name 'clone)
                       (error (make-indirect-buffer (current-buffer)
                                                    buffer-name)))
                (setq new-buffer-p t)))))
    (switch-to-buffer new-buffer)
    (when new-buffer-p
      (rename-buffer buffer-name)
      (org-narrow-to-subtree))))

(advice-add 'org-tree-to-indirect-buffer
            :override 'ap/org-tree-to-indirect-buffer)
#+END_SRC

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Add org-agenda-show-indirect variable
  2019-09-01 14:28 ` Adam Porter
@ 2019-09-02  0:59   ` tumashu
  2020-02-11 15:41     ` Bastien
  0 siblings, 1 reply; 4+ messages in thread
From: tumashu @ 2019-09-02  0:59 UTC (permalink / raw)
  To: Adam Porter; +Cc: emacs-orgmode











At 2019-09-01 22:28:00, "Adam Porter" <adam@alphapapa.net> wrote:
>tumashu <tumashu@163.com> writes:
>
>> +      (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)))))
>
>1.  That does not affect only ibuffer, but most any code that lists
>buffers.
>
>2.  Please don't hide indirect buffers this way.  The user won't be able
>to switch back to it without enabling the display of hidden buffers.
>That will be unexpected, and many users wouldn't even know that such a
>thing can be done.  So if the user was working in that indirect buffer,
>how will he get back to it?

>Also, indirect buffers are not automatically cleaned up; according to
>the manual, if their base buffer is killed, they merely cannot be made
>active again, so hiding them is not a good idea.

In this condition,  indirect buffer is regard as a kind of *tmp* buffer, it should
be showed only when org-agenda-show-and-scroll-up is called, so hide 
indirect buffers should be a good idea.



>
>3.  What if such an indirect buffer already exists?  i.e. what if the
>user activates the command more than once?  It would be good to avoid
>creating multiple indirect buffers pointing to the same subtree.

Seem to no this problem, org-tree-to-indirect-buffer can deal with this .

>
>4.  You could give the indirect buffer a useful name, which would also
>make it possible to reuse indirect buffers if the user activates the
>command more than once.  For example, I use this code in my config:

Do not reuse indirect buffer. for it is a kind of "tmp" buffer.

>
>#+BEGIN_SRC elisp
>(defun ap/org-tree-to-indirect-buffer (&optional arg)
>  "Create indirect buffer and narrow it to current subtree.
>The buffer is named after the subtree heading, with the filename
>appended.  If a buffer by that name already exists, it is
>selected instead of creating a new buffer."
>  (interactive "P")
>  (let* ((new-buffer-p)
>         (buffer-name
>          (let* ((level (org-outline-level))
>                 (heading-string (org-link-display-format
>                                  (org-get-heading t t))))
>            (concat heading-string "::" (buffer-name))))
>         (new-buffer
>          (or (get-buffer buffer-name)
>              (prog1 (condition-case nil
>                         (make-indirect-buffer (current-buffer)
>                                               buffer-name 'clone)
>                       (error (make-indirect-buffer (current-buffer)
>                                                    buffer-name)))
>                (setq new-buffer-p t)))))
>    (switch-to-buffer new-buffer)
>    (when new-buffer-p
>      (rename-buffer buffer-name)
>      (org-narrow-to-subtree))))
>
>(advice-add 'org-tree-to-indirect-buffer
>            :override 'ap/org-tree-to-indirect-buffer)
>#+END_SRC
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Add org-agenda-show-indirect variable
  2019-09-02  0:59   ` tumashu
@ 2020-02-11 15:41     ` Bastien
  0 siblings, 0 replies; 4+ messages in thread
From: Bastien @ 2020-02-11 15:41 UTC (permalink / raw)
  To: tumashu; +Cc: Adam Porter, emacs-orgmode

Hi Tumashu and Adam,

what is the value of this addition?

If integrating it into Org is useful, can you resubmit a final patch
for this?

Thanks!

-- 
 Bastien

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-02-11 15:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-23  2:53 [PATCH] Add org-agenda-show-indirect variable tumashu
2019-09-01 14:28 ` Adam Porter
2019-09-02  0:59   ` tumashu
2020-02-11 15:41     ` Bastien

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).