0

I looking for a way to go to the specific line by number in an org file, when the structure is folded. An ideal solution would be to unfold only necessary headings to put the cursor in the line. I was looking for a while for some solution for this, but I didn't find any silver bullet so far.

  • How about just stringing two functions together, such as goto-line and org-show-entry? Like this: (defun goto-line-unfold-subtree () "Doc-string" (interactive) (call-interactively 'goto-line) (org-show-entry)) – lawlist Jan 22 at 15:28
  • @lawlist thanks, I tried this, it position cursor in correct line but only current heading is shown, all intermediate headings are kind of narrowed. Maybe the solution would be to infold entire tree, position the cursor and hide all not related branches. – Adam Faryna Jan 22 at 23:58
  • How about org-show-subtree instead of org-show-entry? – lawlist Jan 22 at 23:59
  • Or, how about adding a third function in series? E.g., (defun goto-line-unfold-subtree () "Doc-string" (interactive) (call-interactively 'goto-line) (org-show-entry) (org-show-subtree)) – lawlist Jan 23 at 0:01
  • @lawlist it kind of works, but the result is messy. I get only 3 lines snippet on cursor new position, rest of the heading content is hidden behind "..." and can't be reveled without unfolding entire tree. I think unfolding entire tree and jumping to the location would be perfect, hidding other subtrees is optional. – Adam Faryna Jan 23 at 0:12
0

Here the function I use

(defadvice goto-line (after unfold-tree activate)
    (when (outline-invisible-p)
      (save-excursion
        (outline-previous-visible-heading 1)
        (org-show-subtree))))
0

You might like to try M-x reveal-mode which will automatically un-hide things so as to make the text around cursor visible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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