[TxMt] Re: Triggering based on namespace?

Allan Odgaard mailinglist at textmate.org
Mon May 19 00:31:33 UTC 2014


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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macromates.com/textmate/attachments/20140519/a0300548/attachment.html>


More information about the textmate mailing list