SidOfc / mkdx

A vim plugin that adds some nice extra's for working with markdown documents
https://www.vim.org/scripts/script.php?script_id=5620
MIT License
482 stars 13 forks source link

Numbered lists not auto-updated #185

Closed Ginner closed 1 year ago

Ginner commented 1 year ago

Hey Sid. Still using and loving mkdx! :) I have to ask you about the following behavior; in the README examples, it seems your numbered lists are updated automatically. However my experience is different, as described below. I suspect it's a bug in my collection of plug-ins, or maybe it is just not a part of the mkdx feature set.

Thanks.

OS type:

Vim:

Vim version: nvim v0.8.3

Reproduce steps:

Example:

  1. Open a markdown file.
  2. Make a numbered list like:
  3. This
  4. That
  5. The other
  6. Reorder the list:
  7. That
  8. This
  9. The other
  10. Maybe enter and exit insert-mode

Expected: The list numbers will automatically be updated to reflect:

1. That
2. This
3. The other

Actual: The numbers remains not-sequential:

2. That
1. This
3. The other
SidOfc commented 1 year ago

Hey @Ginner, been a while!

Indeed this is not a part of the current implementation of that feature, no need to go scavenge through your configuration to figure out what it is :)

I think I saw quite some complexity in trying to get this to work. Most of it likely due to lack of TextChanged autocommand which would allow for a clean "catch-all" i.e. I'd have to step on my toes to make sure I could override p, dd while allowing other plugins to work as intended.

Anyways, I just pushed a commit which updates any numbered list the cursor is on whenever the buffer changes. Could you give it a spin?

Ginner commented 1 year ago

Wow! Yeah, it seems to be working!

Thank you so much. I was about to say, if it wasn't part of mkdx, don't bother adding it, as I see you're shifting your focus to Lua (looking forward to whatever that might bring). However this is very much appreciated!

SidOfc commented 1 year ago

Yeah I did want to clarify that mkdx is in feature freeze indeed. I decided to take a look regardless because it's not a new feature and I remember that back when I initially implemented it I ended up releasing it in a partially unfinished state.

I know this because when I ran the s:util.UpdateNumberedList() function it already worked for the use-case you mentioned but wasn't "connected" to trigger on various keys for fear of bugs with other plugins.

The change is effectively 3 lines, one for attaching a mkdx#OnChange() function on TextChanged and two for moving a call to s:util.UpdateNumberedList() into this mkdx#OnChange() :)

As for focussing on Lua, indeed this is what I intend to do at some point, mkdx was my first Vim plugin and my first (and last) encounter with VimL. A lot of mkdx can be made significantly faster in Lua and quite a bit more stable since I've also grown a bit as a developer. I also made a metric F-ton of mistakes with the testing setup for mkdx which are cumbersome to fix 😅

I'm looking forward to the moment at which I take another look at building a better markdown plugin in Lua. Only downside is it'll likely be Neovim only due to me refusing to support two different Lua APIs.

Anyways, cheers for the issue, have a good one!