VIM for PHP: List if()'s and include()'s in Taglist
Asked Answered
L

2

7

I use Taglist in VIM, but one particular PHP application which I have inherited is coded with if()'s and elseif()'s and include()'s extensively. Not a single method or function in almost 5000 lines of code per file (and tens or hundreds of files). Is there any way to use Taglist or another plugin to get an overview of the code flow? I'm thinking of something along the lines of showing the conditions in the if()'s in a concise manner in the sidebar, including their hierarchy. Anything remotely close to that would be great.

Thanks!

Lurleen answered 23/10, 2011 at 21:23 Comment(1)
I think you should go and shoot the guy who wrote this? For me? For the good of this language? Seriously, this sort of thing is what has people thinking PHP's just a toy, despite it's widespread use in large applications ...Lordling
M
3

this involves a little bit work, you'll need to compile a modified version of exuberant ctags with modified rules for php.

you might want to have a look over here: http://ctags.sourceforge.net/EXTENDING.html

Meraz answered 6/2, 2012 at 22:48 Comment(3)
Thank you Lucy. I just went over that document, however it does not seem to me that one could add support for ifs and other control statements. Did you have something else in mind?Lurleen
the things that ctags considers a tag are configurable - you would need to define a new 'language' which is explained on the page lucy has linked to. Here's a really old example gist.github.com/f10f372c90474c88557c creating a language for the php framework CakePHPTattler
Thank you Lucy, this might be the closest thing to what I need.Lurleen
E
1

Using foldlist plugin along with foldmethod-syntax (or tweaking your own foldmethod-expr) would work nicely.

In fact, even without the plugin I believe a proper fold setting would work miracles. Some recommendations:

  • set foldmethod=syntax or (set foldmethod=expr and set foldexpr=... for your case)
  • set foldclose=all to hide all those nasty ifs
  • set foldcolumn=2 or greater to see the nesting level
  • set foldtext=MyFoldText() and make a function to show you relevant information,

like:

function! MyFoldText()
   let line = getline(v:foldstart)
   let line = substitute(line, 'if(\(.*\)).*', 'if: \1', 'g')
   " ... etc
   return line
endfunction
Eolande answered 8/2, 2012 at 19:55 Comment(1)
Thank you Eelvex. I do use folding and the function is rather clever.Lurleen

© 2022 - 2024 — McMap. All rights reserved.