Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Collapsing the current outline in Emacs org-mode

Tags:

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.

  • If I press <TAB> it does not collapse ** Section A, as I would need the cursor to be on the stars for this to work.
  • If I press <Shift-TAB> it collapses all outlines, and not the current one.

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

like image 989
Amelio Vazquez-Reina Avatar asked Oct 04 '12 23:10

Amelio Vazquez-Reina


People also ask

How do I enter Org Mode in Emacs?

Emacs does not actually understand you are editing an Org document, yet. To enable Org mode on your current document, type M-x org-mode which will enable the Org mode on the current document.

Does Emacs come with Org mode?

Emacs has included Org Mode as a major mode by default since 2006. Bastien Guerry is the current maintainer, in cooperation with an active development community. Since its success in Emacs, some other systems now provide functions to work with org files.


2 Answers

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
like image 54
cyon Avatar answered Oct 17 '22 14:10

cyon


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.

like image 37
zkytony Avatar answered Oct 17 '22 13:10

zkytony