4

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 !

2 Answers 2

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.

3
  • 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 ! Dec 15, 2016 at 11:12
  • Okay, I've updated the answer and hopefully it does what you want. Dec 15, 2016 at 14:39
  • This helped a lot to find a workaroud for this question. Jun 12, 2020 at 11:06
0

There is strange parameters in (org-reveal), it require '(4) to be passed to works right, idk why.

For Org mode:

(defun my/org-fold-hide-other ()
     "Hide other headers and reveal current and don't hide headers and text in opened ones."
     (interactive)
     (save-excursion
       (org-overview) ;; hide others
       (org-reveal '(4)))) ;; reveal current place appropriate)

(add-hook 'org-mode-hook (lambda ()
                           (local-set-key (kbd "C-c e") 'my/org-fold-hide-other))

For outline mode:

(defun my/outline-hide-other ()
     "Hide other headers and don't hide headers and text in opened ones.
like (outline-hide-other)"
     (interactive)
     (save-excursion
       (outline-hide-sublevels 1) ;; hide all, set level to required!
       (outline-show-children) ;; show headers, not shure how and wehere,
       (outline-back-to-heading t) ;; to header in depths
       (outline-show-entry) ;; show local text
       (outline-up-heading 1 t) ;; go upper
       (while ( > (funcall outline-level) 1) ;; while not at first header
           (outline-show-entry)
           (outline-show-children) ;; show subheaders
           (outline-up-heading 1 t) ;; go upper
           )))
   (add-hook 'outline-mode-hook (lambda ()
      (local-set-key (kbd "C-c e") 'my/outline-hide-other))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.