From 216f8353f8fa9905104c01b1bce4c1e1aa820d5a Mon Sep 17 00:00:00 2001 From: Jess Telford Date: Thu, 10 Mar 2011 13:20:39 +1100 Subject: [PATCH 01/32] Folding private, public, protected class variables + multi-line parameter functions --- plugin/phpfolding.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin/phpfolding.vim b/plugin/phpfolding.vim index b25a3c7..1a3b343 100644 --- a/plugin/phpfolding.vim +++ b/plugin/phpfolding.vim @@ -166,7 +166,7 @@ function! s:PHPCustomFolds() " {{{ call s:PHPFoldPureBlock('function', s:FOLD_WITH_PHPDOC) " Fold class properties with PhpDoc (var $foo = NULL;) - call s:PHPFoldProperties('^\s*var\s\$', ";", s:FOLD_WITH_PHPDOC, 1, 1) + call s:PHPFoldProperties('^\s*\(\(private\)\|\(public\)\|\(protected\)\|\(var\)\)\s\$', ";", s:FOLD_WITH_PHPDOC, 1, 1) " Fold class without PhpDoc (class foo {}) call s:PHPFoldPureBlock('^\s*\(abstract\s*\)\?class', s:FOLD_WITH_PHPDOC) @@ -380,9 +380,9 @@ function! s:FindPureBlockStart(startPattern) " {{{ " This function can match the line its on *again* if the cursor was " restored.. hence we search twice if needed.. let currentLine = line('.') - let line = search(a:startPattern . '.*\%[\n].*\%[\n].*{', 'bW') + let line = search(a:startPattern . '.*\(\%[\n].*\)\{,10\}{', 'bW') if currentLine == line - let line = search(a:startPattern . '.*\%[\n].*\%[\n].*{', 'bW') + let line = search(a:startPattern . '.*\(\%[\n].*\)\{,10\}{', 'bW') endif return line endfunction From 433a972fd8ab7663f7c3e61900d5ba981ec5885c Mon Sep 17 00:00:00 2001 From: everzet Date: Sun, 24 Apr 2011 05:08:07 +0300 Subject: [PATCH 02/32] do not fold classes --- plugin/phpfolding.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/phpfolding.vim b/plugin/phpfolding.vim index b25a3c7..13a0fed 100644 --- a/plugin/phpfolding.vim +++ b/plugin/phpfolding.vim @@ -169,7 +169,7 @@ function! s:PHPCustomFolds() " {{{ call s:PHPFoldProperties('^\s*var\s\$', ";", s:FOLD_WITH_PHPDOC, 1, 1) " Fold class without PhpDoc (class foo {}) - call s:PHPFoldPureBlock('^\s*\(abstract\s*\)\?class', s:FOLD_WITH_PHPDOC) + "call s:PHPFoldPureBlock('^\s*\(abstract\s*\)\?class', s:FOLD_WITH_PHPDOC) " Fold define()'s with their PhpDoc call s:PHPFoldProperties('^\s*define\s*(', ";", s:FOLD_WITH_PHPDOC) From 7524fa620e80e576c7c71d640f13c91ceeb8497c Mon Sep 17 00:00:00 2001 From: Takuya Nishigori Date: Sat, 27 Aug 2011 12:28:17 +0900 Subject: [PATCH 03/32] plugin/phpfolding.vim moved to ftplugin/php/ . --- {plugin => ftplugin/php}/phpfolding.vim | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {plugin => ftplugin/php}/phpfolding.vim (100%) diff --git a/plugin/phpfolding.vim b/ftplugin/php/phpfolding.vim similarity index 100% rename from plugin/phpfolding.vim rename to ftplugin/php/phpfolding.vim From c4c9372e7de07bab0c63175019b1e7dab75a656c Mon Sep 17 00:00:00 2001 From: Gregory Cornelius Date: Thu, 11 Oct 2012 12:26:28 -0400 Subject: [PATCH 04/32] Don't fold classes. --- plugin/phpfolding.vim | 3 --- 1 file changed, 3 deletions(-) diff --git a/plugin/phpfolding.vim b/plugin/phpfolding.vim index b25a3c7..78a4ce8 100644 --- a/plugin/phpfolding.vim +++ b/plugin/phpfolding.vim @@ -168,9 +168,6 @@ function! s:PHPCustomFolds() " {{{ " Fold class properties with PhpDoc (var $foo = NULL;) call s:PHPFoldProperties('^\s*var\s\$', ";", s:FOLD_WITH_PHPDOC, 1, 1) - " Fold class without PhpDoc (class foo {}) - call s:PHPFoldPureBlock('^\s*\(abstract\s*\)\?class', s:FOLD_WITH_PHPDOC) - " Fold define()'s with their PhpDoc call s:PHPFoldProperties('^\s*define\s*(', ";", s:FOLD_WITH_PHPDOC) From 6443ccd3daf769b2889ba8959bb95e26e35b98a1 Mon Sep 17 00:00:00 2001 From: pekepeke Date: Tue, 9 Jul 2013 19:44:00 +0900 Subject: [PATCH 05/32] move to ftplugin/php --- {plugin => ftplugin/php}/phpfolding.vim | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {plugin => ftplugin/php}/phpfolding.vim (100%) diff --git a/plugin/phpfolding.vim b/ftplugin/php/phpfolding.vim similarity index 100% rename from plugin/phpfolding.vim rename to ftplugin/php/phpfolding.vim From 7adee0541e5050d83d2e0cccfdd2fa75e008cc85 Mon Sep 17 00:00:00 2001 From: pekepeke Date: Tue, 9 Jul 2013 19:51:57 +0900 Subject: [PATCH 06/32] trailing white space. add option(fold class). fixes fatal behavior --- ftplugin/php/phpfolding.vim | 53 ++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/ftplugin/php/phpfolding.vim b/ftplugin/php/phpfolding.vim index 1a3b343..464aa57 100644 --- a/ftplugin/php/phpfolding.vim +++ b/ftplugin/php/phpfolding.vim @@ -28,9 +28,9 @@ " " let g:DisableAutoPHPFolding = 1 " -" By default EnableFastPHPFolds is called. Do these mess up your folds, +" By default EnableFastPHPFolds is called. Do these mess up your folds, " you can try to replace EnableFastPHPFolds by EnablePHPFolds. You can -" change this in function s:CheckAutocmdEnablePHPFold. +" change this in function s:CheckAutocmdEnablePHPFold. " " NOTE " It may be that you need to load the plugin from your .vimrc manually, in @@ -64,6 +64,7 @@ let loaded_phpfolding = 1 if !exists("g:DisableAutoPHPFolding") let g:DisableAutoPHPFolding = 0 endif +let g:DisablePHPFoldingClass = get(g:, 'DisablePHPFoldingClass', 1) " }}} command! EnableFastPHPFolds call EnableFastPHPFolds() @@ -109,8 +110,8 @@ function! s:EnablePHPFolds(...) " {{{ let s:savedCursor = line(".") " Initialize variables - set foldmethod=manual - set foldtext=PHPFoldText() + setlocal foldmethod=manual + setlocal foldtext=PHPFoldText() let s:openFoldListItems = 0 let s:fileLineCount = line('$') @@ -119,8 +120,8 @@ function! s:EnablePHPFolds(...) " {{{ " Move to end of file - exec s:fileLineCount - + exec s:fileLineCount + " First pass: Look for Folds, remember opened folds let s:foldingMode = s:MODE_REMEMBER_FOLD_SETTINGS call s:PHPCustomFolds() @@ -128,17 +129,17 @@ function! s:EnablePHPFolds(...) " {{{ " Second pass: Recreate Folds, restore previously opened let s:foldingMode = s:MODE_CREATE_FOLDS " .. Remove all folds first - normal zE + normal! zE let s:foldsCreated = 0 call s:PHPCustomFolds() " .. Fold all - normal zM + normal! zM " Restore previously opened folds let currentItem = 0 while currentItem < s:openFoldListItems exec s:foldsOpenedList{currentItem} - normal zo + normal! zo let currentItem = currentItem + 1 endwhile @@ -147,13 +148,13 @@ function! s:EnablePHPFolds(...) " {{{ " Restore cursor exec s:savedCursor - + endfunction " }}} function! s:DisablePHPFolds() " {{{ - "set foldmethod=manual - set foldtext= - normal zE + "setlocal foldmethod=manual + setlocal foldtext= + normal! zE echo "php fold(s) deleted" endfunction " }}} @@ -168,9 +169,11 @@ function! s:PHPCustomFolds() " {{{ " Fold class properties with PhpDoc (var $foo = NULL;) call s:PHPFoldProperties('^\s*\(\(private\)\|\(public\)\|\(protected\)\|\(var\)\)\s\$', ";", s:FOLD_WITH_PHPDOC, 1, 1) - " Fold class without PhpDoc (class foo {}) - call s:PHPFoldPureBlock('^\s*\(abstract\s*\)\?class', s:FOLD_WITH_PHPDOC) - + if !g:DisablePHPFoldingClass + " Fold class without PhpDoc (class foo {}) + call s:PHPFoldPureBlock('^\s*\(abstract\s*\)\?class', s:FOLD_WITH_PHPDOC) + endif + " Fold define()'s with their PhpDoc call s:PHPFoldProperties('^\s*define\s*(', ";", s:FOLD_WITH_PHPDOC) @@ -237,7 +240,7 @@ function! s:PHPFoldPureBlock(startPattern, ...) " {{{ if s:foldingMode != s:MODE_REMEMBER_FOLD_SETTINGS " Remove created folds - normal zR + normal! zR endif endfunction " }}} @@ -275,7 +278,7 @@ function! s:PHPFoldMarkers(startPattern, endPattern, ...) " {{{ if s:foldingMode != s:MODE_REMEMBER_FOLD_SETTINGS " Remove created folds - normal zR + normal! zR endif endfunction " }}} @@ -320,12 +323,12 @@ function! s:PHPFoldProperties(startPattern, endPattern, ...) " {{{ " Goto fold start (remember we're searching upwards) exec s:lineStart - + endwhile if s:foldingMode != s:MODE_REMEMBER_FOLD_SETTINGS " Remove created folds - normal zR + normal! zR endif endfunction " }}} @@ -351,7 +354,7 @@ function! s:HandleFold() " {{{ let s:foldsOpenedList{s:openFoldListItems} = s:lineStart let s:openFoldListItems = s:openFoldListItems + 1 endif - + elseif s:foldingMode == s:MODE_CREATE_FOLDS " Correct lineStop if needed (the script might have mistaken lines " beyond the file's scope for trailing empty lines) @@ -478,7 +481,7 @@ function! s:FindPureBlockEnd(startPair, endPair, searchStartPairFirst, ...) " {{ " Then be greedy with extra 'trailing' empty line(s) let s:counter = 0 while s:counter < s:searchEmptyLinesPostfixing - let linestr = getline(line + 1) + let linestr = getline(line + 1) if (matchstr(linestr, '^\s*$') == linestr) let line = line + 1 endif @@ -497,7 +500,7 @@ function! s:FindPatternEnd(endPattern) " {{{ " Then be greedy with extra 'trailing' empty line(s) let s:counter = 0 while s:counter < s:searchEmptyLinesPostfixing - let linestr = getline(line + 1) + let linestr = getline(line + 1) if (matchstr(linestr, '^\s*$') == linestr) let line = line + 1 endif @@ -553,7 +556,7 @@ function! PHPFoldText() " {{{ endwhile let lineString = getline(currentLine) endif - + " Some common replaces... " if currentLine != v:foldend let lineString = substitute(lineString, '/\*\|\*/\d\=', '', 'g') @@ -572,7 +575,7 @@ function! PHPFoldText() " {{{ " Append an (a) if there is PhpDoc in the fold (a for API) if currentLine != v:foldstart let lineString = lineString . " " . g:phpDocIncludedPostfix . " " - endif + endif " Return the foldtext return "+--".lines." lines: " . lineString From 0fb5f03bff0ed91aa4fb073fb35279ab8a89306f Mon Sep 17 00:00:00 2001 From: pekepeke Date: Tue, 9 Jul 2013 20:03:22 +0900 Subject: [PATCH 07/32] fixes work well as ftplugin --- ftplugin/php/phpfolding.vim | 41 +++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/ftplugin/php/phpfolding.vim b/ftplugin/php/phpfolding.vim index 464aa57..28585a9 100644 --- a/ftplugin/php/phpfolding.vim +++ b/ftplugin/php/phpfolding.vim @@ -51,9 +51,18 @@ " at the "Script configuration" part. " " This script is tested with Vim version >= 6.3 on windows and linux. +let s:save_cpo = &cpo +set cpo&vim + +" ftplugin section +if &filetype == "php" && ! g:DisableAutoPHPFolding + call s:EnableFastPHPFolds() +endif " Avoid reloading {{{1 if exists('loaded_phpfolding') + let &cpo = s:save_cpo + unlet s:save_cpo finish endif @@ -596,19 +605,21 @@ function! SkipMatch() " {{{ endfun " }}} -" Check filetype == php before automatically creating (fast) folds {{{1 -function! s:CheckAutocmdEnablePHPFold() - if &filetype == "php" && ! g:DisableAutoPHPFolding - call s:EnableFastPHPFolds() - endif -endfunction -" }}} - -" Call CheckAutocmdEnablePHPFold on BufReadPost {{{1 -augroup SetPhpFolds - au! - au BufReadPost * call s:CheckAutocmdEnablePHPFold() -augroup END -" }}} - +" " Check filetype == php before automatically creating (fast) folds {{{1 +" function! s:CheckAutocmdEnablePHPFold() +" if &filetype == "php" && ! g:DisableAutoPHPFolding +" call s:EnableFastPHPFolds() +" endif +" endfunction +" " }}} + +" " Call CheckAutocmdEnablePHPFold on BufReadPost {{{1 +" augroup SetPhpFolds +" au! +" au BufReadPost * call s:CheckAutocmdEnablePHPFold() +" augroup END +" " }}} + +let &cpo = s:save_cpo +unlet s:save_cpo " vim:ft=vim:foldmethod=marker:nowrap:tabstop=4:shiftwidth=4 From 68c6518b223b660cbca9bca3ff6d41d81195f3f9 Mon Sep 17 00:00:00 2001 From: pekepeke Date: Tue, 9 Jul 2013 20:06:47 +0900 Subject: [PATCH 08/32] fixes work well as ftplugin --- ftplugin/php/phpfolding.vim | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/ftplugin/php/phpfolding.vim b/ftplugin/php/phpfolding.vim index 28585a9..1568f5f 100644 --- a/ftplugin/php/phpfolding.vim +++ b/ftplugin/php/phpfolding.vim @@ -54,13 +54,13 @@ let s:save_cpo = &cpo set cpo&vim -" ftplugin section -if &filetype == "php" && ! g:DisableAutoPHPFolding - call s:EnableFastPHPFolds() -endif - " Avoid reloading {{{1 if exists('loaded_phpfolding') + " ftplugin section + if !get(g:, 'DisableAutoPHPFolding', 0) + call s:EnableFastPHPFolds() + endif + let &cpo = s:save_cpo unlet s:save_cpo finish @@ -620,6 +620,11 @@ endfun " augroup END " " }}} +" ftplugin section +if !get(g:, 'DisableAutoPHPFolding', 0) + call s:EnableFastPHPFolds() +endif + let &cpo = s:save_cpo unlet s:save_cpo " vim:ft=vim:foldmethod=marker:nowrap:tabstop=4:shiftwidth=4 From 53604bc95f475db2b3adce6c2e4db461d2b2b863 Mon Sep 17 00:00:00 2001 From: Jonathan Johnson Date: Tue, 13 Aug 2013 13:27:25 -0600 Subject: [PATCH 09/32] don't fold classes --- plugin/phpfolding.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/phpfolding.vim b/plugin/phpfolding.vim index b25a3c7..eab21b8 100644 --- a/plugin/phpfolding.vim +++ b/plugin/phpfolding.vim @@ -169,7 +169,7 @@ function! s:PHPCustomFolds() " {{{ call s:PHPFoldProperties('^\s*var\s\$', ";", s:FOLD_WITH_PHPDOC, 1, 1) " Fold class without PhpDoc (class foo {}) - call s:PHPFoldPureBlock('^\s*\(abstract\s*\)\?class', s:FOLD_WITH_PHPDOC) + " call s:PHPFoldPureBlock('^\s*\(abstract\s*\)\?class', s:FOLD_WITH_PHPDOC) " Fold define()'s with their PhpDoc call s:PHPFoldProperties('^\s*define\s*(', ";", s:FOLD_WITH_PHPDOC) From 3720f03bfb77b786567600cc4045425e86fc7549 Mon Sep 17 00:00:00 2001 From: rayburgemeestre Date: Mon, 26 Aug 2013 00:37:53 +0200 Subject: [PATCH 10/32] Version 1.8 Thanks to Dmitri Perunov for informing me of the fixes pending on github! 1. Fix for folding private, public, protected class variables + multi-line param by Jess Telford 2. Fix to make it work well as ftplugin (default now), add option for folding classes (disabled by default) and fix for fatal behavior by pekepeke --- README | 90 ++++++++++++++++++++++++------------- ftplugin/php/phpfolding.vim | 7 ++- 2 files changed, 64 insertions(+), 33 deletions(-) diff --git a/README b/README index fb003e1..b4985cc 100644 --- a/README +++ b/README @@ -1,43 +1,43 @@ This is a mirror of http://www.vim.org/scripts/script.php?script_id=1623 -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: +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: Based on e.g. functions declared like this: SCREENSHOT -You can view a screenshot here: http://www.fighterz.net/trig/folding.gif +You can view a screenshot here: http://blog.cppse.nl/phpfolding-vim FEATURES -- It remembers fold settings. If you add functions and execute the script again, +- 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. @@ -47,19 +47,47 @@ FEATURES - 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.) +- Folding private, public, protected class variables + multi-line param. +- Foloding the class is now an option disabled by default. +- Now works properly as ftplugin 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.. +- Better 'configurability' as opposed to editting the PHPCustomFolds() function + and some "Script configuration" global variables. -NOTE2: -I'm currently more active again with this project, so if you have any contributions to -this project, please let me know. +CONTRIBUTE / GITHUB +This project is hosted on github as a mirror through + https://github.com/vim-scripts/phpfolding.vim +I do not own vim-scripts, so you could also fork mine: + https://github.com/rayburgemeestre/phpfolding.vim +It's then easier for me to accept pull requests and upload new version(s) here. 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 +1. Put phpfolding.vim in your plugin directory (~/.vim/ftplugin) + + Make sure you have "filetype plugin on" in your .vimrc! + + (folds will then be created after opening a file is recognized as php.) + +2. Alternatively, if you want to control loading manually, you might want to + add the following keyboard mappings to your .vimrc: + + map :EnableFastPHPFolds + map :EnablePHPFolds + map :DisablePHPFolds + +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 (...) { */ +(Edit: not sure if this is an issue anymore..) diff --git a/ftplugin/php/phpfolding.vim b/ftplugin/php/phpfolding.vim index 1568f5f..86248dd 100644 --- a/ftplugin/php/phpfolding.vim +++ b/ftplugin/php/phpfolding.vim @@ -1,7 +1,7 @@ " Plugin for automatic folding of PHP functions (also folds related PHPdoc) " " Maintainer: Ray Burgemeestre -" Last Change: 2010 Jan 15 +" Last Change: 2013 Aug 26 " " USAGE " If you enabled the script in your after/ftplugin directory (see install) @@ -17,7 +17,10 @@ " F7 - To remove all folds. " " INSTALL -" 1. Put phpfolding.vim in your plugin directory (~/.vim/plugin) +" 1. Put phpfolding.vim in your plugin directory (~/.vim/ftplugin) +" +" make sure you have "filetype plugin on" in your .vimrc! +" " 2. You might want to add the following keyboard mappings to your .vimrc: " " map :EnableFastPHPFolds From aeb3bbd5d40a28c9e9da5eaa90fb54b8175e17d8 Mon Sep 17 00:00:00 2001 From: rayburgemeestre Date: Mon, 26 Aug 2013 00:42:43 +0200 Subject: [PATCH 11/32] Small fix -> Version 1.8 --- README | 9 ++++++--- ftplugin/php/phpfolding.vim | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README b/README index b4985cc..45c5821 100644 --- a/README +++ b/README @@ -58,16 +58,19 @@ FUTURE CONTRIBUTE / GITHUB This project is hosted on github as a mirror through https://github.com/vim-scripts/phpfolding.vim -I do not own vim-scripts, so you could also fork mine: +I do not own vim-scripts, so preferably fork mine: https://github.com/rayburgemeestre/phpfolding.vim -It's then easier for me to accept pull requests and upload new version(s) here. +It's then easier for me to accept pull requests and upload new version(s) here, +also I cannot put phpfolding.vim in the ftplugin/php directory through the +vim.org interface. + 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 -1. Put phpfolding.vim in your plugin directory (~/.vim/ftplugin) +1. Put phpfolding.vim in your plugin directory (~/.vim/ftplugin/php/) Make sure you have "filetype plugin on" in your .vimrc! diff --git a/ftplugin/php/phpfolding.vim b/ftplugin/php/phpfolding.vim index 86248dd..ae23d1d 100644 --- a/ftplugin/php/phpfolding.vim +++ b/ftplugin/php/phpfolding.vim @@ -17,7 +17,7 @@ " F7 - To remove all folds. " " INSTALL -" 1. Put phpfolding.vim in your plugin directory (~/.vim/ftplugin) +" 1. Put phpfolding.vim in your plugin directory (~/.vim/ftplugin/php/) " " make sure you have "filetype plugin on" in your .vimrc! " From 1e9194164458e7c354817c006fd329bb42baab1d Mon Sep 17 00:00:00 2001 From: Yuki Matsukura Date: Wed, 2 Oct 2013 10:54:28 +0900 Subject: [PATCH 12/32] changed line break to lf --- plugin/phpfolding.vim | 1266 ++++++++++++++++++++--------------------- 1 file changed, 633 insertions(+), 633 deletions(-) diff --git a/plugin/phpfolding.vim b/plugin/phpfolding.vim index a44fba8..ae23d1d 100644 --- a/plugin/phpfolding.vim +++ b/plugin/phpfolding.vim @@ -1,633 +1,633 @@ -" Plugin for automatic folding of PHP functions (also folds related PHPdoc) -" -" Maintainer: Ray Burgemeestre -" Last Change: 2013 Aug 26 -" -" USAGE -" If you enabled the script in your after/ftplugin directory (see install) -" then it will be executed after you open a .php file. -" -" After e.g. adding/moving functions, you can re-execute the script by using -" the following key mappings: -" -" F5 - To fold functions, classes, and other stuff with PHPdoc (depending -" on your configuration). -" F6 - To do the same with more extensive bracket checking (might work -" better if your folds are messed up due to misinterpreted brackets). -" F7 - To remove all folds. -" -" INSTALL -" 1. Put phpfolding.vim in your plugin directory (~/.vim/ftplugin/php/) -" -" make sure you have "filetype plugin on" in your .vimrc! -" -" 2. You might want to add the following keyboard mappings to your .vimrc: -" -" map :EnableFastPHPFolds -" map :EnablePHPFolds -" map :DisablePHPFolds -" -" 3. You can disable auto folding in your .vimrc with: -" -" let g:DisableAutoPHPFolding = 1 -" -" By default EnableFastPHPFolds is called. Do these mess up your folds, -" you can try to replace EnableFastPHPFolds by EnablePHPFolds. You can -" change this in function s:CheckAutocmdEnablePHPFold. -" -" NOTE -" It may be that you need to load the plugin from your .vimrc manually, in -" case it doesn't work: -" -" 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) -" -" MORE INFORMATION -" - In PHPCustomFolds() you can i.e. comment the PHPFoldPureBlock('class', ...) -" call to have the script not fold classes. You can also change the second -" parameter passed to that function call, to have it or not have it fold -" PhpDoc comments. All other folding you can turn on/off in this function. -" - You can tweak the foldtext to your liking in the function PHPFoldText(). -" - You can set some preferences and default settings a few lines below -" at the "Script configuration" part. -" -" This script is tested with Vim version >= 6.3 on windows and linux. -let s:save_cpo = &cpo -set cpo&vim - -" Avoid reloading {{{1 -if exists('loaded_phpfolding') - " ftplugin section - if !get(g:, 'DisableAutoPHPFolding', 0) - call s:EnableFastPHPFolds() - endif - - let &cpo = s:save_cpo - unlet s:save_cpo - finish -endif - -let loaded_phpfolding = 1 -" }}} - -" .vimrc variable to disable autofolding for php files {{{1 -if !exists("g:DisableAutoPHPFolding") - let g:DisableAutoPHPFolding = 0 -endif -let g:DisablePHPFoldingClass = get(g:, 'DisablePHPFoldingClass', 1) -" }}} - -command! EnableFastPHPFolds call EnableFastPHPFolds() -command! -nargs=* EnablePHPFolds call EnablePHPFolds() -command! DisablePHPFolds call DisablePHPFolds() - -" {{{ Script configuration -" Display the following after the foldtext if a fold contains phpdoc -let g:phpDocIncludedPostfix = '**' -let g:phpDocBlockIncludedPostfix = '**#@+' - -" Default values -" .. search this # of empty lines for PhpDoc comments -let g:searchPhpDocLineCount = 1 -" .. search this # of empty lines that 'trail' the foldmatch -let g:searchEmptyLinesPostfixing = 1 -" }}} -" {{{ Script constants -let s:synIDattr_exists = exists('*synIDattr') -let s:TRUE = 1 -let s:FALSE = 0 -let s:MODE_CREATE_FOLDS = 1 -let s:MODE_REMEMBER_FOLD_SETTINGS = 2 -let s:FOLD_WITH_PHPDOC = 1 -let s:FOLD_WITHOUT_PHPDOC = 2 -let s:SEARCH_PAIR_START_FIRST = 1 -let s:SEARCH_PAIR_IMMEDIATELY = 2 -" }}} - -function! s:EnableFastPHPFolds() " {{{ - call s:EnablePHPFolds(s:FALSE) -endfunction -" }}} -function! s:EnablePHPFolds(...) " {{{ - let s:extensiveBracketChecking = s:TRUE - - " Check function arguments - if a:0 == 1 - let s:extensiveBracketChecking = a:1 - endif - - " Remember cursor information if possible - let s:savedCursor = line(".") - - " Initialize variables - setlocal foldmethod=manual - setlocal foldtext=PHPFoldText() - let s:openFoldListItems = 0 - let s:fileLineCount = line('$') - - let s:searchPhpDocLineCount = g:searchPhpDocLineCount - let s:searchEmptyLinesPostfixing = g:searchEmptyLinesPostfixing - - - " Move to end of file - exec s:fileLineCount - - " First pass: Look for Folds, remember opened folds - let s:foldingMode = s:MODE_REMEMBER_FOLD_SETTINGS - call s:PHPCustomFolds() - - " Second pass: Recreate Folds, restore previously opened - let s:foldingMode = s:MODE_CREATE_FOLDS - " .. Remove all folds first - normal! zE - let s:foldsCreated = 0 - call s:PHPCustomFolds() - " .. Fold all - normal! zM - - " Restore previously opened folds - let currentItem = 0 - while currentItem < s:openFoldListItems - exec s:foldsOpenedList{currentItem} - normal! zo - let currentItem = currentItem + 1 - endwhile - - :redraw - echo s:foldsCreated . " fold(s) created" - - " Restore cursor - exec s:savedCursor - -endfunction -" }}} -function! s:DisablePHPFolds() " {{{ - "setlocal foldmethod=manual - setlocal foldtext= - normal! zE - echo "php fold(s) deleted" -endfunction -" }}} -function! s:PHPCustomFolds() " {{{ - " NOTE: The two last parameters for functions PHPFoldProperties() and - " PHPFoldPureBlock() overwrite: 'g:searchPhpDocLineCount' and - " 'g:searchEmptyLinesPostfixing'.. - - " Fold function with PhpDoc (function foo() {}) - call s:PHPFoldPureBlock('function', s:FOLD_WITH_PHPDOC) - - " Fold class properties with PhpDoc (var $foo = NULL;) - call s:PHPFoldProperties('^\s*\(\(private\)\|\(public\)\|\(protected\)\|\(var\)\)\s\$', ";", s:FOLD_WITH_PHPDOC, 1, 1) - - if !g:DisablePHPFoldingClass - " Fold class without PhpDoc (class foo {}) - call s:PHPFoldPureBlock('^\s*\(abstract\s*\)\?class', s:FOLD_WITH_PHPDOC) - endif - - " Fold define()'s with their PhpDoc - call s:PHPFoldProperties('^\s*define\s*(', ";", s:FOLD_WITH_PHPDOC) - - " Fold includes with their PhpDoc - call s:PHPFoldProperties('^\s*require\s*', ";", s:FOLD_WITH_PHPDOC) - call s:PHPFoldProperties('^\s*include\s*', ";", s:FOLD_WITH_PHPDOC) - - " Fold GLOBAL Arrays with their PhpDoc (some PEAR packages use these) - call s:PHPFoldProperties('^\s*\$GLOBALS.*array\s*(', ";", s:FOLD_WITH_PHPDOC) - - " Fold marker style comments ({{{ foo }}}) - call s:PHPFoldMarkers('{{{', '}}}') - - " Fold PhpDoc "DocBlock" templates (#@+ foo #@-) - call s:PHPFoldMarkers('#@+', '#@-') -endfunction -" }}} -function! s:PHPFoldPureBlock(startPattern, ...) " {{{ - let s:searchPhpDocLineCount = g:searchPhpDocLineCount - let s:searchEmptyLinesPostfixing = g:searchEmptyLinesPostfixing - let s:currentPhpDocMode = s:FOLD_WITH_PHPDOC - - if a:0 >= 1 - " Do we also put the PHP doc part in the fold? - let s:currentPhpDocMode = a:1 - endif - if a:0 >= 2 - " How far do we want to look for PhpDoc comments? - let s:searchPhpDocLineCount = a:2 - endif - if a:0 == 3 - " How greedy are we on postfixing empty lines? - let s:searchEmptyLinesPostfixing = a:3 - endif - - " Move to file end - exec s:fileLineCount - - " Loop through file, searching for folds - while 1 - let s:lineStart = s:FindPureBlockStart(a:startPattern) - - if s:lineStart != 0 - - let s:lineStart = s:FindOptionalPHPDocComment() - let s:lineStop = s:FindPureBlockEnd('{', '}', s:SEARCH_PAIR_START_FIRST) - - " Stop on Error - if s:lineStop == 0 - break - endif - - " Do something with the potential fold based on the Mode we're in - call s:HandleFold() - - else - break - endif - - " Goto fold start (remember we're searching upwards) - exec s:lineStart - endwhile - - - if s:foldingMode != s:MODE_REMEMBER_FOLD_SETTINGS - " Remove created folds - normal! zR - endif -endfunction -" }}} -function! s:PHPFoldMarkers(startPattern, endPattern, ...) " {{{ - let s:currentPhpDocMode = s:FOLD_WITHOUT_PHPDOC - - " Move to file end - exec s:fileLineCount - - " Loop through file, searching for folds - while 1 - let s:lineStart = s:FindPatternStart(a:startPattern) - - if s:lineStart != 0 - let s:lineStart = s:FindOptionalPHPDocComment() - " The fourth parameter is for disabling the search for trailing - " empty lines.. - let s:lineStop = s:FindPureBlockEnd(a:startPattern, a:endPattern, - \ s:SEARCH_PAIR_IMMEDIATELY, s:FALSE) - - " Stop on Error - if s:lineStop == 0 - break - endif - - " Do something with the potential fold based on the Mode we're in - call s:HandleFold() - else - break - endif - - " Goto fold start (remember we're searching upwards) - exec s:lineStart - endwhile - - if s:foldingMode != s:MODE_REMEMBER_FOLD_SETTINGS - " Remove created folds - normal! zR - endif -endfunction -" }}} -function! s:PHPFoldProperties(startPattern, endPattern, ...) " {{{ - let s:searchPhpDocLineCount = g:searchPhpDocLineCount - let s:searchEmptyLinesPostfixing = g:searchEmptyLinesPostfixing - let s:currentPhpDocMode = s:FOLD_WITH_PHPDOC - if a:0 >= 1 - " Do we also put the PHP doc part in the fold? - let s:currentPhpDocMode = a:1 - endif - if a:0 >= 2 - " How far do we want to look for PhpDoc comments? - let s:searchPhpDocLineCount = a:2 - endif - if a:0 == 3 - " How greedy are we on postfixing empty lines? - let s:searchEmptyLinesPostfixing = a:3 - endif - - " Move to end of file - exec s:fileLineCount - - " Loop through file, searching for folds - while 1 - let s:lineStart = s:FindPatternStart(a:startPattern) - - if s:lineStart != 0 - let s:lineStart = s:FindOptionalPHPDocComment() - let s:lineStop = s:FindPatternEnd(a:endPattern) - - " Stop on Error - if s:lineStop == 0 - break - endif - - " Do something with the potential fold based on the Mode we're in - call s:HandleFold() - else - break - endif - - " Goto fold start (remember we're searching upwards) - exec s:lineStart - - endwhile - - if s:foldingMode != s:MODE_REMEMBER_FOLD_SETTINGS - " Remove created folds - normal! zR - endif -endfunction -" }}} -function! s:HandleFold() " {{{ - if s:foldingMode == s:MODE_REMEMBER_FOLD_SETTINGS - " If we are in an actual fold.., - if foldlevel(s:lineStart) != 0 - " .. and it is not closed.., - if foldclosed(s:lineStart) == -1 - " .. and it is more then one lines - " (it has to be or it will be open by default) - if s:lineStop - s:lineStart >= 1 - " Remember it as an open fold - let s:foldsOpenedList{s:openFoldListItems} = s:lineStart - let s:openFoldListItems = s:openFoldListItems + 1 - endif - endif - endif - - " If the cursor is inside the fold, it needs to be opened - if s:lineStart <= s:savedCursor && s:lineStop >= s:savedCursor - " Remember it as an open fold - let s:foldsOpenedList{s:openFoldListItems} = s:lineStart - let s:openFoldListItems = s:openFoldListItems + 1 - endif - - elseif s:foldingMode == s:MODE_CREATE_FOLDS - " Correct lineStop if needed (the script might have mistaken lines - " beyond the file's scope for trailing empty lines) - if s:lineStop > s:fileLineCount - let s:lineStop = s:fileLineCount - endif - " Create the actual fold! - exec s:lineStart . "," . s:lineStop . "fold" - let s:foldsCreated = s:foldsCreated + 1 - endif -endfunction -" }}} -function! s:FindPureBlockStart(startPattern) " {{{ - " When the startPattern is 'function', this following search will match: - " - " function foo($bar) { function foo($bar) - " { - " - " function foo($bar) function foo($bar1, - " .. { $bar2) - " { - " - "return search(a:startPattern . '.*\%[\n].*{', 'W') - "return search(a:startPattern . '.*\%[\n].*\%[\n].*{', 'bW') - - " This function can match the line its on *again* if the cursor was - " restored.. hence we search twice if needed.. - let currentLine = line('.') - let line = search(a:startPattern . '.*\(\%[\n].*\)\{,10\}{', 'bW') - if currentLine == line - let line = search(a:startPattern . '.*\(\%[\n].*\)\{,10\}{', 'bW') - endif - return line -endfunction -" }}} -function! s:FindPatternStart(startPattern) " {{{ - " This function can match the line its on *again* if the cursor was - " restored.. hence we search twice if needed.. - let currentLine = line('.') - let line = search(a:startPattern, 'bW') - if currentLine == line - let line = search(a:startPattern, 'bW') - endif - return line -endfunction -" }}} -function! s:FindOptionalPHPDocComment() " {{{ - " Is searching for PHPDoc disabled? - if s:currentPhpDocMode == s:FOLD_WITHOUT_PHPDOC - " .. Return the original Fold's start - return s:lineStart - endif - - " Skipover 'empty' lines in search for PhpDoc - let s:counter = 0 - let s:currentLine = s:lineStart - 1 - while s:counter < s:searchPhpDocLineCount - let line = getline(s:currentLine) - if (matchstr(line, '^\s*$') == line) - let s:currentLine = s:currentLine - 1 - endif - let s:counter = s:counter + 1 - endwhile - - " Is there a closing C style */ on the above line? - let checkLine = s:currentLine - if strridx(getline(checkLine), "\*\/") != -1 - " Then search for the matching C style /* opener - while 1 - if strridx(getline(checkLine), "\/\*") != -1 - " Only continue adjusting the Fold's start if it really is PHPdoc.. - " (which is characterized by a double asterisk, like /**) - if strridx(getline(checkLine), "\/\*\*") != -1 - " Also only continue adjusting if the PHPdoc opener does - " not contain a '/**#@+'. Those type of comments are - " supposed to match with a #@- .. - if strridx(getline(checkLine), '#@+') == -1 - " .. Return this as the Fold's start - return checkLine - else - break - endif - else - break - endif - endif - let checkLine = checkLine - 1 - endwhile - endif - " .. Return the original Fold's start - return s:lineStart -endfunction -" }}} -function! s:FindPureBlockEnd(startPair, endPair, searchStartPairFirst, ...) " {{{ - " Place Cursor on the opening pair/brace? - if a:searchStartPairFirst == s:SEARCH_PAIR_START_FIRST - let line = search(a:startPair, 'W') - endif - - " Search for the entangled closing brace - " call cursor(line, 1) " set the cursor to the start of the lnum line - if s:extensiveBracketChecking == s:TRUE - let line = searchpair(a:startPair, a:startPair, a:endPair, 'W', 'SkipMatch()') - else - let line = searchpair(a:startPair, a:startPair, a:endPair, 'W') - endif - if line == 0 - let line = search(a:endPair, 'W') - endif - if line == 0 - " Return error - return 0 - endif - - " If the fold exceeds more than one line, and searching for empty lines is - " not disabled.. - let foldExceedsOneLine = line - s:lineStart >= 1 - if a:0 == 1 - let emptyLinesNotDisabled = a:1 - else - let emptyLinesNotDisabled = s:TRUE - endif - if foldExceedsOneLine && emptyLinesNotDisabled - " Then be greedy with extra 'trailing' empty line(s) - let s:counter = 0 - while s:counter < s:searchEmptyLinesPostfixing - let linestr = getline(line + 1) - if (matchstr(linestr, '^\s*$') == linestr) - let line = line + 1 - endif - let s:counter = s:counter + 1 - endwhile - endif - - return line -endfunction -" }}} -function! s:FindPatternEnd(endPattern) " {{{ - let line = search(a:endPattern, 'W') - - " If the fold exceeds more than one line - if line - s:lineStart >= 1 - " Then be greedy with extra 'trailing' empty line(s) - let s:counter = 0 - while s:counter < s:searchEmptyLinesPostfixing - let linestr = getline(line + 1) - if (matchstr(linestr, '^\s*$') == linestr) - let line = line + 1 - endif - let s:counter = s:counter + 1 - endwhile - endif - - return line -endfunction -" }}} - -function! PHPFoldText() " {{{ - let currentLine = v:foldstart - let lines = (v:foldend - v:foldstart + 1) - let lineString = getline(currentLine) - " See if we folded a marker - if strridx(lineString, "{{{") != -1 " }}} - " Is there text after the fold opener? - if (matchstr(lineString, '^.*{{{..*$') == lineString) " }}} - " Then only show that text - let lineString = substitute(lineString, '^.*{{{', '', 'g') " }}} - " There is text before the fold opener - else - " Try to strip away the remainder - let lineString = substitute(lineString, '\s*{{{.*$', '', 'g') " }}} - endif - " See if we folded a DocBlock - elseif strridx(lineString, '#@+') != -1 - " Is there text after the #@+ piece? - if (matchstr(lineString, '^.*#@+..*$') == lineString) - " Then show that text - let lineString = substitute(lineString, '^.*#@+', '', 'g') . ' ' . g:phpDocBlockIncludedPostfix - " There is nothing? - else - " Use the next line.. - let lineString = getline(currentLine + 1) . ' ' . g:phpDocBlockIncludedPostfix - endif - " See if we folded an API comment block - elseif strridx(lineString, "\/\*\*") != -1 - " (I can't get search() or searchpair() to work.., therefore the - " following loop) - let s:state = 0 - while currentLine < v:foldend - let line = getline(currentLine) - if s:state == 0 && strridx(line, "\*\/") != -1 - " Found the end, now we need to find the first not-empty line - let s:state = 1 - elseif s:state == 1 && (matchstr(line, '^\s*$') != line) - " Found the line to display in fold! - break - endif - let currentLine = currentLine + 1 - endwhile - let lineString = getline(currentLine) - endif - - " Some common replaces... - " if currentLine != v:foldend - let lineString = substitute(lineString, '/\*\|\*/\d\=', '', 'g') - let lineString = substitute(lineString, '^\s*\*\?\s*', '', 'g') - let lineString = substitute(lineString, '{$', '', 'g') - let lineString = substitute(lineString, '($', '(..);', 'g') - " endif - - " Emulates printf("%3d", lines).. - if lines < 10 - let lines = " " . lines - elseif lines < 100 - let lines = " " . lines - endif - - " Append an (a) if there is PhpDoc in the fold (a for API) - if currentLine != v:foldstart - let lineString = lineString . " " . g:phpDocIncludedPostfix . " " - endif - - " Return the foldtext - return "+--".lines." lines: " . lineString -endfunction -" }}} -function! SkipMatch() " {{{ -" This function is modified from a PHP indent file by John Wellesz -" found here: http://www.vim.org/scripts/script.php?script_id=1120 - if (!s:synIDattr_exists) - return 0 - endif - let synname = synIDattr(synID(line("."), col("."), 0), "name") - if synname == "phpParent" || synname == "javaScriptBraces" || synname == "phpComment" - return 0 - else - return 1 - endif -endfun -" }}} - -" " Check filetype == php before automatically creating (fast) folds {{{1 -" function! s:CheckAutocmdEnablePHPFold() -" if &filetype == "php" && ! g:DisableAutoPHPFolding -" call s:EnableFastPHPFolds() -" endif -" endfunction -" " }}} - -" " Call CheckAutocmdEnablePHPFold on BufReadPost {{{1 -" augroup SetPhpFolds -" au! -" au BufReadPost * call s:CheckAutocmdEnablePHPFold() -" augroup END -" " }}} - -" ftplugin section -if !get(g:, 'DisableAutoPHPFolding', 0) - call s:EnableFastPHPFolds() -endif - -let &cpo = s:save_cpo -unlet s:save_cpo -" vim:ft=vim:foldmethod=marker:nowrap:tabstop=4:shiftwidth=4 +" Plugin for automatic folding of PHP functions (also folds related PHPdoc) +" +" Maintainer: Ray Burgemeestre +" Last Change: 2013 Aug 26 +" +" USAGE +" If you enabled the script in your after/ftplugin directory (see install) +" then it will be executed after you open a .php file. +" +" After e.g. adding/moving functions, you can re-execute the script by using +" the following key mappings: +" +" F5 - To fold functions, classes, and other stuff with PHPdoc (depending +" on your configuration). +" F6 - To do the same with more extensive bracket checking (might work +" better if your folds are messed up due to misinterpreted brackets). +" F7 - To remove all folds. +" +" INSTALL +" 1. Put phpfolding.vim in your plugin directory (~/.vim/ftplugin/php/) +" +" make sure you have "filetype plugin on" in your .vimrc! +" +" 2. You might want to add the following keyboard mappings to your .vimrc: +" +" map :EnableFastPHPFolds +" map :EnablePHPFolds +" map :DisablePHPFolds +" +" 3. You can disable auto folding in your .vimrc with: +" +" let g:DisableAutoPHPFolding = 1 +" +" By default EnableFastPHPFolds is called. Do these mess up your folds, +" you can try to replace EnableFastPHPFolds by EnablePHPFolds. You can +" change this in function s:CheckAutocmdEnablePHPFold. +" +" NOTE +" It may be that you need to load the plugin from your .vimrc manually, in +" case it doesn't work: +" +" 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) +" +" MORE INFORMATION +" - In PHPCustomFolds() you can i.e. comment the PHPFoldPureBlock('class', ...) +" call to have the script not fold classes. You can also change the second +" parameter passed to that function call, to have it or not have it fold +" PhpDoc comments. All other folding you can turn on/off in this function. +" - You can tweak the foldtext to your liking in the function PHPFoldText(). +" - You can set some preferences and default settings a few lines below +" at the "Script configuration" part. +" +" This script is tested with Vim version >= 6.3 on windows and linux. +let s:save_cpo = &cpo +set cpo&vim + +" Avoid reloading {{{1 +if exists('loaded_phpfolding') + " ftplugin section + if !get(g:, 'DisableAutoPHPFolding', 0) + call s:EnableFastPHPFolds() + endif + + let &cpo = s:save_cpo + unlet s:save_cpo + finish +endif + +let loaded_phpfolding = 1 +" }}} + +" .vimrc variable to disable autofolding for php files {{{1 +if !exists("g:DisableAutoPHPFolding") + let g:DisableAutoPHPFolding = 0 +endif +let g:DisablePHPFoldingClass = get(g:, 'DisablePHPFoldingClass', 1) +" }}} + +command! EnableFastPHPFolds call EnableFastPHPFolds() +command! -nargs=* EnablePHPFolds call EnablePHPFolds() +command! DisablePHPFolds call DisablePHPFolds() + +" {{{ Script configuration +" Display the following after the foldtext if a fold contains phpdoc +let g:phpDocIncludedPostfix = '**' +let g:phpDocBlockIncludedPostfix = '**#@+' + +" Default values +" .. search this # of empty lines for PhpDoc comments +let g:searchPhpDocLineCount = 1 +" .. search this # of empty lines that 'trail' the foldmatch +let g:searchEmptyLinesPostfixing = 1 +" }}} +" {{{ Script constants +let s:synIDattr_exists = exists('*synIDattr') +let s:TRUE = 1 +let s:FALSE = 0 +let s:MODE_CREATE_FOLDS = 1 +let s:MODE_REMEMBER_FOLD_SETTINGS = 2 +let s:FOLD_WITH_PHPDOC = 1 +let s:FOLD_WITHOUT_PHPDOC = 2 +let s:SEARCH_PAIR_START_FIRST = 1 +let s:SEARCH_PAIR_IMMEDIATELY = 2 +" }}} + +function! s:EnableFastPHPFolds() " {{{ + call s:EnablePHPFolds(s:FALSE) +endfunction +" }}} +function! s:EnablePHPFolds(...) " {{{ + let s:extensiveBracketChecking = s:TRUE + + " Check function arguments + if a:0 == 1 + let s:extensiveBracketChecking = a:1 + endif + + " Remember cursor information if possible + let s:savedCursor = line(".") + + " Initialize variables + setlocal foldmethod=manual + setlocal foldtext=PHPFoldText() + let s:openFoldListItems = 0 + let s:fileLineCount = line('$') + + let s:searchPhpDocLineCount = g:searchPhpDocLineCount + let s:searchEmptyLinesPostfixing = g:searchEmptyLinesPostfixing + + + " Move to end of file + exec s:fileLineCount + + " First pass: Look for Folds, remember opened folds + let s:foldingMode = s:MODE_REMEMBER_FOLD_SETTINGS + call s:PHPCustomFolds() + + " Second pass: Recreate Folds, restore previously opened + let s:foldingMode = s:MODE_CREATE_FOLDS + " .. Remove all folds first + normal! zE + let s:foldsCreated = 0 + call s:PHPCustomFolds() + " .. Fold all + normal! zM + + " Restore previously opened folds + let currentItem = 0 + while currentItem < s:openFoldListItems + exec s:foldsOpenedList{currentItem} + normal! zo + let currentItem = currentItem + 1 + endwhile + + :redraw + echo s:foldsCreated . " fold(s) created" + + " Restore cursor + exec s:savedCursor + +endfunction +" }}} +function! s:DisablePHPFolds() " {{{ + "setlocal foldmethod=manual + setlocal foldtext= + normal! zE + echo "php fold(s) deleted" +endfunction +" }}} +function! s:PHPCustomFolds() " {{{ + " NOTE: The two last parameters for functions PHPFoldProperties() and + " PHPFoldPureBlock() overwrite: 'g:searchPhpDocLineCount' and + " 'g:searchEmptyLinesPostfixing'.. + + " Fold function with PhpDoc (function foo() {}) + call s:PHPFoldPureBlock('function', s:FOLD_WITH_PHPDOC) + + " Fold class properties with PhpDoc (var $foo = NULL;) + call s:PHPFoldProperties('^\s*\(\(private\)\|\(public\)\|\(protected\)\|\(var\)\)\s\$', ";", s:FOLD_WITH_PHPDOC, 1, 1) + + if !g:DisablePHPFoldingClass + " Fold class without PhpDoc (class foo {}) + call s:PHPFoldPureBlock('^\s*\(abstract\s*\)\?class', s:FOLD_WITH_PHPDOC) + endif + + " Fold define()'s with their PhpDoc + call s:PHPFoldProperties('^\s*define\s*(', ";", s:FOLD_WITH_PHPDOC) + + " Fold includes with their PhpDoc + call s:PHPFoldProperties('^\s*require\s*', ";", s:FOLD_WITH_PHPDOC) + call s:PHPFoldProperties('^\s*include\s*', ";", s:FOLD_WITH_PHPDOC) + + " Fold GLOBAL Arrays with their PhpDoc (some PEAR packages use these) + call s:PHPFoldProperties('^\s*\$GLOBALS.*array\s*(', ";", s:FOLD_WITH_PHPDOC) + + " Fold marker style comments ({{{ foo }}}) + call s:PHPFoldMarkers('{{{', '}}}') + + " Fold PhpDoc "DocBlock" templates (#@+ foo #@-) + call s:PHPFoldMarkers('#@+', '#@-') +endfunction +" }}} +function! s:PHPFoldPureBlock(startPattern, ...) " {{{ + let s:searchPhpDocLineCount = g:searchPhpDocLineCount + let s:searchEmptyLinesPostfixing = g:searchEmptyLinesPostfixing + let s:currentPhpDocMode = s:FOLD_WITH_PHPDOC + + if a:0 >= 1 + " Do we also put the PHP doc part in the fold? + let s:currentPhpDocMode = a:1 + endif + if a:0 >= 2 + " How far do we want to look for PhpDoc comments? + let s:searchPhpDocLineCount = a:2 + endif + if a:0 == 3 + " How greedy are we on postfixing empty lines? + let s:searchEmptyLinesPostfixing = a:3 + endif + + " Move to file end + exec s:fileLineCount + + " Loop through file, searching for folds + while 1 + let s:lineStart = s:FindPureBlockStart(a:startPattern) + + if s:lineStart != 0 + + let s:lineStart = s:FindOptionalPHPDocComment() + let s:lineStop = s:FindPureBlockEnd('{', '}', s:SEARCH_PAIR_START_FIRST) + + " Stop on Error + if s:lineStop == 0 + break + endif + + " Do something with the potential fold based on the Mode we're in + call s:HandleFold() + + else + break + endif + + " Goto fold start (remember we're searching upwards) + exec s:lineStart + endwhile + + + if s:foldingMode != s:MODE_REMEMBER_FOLD_SETTINGS + " Remove created folds + normal! zR + endif +endfunction +" }}} +function! s:PHPFoldMarkers(startPattern, endPattern, ...) " {{{ + let s:currentPhpDocMode = s:FOLD_WITHOUT_PHPDOC + + " Move to file end + exec s:fileLineCount + + " Loop through file, searching for folds + while 1 + let s:lineStart = s:FindPatternStart(a:startPattern) + + if s:lineStart != 0 + let s:lineStart = s:FindOptionalPHPDocComment() + " The fourth parameter is for disabling the search for trailing + " empty lines.. + let s:lineStop = s:FindPureBlockEnd(a:startPattern, a:endPattern, + \ s:SEARCH_PAIR_IMMEDIATELY, s:FALSE) + + " Stop on Error + if s:lineStop == 0 + break + endif + + " Do something with the potential fold based on the Mode we're in + call s:HandleFold() + else + break + endif + + " Goto fold start (remember we're searching upwards) + exec s:lineStart + endwhile + + if s:foldingMode != s:MODE_REMEMBER_FOLD_SETTINGS + " Remove created folds + normal! zR + endif +endfunction +" }}} +function! s:PHPFoldProperties(startPattern, endPattern, ...) " {{{ + let s:searchPhpDocLineCount = g:searchPhpDocLineCount + let s:searchEmptyLinesPostfixing = g:searchEmptyLinesPostfixing + let s:currentPhpDocMode = s:FOLD_WITH_PHPDOC + if a:0 >= 1 + " Do we also put the PHP doc part in the fold? + let s:currentPhpDocMode = a:1 + endif + if a:0 >= 2 + " How far do we want to look for PhpDoc comments? + let s:searchPhpDocLineCount = a:2 + endif + if a:0 == 3 + " How greedy are we on postfixing empty lines? + let s:searchEmptyLinesPostfixing = a:3 + endif + + " Move to end of file + exec s:fileLineCount + + " Loop through file, searching for folds + while 1 + let s:lineStart = s:FindPatternStart(a:startPattern) + + if s:lineStart != 0 + let s:lineStart = s:FindOptionalPHPDocComment() + let s:lineStop = s:FindPatternEnd(a:endPattern) + + " Stop on Error + if s:lineStop == 0 + break + endif + + " Do something with the potential fold based on the Mode we're in + call s:HandleFold() + else + break + endif + + " Goto fold start (remember we're searching upwards) + exec s:lineStart + + endwhile + + if s:foldingMode != s:MODE_REMEMBER_FOLD_SETTINGS + " Remove created folds + normal! zR + endif +endfunction +" }}} +function! s:HandleFold() " {{{ + if s:foldingMode == s:MODE_REMEMBER_FOLD_SETTINGS + " If we are in an actual fold.., + if foldlevel(s:lineStart) != 0 + " .. and it is not closed.., + if foldclosed(s:lineStart) == -1 + " .. and it is more then one lines + " (it has to be or it will be open by default) + if s:lineStop - s:lineStart >= 1 + " Remember it as an open fold + let s:foldsOpenedList{s:openFoldListItems} = s:lineStart + let s:openFoldListItems = s:openFoldListItems + 1 + endif + endif + endif + + " If the cursor is inside the fold, it needs to be opened + if s:lineStart <= s:savedCursor && s:lineStop >= s:savedCursor + " Remember it as an open fold + let s:foldsOpenedList{s:openFoldListItems} = s:lineStart + let s:openFoldListItems = s:openFoldListItems + 1 + endif + + elseif s:foldingMode == s:MODE_CREATE_FOLDS + " Correct lineStop if needed (the script might have mistaken lines + " beyond the file's scope for trailing empty lines) + if s:lineStop > s:fileLineCount + let s:lineStop = s:fileLineCount + endif + " Create the actual fold! + exec s:lineStart . "," . s:lineStop . "fold" + let s:foldsCreated = s:foldsCreated + 1 + endif +endfunction +" }}} +function! s:FindPureBlockStart(startPattern) " {{{ + " When the startPattern is 'function', this following search will match: + " + " function foo($bar) { function foo($bar) + " { + " + " function foo($bar) function foo($bar1, + " .. { $bar2) + " { + " + "return search(a:startPattern . '.*\%[\n].*{', 'W') + "return search(a:startPattern . '.*\%[\n].*\%[\n].*{', 'bW') + + " This function can match the line its on *again* if the cursor was + " restored.. hence we search twice if needed.. + let currentLine = line('.') + let line = search(a:startPattern . '.*\(\%[\n].*\)\{,10\}{', 'bW') + if currentLine == line + let line = search(a:startPattern . '.*\(\%[\n].*\)\{,10\}{', 'bW') + endif + return line +endfunction +" }}} +function! s:FindPatternStart(startPattern) " {{{ + " This function can match the line its on *again* if the cursor was + " restored.. hence we search twice if needed.. + let currentLine = line('.') + let line = search(a:startPattern, 'bW') + if currentLine == line + let line = search(a:startPattern, 'bW') + endif + return line +endfunction +" }}} +function! s:FindOptionalPHPDocComment() " {{{ + " Is searching for PHPDoc disabled? + if s:currentPhpDocMode == s:FOLD_WITHOUT_PHPDOC + " .. Return the original Fold's start + return s:lineStart + endif + + " Skipover 'empty' lines in search for PhpDoc + let s:counter = 0 + let s:currentLine = s:lineStart - 1 + while s:counter < s:searchPhpDocLineCount + let line = getline(s:currentLine) + if (matchstr(line, '^\s*$') == line) + let s:currentLine = s:currentLine - 1 + endif + let s:counter = s:counter + 1 + endwhile + + " Is there a closing C style */ on the above line? + let checkLine = s:currentLine + if strridx(getline(checkLine), "\*\/") != -1 + " Then search for the matching C style /* opener + while 1 + if strridx(getline(checkLine), "\/\*") != -1 + " Only continue adjusting the Fold's start if it really is PHPdoc.. + " (which is characterized by a double asterisk, like /**) + if strridx(getline(checkLine), "\/\*\*") != -1 + " Also only continue adjusting if the PHPdoc opener does + " not contain a '/**#@+'. Those type of comments are + " supposed to match with a #@- .. + if strridx(getline(checkLine), '#@+') == -1 + " .. Return this as the Fold's start + return checkLine + else + break + endif + else + break + endif + endif + let checkLine = checkLine - 1 + endwhile + endif + " .. Return the original Fold's start + return s:lineStart +endfunction +" }}} +function! s:FindPureBlockEnd(startPair, endPair, searchStartPairFirst, ...) " {{{ + " Place Cursor on the opening pair/brace? + if a:searchStartPairFirst == s:SEARCH_PAIR_START_FIRST + let line = search(a:startPair, 'W') + endif + + " Search for the entangled closing brace + " call cursor(line, 1) " set the cursor to the start of the lnum line + if s:extensiveBracketChecking == s:TRUE + let line = searchpair(a:startPair, a:startPair, a:endPair, 'W', 'SkipMatch()') + else + let line = searchpair(a:startPair, a:startPair, a:endPair, 'W') + endif + if line == 0 + let line = search(a:endPair, 'W') + endif + if line == 0 + " Return error + return 0 + endif + + " If the fold exceeds more than one line, and searching for empty lines is + " not disabled.. + let foldExceedsOneLine = line - s:lineStart >= 1 + if a:0 == 1 + let emptyLinesNotDisabled = a:1 + else + let emptyLinesNotDisabled = s:TRUE + endif + if foldExceedsOneLine && emptyLinesNotDisabled + " Then be greedy with extra 'trailing' empty line(s) + let s:counter = 0 + while s:counter < s:searchEmptyLinesPostfixing + let linestr = getline(line + 1) + if (matchstr(linestr, '^\s*$') == linestr) + let line = line + 1 + endif + let s:counter = s:counter + 1 + endwhile + endif + + return line +endfunction +" }}} +function! s:FindPatternEnd(endPattern) " {{{ + let line = search(a:endPattern, 'W') + + " If the fold exceeds more than one line + if line - s:lineStart >= 1 + " Then be greedy with extra 'trailing' empty line(s) + let s:counter = 0 + while s:counter < s:searchEmptyLinesPostfixing + let linestr = getline(line + 1) + if (matchstr(linestr, '^\s*$') == linestr) + let line = line + 1 + endif + let s:counter = s:counter + 1 + endwhile + endif + + return line +endfunction +" }}} + +function! PHPFoldText() " {{{ + let currentLine = v:foldstart + let lines = (v:foldend - v:foldstart + 1) + let lineString = getline(currentLine) + " See if we folded a marker + if strridx(lineString, "{{{") != -1 " }}} + " Is there text after the fold opener? + if (matchstr(lineString, '^.*{{{..*$') == lineString) " }}} + " Then only show that text + let lineString = substitute(lineString, '^.*{{{', '', 'g') " }}} + " There is text before the fold opener + else + " Try to strip away the remainder + let lineString = substitute(lineString, '\s*{{{.*$', '', 'g') " }}} + endif + " See if we folded a DocBlock + elseif strridx(lineString, '#@+') != -1 + " Is there text after the #@+ piece? + if (matchstr(lineString, '^.*#@+..*$') == lineString) + " Then show that text + let lineString = substitute(lineString, '^.*#@+', '', 'g') . ' ' . g:phpDocBlockIncludedPostfix + " There is nothing? + else + " Use the next line.. + let lineString = getline(currentLine + 1) . ' ' . g:phpDocBlockIncludedPostfix + endif + " See if we folded an API comment block + elseif strridx(lineString, "\/\*\*") != -1 + " (I can't get search() or searchpair() to work.., therefore the + " following loop) + let s:state = 0 + while currentLine < v:foldend + let line = getline(currentLine) + if s:state == 0 && strridx(line, "\*\/") != -1 + " Found the end, now we need to find the first not-empty line + let s:state = 1 + elseif s:state == 1 && (matchstr(line, '^\s*$') != line) + " Found the line to display in fold! + break + endif + let currentLine = currentLine + 1 + endwhile + let lineString = getline(currentLine) + endif + + " Some common replaces... + " if currentLine != v:foldend + let lineString = substitute(lineString, '/\*\|\*/\d\=', '', 'g') + let lineString = substitute(lineString, '^\s*\*\?\s*', '', 'g') + let lineString = substitute(lineString, '{$', '', 'g') + let lineString = substitute(lineString, '($', '(..);', 'g') + " endif + + " Emulates printf("%3d", lines).. + if lines < 10 + let lines = " " . lines + elseif lines < 100 + let lines = " " . lines + endif + + " Append an (a) if there is PhpDoc in the fold (a for API) + if currentLine != v:foldstart + let lineString = lineString . " " . g:phpDocIncludedPostfix . " " + endif + + " Return the foldtext + return "+--".lines." lines: " . lineString +endfunction +" }}} +function! SkipMatch() " {{{ +" This function is modified from a PHP indent file by John Wellesz +" found here: http://www.vim.org/scripts/script.php?script_id=1120 + if (!s:synIDattr_exists) + return 0 + endif + let synname = synIDattr(synID(line("."), col("."), 0), "name") + if synname == "phpParent" || synname == "javaScriptBraces" || synname == "phpComment" + return 0 + else + return 1 + endif +endfun +" }}} + +" " Check filetype == php before automatically creating (fast) folds {{{1 +" function! s:CheckAutocmdEnablePHPFold() +" if &filetype == "php" && ! g:DisableAutoPHPFolding +" call s:EnableFastPHPFolds() +" endif +" endfunction +" " }}} + +" " Call CheckAutocmdEnablePHPFold on BufReadPost {{{1 +" augroup SetPhpFolds +" au! +" au BufReadPost * call s:CheckAutocmdEnablePHPFold() +" augroup END +" " }}} + +" ftplugin section +if !get(g:, 'DisableAutoPHPFolding', 0) + call s:EnableFastPHPFolds() +endif + +let &cpo = s:save_cpo +unlet s:save_cpo +" vim:ft=vim:foldmethod=marker:nowrap:tabstop=4:shiftwidth=4 From 4c4466829db44f7cfdefae759cec2704cbc06a59 Mon Sep 17 00:00:00 2001 From: Yuki Matsukura Date: Mon, 21 Oct 2013 16:17:31 +0900 Subject: [PATCH 13/32] Update README --- README | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README b/README index 0f8d49f..e34c5c1 100644 --- a/README +++ b/README @@ -4,6 +4,7 @@ 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: +``` +``` Based on e.g. functions declared like this: +``` +``` SCREENSHOT You can view a screenshot here: http://blog.cppse.nl/phpfolding-vim From 864c8003ff6acb6905ca04622b327b0640a5f814 Mon Sep 17 00:00:00 2001 From: Yuki Matsukura Date: Mon, 21 Oct 2013 16:20:27 +0900 Subject: [PATCH 14/32] Updated readme --- README => README.md | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) rename README => README.md (87%) diff --git a/README b/README.md similarity index 87% rename from README rename to README.md index e34c5c1..f3d9b85 100644 --- a/README +++ b/README.md @@ -1,3 +1,6 @@ +Abstract +=============== + This is a mirror of http://www.vim.org/scripts/script.php?script_id=1623 This script can fold PHP functions and/or classes, properties with their phpdoc @@ -38,9 +41,11 @@ function fooFunction($bar) ``` SCREENSHOT +---------------- You can view a screenshot here: http://blog.cppse.nl/phpfolding-vim 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. @@ -56,19 +61,24 @@ FEATURES - Now works properly as ftplugin FUTURE +---------------- - Better 'configurability' as opposed to editting the PHPCustomFolds() function and some "Script configuration" global variables. CONTRIBUTE / GITHUB -This project is hosted on github as a mirror through - https://github.com/vim-scripts/phpfolding.vim -I do not own vim-scripts, so please fork mine instead: - https://github.com/rayburgemeestre/phpfolding.vim +---------------- +- This project is hosted on github as a mirror through + - https://github.com/vim-scripts/phpfolding.vim +- I do not own vim-scripts, so please fork mine instead: + - https://github.com/rayburgemeestre/phpfolding.vim + It's then easier for me to accept pull requests and upload new version(s) here, also I cannot put phpfolding.vim in the ftplugin/php directory through the vim.org interface. 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) From 5fed6e11379c845115c37a582ae350123a0c5103 Mon Sep 17 00:00:00 2001 From: Jan Mollowitz Date: Sun, 2 Feb 2014 11:57:19 +0100 Subject: [PATCH 15/32] Added lookup for static properties --- ftplugin/php/phpfolding.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ftplugin/php/phpfolding.vim b/ftplugin/php/phpfolding.vim index ae23d1d..1ac6ada 100644 --- a/ftplugin/php/phpfolding.vim +++ b/ftplugin/php/phpfolding.vim @@ -179,7 +179,7 @@ function! s:PHPCustomFolds() " {{{ call s:PHPFoldPureBlock('function', s:FOLD_WITH_PHPDOC) " Fold class properties with PhpDoc (var $foo = NULL;) - call s:PHPFoldProperties('^\s*\(\(private\)\|\(public\)\|\(protected\)\|\(var\)\)\s\$', ";", s:FOLD_WITH_PHPDOC, 1, 1) + call s:PHPFoldProperties('^\s*\(\(private\)\|\(public\)\|\(protected\)\|\(var\)\)\s\(static\s\)*\$', ";", s:FOLD_WITH_PHPDOC, 1, 1) if !g:DisablePHPFoldingClass " Fold class without PhpDoc (class foo {}) From a35e423d5c50c0f84f4c84101c748b71fc0726a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=95=E6=B5=B7=E6=B6=9B?= Date: Mon, 3 Aug 2015 00:36:32 +0800 Subject: [PATCH 16/32] add support for fold use statement --- ftplugin/php/phpfolding.vim | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/ftplugin/php/phpfolding.vim b/ftplugin/php/phpfolding.vim index 1ac6ada..84aac35 100644 --- a/ftplugin/php/phpfolding.vim +++ b/ftplugin/php/phpfolding.vim @@ -201,6 +201,8 @@ function! s:PHPCustomFolds() " {{{ " Fold PhpDoc "DocBlock" templates (#@+ foo #@-) call s:PHPFoldMarkers('#@+', '#@-') + + call s:PHPFoldUse() endfunction " }}} function! s:PHPFoldPureBlock(startPattern, ...) " {{{ @@ -523,7 +525,33 @@ function! s:FindPatternEnd(endPattern) " {{{ return line endfunction " }}} +function! s:PHPFoldUse() " {{{ + exec 0 + while 1 + let lineStart = search("^\s*use", "W") + + if lineStart == 0 + break + endif + + if (foldclosed(lineStart) >= 0) + break + endif + let lineStop = lineStart + 1 + while match(getline(lineStop), '^\s*use') >= 0 + let lineStop = lineStop + 1 + endwhile + + let s:lineStart = lineStart + let s:lineStop = lineStop - 1 + if s:lineStop > s:lineStart + call s:HandleFold() + endif + exec s:lineStop + 1 + endwhile +endfunction +" }}} function! PHPFoldText() " {{{ let currentLine = v:foldstart let lines = (v:foldend - v:foldstart + 1) From 2577bc90bd92375284833b1edb9ec3ac6e4c4559 Mon Sep 17 00:00:00 2001 From: Mikkel Paulson Date: Tue, 20 Oct 2015 14:28:29 -0400 Subject: [PATCH 17/32] added support for folding consts into their docblocks --- ftplugin/php/phpfolding.vim | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ftplugin/php/phpfolding.vim b/ftplugin/php/phpfolding.vim index 1ac6ada..2b5fd54 100644 --- a/ftplugin/php/phpfolding.vim +++ b/ftplugin/php/phpfolding.vim @@ -189,6 +189,9 @@ function! s:PHPCustomFolds() " {{{ " Fold define()'s with their PhpDoc call s:PHPFoldProperties('^\s*define\s*(', ";", s:FOLD_WITH_PHPDOC) + " Fold consts with their PhpDoc + call s:PHPFoldProperties('^\s*const\s\+', ";", s:FOLD_WITH_PHPDOC) + " Fold includes with their PhpDoc call s:PHPFoldProperties('^\s*require\s*', ";", s:FOLD_WITH_PHPDOC) call s:PHPFoldProperties('^\s*include\s*', ";", s:FOLD_WITH_PHPDOC) From 6398b53b64374f672426f9ffb3b1cf7154b74c4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=95=E6=B5=B7=E6=B6=9B?= Date: Sat, 19 Dec 2015 00:07:28 +0800 Subject: [PATCH 18/32] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E4=B8=80?= =?UTF-8?q?=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ftplugin/php/phpfolding.vim | 86 ++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/ftplugin/php/phpfolding.vim b/ftplugin/php/phpfolding.vim index 84aac35..a54c255 100644 --- a/ftplugin/php/phpfolding.vim +++ b/ftplugin/php/phpfolding.vim @@ -59,14 +59,14 @@ set cpo&vim " Avoid reloading {{{1 if exists('loaded_phpfolding') - " ftplugin section - if !get(g:, 'DisableAutoPHPFolding', 0) - call s:EnableFastPHPFolds() - endif - - let &cpo = s:save_cpo - unlet s:save_cpo - finish + " ftplugin section + if !get(g:, 'DisableAutoPHPFolding', 0) + call s:EnableFastPHPFolds() + endif + + let &cpo = s:save_cpo + unlet s:save_cpo + finish endif let loaded_phpfolding = 1 @@ -74,7 +74,7 @@ let loaded_phpfolding = 1 " .vimrc variable to disable autofolding for php files {{{1 if !exists("g:DisableAutoPHPFolding") - let g:DisableAutoPHPFolding = 0 + let g:DisableAutoPHPFolding = 0 endif let g:DisablePHPFoldingClass = get(g:, 'DisablePHPFoldingClass', 1) " }}} @@ -155,7 +155,7 @@ function! s:EnablePHPFolds(...) " {{{ let currentItem = currentItem + 1 endwhile - :redraw + :redraw echo s:foldsCreated . " fold(s) created" " Restore cursor @@ -181,10 +181,10 @@ function! s:PHPCustomFolds() " {{{ " Fold class properties with PhpDoc (var $foo = NULL;) call s:PHPFoldProperties('^\s*\(\(private\)\|\(public\)\|\(protected\)\|\(var\)\)\s\(static\s\)*\$', ";", s:FOLD_WITH_PHPDOC, 1, 1) - if !g:DisablePHPFoldingClass - " Fold class without PhpDoc (class foo {}) - call s:PHPFoldPureBlock('^\s*\(abstract\s*\)\?class', s:FOLD_WITH_PHPDOC) - endif + if !g:DisablePHPFoldingClass + " Fold class without PhpDoc (class foo {}) + call s:PHPFoldPureBlock('^\s*\(abstract\s*\)\?class', s:FOLD_WITH_PHPDOC) + endif " Fold define()'s with their PhpDoc call s:PHPFoldProperties('^\s*define\s*(', ";", s:FOLD_WITH_PHPDOC) @@ -202,7 +202,7 @@ function! s:PHPCustomFolds() " {{{ " Fold PhpDoc "DocBlock" templates (#@+ foo #@-) call s:PHPFoldMarkers('#@+', '#@-') - call s:PHPFoldUse() + call s:PHPFoldUse() endfunction " }}} function! s:PHPFoldPureBlock(startPattern, ...) " {{{ @@ -253,9 +253,9 @@ function! s:PHPFoldPureBlock(startPattern, ...) " {{{ if s:foldingMode != s:MODE_REMEMBER_FOLD_SETTINGS - " Remove created folds - normal! zR - endif + " Remove created folds + normal! zR + endif endfunction " }}} function! s:PHPFoldMarkers(startPattern, endPattern, ...) " {{{ @@ -273,7 +273,7 @@ function! s:PHPFoldMarkers(startPattern, endPattern, ...) " {{{ " The fourth parameter is for disabling the search for trailing " empty lines.. let s:lineStop = s:FindPureBlockEnd(a:startPattern, a:endPattern, - \ s:SEARCH_PAIR_IMMEDIATELY, s:FALSE) + \ s:SEARCH_PAIR_IMMEDIATELY, s:FALSE) " Stop on Error if s:lineStop == 0 @@ -291,9 +291,9 @@ function! s:PHPFoldMarkers(startPattern, endPattern, ...) " {{{ endwhile if s:foldingMode != s:MODE_REMEMBER_FOLD_SETTINGS - " Remove created folds - normal! zR - endif + " Remove created folds + normal! zR + endif endfunction " }}} function! s:PHPFoldProperties(startPattern, endPattern, ...) " {{{ @@ -341,9 +341,9 @@ function! s:PHPFoldProperties(startPattern, endPattern, ...) " {{{ endwhile if s:foldingMode != s:MODE_REMEMBER_FOLD_SETTINGS - " Remove created folds - normal! zR - endif + " Remove created folds + normal! zR + endif endfunction " }}} function! s:HandleFold() " {{{ @@ -352,13 +352,13 @@ function! s:HandleFold() " {{{ if foldlevel(s:lineStart) != 0 " .. and it is not closed.., if foldclosed(s:lineStart) == -1 - " .. and it is more then one lines - " (it has to be or it will be open by default) - if s:lineStop - s:lineStart >= 1 - " Remember it as an open fold - let s:foldsOpenedList{s:openFoldListItems} = s:lineStart - let s:openFoldListItems = s:openFoldListItems + 1 - endif + " .. and it is more then one lines + " (it has to be or it will be open by default) + if s:lineStop - s:lineStart >= 1 + " Remember it as an open fold + let s:foldsOpenedList{s:openFoldListItems} = s:lineStart + let s:openFoldListItems = s:openFoldListItems + 1 + endif endif endif @@ -562,23 +562,23 @@ function! PHPFoldText() " {{{ if (matchstr(lineString, '^.*{{{..*$') == lineString) " }}} " Then only show that text let lineString = substitute(lineString, '^.*{{{', '', 'g') " }}} - " There is text before the fold opener + " There is text before the fold opener else " Try to strip away the remainder let lineString = substitute(lineString, '\s*{{{.*$', '', 'g') " }}} endif - " See if we folded a DocBlock + " See if we folded a DocBlock elseif strridx(lineString, '#@+') != -1 " Is there text after the #@+ piece? if (matchstr(lineString, '^.*#@+..*$') == lineString) " Then show that text let lineString = substitute(lineString, '^.*#@+', '', 'g') . ' ' . g:phpDocBlockIncludedPostfix - " There is nothing? + " There is nothing? else " Use the next line.. let lineString = getline(currentLine + 1) . ' ' . g:phpDocBlockIncludedPostfix endif - " See if we folded an API comment block + " See if we folded an API comment block elseif strridx(lineString, "\/\*\*") != -1 " (I can't get search() or searchpair() to work.., therefore the " following loop) @@ -599,10 +599,10 @@ function! PHPFoldText() " {{{ " Some common replaces... " if currentLine != v:foldend - let lineString = substitute(lineString, '/\*\|\*/\d\=', '', 'g') - let lineString = substitute(lineString, '^\s*\*\?\s*', '', 'g') - let lineString = substitute(lineString, '{$', '', 'g') - let lineString = substitute(lineString, '($', '(..);', 'g') + let lineString = substitute(lineString, '/\*\|\*/\d\=', '', 'g') + let lineString = substitute(lineString, '^\s*\*\?\s*', '', 'g') + let lineString = substitute(lineString, '{$', '', 'g') + let lineString = substitute(lineString, '($', '(..);', 'g') " endif " Emulates printf("%3d", lines).. @@ -622,8 +622,8 @@ function! PHPFoldText() " {{{ endfunction " }}} function! SkipMatch() " {{{ -" This function is modified from a PHP indent file by John Wellesz -" found here: http://www.vim.org/scripts/script.php?script_id=1120 + " This function is modified from a PHP indent file by John Wellesz + " found here: http://www.vim.org/scripts/script.php?script_id=1120 if (!s:synIDattr_exists) return 0 endif @@ -653,7 +653,7 @@ endfun " ftplugin section if !get(g:, 'DisableAutoPHPFolding', 0) - call s:EnableFastPHPFolds() + call s:EnableFastPHPFolds() endif let &cpo = s:save_cpo From a11630f01f2431f3552c5c719f16fb05c2fd2539 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=95=E6=B5=B7=E6=B6=9B?= Date: Mon, 2 May 2016 17:21:00 +0800 Subject: [PATCH 19/32] deprecated --- README.md | 85 +------------------------------------------------------ 1 file changed, 1 insertion(+), 84 deletions(-) diff --git a/README.md b/README.md index f3d9b85..e857368 100644 --- a/README.md +++ b/README.md @@ -1,84 +1 @@ -Abstract -=============== - -This is a mirror of http://www.vim.org/scripts/script.php?script_id=1623 - -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: - -``` - -``` - -Based on e.g. functions declared like this: - -``` - -``` - -SCREENSHOT ----------------- -You can view a screenshot here: http://blog.cppse.nl/phpfolding-vim - -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.) -- Folding private, public, protected class variables + multi-line param. -- Foloding the class is now an option disabled by default. -- Now works properly as ftplugin - -FUTURE ----------------- -- Better 'configurability' as opposed to editting the PHPCustomFolds() function - and some "Script configuration" global variables. - -CONTRIBUTE / GITHUB ----------------- -- This project is hosted on github as a mirror through - - https://github.com/vim-scripts/phpfolding.vim -- I do not own vim-scripts, so please fork mine instead: - - https://github.com/rayburgemeestre/phpfolding.vim - -It's then easier for me to accept pull requests and upload new version(s) here, -also I cannot put phpfolding.vim in the ftplugin/php directory through the -vim.org interface. - - -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) +No more maintaining. Use [phpfold.vim](https://github.com/phpvim/phpfold.vim) instead. From d3e08a4dfc8364f6b57247c0ece47be196f0f764 Mon Sep 17 00:00:00 2001 From: rayburgemeestre Date: Thu, 19 May 2016 16:54:30 +0200 Subject: [PATCH 20/32] Revert "deprecated" This reverts commit a11630f01f2431f3552c5c719f16fb05c2fd2539. --- README.md | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e857368..f3d9b85 100644 --- a/README.md +++ b/README.md @@ -1 +1,84 @@ -No more maintaining. Use [phpfold.vim](https://github.com/phpvim/phpfold.vim) instead. +Abstract +=============== + +This is a mirror of http://www.vim.org/scripts/script.php?script_id=1623 + +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: + +``` + +``` + +Based on e.g. functions declared like this: + +``` + +``` + +SCREENSHOT +---------------- +You can view a screenshot here: http://blog.cppse.nl/phpfolding-vim + +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.) +- Folding private, public, protected class variables + multi-line param. +- Foloding the class is now an option disabled by default. +- Now works properly as ftplugin + +FUTURE +---------------- +- Better 'configurability' as opposed to editting the PHPCustomFolds() function + and some "Script configuration" global variables. + +CONTRIBUTE / GITHUB +---------------- +- This project is hosted on github as a mirror through + - https://github.com/vim-scripts/phpfolding.vim +- I do not own vim-scripts, so please fork mine instead: + - https://github.com/rayburgemeestre/phpfolding.vim + +It's then easier for me to accept pull requests and upload new version(s) here, +also I cannot put phpfolding.vim in the ftplugin/php directory through the +vim.org interface. + + +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) From 594030d8b7801a2c9f097c5ca4dd0d209ca2afe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20D=2E=20Rodas?= Date: Thu, 20 Apr 2017 15:35:31 -0400 Subject: [PATCH 21/32] Fixed function folding It would incorrectly fold if use a $function variable or word. The following code would be fold incorrectly. ```php foreach ( $foo as $function) { } ``` This commit improves the function selector. --- ftplugin/php/phpfolding.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ftplugin/php/phpfolding.vim b/ftplugin/php/phpfolding.vim index f98078b..8d011ed 100644 --- a/ftplugin/php/phpfolding.vim +++ b/ftplugin/php/phpfolding.vim @@ -176,7 +176,7 @@ function! s:PHPCustomFolds() " {{{ " 'g:searchEmptyLinesPostfixing'.. " Fold function with PhpDoc (function foo() {}) - call s:PHPFoldPureBlock('function', s:FOLD_WITH_PHPDOC) + call s:PHPFoldPureBlock('function\s\+[a-z_][a-z0-9_]*\s*(', s:FOLD_WITH_PHPDOC) " Fold class properties with PhpDoc (var $foo = NULL;) call s:PHPFoldProperties('^\s*\(\(private\)\|\(public\)\|\(protected\)\|\(var\)\)\s\(static\s\)*\$', ";", s:FOLD_WITH_PHPDOC, 1, 1) From 749da895985b6fc5706e70fd0601540ebff8c46c Mon Sep 17 00:00:00 2001 From: sutem Date: Sat, 26 May 2018 02:57:31 +0600 Subject: [PATCH 22/32] Fixed folding camelCase function names and abstract functions in classes. --- ftplugin/php/phpfolding.vim | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ftplugin/php/phpfolding.vim b/ftplugin/php/phpfolding.vim index 8d011ed..8a6d03c 100644 --- a/ftplugin/php/phpfolding.vim +++ b/ftplugin/php/phpfolding.vim @@ -178,6 +178,9 @@ function! s:PHPCustomFolds() " {{{ " Fold function with PhpDoc (function foo() {}) call s:PHPFoldPureBlock('function\s\+[a-z_][a-z0-9_]*\s*(', s:FOLD_WITH_PHPDOC) + " Fold abstract function with PhpDoc + call s:PHPFoldProperties('^\s*\(abstract\)\s\(\(private\)\|\(public\)\|\(protected\)\s\)*\(static\s\)*function\s\+[A-Za-z_][A-Za-z0-9_]*\s*(', ";", s:FOLD_WITH_PHPDOC, 1, 1) + " Fold class properties with PhpDoc (var $foo = NULL;) call s:PHPFoldProperties('^\s*\(\(private\)\|\(public\)\|\(protected\)\|\(var\)\)\s\(static\s\)*\$', ";", s:FOLD_WITH_PHPDOC, 1, 1) From fb2e5b0ca7a47bee49670a5862d2db4df191c836 Mon Sep 17 00:00:00 2001 From: sutem Date: Sat, 26 May 2018 03:12:50 +0600 Subject: [PATCH 23/32] UpperCase at function expression. --- ftplugin/php/phpfolding.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ftplugin/php/phpfolding.vim b/ftplugin/php/phpfolding.vim index 8a6d03c..f47d951 100644 --- a/ftplugin/php/phpfolding.vim +++ b/ftplugin/php/phpfolding.vim @@ -176,7 +176,7 @@ function! s:PHPCustomFolds() " {{{ " 'g:searchEmptyLinesPostfixing'.. " Fold function with PhpDoc (function foo() {}) - call s:PHPFoldPureBlock('function\s\+[a-z_][a-z0-9_]*\s*(', s:FOLD_WITH_PHPDOC) + call s:PHPFoldPureBlock('function\s\+[A-Za-z_][A-Za-z0-9_]*\s*(', s:FOLD_WITH_PHPDOC) " Fold abstract function with PhpDoc call s:PHPFoldProperties('^\s*\(abstract\)\s\(\(private\)\|\(public\)\|\(protected\)\s\)*\(static\s\)*function\s\+[A-Za-z_][A-Za-z0-9_]*\s*(', ";", s:FOLD_WITH_PHPDOC, 1, 1) From f0483e8e511ec25941480b90214acac5832c8bf5 Mon Sep 17 00:00:00 2001 From: Sudaraka Wijesinghe Date: Wed, 2 Oct 2013 12:45:46 +0530 Subject: [PATCH 24/32] Changed line ending from CR/LF to LF The recent update of the plugin was throwing some warning about line endings when used in Linux. Changing line ending style of the file to Unix style LF got rid of the warnings. From f29b65511b161dc9f53eab9b80ae099e37c03b27 Mon Sep 17 00:00:00 2001 From: blu3gui7ar Date: Thu, 15 May 2014 18:28:36 +0800 Subject: [PATCH 25/32] fix: error matching 'function' in function names such as 'register_shutdown_function'. From 9c26734e3e9fd5586242442921ecfa4d62ad51ff Mon Sep 17 00:00:00 2001 From: blu3gui7ar Date: Thu, 15 May 2014 18:59:30 +0800 Subject: [PATCH 26/32] Pass some more test cases. From 42f8534e58023b35878f715e68000af7e387c8d9 Mon Sep 17 00:00:00 2001 From: Glendon Solsberry Date: Thu, 24 Sep 2015 12:33:48 -0400 Subject: [PATCH 27/32] Remove echo for fold(s) created This echo needlessly clutters the output of vim. Remove it so that there is no output. --- ftplugin/php/phpfolding.vim | 1 - 1 file changed, 1 deletion(-) diff --git a/ftplugin/php/phpfolding.vim b/ftplugin/php/phpfolding.vim index f47d951..f247fd6 100644 --- a/ftplugin/php/phpfolding.vim +++ b/ftplugin/php/phpfolding.vim @@ -156,7 +156,6 @@ function! s:EnablePHPFolds(...) " {{{ endwhile :redraw - echo s:foldsCreated . " fold(s) created" " Restore cursor exec s:savedCursor From 0d99b965ab2bfde696088d1300e01c18c04a14af Mon Sep 17 00:00:00 2001 From: blu3gui7ar Date: Thu, 15 May 2014 18:28:36 +0800 Subject: [PATCH 28/32] fix: error matching 'function' in function names such as 'register_shutdown_function'. EDIT (Ray): Cherry-picked correctly this time. --- ftplugin/php/phpfolding.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ftplugin/php/phpfolding.vim b/ftplugin/php/phpfolding.vim index f247fd6..15cf19c 100644 --- a/ftplugin/php/phpfolding.vim +++ b/ftplugin/php/phpfolding.vim @@ -175,7 +175,7 @@ function! s:PHPCustomFolds() " {{{ " 'g:searchEmptyLinesPostfixing'.. " Fold function with PhpDoc (function foo() {}) - call s:PHPFoldPureBlock('function\s\+[A-Za-z_][A-Za-z0-9_]*\s*(', s:FOLD_WITH_PHPDOC) + call s:PHPFoldPureBlock('\(^\|\s\)function\s\+[A-Za-z_][A-Za-z0-9_]*\s*(', s:FOLD_WITH_PHPDOC) " Fold abstract function with PhpDoc call s:PHPFoldProperties('^\s*\(abstract\)\s\(\(private\)\|\(public\)\|\(protected\)\s\)*\(static\s\)*function\s\+[A-Za-z_][A-Za-z0-9_]*\s*(', ";", s:FOLD_WITH_PHPDOC, 1, 1) From 14ba3579e012db75acd67dba25fcb25ad06e8e37 Mon Sep 17 00:00:00 2001 From: Ray Burgemeestre Date: Fri, 19 Mar 2021 13:01:02 +0100 Subject: [PATCH 29/32] No longer :redraw by default everytime folds are being created. --- ftplugin/php/phpfolding.vim | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ftplugin/php/phpfolding.vim b/ftplugin/php/phpfolding.vim index 15cf19c..7ebe47e 100644 --- a/ftplugin/php/phpfolding.vim +++ b/ftplugin/php/phpfolding.vim @@ -1,7 +1,7 @@ " Plugin for automatic folding of PHP functions (also folds related PHPdoc) " " Maintainer: Ray Burgemeestre -" Last Change: 2013 Aug 26 +" Last Change: 2021 Mar 19 " " USAGE " If you enabled the script in your after/ftplugin directory (see install) @@ -93,6 +93,10 @@ let g:phpDocBlockIncludedPostfix = '**#@+' let g:searchPhpDocLineCount = 1 " .. search this # of empty lines that 'trail' the foldmatch let g:searchEmptyLinesPostfixing = 1 +" .. force redraw screen everytime folds have been created +" .. redrawing during .vimrc load can cause artifacts when exiting vim later +" .. at least this is my experience with newer versions of vim +let g:forceRedrawScreen = 0 " }}} " {{{ Script constants let s:synIDattr_exists = exists('*synIDattr') @@ -155,7 +159,9 @@ function! s:EnablePHPFolds(...) " {{{ let currentItem = currentItem + 1 endwhile - :redraw + if g:forceRedrawScreen == s:TRUE + :redraw + endif " Restore cursor exec s:savedCursor From 5fd79d44c83d9de4cc88ac352c78a19dc7fe1cfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20H=C3=A4rtl?= Date: Fri, 13 Aug 2021 18:10:53 +0200 Subject: [PATCH 30/32] Improve detection of functions and abstract functions --- ftplugin/php/phpfolding.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ftplugin/php/phpfolding.vim b/ftplugin/php/phpfolding.vim index 7ebe47e..c51008b 100644 --- a/ftplugin/php/phpfolding.vim +++ b/ftplugin/php/phpfolding.vim @@ -181,10 +181,10 @@ function! s:PHPCustomFolds() " {{{ " 'g:searchEmptyLinesPostfixing'.. " Fold function with PhpDoc (function foo() {}) - call s:PHPFoldPureBlock('\(^\|\s\)function\s\+[A-Za-z_][A-Za-z0-9_]*\s*(', s:FOLD_WITH_PHPDOC) + call s:PHPFoldPureBlock('^\(public\|private\|protected\|static\|\s\)*function\s\+[A-Za-z_][A-Za-z0-9_]*\s*(', s:FOLD_WITH_PHPDOC) " Fold abstract function with PhpDoc - call s:PHPFoldProperties('^\s*\(abstract\)\s\(\(private\)\|\(public\)\|\(protected\)\s\)*\(static\s\)*function\s\+[A-Za-z_][A-Za-z0-9_]*\s*(', ";", s:FOLD_WITH_PHPDOC, 1, 1) + call s:PHPFoldProperties('^\s*abstract\(public\|private\|protected\|static\|\s\)*function\s\+[A-Za-z_][A-Za-z0-9_]*\s*(', ";", s:FOLD_WITH_PHPDOC, 1, 1) " Fold class properties with PhpDoc (var $foo = NULL;) call s:PHPFoldProperties('^\s*\(\(private\)\|\(public\)\|\(protected\)\|\(var\)\)\s\(static\s\)*\$', ";", s:FOLD_WITH_PHPDOC, 1, 1) From 8361d436b3296dc8a787041be590ce2ea09652bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20H=C3=A4rtl?= Date: Fri, 13 Aug 2021 18:33:57 +0200 Subject: [PATCH 31/32] Fix property detection --- ftplugin/php/phpfolding.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ftplugin/php/phpfolding.vim b/ftplugin/php/phpfolding.vim index c51008b..1a13774 100644 --- a/ftplugin/php/phpfolding.vim +++ b/ftplugin/php/phpfolding.vim @@ -186,8 +186,8 @@ function! s:PHPCustomFolds() " {{{ " Fold abstract function with PhpDoc call s:PHPFoldProperties('^\s*abstract\(public\|private\|protected\|static\|\s\)*function\s\+[A-Za-z_][A-Za-z0-9_]*\s*(', ";", s:FOLD_WITH_PHPDOC, 1, 1) - " Fold class properties with PhpDoc (var $foo = NULL;) - call s:PHPFoldProperties('^\s*\(\(private\)\|\(public\)\|\(protected\)\|\(var\)\)\s\(static\s\)*\$', ";", s:FOLD_WITH_PHPDOC, 1, 1) + " Fold class properties with PhpDoc (public $foo = null;) + call s:PHPFoldProperties('^\s*\(static\)\?\s*\(public\|private\|protected\|var\)\s*\(static\)\?\s*\$', ";", s:FOLD_WITH_PHPDOC, 1, 1) if !g:DisablePHPFoldingClass " Fold class without PhpDoc (class foo {}) From 80fe632ef93babb81ec5e9dfd2ace42e39ab605d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20H=C3=A4rtl?= Date: Tue, 31 Aug 2021 14:53:44 +0200 Subject: [PATCH 32/32] Issue #9: Add demo PHP file as basis for testing --- tests/demo.php | 237 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 237 insertions(+) create mode 100644 tests/demo.php diff --git a/tests/demo.php b/tests/demo.php new file mode 100644 index 0000000..6bc8b14 --- /dev/null +++ b/tests/demo.php @@ -0,0 +1,237 @@ +