5

Is there a property I can set on a headline that makes Tab / (org-cycle) show everything in the subtree (i.e., effectively call (outline-show-subtree))?

Whereas subtree cycling rotates a subtree among the three states, FOLDED, CHILDREN, and SUBTREE, I would like to limit the state space to just FOLDED and SUBTREE for select subtrees. This mechanism implicitly indicates that a particular subtree is meant to be viewed as an atomic unit, which is helpful for incorporating complete documents within an Org-mode tree. I find the alternative somewhat distracting—i.e., identifying the right subtree to expand, hitting Tab twice, and visually confirming whether I'm in the right location.

4

This is a good job for advice.

(advice-add 'org-cycle :around #'my/org-cycle)

(defun my/toggle-bimodal-cycling (&optional pos)
  "Enable/disable bimodal cycling behavior for the current heading."
  (interactive)
  (let* ((enabled (org-entry-get pos "BIMODAL-CYCLING")))
    (if enabled
        (org-entry-delete pos "BIMODAL-CYCLING")
      (org-entry-put pos "BIMODAL-CYCLING" "yes"))))

(defun my/org-cycle (fn &optional arg)
  "Make org outline cycling bimodal (FOLDED and SUBTREE) rather than trimodal (FOLDED, CHILDREN, and SUBTREE) when a heading has a :BIMODAL-CYCLING: property value."
  (interactive)
  (if (and (org-at-heading-p)
           (org-entry-get nil "BIMODAL-CYCLING"))
      (my/toggle-subtree)
    (funcall fn arg)))

(defun my/toggle-subtree ()
  "Show or hide the current subtree depending on its current state."
  (interactive)
  (save-excursion
    (outline-back-to-heading)
    (if (not (outline-invisible-p (line-end-position)))
        (outline-hide-subtree)
      (outline-show-subtree))))
1

ebpa's answer is quite nice, and I've already started using it.

One thing about it, though, is that it leaves a :PROPERTIES: drawer hanging open, which I find ugly.

You can totally hide the drawer with the technique here, although you have to hide all of them, and there's no nice way to hint that they're hidden, nor to re-show them. I haven't decided yet if I'm going to stick with that approach.

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.