Reply to message «Re: [BUG] v:count1 sometimes returns column number for <expr> mappings if returned expression moves cursor using `|'», sent 16:16:25 24 November 2010, Wednesday by Bram Moolenaar:
> Try out this patch: <...> Yes, this works. But 'normal ssssss' still echoes 0 at startup (not if I add it to echo $'...'). I thought that v:count1 cannot ever be `0', what caused it? Original message: > ZyX wrote: > > After launching > > > > echo $':echom "Here"\nsshsshss:redir! >messages\n:messages\n:redir > > END\n:qa!\n' | vim > > > > -u NONE -c 'so test-expr-count.vim' -c 'normal a...' -c 'normal ssssss' > > > > I get the following output in messages file: > > Messages maintainer: Bram Moolenaar <[email protected]> > > 0 > > 0 > > 0 > > 0 > > 0 > > 0 > > Here > > 1 > > 3 > > 1 > > 2 > > 1 > > 1 > > > > while expected to have all 1's. Contents of `test-expr-count.vim': > > function! DelNthSpace() > > > > echom v:count1 > > return virtcol('.').'|' > > > > endfunction > > nnoremap <expr> s DelNthSpace() > > > > I get almost the same results for `v:count' and any bar movements, but > > not with other movements and expressions. Tested on vim-7.3 and > > vim-7.3.62-r840c3cadb842. > > If I understand it correctly, your problem is that v:count and v:count1 > are not reset when evaluating the expression of a mapping when there is > no count. > > What happens is that the variables are only set when entering a count, > and after the command character has been entered. I suppose we also > need to set them before getting the first character, when we don't know > yet whether it's a count or not. That's when the expression will be > evaluated when there is no count. > > Try out this patch: > > *** ../vim-7.3.063/src/normal.c 2010-10-13 18:06:42.000000000 +0200 > --- src/normal.c 2010-11-24 13:10:46.000000000 +0100 > *************** > *** 648,653 **** > --- 648,669 ---- > dont_scroll = FALSE; /* allow scrolling here */ > #endif > > + #ifdef FEAT_EVAL > + /* Set v:count here, when called from main() and not a stuffed > + * command, so that v:count can be used in an expression mapping > + * when there is no count. */ > + if (toplevel && stuff_empty()) > + { > + long count = ca.count0; > + > + /* multiply with ca.opcount the same way as below */ > + if (ca.opcount != 0) > + count = ca.opcount * (count == 0 ? 1 : count); > + set_vcount(count, count == 0 ? 1 : count, set_prevcount); > + set_prevcount = FALSE; /* only set v:prevcount once */ > + } > + #endif > + > /* > * Get the command character from the user. > */
signature.asc
Description: This is a digitally signed message part.
