swekaj / php-foldexpr.vim Goto Github PK
View Code? Open in Web Editor NEWVim folding for PHP with foldexpr
License: MIT License
Vim folding for PHP with foldexpr
License: MIT License
@swekaj , first, thanks for the plugin. Been using it for several weeks now and for the most part has been working well.
One area where it has not worked is when I open the same *.php
file in a vim split window in order to examine two areas of the same file at the same time. The first window has the folds working just fine but the second window opens without any folds at all. Whenever I attempt to fold (zc
) any function / method in that second window... I simply am told that there are no folds, whereas in the original window all the folds function as normal.
Do you see this as well?
While these are useful, I often find they're a bit of overkill, esp. if a function has lots of if {}
logic in it, I spend a lot of time opening folds (I know about zO
)?
Is there an option to only fold classes, methods, functions, but not the lower level stuff?
Brilliant plug in anyway, thanks.
I added the following configuration variables to my .vimrc:
let b:phpfold_text_right_lines=1
let b:phpfold_text_percent = 0
let b:phpfold_doc_with_funcs=0
let b:phpfold_docblocks=1
+-- 12 lines: public __construct() {...} - StylesController constructor.-----------------------------------------------------------------------------------------------
4
3
2 +-- 190 lines: public index() {...}-------------------------------------------------------------------------------------------------------------------------------------
1
227 +-- 34 lines: public show() {...} - Display the specified resource.----------------------------------------------------------------------------------------------------
1
2 +-- 27 lines: public updateSingleStyleSizingChart() {...}--------------------------------------------------------------------------------------------------------------
3
4 +-- 27 lines: public updateSingleSizingChartException() {...}----------------------------------------------------------------------------------------------------------
5
6 +-- 47 lines: public updateMultiSizingChartExceptions() {...}-----------
I don't seem to see the right-alignment and the default behavior of the function + doc folding seems to be persist even if I set the doc_with_func to false.
I'm using the following version:
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Mar 14 2018 14:26:22)
Included patches: 1-1605
Profile info
FUNCTIONS SORTED ON TOTAL TIME
count total (s) self (s) function
186694 132.447726 45.251909 GetPhpFold()
166864 87.179004 FindPrevClassFunc()
13 4.674672 0.002486 <SNR>86_UpdateErrors()
13 3.091846 0.008128 <SNR>86_CacheErrors()
FUNCTIONS SORTED ON SELF TIME
count total (s) self (s) function
166864 87.179004 FindPrevClassFunc()
186694 132.447726 45.251909 GetPhpFold()
13 0.777582 0.767910 98()
13 0.693651 0.685620 99()
When a DocBlock only contains {@inheritDoc}
as the summary, or anything else without a .
, it doesn't display in the best manner.
e.g.
<?php
class foo extends bar
{
/**
* {@inheritDoc}
*/
public function func()
{
// code
}
}
Should fold to
<?php
class foo extends bar
{
+-- 7 lines: public selectQueue() {...} - {@inheritDoc}-----
}
For some reason, not all /*...*/
comments are being folded. Looks like it's only blocks with a {
or }
in them. The checks for {
and }
should probably be made a bit smarter to detect if it's inside a string or comment.
Just realized I forgot to implement folding for HEREDOCs and NOWDOCs.
Probably open folds on the pattern /<<<\w+/
and close on /^\w+;$/
The following:
<?php
$a = Array(
1,
2,
3,
4, );
$this_should_not_fold = [];
folds to:
$a = Array(...];------------ 7 lines +-
i.e. the fold is too greedy; the end of the array is not noticed.
This is a simple one. The regex includes private twice, but I suspect one should be protected.
" handle class methods and independent functions
if line =~? '\v\s*(abstract\s+|public\s+|private\s+|static\s+|private\s+)*function\s+(\k|\()' && line !~? ';$'
The DocBlock before a trait is not folded, it should fold.
Currently I have this code in my vimrc: http://www.gregsexton.org/2011/03/improving-the-text-displayed-in-a-fold/
And there are many variants of lines-of-code indicators. I like it, it gives you a better view how much it's folded.
Except for PHP files. Then I use your plugin, but I'm not able to see how much is folded. It's bothering me. So I was wondering if there is any chance to integrate this in your awesome plugin, like "'44 lines of code" '
Thanks in advance for your reply.
I would like to have extra variable, namely to disable auto-folding of class. In that way the functions inside the class will be folded automatically when I open the file, but the class-tag will not be folded.
Is that possible?
Edit: nevermind, I was wrong.
Add two options:
/* */
)code like this:
class A
{
Const NAME = 'a';
}
Add an option for folding method chains. The foldtext
should display the chain as if it's on one line.
function let(Config $config)
{
$config
->get('.buildable')
->willReturn('value');
}
Should fold into
function let(Config $config)
{
+--- 3 lines: $config->get(...)->willReturn(...)-----------------------------
}
When there is no period (.) on the first or second lines, the *
isn't stripped from the first line.
The second lines should not be included if it starts with a tag (* @something
).
I don't have any bug to report or enhancement to offer, but just wanted to let you know that I am extremely impressed with your vim addon.
Thank you very much for releasing this addon.
I am using vim-plug. I followed the instructions for installing, and :PlugInstall shows that php-foldexpr is installed. However when I open a php file in vim. There is no code folding with zR zr za za, etc.
:verbose let b:phpfold_use yields "variable undefined" and php-foldexpr shows up in :scriptnames
The script acts as if it is not loaded automatically when I open a php file.
There appears to be a bug when there's a ([ ])
fold.
function let(Config $config)
{
$config
->get(strtolower($this->module).'.buildable')
->willReturn([
$this->classname,
[]
]);
$config
->get(strtolower($this->nonexistentModule).'.buildable')
->willReturn([
$this->nonexistantClassname,
[]
]);
$config
->get(strtolower($this->moduleWithGoodConstruct).'.buildable')
->willReturn([
$this->moduleWithGoodConstructClassname,
[
'arg1',
'named' => 'arg'
]
]);
$config
->get(strtolower($this->moduleWithBadConstruct).'.buildable')
->willReturn([
$this->moduleWithBadConstructClassname,
'badConstruct'
]);
$this->beConstructedWith($config);
}
resulted in
function let(Config $config)
{
$config
->get(strtolower($this->module).'.buildable')
+--- 27 lines: ->willReturn([...}-----------------------------
/* */
are usually used to comment out sections of code, whereas /** */
are usually DocBlocks. Only fold DocBlocks.
Methods folded correct, names of methods not displayed:
30 class Zend_Locale
31 {
...
Some of the folds don't provide useful information when folded (e.g. /** */
comments just display +---- 5 lines: *------------
. Write a function for fold-text
to handle this better.
See :help foldtext()
and :help fold-text
Create spec tests using https://github.com/tomtom/spec_vim
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.