Amelio Vazquez-Reina
Amelio Vazquez-Reina

Reputation: 96398

Collapsing the current outline in Emacs org-mode

Say I am in org-mode in a document with the following structure:

* First headline 
* Second headline
** Section A
   Here is one line
   Here is another line
   blah, blah
** Section B

Say the cursor is on the line that reads Here is another line. I would like to collapse ** Section A from this location with a keyboard shortcut.

Is there any way to cycle through the collapsing of the outline in scope (i.e. the "current outline")?

Upvotes: 21

Views: 8070

Answers (2)

zkytony
zkytony

Reputation: 1508

If you don't mind doing this in two steps:

  1. C-c C-p: move the cursor to the previous heading (** Section A in your example)

  2. TAB: fold the section

This method doesn't require any configuration, as long as you get used to it.

Upvotes: 4

cyon
cyon

Reputation: 9538

You can customize the behaviour of the org-cycle command (which is bound to <TAB>) by changing the value of org-cycle-emulate-tab.

To get it to collapse ** Section A when your cursor is on Here is another line add the following line to your .emacs file:

(setq org-cycle-emulate-tab 'white)

The white will allow you to still use <TAB> to indent in empty lines. From org-mode Github:

org-cycle-emulate-tab's value is t

Documentation:
Where should `org-cycle' emulate TAB.
nil         Never
white       Only in completely white lines
whitestart  Only at the beginning of lines, before the first non-white char
t           Everywhere except in headlines
exc-hl-bol  Everywhere except at the start of a headline

Upvotes: 22

Related Questions