views:

275

answers:

1

I know nothing about Vim expressions. I have a vim foldexpr that comes with a syntax file for xdebug trace files. The existing expression looks like this:

foldexpr=strlen(substitute(substitute(substitute(substitute(getline(v:lnum),'^TR.*$','',''),'\\s>=>','->',\"g\"),'^\\s.\\{20\\}\\(\\s\\+\\)\\?->.*$','\\1',''),'\\s\\s','\',\"g\"))-2

That works OK for default trace files, which look like this:

0.0974    3908596     -> GenericDispatcher->dispatch() /home/tomw/source/public_html/main.php:49
0.0975    3908676       -> ReflectionClass->getMethods() /home/tomw/source/presentation/framework/routing/GenericDispatcher.php:59
0.0975    3910532       -> ReflectionFunctionAbstract->getName() /home/tomw/source/presentation/framework/routing/GenericDispatcher.php:60

etc.

However, if you configure Xdebug to show mem deltas in the trace, the trace files end up like this (note the extra column with memory deltas, eg. +80):

0.0964    3908336      +84     -> GenericDispatcher->dispatch() /home/tomw/source/public_html/main.php:49
0.0965    3908416      +80       -> ReflectionClass->getMethods() /home/tomw/source/presentation/framework/routing/GenericDispatcher.php:59
0.0965    3910272    +1856       -> ReflectionFunctionAbstract->getName() /home/tomw/source/presentation/framework/routing/GenericDispatcher.php:60

Can anyone tell me how to modify the original expression so that folding works properly in the second example? I can't make head nor tail of it.

Thanks

+1  A: 

The portion that reads

'^\\s.\\{20\\}\\(\\s\\+\\)\\?->.*$'

is searching for the beginning of a line [^], then 1 space [\\s], then any character for 20 repetitions [.\\{20\\}], then optionally one or spaces remembered for later [\\(\\s\\+\\)\\?], and finally an arrow plus anything else to the end of the line [->.*$]. If you are always going to be using the extra column, I would just change the 20 character search to 30, like so:

'^\\s.\\{30\\}\\(\\s\\+\\)\\?->.*$'

Otherwise, you might try a range, like this:

'^\\s.\\{20,30\\}\\(\\s\\+\\)\\?->.*$'

I haven't actually tested any of these, so you might have to tweak the numbers a bit, but this should get you started towards having it work.

Caleb Huitt - cjhuitt
Great, that does the trick. Cheers!
EvilPuppetMaster