azzamsa · 2022-08-29 16:42
Hi.
I want to toggle list type similar to this https://github.com/yzhang-gh/vscode-markdown#available-commands
I can't find it here https://leanpub.com/markdown-mode/read#leanpub-auto-lists and here https://jblevins.org/projects/markdown-mode/
Is this possible in `https://jblevins.org/projects/markdown-mode/`?
Thanks.
sebhoagie · 2022-08-31 15:09
Well , I was expecting that someone would share the existing command (not super familiar with markdown-mode) but just checked myself and didn't find anything.
It can be done relatively easy manually.
Unordered to ordered:
1. Mark the region with the list you want to convert
2. Run `query-replace-regexp` from "- " (or "\* " or "+ ") to "#. "
3. Then `C-x C-x` to mark the region again, and do `C-c C-c n` which runs `markdown-cleanup-list-numbers` which will fix the numbering to start from 1
Ordered to unordered:
1. Mark the region with the list you want to convert
2. Run `query-replace-regexp` from "\[0-9\]*. " to "- " (or "* " or "+ ")
Of course these could be the basis of a proper toggle command, but then you have to deal with corner cases, nested lists etc.
Thanks to your question I re-learned about `\#`, which stands for "replacement number". I read about query-replace counters at some point of my Emacs journey but this is the first time I used them!
​
EDIT: I think the regexp for numbers should be "\[0-9\]\*\\. " to account for lists with 10 or more items, also escape the \`.\` :)