From 216f8353f8fa9905104c01b1bce4c1e1aa820d5a Mon Sep 17 00:00:00 2001 From: Jess Telford Date: Thu, 10 Mar 2011 13:20:39 +1100 Subject: [PATCH 01/11] 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/11] 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/11] 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/11] 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/11] 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/11] 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/11] 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/11] 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/11] 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/11] 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/11] 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! "