Friday, November 27, 2009

Re: Detect when a return follow an if instruction without bracket

epanda schrieb:
> I would like just to refined my original goal.
> In fact my goal is to add surround bracket that are missing around a
> return which follow if while etc...
>
> Actual PB :
> -------------------
>
> Case 1 :
> if ( cd1
> && cd2 )
> return;
>
> Case 2 :
> if ( cd1
> && cd2 )
> // COMMENT
> /****/* another comment*/
> return;
>
> Case 3 :
> while ( cd1
> && cd2 )
> // COMMENT
> /****/* another comment*/
> return;
>
>
> Goal to reach:
> -------------------
> All that have to become :
> while(cd1 && cd2)
> {
> return;
> }

Use the Long Pattern (from my first post):
/)\_s*\%(\%(\/\*\_[^*]*\*\+\%(\_[^\/*]\_[^*]*\*\+\)*\/\|\/\/.*\n\)\_s*\)\{-}return

Try it out ...

You can turn it directly into a :subst command, e.g.
:%s/Long Pattern/)\r{\rreturn;\r}/

Execute it, then re-indent the file (the :subst-command cannot do that).

Use :DiffOrig or similar to check the result (and be able to undo certain things).

--
Andy

--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php

No comments: