I use indentation with Markdown to allow folding to give me an overview of a file. But after typing in an indented section under a heading, I want to select the whole thing to copy and paste elsewhere. A trivial example looks like this:
## Heading of article Stuff More stuff[cursor] ## New Heading Further stuff
If I press Cmd-Opt-[ at that cursor position, the section marked “Heading” will fold away. But I want to select that folded text (“Stuff\nMore stuff”)so that I can copy it. I would also like to be able to assign a separate command to highlight the “Heading of article” text, also to be copied. Bonus points for letting me strip the 2-space indention off the copied lines.
It looks like getting and setting the selection is pretty straightforward, but I’m not sure how to get folding information out of the API available. Maybe I can just walk forward and back in the buffer and look for indented lines and then extend the selection to encompass them all? What would I use for this, and where would it go?
I have considered folding and then selecting the folded ‘ellipsis’ icon to copy that. But I’ve seen strange behavior when the folded region contains folded sub-regions, so I don’t think that will work for me.