I would like to be able to fold nested list items in markdown-mode in the same way that it is possible to do in org-mode, so that, for example, the first sub-item in the following list can be easily hidden.

  • List item 1
    • List item 1.1
  • List item 2

The result would look something like the following.

  • List item 1 ...
  • List item 2

And ideally I would like to be able to use the mouse to fold and unfold the relevant blocks of text, and to have a marker displayed in the left margin to indicate that a block can be, or has been, folded.

From what I've read, it looks like the most promising option may be to use hs-minor-mode, which allows the use of the mouse to fold and unfold blocks, along with hideshowvis, which displays indicators in the margin for the blocks that can be folded, or have been folded, by hs-minor-mode. I've tried out a few other ways of doing the folding that work ok---in particular, selective display, origami, and yafolding---but, as far as I could see, none of them allowed for the use of the mouse to fold and unfold blocks.

I tried to set this up using hs-minor-mode but couldn't get it to work. I think I needed to define a 'forward-sexp' function, or something, but this is beyond my current capabilities.

Has anyone set up markdown-mode to fold nested list items like this? Does anyone have any advice on how I could get it working?

1 Answer 1


markdown-mode uses parts of outline-mode for folding. So, IMHO it is most natural to implement the folding of items also with the help of outline-mode.

The most obvious way would be:

  1. to include beside markdown-regex-header also markdown-regex-list in outline-regexp
  2. to replace the function markdown-outline-level as value of variable outline-level by some other function which also assigns levels to matched lists.

Pityingly, step 2 of this strategy does not work since markdown-mode uses outline-level in other contexts. So, an advice is needed for markdown-outline-level.

Setting the mouse-face and keymap text properties on heading markers and list items is quite standard.

md-outline-list.el is an example implementation of a package that can fold items in Markdown files. You can toggle the folding by mouse-clicks on the bullets or the heading markers.

Marking the foldable regions on the fringe is not (yet) implemented.

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.