Sometimes when I close all the folds in org mode one of my headings becomes invisible.
It depends on where my cursor is at the time of the fold. But despite my testing I don't know a hard fast rule for where the cursor needs to be to reproduce it. Although it occurs often enough that I can reproduce it by blind guessing a cursor point and calling
C-u C-u org-cycle-folds.
This is an example of an invisible heading:
This is what the org document should look like:
To fix this I have looked into
(add-advice #'org-cycle-folds :after (lambda () (redraw-display))
Unfortunately and unusually this did not work. Or, at least, when the display was redrawn it was redrawn with the hidden fold.
The only solution that seems to work is placing my cursor on the heading.
Based on this I made a hack that seems to work (I haven't been able to reproduce the problem again).
(advice-add #'org-cycle :after (lambda (&rest rest) (next-line) (previous-line))) ;; I also tested this for evil and it works the same way (advice-add #'evil-close-folds :after (lambda () (next-line) (previous-line)))
Interestingly, If I do
(save-excursion (next-line) (previous-line)) (which I tried because I'm paranoid and think I could end up on different original point somehow), it doesn't work.
Of course, this not the best solution. What confuses me the most is what exactly triggers the heading to display correctly. I know it's associated with moving the point into the heading, which is why I move to the next line and back again.
Any ideas as to what's actually responsible for this heading hiding and how I can resolve it in a more direct way (rather than the hacky way I have)?