I just need a function that will say if a heading is collapsed or not.

Need it to ensure an open heading, because org-cycle, well, cycles and it appears there are no good alternatives (e.g. org-show-entry shows ellipsis instead of children).

  • 1
    Why not using org-show-subtree on the headline in question? – Tobias Sep 11 '19 at 13:03
  • @Tobias org-show-subtree: Show everything after this heading at deeper levels. This would be OK, but I want the children collapsed. – user3496846 Sep 11 '19 at 19:36

I have not seen a particular function that does this. What I have seen org-mode and outline-mode code use is the expression: (outline-invisible-p (line-end-position)). To tell if a heading is collapsed you can evaluate this expression when on a heading (you can check if you're on a heading with org-at-heading-p). If it returns t, then the heading is collapsed; otherwise it is not collapsed.

I'll explain a little bit about how it works. outline-invisible-p takes a point in the buffer as an argument returns t if the character after the point is invisible or not. When a heading is collapsed the point right after the heading (ie. the one after the end position of the line) will be invisible. So calling outline-invisible-p with (line-end-position) is an indicator of whether a heading is collapsed.

You could easily write a function to check for this. (In fact I would recommend doing this as opposed to using the expression because it's clearer what is being checked).

(defun +org-heading-collapsed-p ()
  "Return t if an current heading is collapsed."
  (outline-invisible-p (line-end-position)))

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.