On Sat, 24 Jun 2006, Luc Hermitte wrote:

> * On Sat, Jun 24, 2006 at 08:52:47AM +0800, Dr Bean
> <[EMAIL PROTECTED]> wrote:
> > On Fri, 23 Jun 2006, [EMAIL PROTECTED] wrote:

> > >   "--if    insert "if" statement                   {{{
> > >     Inoreabbr <buffer> <silent> if <C-R>=Def_AbbrC('if ',
> > >   \ '\<c-f\>if (!cursorhere!) {\n!mark!\n}!mark!')<cr>

> > perl
> > In a compound statement 'if' works just like in C. However it
> > may also be used to modify a single statement, as in 'print
> > "Hello, world" if 1'.

> What you will need is to analyze the lines before the cursor. if the
> `if' you are typing starts a new instruction, then you can expand 
> `if (!cursorhere!) {\n!mark!\n}!mark!', otherwise just
> `if (!cursorhere!);!mark!'.
> checking for the previous non comment code can be a little tricky.

Using your suggestion of InsertIfNotAfter, this:

  Inoreabbr <buffer> <silent> if <C-R>=InsertIfNotAfter('if ',
        \ '\<c-f\>if (!cursorhere!) {\n!mark!\n}!mark!', '\S')<cr>

will not expand 'if' it follows non-whitespace characters in the
same line.

Searching the previous line with getline(line('.')-1) will be
necessary when I split over-long instructions. I'm sure I do this
some time, but I'm not sure how often.

I think I will use this quick and dirty abbreviation first and see
how often it is not satisfactory.

> Feel free to ask for any precision.

Another common idiom in perl is q//,qq//,qw//,qr// as a form of
quotation, like ''. I need to look at how the '' mappings are
done. I think it should be fairly easy to copy and paste them.

-- 
Dr Bean                      Teaching: The last refuge of the manipulative.

Reply via email to