At 2019-09-01 22:28:00, "Adam Porter" <a...@alphapapa.net> wrote:
>tumashu <tuma...@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
>