Hi,
I have two questions regarding to the internal language grammar.
1) Is it possible to look for the internal markups which TM is using like "<support.function.perl>(.*?)</support.function.perl>" directly? I only know the way to use the 'magic keyword' in a tmCommand "<key>inputFormat</key><string>xml</string>" and parse the output.
2) Is there a way to modify the current language grammar dynamically? Example:
{ scopeName = 'text.plain'; fileTypes = ( '' ); patterns = ( { name = 'my.tag'; match = '(a)'; } ); }
Then I write a command or what ever to change match = '(a)'; in match = '(b)';
If I do so I have to quit TM and restart it. A 'Reload Bundles' doesn't work. [I don't know whether it is possible to write an Applescript to control TM in that respect.]
2a) Or to use an external file which holds the actual 'match' expression for a given pattern.
2b) Or to change the current used language grammar by using a tmCommand.
Many thanks in advance,
Hans
On Jul 24, 2007, at 3:23 AM, Hans-Jörg Bibiko wrote:
- Is it possible to look for the internal markups which TM is
using like "<support.function.perl>(.*?)</support.function.perl>" directly? I only know the way to use the 'magic keyword' in a tmCommand "<key>inputFormat</key><string>xml</string>" and parse the output.
Need to know why you need this to better answer it. For some cases you might have to do that, if you want the content of a scope for a command that is easy. Change the input to selected text, then choose scope as the alternate. Now the text around the caret matching the scope given will be available to the command.
If that doesn't work, explain better what the use is.
- Is there a way to modify the current language grammar dynamically?
Put simply, no.
Thanks.
On 24 Jul 2007, at 15:15, Michael Sheets wrote:
On Jul 24, 2007, at 3:23 AM, Hans-Jörg Bibiko wrote:
- Is it possible to look for the internal markups which TM is
using like "<support.function.perl>(.*?)</support.function.perl>" directly? I only know the way to use the 'magic keyword' in a tmCommand "<key>inputFormat</key><string>xml</string>" and parse the output.
Need to know why you need this to better answer it. For some cases you might have to do that, if you want the content of a scope for a command that is easy. Change the input to selected text, then choose scope as the alternate. Now the text around the caret matching the scope given will be available to the command.
Yes, I know. I'm using TM not only for writing source code but also for text analysis (n-gram, morphemes, special consonant clusters, unwanted glyphs, etc.). I find it quite convient to see what's going on within the text while writing. That's why I wrote a special language grammar to highlight these patterns (unfortunately a dynamic grammar doesn't work). Then I want to find the next morpheme for instance. Within TM's Find Dialog I cannot look for for these tags, I "only" can look for the regexp, but sometimes the regexp is really long (like for the next example).
Or an other example. A friend of mine is teaching Perl. He would find it very helpful to parse the current Perl code for all <support.function.perl> and <variable.other.predefined.perl> in order to list the used Perl functions/variables for a kind of glossary.
Of course, everything is doable by using Regexps in a command with inputFormat=xml. So my question only was whether there is a more direct way to use the internal markups, because these tags are already there.
Hans
On 25. Jul 2007, at 11:10, Hans-Joerg Bibiko wrote:
[...] Or an other example. A friend of mine is teaching Perl. He would find it very helpful to parse the current Perl code for all <support.function.perl> and <variable.other.predefined.perl> in order to list the used Perl functions/variables for a kind of glossary.
Of course, everything is doable by using Regexps in a command with inputFormat=xml. So my question only was whether there is a more direct way to use the internal markups, because these tags are already there.
Just for the records, TextMate does not internally store the document marked up like what you get when you set the input format to XML.
But giving access to the internal markup is something I would like to allow, but haven’t really settled on an API.
One common use-case for the internal markup is iteration, and we have tried this preliminary API for full (filtered) iteration of the document: http://macromates.com/svn/Bundles/trunk/Review/Support/lib/ xml_input.rb -- you/your friend may want to play with that and provide feedback.