Monday, February 1, 2010

Re: how to match a "," that IS NOT in comment

I don't think it's possible with a regexp (due to the examples given
previously).
However, inside a function, you should be able to search for a comma,
then check to see what syntax group it belongs to; if it's
"javaComment" (and probably some others) with something like this:

synIDattr(synID(line("."), col("."), 1), "name")

-gary

On Jan 29, 9:14 pm, Tony Mechelynck <antoine.mechely...@gmail.com>
wrote:
> On 15/12/09 03:15, aj3423 wrote:
>
>
>
> > Thanks for your reply. I'm trying to write a vim plugin that checks trailing
> > comma for .js file, I'm using "match Error" when the buffer saves, but there
> > is another function in the plugin:
> > :vimgrep /the regex/ **/*.js
>
> > so there should be a regex to fit these 2 functions.
>
> > //Brs
>
> The problem here is that there can be any number of lines between /* and
> */ -- for example, you might have /* at the start of line 1, then a
> copyright statement and license agreement (in lawyers' English with
> plenty of commas in it), then the closing */ on line 450; or the
> description of a function (in programmers' English this time, but again
> with plenty of commas in it), again occupying any number of lines with
> /* on the first of them and */ on the last.
>
> I don't see how to search any number of lines backwards and forwards for
> /* and */ (aven assuming that you won't have such niceties as
>
>         function(arg1, "/*", arg2, "*/", arg3)
>
> where the commas around arg2 are *not* in a comment), unless your script
> can make good use of syntax functions such as synID(), synIDattr() and
> synIDtrans() (q.v.).
>
> Best regards,
> Tony.
> --
> If this fortune didn't exist, somebody would have invented it.

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

No comments:

Post a Comment