1

The following example implements an internal link to a headline:

* Heading1
- Important facts
* Heading2
- Jump to [[*Heading1][Link]]

When following/opening the "Link" with C-c C-o, point moves to "Heading1". If the headline is closed, I would like it to open (unfold, expand) automatically when point lands. If the headline is already open, then do nothing (meaning, org-cycle can't be used).

1
  • 1
    You can use org-show-subtree.
    – NickD
    May 28 '20 at 18:00
2

Something like this perhaps:

(defun sw-org-unfold-headline-maybe ()
  (when (eq (car (org-element-at-point)) 'headline)
    (org-show-subtree)))

(add-hook 'org-follow-link-hook #'sw-org-unfold-headline-maybe)

The hook runs the function after the link has been followed and the function checks that it's at a headline before it unfolds it. There may be some spurious headline unfoldings though: I doubt that the function is selective enough as is.

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.