Reputation: 2091
I found this nifty little function for Org-mode:
;;; Move to next heading with dedicated buffer preview
(defun ded/org-show-next-heading-tidily ()
"Show next entry, keeping other entries closed."
(if (save-excursion (end-of-line) (outline-invisible-p))
(progn (org-show-entry) (show-children))
(outline-next-heading)
(unless (and (bolp) (org-on-heading-p))
(org-up-heading-safe)
(hide-subtree)
(error "Boundary reached"))
(org-overview)
(org-reveal t)
(org-show-entry)
(show-children)))
It moves from headline to headline, and shows its direct content and children.
I liked the idea, but would rather it would show in a dedicated buffer, using (org-tree-to-indirect-buffer)
.
I tried to do it like so:
(defun ded/org-show-next-heading-test ()
"Show next entry, keeping other entries closed."
(if (save-excursion (end-of-line) (outline-invisible-p))
(progn (org-show-entry) (org-tree-to-indirect-buffer))
(outline-next-heading)
(unless (and (bolp) (org-on-heading-p))
(org-up-heading-safe)
(hide-subtree)
(error "Boundary reached"))
(org-overview)
(org-reveal t)
(org-tree-to-indirect-buffer)
(show-children)))
But then I have to double press the key - once it shows the entry in a dedicated buffer and secondly it still shows the entry.
I tried to remove the progn
function, but then it didn't work entirely.
I'm not a lisp programmer, and I tried to play with it for an hour or so but to no avail, so I would love someone with some experience to help me sort this thing :)
Much obliged.
Upvotes: 3
Views: 2002
Reputation: 2091
I ended up making my own, simple functions to navigate more easily:
(defun forward-and-preview ()
"Go to same level next heading and show preview in dedicated buffer"
(hide-subtree)
(org-speed-move-safe (quote outline-next-visible-heading))
(show-children)
(org-tree-to-indirect-buffer)
)
(defun back-and-preview ()
"Go to same level previous heading and show preview in dedicated buffer"
(hide-subtree)
(org-speed-move-safe (quote outline-previous-visible-heading))
(show-children)
(org-tree-to-indirect-buffer)
)
(defun up-back-and-preview ()
"Go to previous level heading and show preview in dedicated buffer"
(org-speed-move-safe (quote outline-up-heading))
(org-tree-to-indirect-buffer)
(hide-subtree)
)
(defun up-forward-and-preview ()
"Go to previous level next heading and show preview in dedicated buffer"
(org-speed-move-safe (quote outline-up-heading))
(hide-subtree)
(org-speed-move-safe (quote outline-next-visible-heading))
(org-tree-to-indirect-buffer)
)
(defun inside-and-preview ()
"Go to next level heading and show preview in dedicated buffer"
(org-speed-move-safe (quote outline-next-visible-heading))
(show-children)
(org-tree-to-indirect-buffer)
)
(add-to-list 'org-speed-commands-user '("l" inside-and-preview))
(add-to-list 'org-speed-commands-user '("j" forward-and-preview))
(add-to-list 'org-speed-commands-user '("k" back-and-preview))
(add-to-list 'org-speed-commands-user '("J" up-forward-and-preview))
(add-to-list 'org-speed-commands-user '("K" up-back-and-preview))
Upvotes: 2
Reputation: 21182
Not quite sure what you want but as far as I can understand you should call org-tree-to-indirect-buffer
at the end:
;;; Move to next heading with dedicated buffer preview
(defun ded/org-show-next-heading-tidily ()
"Show next entry, keeping other entries closed."
(if (save-excursion (end-of-line) (outline-invisible-p))
(progn (org-show-entry) (show-children))
(outline-next-heading)
(unless (and (bolp) (org-on-heading-p))
(org-up-heading-safe)
(hide-subtree)
(error "Boundary reached"))
(org-overview)
(org-reveal t)
(org-show-entry)
(show-children)
(org-tree-to-indirect-buffer)))
If it's not what you want then could you please give more details.
Upvotes: 2