On 19/07/09 13:59, sinbad wrote:
>
> On Jul 19, 4:49 pm, Tony Mechelynck<[email protected]>
> wrote:
>> On 19/07/09 12:54, sinbad wrote:
>>
>>
>>
>>> hi,
>>
>>> How to match a C function declaration. I tried the following but
>>> didn't work.
>>
>>> :%s/\_.*(\_.*);//gc
>>
>>> thanks
>>
>> Since \_.* matches _as many as possible_ of anything including a
>> linebreak, the above would delete everything in the file until the last
>> ); pair, provided that there is at least one ( anywhere before it in the
>> file.
>>
>> How would you formulate your desired search-replace, in plain English?
>>
>> Best regards,
>> Tony.
>> --
>> Bare feet magnetize sharp metal objects so they point upward from the
>> floor -- especially in the dark.
>
> yeah, that's true it's matching the whole file. but the reason i used
> it is to
> match a new line char. the following are possible c function
> declarations.
>
> type_name fun_name(type_name p1);
>
> type_name
> fun_name(type_name p1);
>
> type_name fun_name (type_name p1, type_name p2);
> e
> the trick is there can be any no.of parameters are no parameters at
> all
> and there can be a line break anywhere after a valid c token.
>
> I think the regular expression in plain english is
> "
> any string with, sequence of characters followed by one or more spaces
> followed by a "(" and
> sequence of characters includeing "," or "_" followed by a ");"
Well, "any sequence of characters" includes everything before your
function declaration (which is why your regexp happily deletes it).
How would you describe it more narrowly? Can there be non-keyword
characters other than spaces before the left paren? Asterisks maybe? Can
there be other than keyword characters, commas, whitespace and
linebreaks inside the () pair? Again, asterisks maybe? If there are
blank lines before the function declaration, do you want to remove them
or keep them?
Best regards,
Tony.
--
For perfect happiness, remember two things:
(1) Be content with what you've got.
(2) Be sure you've got plenty.
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---