Hirohito Higashi wrote:

> Hi Bram and Vim developers,
> 
> :help g@
> doc>                                                  *g@* *E774* *E775*
> doc> g@{motion}               Call the function set by the 'operatorfunc' 
> option.
> (snip)
> doc> 
> doc> Here is an example that counts the number of spaces with <F4>: >
> doc> 
> doc>  nmap <silent> <F4> :set opfunc=CountSpaces<CR>g@
> doc>  vmap <silent> <F4> :<C-U>call CountSpaces(visualmode(), 1)<CR>
> doc> 
> doc>  function! CountSpaces(type, ...)
> doc>    let sel_save = &selection
> doc>    let &selection = "inclusive"
> doc>    let reg_save = @@
> doc> 
> doc>    if a:0  " Invoked from Visual mode, use '< and '> marks.
> doc>      silent exe "normal! `<" . a:type . "`>y"
> doc>    elseif a:type == 'line'
> doc>      silent exe "normal! '[V']y"
> doc>    elseif a:type == 'block'
> doc>      silent exe "normal! `[\<C-V>`]y"
> doc>    else
> doc>      silent exe "normal! `[v`]y"
> doc>    endif
> doc> 
> doc>    echomsg strlen(substitute(@@, '[^ ]', '', 'g'))
> doc> 
> doc>    let &selection = sel_save
> doc>    let @@ = reg_save
> doc>  endfunction
> 
> This sample script does not work properly when use visual-block-mode with '$'.
> 
> How to reproduce:
> (0) Prepare test.txt containing the following.
> a a
>  b b b b
> cc
> 
> (1) Copy to ~/.vimrc above sample script.
> (2) Open test.txt
> (3) Input below command.
>     <C-V>G$
> (4) Press <F4>
> 
> Expected behavior:
> - Display '5' on command line.
> 
> Actual behavior:
> - Display '3'.
> 
> 
> I think that we should use 'gv' in this case.
> Attached a patch.

Thanks!

> PS
> Is it necessary condition "elseif a:type == 'block'" ?
> Help says unnecessary. (Following excerpt)
> doc> Although "block" would rarely appear, since it can
> doc> only result from Visual mode where "g@" is not useful.

Right, it can be removed.  I wonder if there is an example where "block"
would matter.  Perhaps when changing text, e.g. adding a number to all
numbers in the selected area.  That's much more complicated though.

-- 
Eagles may soar, but weasels don't get sucked into jet engines.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
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