I'm guessing this isn't possible but I'd love to have my 'doc' tab trigger for PHP distinguish between the namespace it is in. Is this possible?
ken
On 15 May 2014, at 15:59, Ken Snyder wrote:
I'm guessing this isn't possible but I'd love to have my 'doc' tab trigger for PHP distinguish between the namespace it is in. Is this possible?
There are two options:
1. Put the namespace in the scope. We do this for C++, so for this code:
namespace oak { ‸ }
The scope contains `meta.namespace-block.oak.c++`. Though we don’t actually use this extra information for anything.
2. Change the `doc⇥` trigger to run a command that takes ‘document’ as input and have the command itself extract the namespace and act accordingly. In Objective-C we do that for the `logm⇥` and `super⇥` snippets, the first one inserts a log statement that output all the parameters passed to the method, the latter inserts a call to the superclass.
As I don't really know *ruby *at all the second option would be hard without an example. I am gravitating to your first option but I'm not sure what's involved in creating the namespace scope. For instance I have a namespace of:
namespace LG\API;
and after placing the cursor in front of a function within that namespace my scope is:
text.html.php
meta.embedded.block.php source.php attr.os-version.10.9.2 attr.rev-path.php.Insights.API.LG.src.api.*path.to.file* attr.scm.branch.feature/insights-timeseries attr.scm.git attr.scm.status.clean dyn.caret.end.line
I don't know if the PHP syntax for namespace, which doesn't bracket the scope but instead implies the whole file, is somehow to blame?
Ken
On 16 May 2014 00:35, Allan Odgaard mailinglist@textmate.org wrote:
On 15 May 2014, at 15:59, Ken Snyder wrote:
I'm guessing this isn't possible but I'd love to have my 'doc' tab trigger for PHP distinguish between the namespace it is in. Is this possible?
There are two options:
Put the namespace in the scope. We do this for C++, so for this code:
namespace oak { ‸ }
The scope contains meta.namespace-block.oak.c++. Though we don’t actually use this extra information for anything. 2.
Change the doc⇥ trigger to run a command that takes ‘document’ as input and have the command itself extract the namespace and act accordingly. In Objective-C we do that for the logm⇥ and super⇥snippets, the first one inserts a log statement that output all the parameters passed to the method, the latter inserts a call to the superclass.
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
On 16 May 2014, at 14:22, Ken Snyder wrote:
As I don't really know *ruby *at all the second option would be hard without an example.
I pointed you to two examples… but you can also write it in PHP (which from the request, I assume you know).
Create a new command and set input to ‘Document’, output format to ‘Snippet’, and then write a command a la:
#!/usr/bin/php <?php
$namespace = NULL;
$document = file_get_contents('php://stdin'); if(preg_match('/^\s*namespace (.+);/m', $document, $matches)) $namespace = $matches[1];
switch($namespace) { case 'foo': echo "Documentation for ${1:foo}…\n"; break;
case 'bar': echo "Documentation for ${1:bar}…\n"; break;
default: echo "Documentation for ${1:unknown}…\n"; break; }
I am gravitating to your first option but I'm not sure what's involved in creating the namespace scope […]
You would have to create a grammar rule for the PHP grammar like this:
{ name = 'meta.namespace.$1.php'; begin = '\bnamespace ([A-Za-z\]+)'; end = '\z'; patterns = ( { include = '$self'; } ); },
This should make the scope contain ‘meta.namespace.LG\API.php’ when the caret is below the namespace directive (declaring that namespace).
Given the complexity of the PHP grammar (it’s written as injections for the HTML grammar), I’d only suggest this to people who are experienced with TextMate language grammars.