On Fri, 30 Jun 2006, Luc Hermitte wrote:

> Hello,

> > > He used the function InsertIfNotAfter() I define in my C++ ftplugin
> > > cpp_set.vim available in lh-cpp.tar.gz [1].
> > > In your case, I guess it will look like:

> > >     inoremap <silent> ,
> > >         \ <c-r>=InsertIfNotAfter(',', ', ', '[[(][^]]\+')<cr>

> > It's a mapping to add a space after the comma, but only when the comma
> > is not preceded by something the regex matches.

> I must admit I never remember which parameter is expanded when.
> If the pattern is matched, we expand the first parameter. The second
> otherwise.

The function, InsertIfNotAfter, is defined as

        function! InsertIfNotAfter(key, what, pattern)
          let c = col('.') - 1
          let l = getline('.')
          let l = strpart(l, 0, c)
          if l =~ a:pattern.'\s*$'
            return a:key
          else
            return Def_AbbrC(a:key, a:what)
          endif
        endfunction

I thought that if a:pattern matches, then a:key is not expanded.
And if it is not matched, it is expanded, to a:what.

Oh, wait, I see. This function is part of a mapping. As you said,
if the pattern matches, the comma is expanded to whatever the
first parameter of InsertIfNotAfter is. If it doesn't match, it
is expanded to the second parameter of InsertIfNotAfter.

-- 
Dr Bean                      More Pricks than Kicks.
                             --Samuel Beckett

Reply via email to