3

When using org build subtree navigation functions to move around, I want to show all the content of current one recursively, and hide any other subtrees that having a higher or same level of the current one. How to achieve this ? Thanks !

Saddle Point
  • 481
  • 7
  • 23

1 Answers1

4

Edited in response to first comment

Not quite sure if this is what you want, but here's a function that will show the current subtree (and its children) and fold all other headings to their top level:

(defun ess/org-show-just-me (&rest _)
  "Fold all other trees, then show entire current subtree."
  (interactive)
  (org-overview)
  (org-reveal)
  (org-show-subtree))

Now you can add advices for each command you want to use this function together with:

(advice-add 'org-forward-heading-same-level :after #'ess/org-show-just-me)
(advice-add 'org-backward-heading-same-level :after #'ess/org-show-just-me)

Another alternative is to use org-narrow-to-subtree to hide all other content than the current subtree. It is bound to C-x n s by default. To go back, use widen, bound to C-x n w. A great alternative is narrow-or-widen-dwim.

You could add widen followed by org-narrow-to-subtree to a function and create this as an advice in the same way as the example above.

Erik Sjöstrand
  • 826
  • 4
  • 14
  • I know about `org-narrow-to-subtree`, but I want to show and hide content automatically every time I use a build in function like `org-forward-heading-same-level` to move around. I'll read about `narrow-or-widen-dwim` soon. Thanks ! – Saddle Point Dec 15 '16 at 11:12
  • Okay, I've updated the answer and hopefully it does what you want. – Erik Sjöstrand Dec 15 '16 at 14:39
  • This helped a lot to find a workaroud for [this question](https://emacs.stackexchange.com/questions/58167/org-sort-expands-all-subtrees-and-drawers/59045#59045). – breathe_in_breathe_out Jun 12 '20 at 11:06