markdown-mode
markdown-mode copied to clipboard
Per-list detection of indentation, repurpose `markdown-list-indent-width`
It is often the case, that documents are written different indentation levels for lists. Sometimes people use 2 spaces of indentation, sometimes 4 or anything other. It can also happen that different indentation levels are used within the same document for different lists.
Since the value of markdown-list-indent-width is also used for stylizing, I find myself adjusting this value often per document to get the right list style of bullet points.
Could we detect the beginning of a sublist as a per-list value during parsing and not based on what markdown-list-indent-width is set to? Rather we could slightly repurpose its value to be only of meaning during editing and composing new lists. There the value could be used to set the indentation.
If my understanding is correct, this more dynamic approach is more often used. You can try out what I mean for example in this editor here:
https://commonmark.org/help/tutorial/06-lists.html
as well as, for example in the GitHub editor. Here is a demo text of what is mean, you should see both lists rendered equally, even though the sub-entry has a different amount of leading spaces:
- first entry in list
- This entry has 4 spaces at the beginning of the line
Here comes some separating text.
- First entry in another list
- this entry has only 2 spaces at the beginning of the line
Expected Behavior
Correctly detected sublists on a per-list basis.
Actual Behavior
Sublists are classified based on markdown-list-indent-width
Steps to Reproduce
- use emacs -Q and load current master branch
- copy the demo text above
- M-x markdown-toggle-markup-hiding RET
Software Versions
- Markdown Mode: From Git on 2021-07-28
- Emacs: 28.0.50 (master branch)
- OS: linux
While investigating this more I found another odd case:
When the indentation character of the sublist entry consist of a multiple of
markdown-list-indent-width , then the bullet point of that entry is one of
several layers deep instead of that that of the second layer.
If you find this whole behavior to be a bug, I can gladly try to draft out a PR that might fix this.
Yeah, CommonMark (which both GitHub and GitLab-flavored markdown use) specifically mandates "dynamic" indentation as opposed to fixed width as you point out. This is not optional in CommonMark, the spec explicitly says that only dynamic indentation for nested items is supported. This section of CommonMark spec covers indented lists: https://spec.commonmark.org/0.30/#list-items (brace yourself).
I find this particularly unexpected/confusing/undesirable considering that the tab key (markdown-cycle) does dynamic indentation correctly, instead of using this markdown-list-indent-width variable.
In my opinion, it would be ideal to kill off markdown-list-indent-width and instead make commands like markdown-demote and markdown-promote use the same dynamic logic that markdown-cycle uses. I'm a little surprised this issue is so old, but I suspect it's because the tab key (markdown-cycle) already does the right thing, so a lot of people haven't noticed the quirks of other commands. That's the case for me, at least.
I'm not a maintainer and have no say, but personally I would love a PR that changes this.