1

I can un/fold a section in org-mode by calling org-cycle. However, the cursor has to stay on the heading in order for that to work. What can I do to collapse the section in which I am currently stationed?

Example:

* Section 1
** Section 1.1
** Section 1.2
   lots of lines
   information [] <-- cursor somewhere here
   lots of lines
** Section 1.3

----> fold outer

* Section 1
** Section 1.1
** Section 1.2 [] <--- cursor somewhere here
** Section 1.3

----> fold outer

* Section 1 [] <--- cursor somewhere here

I feel like there should be a way to do this by jumping to the first heading of the outer level and calling org-cycle, but making this jump seems to require some dev knowledge of org-mode, so I am here to ask for help.

1

You can try this function. (surely not perfect)

(defun org-fold-outer ()
  (interactive)
  (beginning-of-line)
  (if (string-match "^*+" (thing-at-point 'line t))
      (outline-up-heading 1))
  (outline-hide-subtree)
  )
1

There are some predefined settings available for the behavior of org-cycle.

You can play with the settings using

M-x customize-variable org-cycle-emulate-tab
  • 1
    good to know about this option: with (setq org-cycle-emulate-tab nil), org-cycle on a non-heading achieves the desired result (part 1 of the example). Staying on top of a heading, however, simply unfolds that heading instead of the folding the upper level (part 2 of the example). I am still to see what's more useful for me, so thanks! – user3496846 May 29 '18 at 11:14

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.