Hi Christian,

On Tue, May 2, 2023 at 9:43 AM Christian Brabandt
<[email protected]> wrote:
>
> I am still confused by the output, even after reading the help section 
> several times. So index is the index into the list input and byte is the 
> start byte from that list[index]? And count is the number of changes 
> performed? That is a bit confusing, because if an item was added to the list, 
> like here:
>
> " few lines added at the end
>   :echo diff(['abc'], ['abc', 'def', 'ghi'])
>    [{'from': {'start': {'idx': 1, 'byte': -1}, 'end': {'idx': -1, 'byte': -1},
>      'count': 0},
>      'to': {'start': {'idx': 1, 'byte': 0}, 'end': {'idx': 2, 'byte': 2},
>    'count': 2}}]
>
> the count in the to dict means two additional items have been added 
> (appended) to the list. But then if you take this example:
>
>   " word is removed in the middle of a string
>   :echo diff(['abc def ghi'], ['abc ghi'])
>    [{'from': {'start': {'idx': 0, 'byte': 4}, 'end': {'idx': 0, 'byte': 7},
>      'count': 1},
>      'to': {'start': {'idx': 0, 'byte': 4}, 'end': {'idx': 0, 'byte': -1},
>    'count': 1}}]
>
> Then count does not mean to add or remove a single item to the list, but 
> apparently that only one single change has been done, e.g. removing from byte 
> 4 to byte 7.
>
> Also, I guess the help could be a bit more precise, I suppose the -1 applies 
> only for added items in the from Dict and removed items in the to Dict
>
>     Each item in the returned List is a Dict containing
>     information about a diff hunk.  Each Dict contains the
>     following items:
>         from  Dict with {list1} diff hunk information
>         to    Dict with {list2} diff hunk information
>     The "from" and "to" Dicts contain the following items:
>         start  Dict containing the starting index and byte of the
>          diff hunk.  The "byte" is -1 if text is added
>          (in the "from" Dict) or removed (in the "to" Dict).
>         end    Dict containing the ending index and byte of the
>          diff hunk.  The "idx" and "byte" are -1 if text is
>          added (in the "from" Dict) or removed (in the "to" Dict).
>         count  number of items added/removed/modified in this diff
>          hunk.
>
> And how would this look like if we have several hunks? Can we have this as 
> example as well?

I have updated the help with an example for multiple diff hunks.

Regards,
Yegappan

>
> Also I would have thought you would need something like oldstart,oldcount 
> newstart,newcount which basically is the hunk header from a unified diff. So 
> perhaps we can just also add the raw diff output per hunk as well?
>

-- 
-- 
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/CAAW7x7%3D5%3DdSP5PhKT_t%3DBu6WOsuzwPEbTeRy8ehocu4NHjyuhg%40mail.gmail.com.

Raspunde prin e-mail lui