On Fri, 30 Jun 2006, Luc Hermitte wrote:
> * On Thu, Jun 29, 2006 at 02:45:16PM +0100, Zhang Le <[EMAIL PROTECTED]>
> wrote:
> > Most of time I want a space after a comma, so I use "imap , , "
> > The problem is, sometime I do not want a comma inside square
> > brackets in some programming language such python and matlab:
> > a[10,:] or a(10,:)
> > Is there a way to not insert a space based on context around the
> > cursor so that if the text before cursor is [xxx, or (xxx, no space
> > will be inserted?
> I see two ways:
> 2- The second is to define context dependent mapping. You can search for
> the discussion I had with Dr Bean last week on this topic.
> You can search for the following Message-ID on gmane:
> <[EMAIL PROTECTED]>
> 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>
Just for my own benefit, and to refresh my memory about what this means:
It's a mapping to add a space after the comma, but only when the
comma is not preceded by something the regex matches.
What the regex matches is an opening bracket or parenthesis followed by
a number of non-closing-bracket characters.
Shouldn't the closing parenthesis be included also in the regex?
'[[(][^])]\+'
--
Dr Bean People don't know what they say or
what they think they ought to say.
--Leonard Bloomfield, quoted by Virginia McDavid