Created
August 9, 2012 07:11
-
-
Save tobyS/3301871 to your computer and use it in GitHub Desktop.
Fold method calls in Xdebug function traces in VIM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func! FoldCalls(regex) range | |
let l:lastLine = a:lastline | |
let l:firstLine = a:firstline | |
let l:currentSpaceCount = -1 | |
let l:startTime = localtime() | |
let l:currentLine = l:firstLine | |
while l:currentLine <= l:lastLine | |
let l:lineText = getline(l:currentLine) | |
" 1.6975 24568256 -> str_replace(string(1), string(2), string(25)) /h | |
let l:matches = matchlist(l:lineText, '\S\(\s\+\)-> \(.*\)$') | |
if len(l:matches) > 0 | |
let l:whiteSpaceCount = strlen(l:matches[1]) | |
" Continue fold regex matches again | |
if l:whiteSpaceCount <= l:currentSpaceCount && match(l:matches[2], a:regex) == -1 | |
call append(l:currentLine - 1, "}}}") | |
let l:currentLine += 1 | |
let l:lastLine += 1 | |
let l:currentSpaceCount = -1 | |
endif | |
if l:currentSpaceCount == -1 && match(l:matches[2], a:regex) > -1 | |
call append(l:currentLine - 1, "{{{ " . l:matches[2]) | |
let l:currentLine += 1 | |
let l:lastLine += 1 | |
let l:currentSpaceCount = l:whiteSpaceCount | |
endif | |
endif | |
let l:currentLine += 1 | |
endwhile | |
let l:elapsedTime = localtime() - l:startTime | |
echomsg "Elapsed: " . l:elapsedTime | |
endfunc |
<3
What about folds of descendants using vims folding technique is that already covered by something else?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This little VIM function allows you to fold method calls in an Xdebug function trace. Just call it on a range of lines, giving it a regex that matches on a class name, method name or file name and it will fold away all calls (and its descendants) that match the regex.
Note that this script is quite slow by now (even though I had slower versions previously). Folding ~23k calls in a ~150k lines trace took ~7 mins on my machine. Performance improvements highly welcome!