Re: matchit doesn't work for php

2006-07-20 Thread Benji Fisher
On Thu, Jul 20, 2006 at 12:39:28AM +0200, Cesar Romani wrote:
> 
> In the following code, "if" from line 2 doesn't match "else" from line 7
> 
>  
>  1   2 if($a > $b)
>  3 {
>  4   echo "a is bigger than b";
>  5   if($a=10) $b=5;
>  6 }
>  7 else
>  8 {
>  9   echo "a is smaller than b";
> 10 }
> 11 ?>
> 
> 
> Many thanks in advance.
> 
> Cesar

 PHP syntax, like that of C, is not really suited to matchit.  If
you use the alternative syntax for control structures, it will work much
better:

 $b):
  echo "a is bigger than b";
  if($a=10): $b=5; endif;
else:
  echo "a is smaller than b";
endif;
?>

It would be nice if you could insist on the ":" character after the
condition, but that will not be possible until I get around to rewriting
matchit.vim .  (Consider that the condition could be much more
complicated than "($a > $b)".  It could span several lines, and it could
include nested parentheses, strings, comments, and ?: operators.)

 You can always match on the braces instead of the key words.

 If you decide that the problems with matching on "if" outweigh the
benefits, either take it up with the maintainer of ftplugin/php.vim or
else modify it to your taste:

:help ftplugin-overrule

HTH --Benji Fisher


R: R: matchit doesn't work for php

2006-07-19 Thread Cesar Romani

> -Messaggio originale-
> Da: Benji Fisher [mailto:[EMAIL PROTECTED]
> Inviato: mercoledì 19 luglio 2006 15.17
> A: vim
> Oggetto: Re: R: matchit doesn't work for php
> 
> On Fri, Jul 14, 2006 at 04:16:44AM +0200, Cesar Romani wrote:
> >
> > Thanks a lot, it works but I also notice that "else if" is not part of
> the
> > matching, although "else if" is a valid expression in php:
> > It matches if, else, elseif
> > but it doesn't match if, else, else if
> > How can I include "else if" in the matching?
> > Many thanks in advance.
> >
> > Cesar
> 
>  First of all, it is not clear to me that everyone would want to
> treat "else if" the same as "elseif".  From the PHP manual,
> 
>   In PHP, you can also write 'else if' (in two words) and the
>   behavior would be identical to the one of 'elseif' (in a single
>   word). The syntactic meaning is slightly different (if you're
>   familiar with C, this is the same behavior) but the bottom line
>   is that both would result in exactly the same behavior.
> 
> Personally, I would use "elseif" for something like the example given
> there,
> 
>   if ($a > $b) {
>   echo "a is bigger than b";
>   } elseif ($a == $b) {
>   echo "a is equal to b";
>   } else {
>   echo "a is smaller than b";
>   }
> 
> but I might write "else if" for something like
> 
>   if ($a > $b) {
>   echo "a is bigger than b";
>   } else  if ($a == $b) { # This is the complicated case!
>   # Many lines of code
>   } else {
>   echo "a is smaller than b";
>   }
> 
> and then I would be annoyed if "else if" were treated the same as
"elseif".
> 
>  If you still want to treat them the same, then replace 'elseif' in
> the
> matchit patterns with 'else\s*if'.  Then test it:  you should get
> different
> results depending on whether you start with the cursor on the first or
> second
> word of "else if", and you may like it.  If you really want the two cases
> treated identically, then you have to make sure that the second part of
> "else
> if" is not treated as an "if", so replace '\ with
> '\%(\ 
> if (help for matchit not yet installed)
>   :help matchit-install
> 
> :help matchit-spaces
> 
> HTH   --Benji Fisher

In the following code, "if" from line 2 doesn't match "else" from line 7

 
 1  $b)
 3 {
 4   echo "a is bigger than b";
 5   if($a=10) $b=5;
 6 }
 7 else
 8 {
 9   echo "a is smaller than b";
10 }
11 ?>


Many thanks in advance.

Cesar



Re: R: matchit doesn't work for php

2006-07-19 Thread Benji Fisher
On Fri, Jul 14, 2006 at 04:16:44AM +0200, Cesar Romani wrote:
> 
> Thanks a lot, it works but I also notice that "else if" is not part of the
> matching, although "else if" is a valid expression in php:
> It matches if, else, elseif
> but it doesn't match if, else, else if
> How can I include "else if" in the matching?
> Many thanks in advance.
> 
> Cesar

 First of all, it is not clear to me that everyone would want to
treat "else if" the same as "elseif".  From the PHP manual,

In PHP, you can also write 'else if' (in two words) and the
behavior would be identical to the one of 'elseif' (in a single
word). The syntactic meaning is slightly different (if you're
familiar with C, this is the same behavior) but the bottom line
is that both would result in exactly the same behavior.

Personally, I would use "elseif" for something like the example given
there,

if ($a > $b) {
echo "a is bigger than b";
} elseif ($a == $b) {
echo "a is equal to b";
} else {
echo "a is smaller than b";
}

but I might write "else if" for something like

if ($a > $b) {
echo "a is bigger than b";
} else  if ($a == $b) { # This is the complicated case!
# Many lines of code
} else {
echo "a is smaller than b";
}

and then I would be annoyed if "else if" were treated the same as "elseif".

 If you still want to treat them the same, then replace 'elseif' in the
matchit patterns with 'else\s*if'.  Then test it:  you should get different
results depending on whether you start with the cursor on the first or second
word of "else if", and you may like it.  If you really want the two cases
treated identically, then you have to make sure that the second part of "else
if" is not treated as an "if", so replace '\

R: matchit doesn't work for php

2006-07-13 Thread Cesar Romani

> -Messaggio originale-
> Da: Benji Fisher [mailto:[EMAIL PROTECTED]
> Inviato: giovedì 13 luglio 2006 15.35
> A: vim
> Cc: Dan Sharp
> Oggetto: Re: matchit doesn't work for php
> 
> On Thu, Jul 13, 2006 at 06:42:43AM +0200, Cesar Romani wrote:
> >
> > In the following function the bracket at 3 doesn't match the bracket at
> 17
> > And the bracket at 5 doesn't match the bracket at 8
> >
> >  1  >  2   function test1($a,$b,$c,$d,$e,$f)
> >  3   {
> >  4 if($e=='hola')
> >  5 {
> >  6   if($f=='') $f='1000';
> >  7   $s='{'.$d.':'.$f.'}amigo';
> >  8 }
> >  9 else
> > 10 {
> > 11   $s='{'.$d.':'.$f.'}amiga';
> > 12 }
> > 13 $this->s=$s;
> > 14 $this->a=$a;
> > 15 $this->b=$b;
> > 16 $this->c=$c;
> > 17   }
> > 18 ?>
> >
> > Many thanks in advance.
> >
> > Cesar
> 
>  The problem is that "{" is included in the 'matchpairs' option but
> not in b:match_words.  The matchit script recognizes that "{" is a
> matching character, but does not have a rule for it, so it defaults to
> the built-in % matching behavior.  You can confirm this with
> 
> :normal! %
> 
>  The solution is to add '{:}' to b:match_words ; probably also '(:)'
> and '[:]' while you are at it.  Also, I notice that ftplugin/php.vim
> :source's ftplugin/html.vim and so inherits the HTML setting of
> b:match_skip .  I think that PHP would do better with the default skip
> behavior, so it should :unlet this variable.
> 
>  I am cc'ing the maintainer of ftplugin/php.vim .
> 
> HTH   --Benji Fisher

Thanks a lot, it works but I also notice that "else if" is not part of the
matching, although "else if" is a valid expression in php:
It matches if, else, elseif
but it doesn't match if, else, else if
How can I include "else if" in the matching?
Many thanks in advance.

Cesar



Re: matchit doesn't work for php

2006-07-13 Thread Benji Fisher
On Thu, Jul 13, 2006 at 06:42:43AM +0200, Cesar Romani wrote:
>  
> In the following function the bracket at 3 doesn't match the bracket at 17
> And the bracket at 5 doesn't match the bracket at 8
> 
>  1   2   function test1($a,$b,$c,$d,$e,$f)
>  3   {
>  4 if($e=='hola')
>  5 {
>  6   if($f=='') $f='1000'; 
>  7   $s='{'.$d.':'.$f.'}amigo'; 
>  8 }
>  9 else
> 10 {
> 11   $s='{'.$d.':'.$f.'}amiga'; 
> 12 }
> 13 $this->s=$s;
> 14 $this->a=$a;
> 15 $this->b=$b;
> 16 $this->c=$c;
> 17   }
> 18 ?>
> 
> Many thanks in advance.
> 
> Cesar

 The problem is that "{" is included in the 'matchpairs' option but
not in b:match_words.  The matchit script recognizes that "{" is a
matching character, but does not have a rule for it, so it defaults to
the built-in % matching behavior.  You can confirm this with

:normal! %

 The solution is to add '{:}' to b:match_words ; probably also '(:)'
and '[:]' while you are at it.  Also, I notice that ftplugin/php.vim
:source's ftplugin/html.vim and so inherits the HTML setting of
b:match_skip .  I think that PHP would do better with the default skip
behavior, so it should :unlet this variable.

 I am cc'ing the maintainer of ftplugin/php.vim .

HTH --Benji Fisher


Re: matchit doesn't work for php

2006-07-13 Thread Mark Woodward
Hi Cesar,

On Thu, 13 Jul 2006 06:42:43 +0200
"Cesar Romani" <[EMAIL PROTECTED]> wrote:

>  
> In the following function the bracket at 3 doesn't match the bracket
> at 17 And the bracket at 5 doesn't match the bracket at 8
> 
>  1   2   function test1($a,$b,$c,$d,$e,$f)
>  3   {
>  4 if($e=='hola')
>  5 {
>  6   if($f=='') $f='1000'; 
>  7   $s='{'.$d.':'.$f.'}amigo'; 
>  8 }
>  9 else
> 10 {
> 11   $s='{'.$d.':'.$f.'}amiga'; 
> 12 }
> 13 $this->s=$s;
> 14 $this->a=$a;
> 15 $this->b=$b;
> 16 $this->c=$c;
> 17   }
> 18 ?>
> 
> Many thanks in advance.
> 
> Cesar
>

I just replaced all ' ' ' with ' " ' and its working?
'{' and '}' are the culprits. Not sure if it should 
behave this way, but thats whats causing the % confusion

cheers,


-- 
Mark


Re: matchit doesn't work for php

2006-07-12 Thread Pete Johns
On Thu, 2006-07-13 at 06:42:43 +0200, Cesar Romani sent:
>In the following function the bracket at 3 doesn't match the
>bracket at 17 And the bracket at 5 doesn't match the bracket at
>8
>
I don't think matchit.vim is to blame here. I have tried your
code with VIM - Vi IMproved 7.0 (2006 May 7, compiled Jun 26 2006
20:24:17) with matchit.vim removed and it still misbehaves.

Somewhat surprisingly, though, matchparen.vim is highlighting the
correct braces!

I'm sorry I cannot provide a solution, but hopefully this will
point you in the right direction.


Best wishes;


--paj
-- 
Pete Johns   
Contact Information  
Bothered   


pgpMJdEjnEt04.pgp
Description: PGP signature


matchit doesn't work for php

2006-07-12 Thread Cesar Romani
 
In the following function the bracket at 3 doesn't match the bracket at 17
And the bracket at 5 doesn't match the bracket at 8

 1 s=$s;
14 $this->a=$a;
15 $this->b=$b;
16 $this->c=$c;
17   }
18 ?>

Many thanks in advance.

Cesar