17

I use markdown-mode (in conjunction with writeroom-mode) for writing in Emacs. My markdown files generally gets quite large, and I would like to be able to focus on a particular section for extended periods of time.

How can I achieve this? Specifically I'm looking to hide or collapse other sections (heading and their text) while working on the current one. http://www.foldingtext.com behaves in this manner.

1

2 Answers 2

18

With markdown-mode by Jason Blevins you can toggle folding of the heading with Tab (same as in org-mode).

2
  • 7
    True (+1). However, with emacs -nw, it turns out that you want to use Shift + Tab to get things to fold. (Which I only mention because I only found out by accident that this works....)
    – jon
    Commented Jan 11, 2016 at 16:40
  • 2
    Also, C-x n d will narrow to the current section*, and -- importantly -- C-x n w undoes this by running widen. *** via narrow-to-defun, which is markdown-mode is mapped to markdown-narrow-to-section. You can type C-x n s to run markdown-narrow-to-section, which is directly what you want, but since C-x n d does what you want and is useful in other modes, I prefer to use that for better muscle-memory-applicability.
    – mtd
    Commented Mar 24, 2021 at 17:39
3

I've found two ways that can be useful:

  1. enable hideshow mode (hs-minor-mode) and use the provided functions
  2. Apparently markdown-mode inherits from outline mode (or at least the functions are available here!) so you can use functions like hide-subtree and show-subtree.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.