25

I'm making an outline for my thesis using org-mode, and I'd like to show all headings up to a certain level (e.g. all level-1 and level-2 headings).

I haven't found anything about that in the org-mode manual. Cycling shows either only level-1 headings, or all headings, which is too much information in my outline right now.

Thanks,

daniel.

Update: I found a workaround for his: set the variable org-cycle-max-level. This is a global setting, though.

Martin Liversage
  • 104,481
  • 22
  • 209
  • 256
daniel kullmann
  • 13,653
  • 8
  • 51
  • 67

4 Answers4

31

Just stumbled on this question. One year later but what the heck.. There are commands for this that allows you to show headings to a certain level.

One command is C-<n> C-c tab will show subheadings up to level <n> (<n>=1,2,3...).

Another command is C-<n> S-tab which will operate on the whole buffer. It shows all headings up to level <n> (<n>=1,2,3...)

Whil
  • 471
  • 4
  • 6
  • @Whil I fully agree with Andrew; however, the second command does not work for me, `C-tab` is bound to `org-force-cycle-archived`. – daniel kullmann May 30 '12 at 07:11
  • 1
    @danielkullmann Sorry - should be `C- S-tab`. Edited above for clarity. – Whil Nov 10 '12 at 10:21
  • 1
    Is there a way to apply this by default when opening the file? The options [here](https://orgmode.org/manual/Initial-visibility.html) seem to be all or nothing. – Elliott Slaughter Feb 20 '19 at 21:43
  • 1
    @ElliottSlaughter See here: https://emacs.stackexchange.com/questions/12938/how-can-i-evaluate-elisp-in-an-orgmode-file-when-it-is-opened – Ryan C. Thompson Jan 19 '20 at 01:54
13

I found a solution that suits me: The command org-content shows the folder hierarchy, and giving it a numeric argument does exactly what I want: limit the maximum level shown. In my example, I wanted to show 2 levels, so I can do C-2 M-x org-content <RET>.

I also added my own command to my .emacs init file, binding that command to C-c m

(defun org-show-two-levels ()
  (interactive)
  (org-content 2))

(add-hook 'org-mode-hook
  (lambda ()
    (define-key org-mode-map "\C-cm" 'org-show-two-levels)))
daniel kullmann
  • 13,653
  • 8
  • 51
  • 67
  • `org-content` works on the whole buffer - why is often what you want. If you are want to operate on the subtree under the point then you can use `show-children` in an identical fashion. – Att Righ Sep 06 '16 at 22:14
  • More generally, one should appreciate that `org-mode` is build upon `outline-mode`, so you can use many of its display functions (https://www.gnu.org/software/emacs/manual/html_node/emacs/Outline-Visibility.html) – Att Righ Sep 06 '16 at 22:18
1

If the prefix arguments from M. Kullman's answer take too much mental capacity for you (a limited resource when you are thinking hard about something else at the same time) then you can use the following functions to expand contract headings

(defvar hf-org-depth-point nil)
(defvar hf-org-depth-depth nil)

(defun hf-org-depth-increase ()
   (interactive)
   (hf-org-depth-incr 1))

(defun hf-org-depth-decrease ()
    (interactive)
    (hf-org-depth-incr -1))

(defun hf-org-depth-incr (incr)
    (when (not (equal (point) hf-org-depth-point))
        (setq hf-org-depth-point nil)
        (setq hf-org-depth-depth 0))a
    (setq hf-org-depth-point (point))
    (setq hf-org-depth-depth (max (+ hf-org-depth-depth incr) 0))
    (hide-subtree)
    (show-children hf-org-depth-depth))

```

Att Righ
  • 1,439
  • 1
  • 16
  • 29
1

I am way late to the party, but let us add a simple way for posterity. Simply use Cycle Global Visibility (<backtab>). If your headings are open, it will close them. However, if you apply it repeatedly with all headings collapsed, they will open to the level you want.

I use it from the keyboard by <SHIFT>+<TAB>. You can also find it in the Org menu (in Emacs) under Show/Hide -> Cycle Global Visibility ()