Hi,
On Fri, Feb 2, 2024 at 10:54 PM rickhowe <[email protected]> wrote:
> Hi,
>
> Thank you for providing diff(). I checked how it works while comparing
> with nvim's vim.diff() as follows.
>
Note that nvim's vim.diff() is a lua function whereas the newly introduced
diff() is a
Vim builtin function. Lua uses 1-based indexing whereas Vimscript uses
0-based
indexing. So the indices returned by the diff() function are 0-based
whereas the
indices returned by the vim.diff() lua function are 1-based.
An interpretation of the indices for the below examples is inline.
diff(['a'], ['x', 'a'])
> unified: @@ -0,0 +1 @@
> indices: {0, 0, 0, 1} *
> nvim: [0, 0, 1, 1]
>
>
One string at index 0 in {list2} is inserted before the string at index 0
in {list1}.
>
>
> diff(['a'], ['a', 'x'])
> unified: @@ -1,0 +2 @@
> indices: {1, 0, 1, 1} *
> nvim: [1, 0, 2, 1]
>
>
One string at index 1 in {list2} is inserted before the string at index 1
in {list1}.
>
> diff(['x', 'a'], ['a'])
> unified: @@ -1 +0,0 @@
> indices: {0, 1, 0, 0} *
> nvim: [1, 1, 0, 0]
>
>
One string at index 0 in {list1} is removed from {list2} at index 0.
> diff(['a', 'x'], ['a'])
> unified: @@ -2 +1,0 @@
> indices: {1, 1, 1, 0} *
> nvim: [2, 1, 1, 0]
>
>
One string at index 1 in {list1} is removed from {list2} at index 1.
>
> *: {from_idx, from_count, to_idx, to_count}
>
>
When the from_count is zero, the strings from to_idx to (to_idx + to_count)
in {list2} are inserted at from_idx in {list1}.
When the to_count is zero, the strings from from_idx to (from_idx +
from_count) are removed from {list2} at to_idx.
> I am a bit confused about idx, In unified, idx 0 always means '^'. But
> in indices, idx 0 means '^' if count = 0 else the first index of hunk. In
> nvim, vim.diff() returns the equivalent value of the unified as indices.
>
We can add the "idx 0 means '^' if count is 0, otherwise it is the first
index of the hunk" note to
the help text.
> Is it difficult to follow vim.diff() as indices to make it simple and
> consistent between vim and nvim?
>
>
> Yes. The Vimscript diff() function should use 0-based indexing. This
helps the caller in
directly using the returned index to access the lists.
Regards,
Yegappan
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/CAAW7x7mTM7DG0y%2BZrUHsZwY_sWeouOrpYq4FmnVS4hdO0FneCw%40mail.gmail.com.