On 2009-04-16, Tony Mechelynck <[email protected]> wrote:
>
> Here's another proposal, which can meet every possibility, and doesn't 
> loop over all characters (faster for long strings), but at the cost of 
> opening a temporary window (IOW, it requires has('windows))
>
>       function VirtLen(string)
>               new
>               0put =a:string
>               let rv = virtcol('$') - 1
>               q!
>               return rv
>       endfunction
>

Very interesting.  I'll probably have to re-use a scratch buffer to
prevent accumulation of new buffers...  In any case, this made me learn
about the = register, which I didn't know about.

Before, I had sort of "cheated" using perl.

        perl << EOF
        use Text::CharWidth qw(mbswidth);
        sub my_wcswidth {
                my $str = VIM::Eval("a:str");
                my $len = mbswidth($str);
                VIM::DoCommand("let l:return_value = $len");
        }
        EOF

        function! WideStringWidth(str)
                perl my_wcswidth()
                return l:return_value
        endfunction

Thanks, 
-Yozo



--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to