sponsor Vim development Vim logo Vim Book Ad

phpfolding.vim : Automatic folding of PHP functions, classes,.. (also folds related PhpDoc)

 script karma  Rating 139/48, Downloaded by 4767    Comments, bugs, improvements  Vim wiki

created by
Ray Burgemeestre
 
script type
utility
 
description
This script can fold PHP functions and/or classes, properties with their PhpDoc,
without manually adding marker style folds ({{{ and }}}). It will generate the following
folds when executed:

<?php
/**
* This is Foo...
* @author Foo
*/
class Foo {
+-- 11 lines: function fooFunction($bar) ** -----------------------------------------
+--   8 lines: function fooFunction2($bar) ** ----------------------------------------
+-- 24 lines: function fooFunction3($bar) -------------------------------------------
}

+--112 lines: class Foo2 ** -------------------------------------------------------------
?>

Based on e.g. functions declared like this:

<?php
/**
* This is fooFunction...
*
* @param mixed $bar
* @access public
* @return void
*/
function fooFunction($bar) {
    [...]
}
?>

SCREENSHOT
You can view a screenshot here: http://blog.cppse.nl/phpfolding-vim
Or direct link: http://blog.cppse.nl/folding.gif

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.

NOTE
If anyone has emailed me and I have not replied, it's probably lost. I just found out
hotmail recognizes alot as junk. I now turned off the junk filter..

NOTE2:
I'm currently more active again with this project, so if you have any contributions to
this project, please let me know.

NOTE3:
Will update some stuff tomorrow (30-12-2012) and answer some mails, I had problems
with the Junk filter of Hotmail again, so I changed my email here. And will write replies
tomorrow. You can also reply here now: http://blog.cppse.nl/phpfolding-vim

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)
 
install details
INSTALL
1. Put phpfolding.vim in your plugin directory (~/.vim/plugin)
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

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 :)
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
phpfolding.vim 1.7 2010-01-16 6.0 Ray Burgemeestre The following much appreciated contributions are from LiTWoL (Oleg Terenchuk):
1. Check if filetype is PHP before automatically creating folds
2. Call EnableFastPHPFolds after reading file into the buffer
3. Avoid reload check
4. Added configuration variable to disable autofolding.
phpfolding.vim 1.6 2006-08-26 6.0 Ray Burgemeestre 1. Added nested fold support (recursion).
2. Improved install instructions. Thanks to Peter Hodge for some useful information.
3. Added phpdoc "docblock" support (/**#@+ and #@- templates).
4. Minor adjustments in FindPureBlockStart and FindPatternStart.
phpfolding.vim 1.5 2006-08-16 6.0 Ray Burgemeestre 1. Previously opened folds are now remembered again. I accidentally broke this in another version.
2. The script now can fold abstract classes too. Thanks to Stefan Walk for adjusting the regex.
3. Changed behaviour and fixed a bug in searching for trailing empty lines.
4. Correct folding of nested folds will be supported in the *next* version.
5. Changed some default settings.
phpfolding.vim 1.4.1 2006-08-08 6.0 Ray Burgemeestre 1. Removed windows carriage returns (^M) throughout the file.
phpfolding.vim 1.4 2006-08-06 6.0 Ray Burgemeestre 1. The sequence of creating the custom folds no longer matters.
2. Added some more custom folds (includes, defines, .. with phpdoc can now be folded too).
3. It can search farther for PhpDoc comments.
4. It can be configured to fold more empty 'trailing' lines.
5. Adjusted PHPFoldText a bit.
6. Fixed a minor bug in the class fold regex (PEAR's QuickForm.php works now too).
phpfolding.vim 1.3 2006-07-30 6.0 Ray Burgemeestre 1. Extensive/slow parsing of brackets is now optional.
2. Class variables "var $foo = '';" can be folded with their PhpDoc.
3. Marker style folds ({{{, }}}) can be folded now too.
phpfolding.vim 1.2 2006-07-30 6.0 Ray Burgemeestre 1. Previously opened folds are restored when executing the script multiple times (thanks to Marijn Koesen for that idea)
2. The cursor position is now remembered and restored in Linux
3. Cleaned up foldtext a bit
phpfolding.vim 1.1 2006-07-29 6.0 Ray Burgemeestre 1. PHP API comments no longer appear in the fold names.
2. The following function header is now recognized:

function (...,
    ....)
{
phpfolding.vim 1.0 2006-07-29 6.0 Ray Burgemeestre Initial upload
ip used for rating: 50.16.108.167

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
SourceForge.net Logo