7

For example, say I have a buffer that looks like this:

* Org-Mode

This is a document written in Org-Mode

** This is a subheading below that

Would it be possible to narrow the buffer to just "This is a document written in Org-Mode" and continue on then come back to the full buffer, excluding the subheading below.

(Edited to clarify regarding subheadings)

  • If I understand your question correctly, you want Org-mode to work somewhat like the Workflowy app ? – Arjun J Rao Apr 5 '16 at 1:10
9

Perhaps this does what you want?

(defun org-narrow-to-here ()
   (interactive)
   (org-narrow-to-subtree)
   (save-excursion
     (org-next-visible-heading 1)
     (narrow-to-region (point-min) (point))))

Edit: If you really really want to exclude the current heading, this more elaborate variant:

(defun org-narrow-to-here ()
  (interactive)
  (save-excursion
    (narrow-to-region
     (progn (unless (org-at-heading-p) (org-next-visible-heading -1))
            (forward-line)
            (point))
     (progn (org-next-visible-heading 1)
            (point)))))
  • To make it more robust, consider adding code to the start of the second progn to throw an error if (org-at-heading-p) is true. In this case, there is no text to narrow to between the two headings. – Harald Hanche-Olsen Apr 1 '16 at 19:56
13

org-narrow-to-subtree (C-x n s) will display only the current heading. It does however include the heading itself, not just the text. Maybe that is OK for you?

widen (C-x n w) will widen the view again.

See for example: https://stackoverflow.com/questions/17156595/in-emacs-org-mode-how-to-narrow-display-to-two-subtrees-in-two-separate-files

  • 1
    Not exactly. The problem with that approach is that if there are subheadings below that text, they're included in the narrowed in the buffer as well. Thank you, though. – Bob Apr 1 '16 at 19:05
  • 2
    Ah OK - maybe you could clarify in your question that you specifically want to exclude subheadings below the given heading – Reign of Error Apr 1 '16 at 19:06
  • also this has the problem that the indentation stays the same :( does not help on phones where there is little space... – jhegedus Jun 2 '17 at 9:00

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.