Skip to content

Instantly share code, notes, and snippets.

@tobyS
Created August 9, 2012 07:11
Show Gist options
  • Save tobyS/3301871 to your computer and use it in GitHub Desktop.
Save tobyS/3301871 to your computer and use it in GitHub Desktop.
Fold method calls in Xdebug function traces in VIM
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
@beberlei
Copy link

beberlei commented Aug 9, 2012

<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