title: Emacs org-mode: How can i fold everything but the current headline?
body: <p>I use org-mode to handle my tasks and projects in multiple files.</p>
  
  <p>In the weekly agenda, it is possible to jump to the location of each TODO entry using <code>&lt;TAB&gt;</code> or <code>&lt;RET&gt;</code>. If the target file was not previously open, it is loaded an the cursor is set to the correct headline and <em>the entire document is unfolded, including drawers</em>.</p>
  
  <p>I would very much prefer to see only a sparse tree with everything but the correct headline folded (subtree visibility does not matter).</p>
  
  <p>It is possible to collapse the entire tree by cycling global visibility using <code>C-u &lt;TAB</code>, but then I have to find the heading again.</p>
  
  <p>I know I can hide the rest by narrowing the buffer as described here:
  <a href="https://stackoverflow.com/questions/13720898/emacs-how-can-i-display-only-current-task-and-hide-others-in-org-mode">Emacs, How can I display only current task and hide others in org-mode?</a>
  but then I loose context (parent heading, easy access to siblings) and the drawers are still open.</p>
  
  <p>Ideally, I would like to have a command that shows the following:</p>
  
  <ul>
  <li>The top level headings</li>
  <li>The current headline, and all it's parents up to the top level</li>
  <li>The current headline's children</li>
  </ul>
  
  <p><strong>Edit:</strong></p>
  
  <p>A slighty modified version of the functions <a href="https://stackoverflow.com/users/3173715/user3173715">user3173715</a> posted seems to do the trick:</p>
  
  <pre><code>(defun org-show-current-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-back-to-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)))
  </code></pre>