16

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
    My ten-seconds not-thought-out answer is: does it work with hideshow mode? https://www.gnu.org/software/emacs/manual/html_node/emacs/Hideshow.html – Trevoke Jan 07 '15 at 04:12

2 Answers2

18

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

Adobe
  • 1,859
  • 13
  • 27
  • 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 Jan 11 '16 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 Mar 24 '21 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.
Trevoke
  • 2,375
  • 21
  • 34