Skip to main content
advice is not needed of course, added screenshot
Source Link
Hubisan
  • 1.7k
  • 9
  • 11

Looks like outline-hide-body does exactly what you want:

Hide all body lines in buffer, leaving all headings visible.

Note that this does not hide the lines preceding the first heading line.

So after creating the sparse tree use M-x outline-hide-body RET.

Or create a custom command that calls org-occur and hides the body lines afterwards:

(defun my-org-occur-and-hide-content ()
  "Interactively call `org-occur' and hide body lines after."
  (interactive)
  ;; Temporarily add an advice to `org-occur'.
  (advicecall-addinteractively 'org#'org-occur :after
              (lambda (&rest r)
                (outline-hide-body)
                (advice-remove 'org-occur 'my-org-occur-advice))
              '((name . my-org-occur-advice)))
  (call-interactively #'org-occur))

Call it with M-x my-org-occur-and-hide-content RET.

Result with the example from the question:

enter image description here

Looks like outline-hide-body does exactly what you want:

Hide all body lines in buffer, leaving all headings visible.

Note that this does not hide the lines preceding the first heading line.

So after creating the sparse tree use M-x outline-hide-body RET.

Or create a custom command that calls org-occur and hides the body lines afterwards:

(defun my-org-occur-and-hide-content ()
  "Interactively call `org-occur' and hide body lines after."
  (interactive)
  ;; Temporarily add an advice to `org-occur'.
  (advice-add 'org-occur :after
              (lambda (&rest r)
                (outline-hide-body)
                (advice-remove 'org-occur 'my-org-occur-advice))
              '((name . my-org-occur-advice)))
  (call-interactively #'org-occur))

Call it with M-x my-org-occur-and-hide-content RET.

Looks like outline-hide-body does exactly what you want:

Hide all body lines in buffer, leaving all headings visible.

Note that this does not hide the lines preceding the first heading line.

So after creating the sparse tree use M-x outline-hide-body RET.

Or create a custom command that calls org-occur and hides the body lines afterwards:

(defun my-org-occur-and-hide-content ()
  "Interactively call `org-occur' and hide body lines after."
  (interactive)
  (call-interactively #'org-occur)
  (outline-hide-body))

Call it with M-x my-org-occur-and-hide-content RET.

Result with the example from the question:

enter image description here

Source Link
Hubisan
  • 1.7k
  • 9
  • 11

Looks like outline-hide-body does exactly what you want:

Hide all body lines in buffer, leaving all headings visible.

Note that this does not hide the lines preceding the first heading line.

So after creating the sparse tree use M-x outline-hide-body RET.

Or create a custom command that calls org-occur and hides the body lines afterwards:

(defun my-org-occur-and-hide-content ()
  "Interactively call `org-occur' and hide body lines after."
  (interactive)
  ;; Temporarily add an advice to `org-occur'.
  (advice-add 'org-occur :after
              (lambda (&rest r)
                (outline-hide-body)
                (advice-remove 'org-occur 'my-org-occur-advice))
              '((name . my-org-occur-advice)))
  (call-interactively #'org-occur))

Call it with M-x my-org-occur-and-hide-content RET.