Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vimdiff does not work correctly when using &diffexpr #14437

Open
rickhowe opened this issue Apr 7, 2024 · 0 comments
Open

vimdiff does not work correctly when using &diffexpr #14437

rickhowe opened this issue Apr 7, 2024 · 0 comments
Labels

Comments

@rickhowe
Copy link

rickhowe commented Apr 7, 2024

Steps to reproduce

I am trying to use diff mode and compare line-by-line by setting a following simple script to &diffexpr. This script skips an empty line and continues to compare the next line.

set diffexpr=MyDiff()
function! MyDiff()
  let [in, new] = [readfile(v:fname_in), readfile(v:fname_new)]
  let [len_in, len_new] = [len(in), len(new)]
  let out = []
  let [ln_in, ln_new] = [0, 0]
  while ln_in < len_in && ln_new < len_new
    let [text_in, text_new] = [in[ln_in], new[ln_new]]
    let [empty_in, empty_new] = [empty(text_in), empty(text_new)]
    if empty_in == empty_new
      if text_in != text_new
        let out += [(ln_in + 1) . 'c' . (ln_new + 1)]
      endif
      let [ln_in, ln_new] += [1, 1]
    else
      if empty_in | let ln_in += 1 | endif
      if empty_new | let ln_new += 1 | endif
    endif
  endwhile
  call writefile(out, v:fname_out)
endfunction

Case 1:

image
:windo diffthis
image
Both lines should be highlighted as changed lines, but the 2nd one in the left window is highlighted as added line.
In this case, ['1c1', '2c2'] is written to v:fname_out.

Case 2:

image
:windo diffthis
image
Both lines should be highlighted as changed lines, but the 2nd one in the right window is not highlighted.
In this case, ['1c1', '3c2'] is written to v:fname_out.

Expected behaviour

Both lines should be highlighted as changed lines.

Version of Vim

9.1.0271 but same thing happens in 8.2 as well.

Environment

Windows 10

Logs and stack traces

No response

@rickhowe rickhowe added the bug label Apr 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant