Neither one nor Many

 
December 29 2012

To everybody that contacted me, and whom I didn't reply to from my hotmail address: please read this, I had problems with the Hotmail Junk filter *again* sorry!

This script can fold PHP functions and/or classes, properties with their PhpDoc, without manually adding marker style folds ({{{ and }}}). It will fold stuff into something like the following screenshot.

Features

  • It remembers fold settings. If you add functions and execute the script again, your opened folds will not be closed.
  • It will not be confused by brackets in comment blocks or string literals.
  • The folding of class properties with their PhpDoc comments.
  • The folding of all class properties into one fold.
  • Folding the original marker style folds too.
  • An "**" postfixing the fold indicates PhpDoc is inside (configurable).
  • An "**#@+" postfixing the fold indicates PhpDocBlock is inside (configurable).
  • Empty lines postfixing the folds can be configured to be included in the fold.
  • Nested folds are supported (functions inside functions, etc.)

Future

  • Better 'configurability' as opposed to editting the PHPCustomFolds() function and some "Script configuration" global variables.

Compatibility

This script is tested successfully with Vim version >= 6.3 on windows and linux (With 6.0 it works sometimes, I don't recommend using it in that version)

But I'd recommend using a new vim, at the time of writing 7.3 works fine with it!

spf13's vim distribution

You can also install spf13's vim distribution (if you like it). phpfolding.vim is included in this package too. I'm testing it out at the moment, like it so far. Kind of missed my mappings though, so I still added <F5>, <F6> and <F7> to my .vimrc.

Also I noticed EnableFastPHPFolds gives better results now better than EnablePHPFolds, this is what I experienced at work anyway, with vim 7.3. This used to be the other way around..

INSTALL

  1. Put phpfolding.vim in your plugin directory (~/.vim/plugin)
    i.e., wget: http://www.vim.org/scripts/script.php?script_id=1623
  2. You might want to add the following keyboard mappings to your .vimrc:
    map <F5> <Esc>:EnableFastPHPFolds<Cr>
    map <F6> <Esc>:EnablePHPFolds<Cr>
    map <F7> <Esc>:DisablePHPFolds<Cr>
    
  3. You might want to add the following lines to php.vim in your after/ftplugin directory (~/.vim/after/ftplugin/php.vim), this will be executed after opening a .php file:
    " Don't use the PHP syntax folding
    setlocal foldmethod=manual
    
    " Turn on PHP fast folds
    EnableFastPHPFolds
    
  4. It might be necessary that you load the plugin from your .vimrc, i.e.:
    let php_folding=0
      (if you can't use the after directory in step 3)
    source ~/path/to/phpfolding.vim
      (if you're not using the default plugin directory)
    

Known issues

  1. C++ style commented brackets can still interfere with the bracket matching.
    For example comments like are not recognized as comments: // old: for (...) {
    Whereas C-style comments are, e.g.: /* old: for (...) { */
  2. The following won't be matched with the Regex in FindFoldStart():
    function (...,
    ....,
    ....,
    ) {
    Though Steve McConnell (writer of Code Complete) would ask why you'd need more then two lines for function parameters :)

Note: My Hotmail Junk filter probably ate a some e-mails I received from vim.org

I use my hotmail address for accounts where my e-mail is publicaly displayed, like in my profile page on vim.org. (I don't want spam in my primary e-mail inbox). So I only check my e-mail this hotmail address every now and then, probably every 6 months and it's full of stuff spam so I could have easily missed e-mails regarding phpfolding. I discovered in 2010 that there was feedback in my Junk filter, so I turned the Junk filter off, anyways that's how I remember it (and how I wrote it down). Now in 2012 I check the Junk filter again, and there is another email. Junk is automatically deleted after X days, so who knows how many mails I might have missed.

Really don't understand why it got into Junk, this specific person wrote hello, introduced himself, said something nice and signs off the e-mail. All in normal letter formatting, no URL's or e-mail addresses used, no images, just plain text. It was a valid gmail address, there were no weird Headers, and it was sent from gmail itself not some other smtp server...

You can contact me here by commenting, or send me an e-mail to the new one I use in my profile at vim.org.

Webdevelopment Comments (3)

Raül

2014-05-30 13:01:14

Hi,

When i try to install this plugin with vundle plugin vim shows the following error:

Se ha detectado un error al procesar /home/rtorralba/.vim/bundle/phpfolding.vim/plugin/phpfolding.vim:
línea 57
E15: La expresión no es válida: &cpo^M
línea 58
E488: Caracteres en exceso al final de la línea: cpo&vim^M
línea 59
E492: No es una orden del editor: ^M
línea 61
E15: La expresión no es válida: exists('loaded_phpfolding')^M
línea 68
E488: Caracteres en exceso al final de la línea
línea 632
E488: Caracteres en exceso al final de la línea
línea 634
E171: Falta ":endif"

Greetings.

Raül

2014-05-30 13:01:54

Hi,

When i try to install this plugin with vundle plugin vim shows the following error:

Se ha detectado un error al procesar /home/rtorralba/.vim/bundle/phpfolding.vim/plugin/phpfolding.vim:
línea 57
E15: La expresión no es válida: &cpo^M
línea 58
E488: Caracteres en exceso al final de la línea: cpo&vim^M
línea 59
E492: No es una orden del editor: ^M
línea 61
E15: La expresión no es válida: exists('loaded_phpfolding')^M
línea 68
E488: Caracteres en exceso al final de la línea
línea 632
E488: Caracteres en exceso al final de la línea
línea 634
E171: Falta ":endif"

Greetings.

rayburgemeestre

2014-06-01 20:28:28

Hi Raül


I see it's a problem with the line endings. Looks like I made a mistake in 1.8 @:(@
Someone issued a PR, that I just merged, and I've uploaded a new version 1.9.

See:

- http://www.vim.org/scripts/script.php?script_id=1623
- https://github.com/rayburgemeestre/phpfolding.vim/tree/1.9 (or master)

The vim-scripts git repository should be updated soon. I have no control over that account..

Thanks for your feedback, Ray


Leave a Reply

Comment may not be visible immediately, because I process everything manually.**

**) I plan to automate this.., but it's on my ToDo since for ever..


Author:
Ray Burgemeestre
february 23th, 1984

Topics:
C++, Linux, Webdev

Other interests:
Music, Art, Zen