I wrote a PHP Snippet that outputs some FirePHP-based debugging information.
fb($${1:variable}, '${2:function} $${1:label}');
I would like to replace ${2:function} with something that automatically puts in the current function or class::method (if available);
I notice in the status bar at the bottom of the editor window (to the right of the Tab Size), there is a "Symbol Popup" menu. So it seems like the information I need is available. Is there a variable in TextMate that I can slap into the snippet? A $TM_CURRENT_SYMBOL or something?
Thanks for your help!
Regards,
Daniel Royer
On 14 Apr 2009, at 17:24, Daniel Royer wrote:
[...] I notice in the status bar at the bottom of the editor window (to the right of the Tab Size), there is a "Symbol Popup" menu. So it seems like the information I need is available [...]
It is not, but oft requested. The symbol in the status bar is not necessarily the “current function”, it is just the first thing matched via some scope selector (optionally passed through some regexps) above the caret.
What you can do is make a command that takes stdin as input and then do something like: SYMBOL=$(head -n$TM_LINE_NUMBER|grep «function prototype regexp»|tail -n1). Have the command “insert as snippet” and construct the snippet from the previous.
I am adding an “expose current symbol” to the to-do, since it seems a lot want this and don’t care that it might not be 100% correct (and whatever hand-roled solution they make is probably even less correct ;) ).
On 2009-Apr-16, at 6:06 AM, Allan Odgaard wrote:
I am adding an “expose current symbol” to the to-do
Don't know if this has been requested also, but a related feature I've occasionally wished for is a way to add the symbols to the list of completions. Probably not something that should be on by default, but perhaps a preference like "useForComplete = 1;". I guess that's not limited to symbols, so maybe it's not as related as I thought, but you get the idea.
I know the words themselves are already available for completion, but it might be more than one "word" or you might want the thing that results from a symbolTransformation instead of the original thing.
On 16 Apr 2009, at 15:44, Rob McBroom wrote:
[...] Don't know if this has been requested also, but a related feature I've occasionally wished for is a way to add the symbols to the list of completions. Probably not something that should be on by default, but perhaps a preference like "useForComplete = 1;". I guess that's not limited to symbols, so maybe it's not as related as I thought, but you get the idea.
I know the words themselves are already available for completion, but it might be more than one "word" or you might want the thing that results from a symbolTransformation instead of the original thing.
Can you give an example of when this is useful?
I think this should be handled by a custom completion command, which is already supported (rather than try to make something designed for one purpose somehwat useful in rare cases for another purpose).
On 2009-Apr-18, at 3:16 AM, Allan Odgaard wrote:
On 16 Apr 2009, at 15:44, Rob McBroom wrote:
I know the words themselves are already available for completion, but it might be more than one "word" or you might want the thing that results from a symbolTransformation instead of the original thing.
Can you give an example of when this is useful?
I thought you might ask that. I'll use the [Puppet][1] syntax as an example.
I've modified the Puppet bundle posted on Git hub and haven't shared my changes with the author yet, so I don't want to include it here, but I can describe the scenario.
If you have a resource like
file { "xyz.conf": # stuff }
you would refer to this resource elsewhere in the file as 'File["xyz.conf"]'. The Puppet bundle on Git hub would list this as "xyz.conf" in the symbols list, but that caused things like Service["postfix"] and Package["postfix"] to both show up as simply "postfix" in the list. I modified the bundle so the symbols list would contain the actual string that you would use to refer to the resource in your file so they could be distinguished from one another.
These things are obviously a bit awkward to type, and it's more common than you might think, so it would be nice if you could just ⎋ to complete them. Let em know if I didn't explain that well enough.
I think this should be handled by a custom completion command, which is already supported (rather than try to make something designed for one purpose somehwat useful in rare cases for another purpose).
I thought of a completion command. It just seems inefficient to redefine the regex that matches the "symbol", redefine the transformation, and re-parse the file on every completion when all of that has been done and the results are sitting right there in the symbols list.
I suppose on modern hardware, scanning the file over and over isn't a big deal, but the fact that a human has to remember to maintain the matching/transformation logic in both the language grammar and the completion command makes me hesitant to go down that road.
[1]: http://reductivelabs.com/trac/puppet
On 19 Apr 2009, at 04:02, Rob McBroom wrote:
[...] I thought of a completion command. It just seems inefficient to redefine the regex that matches the "symbol", redefine the transformation, and re-parse the file on every completion when all of that has been done and the results are sitting right there in the symbols list.
But if a general (scope selector based) document querying API was provided, you can strike all but the redefinition of the transformation (and I guess you can argue that the scope selector is also duplicated).
So I think there are too few use-cases for this feature, and having to maintain the same regexp in two bundle items is probably a small price for the complexity I then don’t have to add to the TM code base ;)