RE: Vote for the default PHP indent script

classic Classic list List threaded Threaded
16 messages Options
Reply | Threaded
Open this post in threaded view
|

RE: Vote for the default PHP indent script

John Wellesz
So nobody wants to vote for either one of those scripts?

You just have to say if you prefer mine or the current one...


-----Message d'origine-----
De : John Wellesz [mailto:[hidden email]]
Envoyé : mardi 17 mai 2005 04:59
À : [hidden email]
Cc : [hidden email]
Objet : Vote for the default PHP indent script

Hello everybody,

I've written a new indent script for PHP.

If I'm posting this here, it's to ask you to vote for the script you prefer
so mine could replace the one currently bundled with VIM.

I tried to discuss with Miles Lott (the author of the default script) but he
cares very much for his script and doesn't want it to be replaced by mine...

So Bram told me that the best solution was to let the users decide which
script is the best for them and to start this vote.

So here are the improvements with regard to the indent script included in
vim distribution (For me those improvements clearly justify the
replacement):

- Comment or non-PHP code doesn't break the algorithm (they are ignored).
- Non-PHP code, multi-lines /**/ comments and "Here Document" content remain
unchanged.
- HTML <Script.*> tags and their content are indented as PHP and like if
their content was part of the surrounding PHP code.
- Support folding (folds don't break the indenting)
- Indent correctly complex "non bracketed blocks" (like in language C):

if (!isset($foo))
    if (!isset($foo))
        if (!isset($foo)) {
            $ foo =0;
        } else
            $foo=1;
    else
        $bla= "foo";
$foo = TRUE;

- Direct indenting, the text is indented as you type it.
- Fast optimized indenting; the script knows when it's indenting large
  blocks and skips some unnecessary tests...
- Bug free as far as I know. (The script is tested since November 2004,
current version is 1.10)

(There are examples of what it can do on its page at VIM.ORG - URI below)

NOTE: in the current VIM version there is a bug with the searchpair()
scripting function when using utf-8 encoding and the 'r' flag, it can make
my script to hang (it only happens if you are using utf-8). I've reported
this bug; Bram told me he will fix it.

This script also use syntax coloring, syntax must be turned on.


So please answer with your vote (and the reasons of your vote). Additionally
you can also vote on the script pages on VIM.org (URIs below)

I'm also interested by your remarks.

New script:
http://www.vim.org/scripts/script.php?script_id=1120
Or here:
http://www.2072productions.com/?to=phpindent.txt

Miles Lott script (the one bundled with VIM):
http://www.vim.org/scripts/script.php?script_id=346


Best regards,

John Wellesz



Reply | Threaded
Open this post in threaded view
|

Re: Vote for the default PHP indent script

Timon Christl
On 5/29/05, John Wellesz <[hidden email]> wrote:
> So nobody wants to vote for either one of those scripts?
>
> You just have to say if you prefer mine or the current one...

I've just tested your indent script. For me, it works better than the
one that comes with vim. The thing that caught my attention was
'complex "non bracketed blocks"'. I make use of this a lot, and it has
always been annoying that the original PHP script does not handle this
well.

The UTF-8 bug could be a problem, though, since UTF-8 is my default
encoding for pretty much everything. Does this bug occur only if there
are actually non-ASCII characters in a file, or does it even occur if
you restrict yourself to plain old ASCII?

Anyway, thumbs up! I've rated your script "life-changing" on vim.org.
With >15K lines of PHP this script is definitely going to help me.

--
(defun f(p x)(If(Eq x nil)nil(If(p(Car x))(Cons(Car x)(f p(Cdr x)))(f p
(Cdr x)))))(defun q(x)(Q nil x))(defun Q(a x)(If(Eq x nil)a(Q(Cons(Car
x)(Q a(f(Lt(Car x))(Cdr x))))(f(Gt(Car x))(Cdr x)))))
Reply | Threaded
Open this post in threaded view
|

RE: Vote for the default PHP indent script

John Wellesz
Thank you very much for testing my script :-D

> The UTF-8 bug could be a problem, though, since UTF-8 is my default
> encoding for pretty much everything. Does this bug occur only if there
> are actually non-ASCII characters in a file, or does it even occur if
> you restrict yourself to plain old ASCII?

Unfortunately it happens as soon as UTF-8 encoding is used no matter what
contains the file... but it will be corrected in the next version of VIM.

There is something you can to prevent this bug from happening: in my script
search for the strings "bWr" (without the quotes) and replace them by "bW".

But if you have weird comments like:

/*
Blablabla
Blablabla
Blablabla
/*  <----- this "/*" will be wrongly identified as the start of the comment.
Blablabla
Blablabla
Blablabla
*/

The script will have troubles and will make mistakes. If you have no such
comment then the script will work perfectly :-)



John



-----Message d'origine-----
De : Timon Christl [mailto:[hidden email]]
Envoyé : dimanche 29 mai 2005 23:42
À : John Wellesz
Cc : [hidden email]
Objet : Re: Vote for the default PHP indent script

On 5/29/05, John Wellesz <[hidden email]> wrote:
> So nobody wants to vote for either one of those scripts?
>
> You just have to say if you prefer mine or the current one...

I've just tested your indent script. For me, it works better than the
one that comes with vim. The thing that caught my attention was
'complex "non bracketed blocks"'. I make use of this a lot, and it has
always been annoying that the original PHP script does not handle this
well.

The UTF-8 bug could be a problem, though, since UTF-8 is my default
encoding for pretty much everything. Does this bug occur only if there
are actually non-ASCII characters in a file, or does it even occur if
you restrict yourself to plain old ASCII?

Anyway, thumbs up! I've rated your script "life-changing" on vim.org.
With >15K lines of PHP this script is definitely going to help me.

--
(defun f(p x)(If(Eq x nil)nil(If(p(Car x))(Cons(Car x)(f p(Cdr x)))(f p
(Cdr x)))))(defun q(x)(Q nil x))(defun Q(a x)(If(Eq x nil)a(Q(Cons(Car
x)(Q a(f(Lt(Car x))(Cdr x))))(f(Gt(Car x))(Cdr x)))))

Reply | Threaded
Open this post in threaded view
|

RE: Vote for the default PHP indent script

David Fishburn
In reply to this post by John Wellesz

I was having problems sometime ago with the original indent script and was
quite pleased that this new one showed up.  I haven't had any issues
indenting with the new version.

You get my vote.

Thanks,
Dave
 

> -----Original Message-----
> From: John Wellesz [mailto:[hidden email]]
> Sent: Sunday, May 29, 2005 6:13 AM
> To: [hidden email]
> Subject: RE: Vote for the default PHP indent script
>
> So nobody wants to vote for either one of those scripts?
>
> You just have to say if you prefer mine or the current one...
>
>
> -----Message d'origine-----
> De : John Wellesz [mailto:[hidden email]] Envoyé :
> mardi 17 mai 2005 04:59 À : [hidden email] Cc :
> [hidden email] Objet : Vote for the default PHP indent script
>
> Hello everybody,
>
> I've written a new indent script for PHP.
>
> If I'm posting this here, it's to ask you to vote for the
> script you prefer so mine could replace the one currently
> bundled with VIM.
>
> I tried to discuss with Miles Lott (the author of the default
> script) but he cares very much for his script and doesn't
> want it to be replaced by mine...
>
> So Bram told me that the best solution was to let the users
> decide which script is the best for them and to start this vote.
>
> So here are the improvements with regard to the indent script
> included in vim distribution (For me those improvements
> clearly justify the
> replacement):
>
> - Comment or non-PHP code doesn't break the algorithm (they
> are ignored).
> - Non-PHP code, multi-lines /**/ comments and "Here Document"
> content remain unchanged.
> - HTML <Script.*> tags and their content are indented as PHP
> and like if their content was part of the surrounding PHP code.
> - Support folding (folds don't break the indenting)
> - Indent correctly complex "non bracketed blocks" (like in
> language C):
>
> if (!isset($foo))
>     if (!isset($foo))
>         if (!isset($foo)) {
>             $ foo =0;
>         } else
>             $foo=1;
>     else
>         $bla= "foo";
> $foo = TRUE;
>
> - Direct indenting, the text is indented as you type it.
> - Fast optimized indenting; the script knows when it's indenting large
>   blocks and skips some unnecessary tests...
> - Bug free as far as I know. (The script is tested since
> November 2004, current version is 1.10)
>
> (There are examples of what it can do on its page at VIM.ORG
> - URI below)
>
> NOTE: in the current VIM version there is a bug with the
> searchpair() scripting function when using utf-8 encoding and
> the 'r' flag, it can make my script to hang (it only happens
> if you are using utf-8). I've reported this bug; Bram told me
> he will fix it.
>
> This script also use syntax coloring, syntax must be turned on.
>
>
> So please answer with your vote (and the reasons of your
> vote). Additionally you can also vote on the script pages on
> VIM.org (URIs below)
>
> I'm also interested by your remarks.
>
> New script:
> http://www.vim.org/scripts/script.php?script_id=1120
> Or here:
> http://www.2072productions.com/?to=phpindent.txt
>
> Miles Lott script (the one bundled with VIM):
> http://www.vim.org/scripts/script.php?script_id=346
>
>
> Best regards,
>
> John Wellesz
>
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Vote for the default PHP indent script

Jason Diamond
In reply to this post by John Wellesz
John Wellesz wrote:

> > The UTF-8 bug could be a problem, though, since UTF-8 is my default
> > encoding for pretty much everything. Does this bug occur only if
> > there are actually non-ASCII characters in a file, or does it even
> > occur if you restrict yourself to plain old ASCII?
>
>  Unfortunately it happens as soon as UTF-8 encoding is used no matter
>  what contains the file... but it will be corrected in the next
>  version of VIM.

Would a line like this in my .vimrc file prevent the bug from happening?

autocmd BufNewFile,BufRead *.php set fileencoding=ascii

Or is it the fact that I have encoding set to utf-8 enough to trigger
this bug?

>  There is something you can to prevent this bug from happening: in my
>  script search for the strings "bWr" (without the quotes) and replace
>  them by "bW".
>
>  But if you have weird comments like:
>
>  /* Blablabla Blablabla Blablabla /* <----- this "/*" will be wrongly
>  identified as the start of the comment. Blablabla Blablabla Blablabla
>  */
>
>  The script will have troubles and will make mistakes. If you have no
>  such comment then the script will work perfectly :-)

Could you modify the script so that it can detect the version of VIM
that's running and do this for us automatically if it should be done?
That seems like the safest thing to do.

I'd love to try out the script (I actually disabled indenting on PHP
files because I was so annoyed with the last script) but I don't want
Vim to hang or do anything else which might cause me to lose data.

--
Jason


--
Jason

Reply | Threaded
Open this post in threaded view
|

RE: Vote for the default PHP indent script

John Wellesz
Jason Diamond écrit :
 
> Would a line like this in my .vimrc file prevent the bug from happening?
>
> autocmd BufNewFile,BufRead *.php set fileencoding=ascii
>
> Or is it the fact that I have encoding set to utf-8 enough to trigger this

> bug?

I've just done the test and it doesn't change anything :-(

> Could you modify the script so that it can detect the version of VIM
> that's running and do this for us automatically if it should be done? That

> seems like the safest thing to do.

Ok I'll do it; I will add a warning on the script page at Vim.org about the
resulting problem with the use of weird comments.
 
> I'd love to try out the script (I actually disabled indenting on PHP files

> because I was so annoyed with the last script) but I don't want Vim to
> hang or do anything else which might cause me to lose data.

Don't worry, this bug doesn't make Vim to crash, the function Searchpair()
just never returns and you have to push CTRL-C to interrupt the function and
the indent script.

Here is a simple way to reproduce this bug without my script:

Open a new empty file in VIM and put the following 2 lines inside:

/* Hang Condition 1*/
d /* Hang Condition 2 -  with the 'd' before */


Run the command:

:set enc=utf-8

Then put the cursor on the '/' of the last '*/' and run the command:

:call searchpair('/\*', '', '\*/\zs', 'bWr', '')

You'll see that the command never returns. You have to push CTRL-C to
interrupt it.


Thanks,

John

Reply | Threaded
Open this post in threaded view
|

RE: Vote for the default PHP indent script

John Wellesz
In reply to this post by John Wellesz
Version 1.12 has been released!
 
What's new:
 
- The bug involving searchpair() and utf-8 encoding in Vim 6.3 will not
make this script to hang but you'll have to be careful to not write
'/* */' comments with other '/*' inside the comments else the indentation
won't be correct.

Example:

/*
Blablabla
Blablabla
Blablabla
/*  <----- this "/*" will be wrongly identified as the start of the
comment.
Blablabla
Blablabla
Blablabla
*/

NOTE: This is true only if you are using utf-8 and vim 6.3.

 
Download:

 http://www.vim.org/scripts/download_script.php?src_id=4330

Or

 http://www.2072productions.com/vim/indent/php.vim


Contact me if you have any problem with this version.

Reply | Threaded
Open this post in threaded view
|

RE: Vote for the default PHP indent script

John Wellesz
Version 1.15 has been released!
 
What's new:
 
- Corrected some problems with the indentation of multiline "array()"
declarations.

- Added auto-formatting for comments (using the Vim option
formatoptions=qroc).

- Added the script option PHP_BracesAtCodeLevel to indent the '{' and '}' at
the same level than the code they contain.

- Some code cleaning and typo corrections (Thanks to Emanuele Giaquinta for
his patches).
 
 Download:
   
 http://www.vim.org/scripts/download_script.php?src_id=4387
   
 Or
 
 http://www.2072productions.com/vim/indent/php.vim
 
 
 Contact me if you have any problem with this version.

Reply | Threaded
Open this post in threaded view
|

RE: Vote for the default PHP indent script

John Wellesz
In reply to this post by John Wellesz
Hi,

Are you using utf-8 encoding? Which version of the script were you using?
This hang problem has been fixed in version 1.12, the script detects when
you’re using utf-8 and makes what is necessary to prevent VIM to hang.

Please tell me if it works.

Thank you,

John Wellesz

________________________________________
De : Jose Cedeno [mailto:[hidden email]]
Envoyé : vendredi 24 juin 2005 05:59
À : John Wellesz
Cc : [hidden email]
Objet : Re: Vote for the default PHP indent script

Hi,

I hated the old php indenting script. I almost thought about switching to
emacs because of the problems with it. When I saw your script in the vim.org
site, I downloaded and started to use it. I must say that I love it, I rated
it life changing. Unfortunately I had to stop using it due to the fact that
vim hangs a lot. I discovered on my own that Ctrl+C would stop it, but it
was hanging all the time :( . I know the problem is not with this script and
that's why I'm not complaining :) .

Keep the good work,
Jose

On 6/23/05, John Wellesz <[hidden email]> wrote:
Version 1.15 has been released!

What's new:

- Corrected some problems with the indentation of multiline "array()"
declarations.

- Added auto-formatting for comments (using the Vim option
formatoptions=qroc).

- Added the script option PHP_BracesAtCodeLevel to indent the '{' and '}' at
the same level than the code they contain.

- Some code cleaning and typo corrections (Thanks to Emanuele Giaquinta for
his patches).

Download:

http://www.vim.org/scripts/download_script.php?src_id=4387

Or

http://www.2072productions.com/vim/indent/php.vim


Contact me if you have any problem with this version.


Reply | Threaded
Open this post in threaded view
|

RE: Vote for the default PHP indent script

John Wellesz
In reply to this post by John Wellesz
Version 1.17 has been released!
 
What's new:
 
- Now starting and ending '*' of multiline '/* */' comments are aligned on
  the '*' of the '/*' comment starter.
- Some code improvements that make indentation faster.
- Now following parts of split lines are indented:
    Instead of:
        $foo=
        "foo"
        ."foo";

    You have:
        $foo=
            "foo"
           ."foo";

- If a "case : break;" was declared on a single line, the following "case"
  was not indented correctly.
- If a </script> html tag was preceded by a "?>" it wasn't indented.
- Some other minor corrections and improvements.


 Download:
   
 http://www.vim.org/scripts/download_script.php?src_id=4411
   
 Or
 
 http://www.2072productions.com/vim/indent/php.vim
 
 
 Contact me if you have any problem with this version.

Reply | Threaded
Open this post in threaded view
|

RE: Vote for the default PHP indent script

Bram Moolenaar

John Wellesz wrote:

> Version 1.17 has been released!

I'm glad you keep improving the script.  That by itself would already be
enough reason to include this version.

When you have a version that appears to be working well (after a few
days of testing) could you send me a copy without the change history?
A hint that the version on the website has more comments should be
sufficient.  Just trying to keep the runtime file size a tiny bit
smaller...

--
Two fish in a tank. One says to the other:
"Do you know how to drive this thing?"

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\              Project leader for A-A-P -- http://www.A-A-P.org        ///
 \\\     Buy LOTR 3 and help AIDS victims -- http://ICCF.nl/lotr.html   ///
Reply | Threaded
Open this post in threaded view
|

RE: Vote for the default PHP indent script

John Wellesz
> I'm glad you keep improving the script.  That by itself would already be
> enough reason to include this version.

Thank you :)

> When you have a version that appears to be working well (after a few
> days of testing) could you send me a copy without the change history?
> A hint that the version on the website has more comments should be
> sufficient.  Just trying to keep the runtime file size a tiny bit
> smaller...

OK, I'll send you the current version with fewer comments on Saturday if no
bug is found because I will be away from the net from July the 10 till
August the 1st...

The version 1.17 should be OK; I tested it thoroughly before releasing it on
VIM.ORG


Reply | Threaded
Open this post in threaded view
|

RE: Vote for the default PHP indent script

John Wellesz
In reply to this post by John Wellesz
Version 1.18 has been released!

What's new:

- No more problems with Vim 6.3 and UTF-8.
- Opening braces "{" are always indented according to their block starter.
                Instead of:
                        if( $test
                                && $test2 )
                                {
                    }

                You have:
                        if( $test
                                && $test2 )
                        {
                  }

Download:
 
 http://www.vim.org/scripts/download_script.php?src_id=4587
 
  Or
 
 http://www.2072productions.com/vim/indent/php.vim


Contact me if you have any problem with this version.

Reply | Threaded
Open this post in threaded view
|

RE: Vote for the default PHP indent script

John Wellesz
Version 1.181 corrects a mistake: I Forgot to register 'class' as a block
starter so the '{' after a 'class' could be wrongly indented...

  http://www.vim.org/scripts/download_script.php?src_id=4590
 
   Or
 
  http://www.2072productions.com/vim/indent/php.vim


John


> -----Message d'origine-----
> De : John Wellesz [mailto:[hidden email]]
> Envoyé : jeudi 15 septembre 2005 23:32
> À : [hidden email]
> Objet : RE: Vote for the default PHP indent script
>
> Version 1.18 has been released!
>
> What's new:
>
> - No more problems with Vim 6.3 and UTF-8.
> - Opening braces "{" are always indented according to their block starter.
> Instead of:
> if( $test
> && $test2 )
> {
>                     }
>
> You have:
> if( $test
> && $test2 )
> {
>                   }
>
> Download:
>
>  http://www.vim.org/scripts/download_script.php?src_id=4587
>
>   Or
>
>  http://www.2072productions.com/vim/indent/php.vim
>
>
> Contact me if you have any problem with this version.


Reply | Threaded
Open this post in threaded view
|

Re: Vote for the default PHP indent script

Bart Kuik
I tested it and found it very helpful, but I've got one problem with it.
I often write php code like this:

------8<---------8<------------8<---------8<------
<?
$list = array(
____"key"____________=> "value",
____"anotherKey"____=> "anotherValue"
);
?>
<html>
____<head>
________<title>indent</title>
____</head>
____<body>
________<table>
<?
____________foreach ($list as $key=>$value) {
?>
________________<tr>
____________________<td><?=$key?></td>
____________________<td><?=$value?></td>
________________</tr>
<?
____________}
?>
________</table>
____</body>
</html>
------8<---------8<------------8<---------8<------

As you can see, I keep the php start- and end-tags on the start of the
line, but the tags inside them are aligned with the HTML code. This
way I have a clear view of the structure. Your script indents the
foreach-statement like this:

------8<---------8<------------8<---------8<------
<?
foreach ($list as $key=>$value) {
?>
------8<---------8<------------8<---------8<------

Could this be fixed so that the php-code knows about the indentation
of the html/javascript/css-code and will indent accordingly,
independent of the place of the '<?' and '?>' tags?

Bart

2005/9/17, John Wellesz <[hidden email]>:

> Version 1.181 corrects a mistake: I Forgot to register 'class' as a block
> starter so the '{' after a 'class' could be wrongly indented...
>
>   http://www.vim.org/scripts/download_script.php?src_id=4590
>
>    Or
>
>   http://www.2072productions.com/vim/indent/php.vim
>
>
> John
>
>
> > -----Message d'origine-----
> > De: John Wellesz [mailto:[hidden email]]
> > Envoyé: jeudi 15 septembre 2005 23:32
> > À: [hidden email]
> > Objet: RE: Vote for the default PHP indent script
> >
> > Version 1.18 has been released!
> >
> > What's new:
> >
> > - No more problems with Vim 6.3 and UTF-8.
> > - Opening braces "{" are always indented according to their block starter.
> >               Instead of:
> >                       if( $test
> >                               && $test2 )
> >                               {
> >                       }
> >
> >               You have:
> >                       if( $test
> >                               && $test2 )
> >                       {
> >                   }
> >
> > Download:
> >
> >  http://www.vim.org/scripts/download_script.php?src_id=4587
> >
> >   Or
> >
> >  http://www.2072productions.com/vim/indent/php.vim
> >
> >
> > Contact me if you have any problem with this version.
>
>
>


--
blog : http://foobart001.blogspot.com
Reply | Threaded
Open this post in threaded view
|

RE: Vote for the default PHP indent script

John Wellesz
Hello,


> ------8<---------8<------------8<---------8<------
> <?
> $list = array(
> ____"key"____________=> "value",
> ____"anotherKey"____=> "anotherValue"
> );
> ?>
> <html>
> ____<head>
> ________<title>indent</title>
> ____</head>
> ____<body>
> ________<table>
> <?
> ____________foreach ($list as $key=>$value) {
> ?>
> ________________<tr>
> ____________________<td><?=$key?></td>
> ____________________<td><?=$value?></td>
> ________________</tr>
> <?
> ____________}
> ?>
> ________</table>
> ____</body>
> </html>
> ------8<---------8<------------8<---------8<------
>
> As you can see, I keep the php start- and end-tags on the start of the
> line, but the tags inside them are aligned with the HTML code. This
> way I have a clear view of the structure. Your script indents the
> foreach-statement like this:
>
> ------8<---------8<------------8<---------8<------
> <?
> foreach ($list as $key=>$value) {
> ?>
> ------8<---------8<------------8<---------8<------
>
> Could this be fixed so that the php-code knows about the indentation
> of the html/javascript/css-code and will indent accordingly,
> independent of the place of the '<?' and '?>' tags?

I don't think so because one of the principles of this script is to ignore
what is outside the '<?' and '?>' to indent correctly the PHP code...  (The
script sees a file where everything but the PHP code has been removed)
Furthermore, this script has no knowledge of the html structure; it would be
very difficult to implement this behavior.

John