Error messages due to backslashes on filepaths #3

Closed
mMontu opened this Issue Aug 8, 2012 · 9 comments

2 participants

@mMontu

When opening the diff tab the plugin displayed some error messages, similar to

  Error detected while processing function <SNR>54_Linediff..<SNR>54_PerformDiff..linediff#differ#CreateDiffBuffer..linediff#differ#SetupDiffBuffer:
  line    7:
  E518: Unknown option: <corruptedFilePath>^I

This problem occurs with gVim under ms-windows, and changing line 100 of autoload/differ.vim to

 let statusline = printf('[%s:%%{b:differ.from}-%%{b:differ.to}]', 
          \ substitute(bufname(self.original_buffer), '\', '/', 'g'))

solved the issue, but I didn't tested on different systems.

Thanks for sharing this awesome plugin!

@AndrewRadev
Owner

I think I've found the root problem, it seems the substitute call was getting confused due to the backslashes. I've pushed a commit that should fix this, could you check it out?

Thanks for sharing this awesome plugin!

Thank you for the kind words, glad you like it :).

@mMontu

Wow, this was very quick! :-)
I've tested the new version, and it indeed solved the error message.
But unfortunately the status line display the path with no slashes at all - that is, X:\dir1\dir2\file3.xyz displays as dir1dir2file3.xyz

The change below makes it display dir1/dir2/file3.xyz,

 if &statusline =~ '%[fF]'
   let statusline = substitute(&statusline, '%[fF]', substitute(statusline, '\', '/', 'g'), '')
 endif

, but again, I'm not sure this is the best solution.
Thanks!

@mMontu

Another solution may be

 exe "setlocal statusline=" . escape(statusline, ' |\')
@AndrewRadev
Owner

Hmm, yeah, I should've tested it when the statusline is set as well. I went with the second solution you proposed. I'd rather not replace \ with /, because it's perfectly correct to show that in Windows, and there really shouldn't be a reason to do it anyway.

I've pushed a new commit, could you confirm that it works?

@mMontu

It worked fine!!
I agree with you that the last solution is better, and also show the backslashes if they are present on the filepaths.

I've just noticed that now that no error message is displayed, the diffs are not immediately displayed after selecting the lines - it displays messages about the created temp files and about deleting one line, and stops on the hit-enter prompt. This also happens with your system/configurations?

Including silent on two lines of autoload/linediff.vim removed this messages with my configurations:

  function! linediff#differ#CreateDiffBuffer(edit_command) dict

    :
    :

    silent exe a:edit_command . " " . temp_file
    call append(0, lines)
    silent $delete _

It is better to open a new issue for this?
Thanks!

@AndrewRadev
Owner

Hmm, it's probably related, so please leave the issue open for now. The thing is, I don't have a windows box handy, so testing will be difficult -- I'll have to setup a VirtualBox and see what I can do. This won't happen in the next couple of days at least, I'm afraid -- I'm in a bit of a vacation. I'll work on it later on, though. As for the fix, I'd rather not silence it, because there should be a specific problem there.

@mMontu

I agree with you that silent may hide useful error messages.
When you have time to work on this, you may send me your code to test if you wish to avoid setting up the VirtualBox.

Enjoy your vacation :-)

@AndrewRadev
Owner

Sorry it took so absurdly long to get to this issue. I kept postponing it for one reason or another.

I installed Windows and tried it out with a clean Vim install, but I was unable to reproduce this. It does seem like the edit call and the delete should output messages, however, so I'm not sure what kind of setting would suppress them...

However, your fix is perfectly safe to add. I hadn't realized back then that silent doesn't suppress errors unless given a !. Even if I can't reproduce your setup, I've pushed a commit that silences these two lines. Since you did report that this fixes the problem, I'm going to consider the ticket closed, but please reopen it if you notice any related breakage.

@mMontu

Sorry for the delay, it was my turn to take vacation :D

I've also missed the information that silent doesn't affects error messages.
This new version works fine, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment