Hi Ken!

2015-7-23(Thu) 12:48:11 UTC+9 Ken Takata:
> Hi,
> 
> 2015/7/23 Thu 6:31:09 UTC+9 ZyX wrote:
> > 2015-07-22 18:55 GMT+03:00 Ken Takata:
> > > Hi Benji and list,
> > >
> > > I found a problem that % in Operator pending mode doesn't work properly
> > > when multibyte characters are set in b:match_words.
> > >
> > > E.g. consider setting "(" (U+FF08, FULLWIDTH LEFT PARENTHESIS) and
> > > ")" (U+FF09, FULLWIDTH RIGHT PARENTHESIS) as a pair.
> > >
> > > Step to reproduce:
> > > 1. Execute vim with the following command line
> > > vim -u NONE -N -c 'runtime macros/matchit.vim' -c 'let 
> > > b:match_words="(:)"'
> > >
> > > 2. Insert the following text
> > > aaa(bbb)ccc
> > >
> > > 3. Move the cursor on (, then type d%
> > > Actual result is:
> > > aaac
> > >
> > > Expected result is:
> > > aaaccc
> > >
> > >
> > > This is caused in s:CleanUp(). Character count should be used instead of
> > > byte count.
> > >
> > > The following patch fixes the problem:
> > >
> > > --- a/runtime/macros/matchit.vim
> > > +++ b/runtime/macros/matchit.vim
> > > @@ -303,7 +303,10 @@ fun! s:CleanUp(options, mode, startline,
> > >        let regexp = s:Wholematch(matchline, a:1, currcol-1)
> > >        let endcol = matchend(matchline, regexp)
> > >        if endcol > currcol  " This is NOT off by one!
> > > -       execute "normal!" . (endcol - currcol) . "l"
> > > +       let charcount = strlen(substitute(matchline[currcol-1 : 
> > > endcol-1], ".", "x", "g"))
> > > +       if charcount > 1
> > > +         execute "normal!" . (charcount - 1) . "l"
> > > +       endif
> > 
> > This code looks rather suspicious for me. (:h 'virtualedit', `l` may
> > not move over characters in some cases.)
> > 
> > I think that `go` motion may be used instead:
> > 
> >     execute 'goto' (line2byte('.') + endcol - 1)
> > 
> > >        endif
> > >      endif " a:0
> > >    endif " a:mode != "o" && etc.
> > >
> > >
> > >
> > > Note: This patch can be a little bit simple after Vim 7.4.755.
> > >
> > > Before 7.4.755:
> > > let charcount = strlen(substitute(matchline[currcol-1 : endcol-1], ".", 
> > > "x", "g"))
> > > After 7.4.755:
> > > let charcount = strchars(matchline[currcol-1 : endcol-1], 1)
> > >
> > > More detail:
> > > https://github.com/vim-jp/vim/blob/v7-4-778/runtime/doc/eval.txt#L5855-5873
> > >
> > >
> > > Regards,
> > > Ken Takata
> 
> I think I found a better solution:
> 
> --- a/runtime/macros/matchit.vim
> +++ b/runtime/macros/matchit.vim
> @@ -303,7 +303,7 @@ fun! s:CleanUp(options, mode, startline,
>        let regexp = s:Wholematch(matchline, a:1, currcol-1)
>        let endcol = matchend(matchline, regexp)
>        if endcol > currcol  " This is NOT off by one!
> -     execute "normal!" . (endcol - currcol) . "l"
> +     call cursor(0, endcol)
>        endif
>      endif " a:0
>    endif " a:mode != "o" && etc.

Wow! It's a simple and great solution.

--
Best regards,
Hirohito Higashi (a.k.a h_east)

-- 
-- 
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].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui