Tuesday, December 10, 2013

Re: "Diff with Vim" not work properly (cont.)

On Tuesday, December 10, 2013 4:41:42 AM UTC-6, shada wrote:
> 2013/12/10 Ben Fritz <fritzo...@gmail.com>
> > On Monday, December 9, 2013 2:21:52 AM UTC-6, shada wrote:
> > > modify one line in $home/_vimrc:
> > > function MyDiff()
> > > ...
> > >   if $VIMRUNTIME =~ ' '
> > >     if &sh =~ '\<cmd'
> > >
> > > ...
> > >
> > > to:
> > >
> > > function MyDiff()
> > > ...
> > >   if $VIMRUNTIME =~ ' '
> > >     if &sh =~ "\<cmd"
> > >
> > > ...
> > >
> >
> > Ugh. NO. This just makes the test fail so that the broken code that
> > was intended to run doesn't actually run.
> >
> > The correct fix is to remove the extra quotes added inside that test
> > and let shellxquote handle the quoting.
>
>
> can give me a full corrent MyDiff?
>

Here is what is currently installed by default in Vim 7.4.113. The
reset/restore of shellxquote is actually not needed, if you leave that
setting at its default value. It is there in case people have messed
with it to give it a value that won't work.

function MyDiff()
let opt = '-a --binary '
if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
let arg1 = v:fname_in
if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
let arg2 = v:fname_new
if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
let arg3 = v:fname_out
if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
if $VIMRUNTIME =~ ' '
if &sh =~ '\<cmd'
if empty(&shellxquote)
let l:shxq_sav = ''
set shellxquote&
endif
let cmd = '"' . $VIMRUNTIME . '\diff"'
else
let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
endif
else
let cmd = $VIMRUNTIME . '\diff'
endif
silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3
if exists('l:shxq_sav')
let &shellxquote=l:shxq_sav
endif
endfunction

--
--
You received this message from the "vim_use" 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_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment