Hi,
I was wondering what the best approach to enable this functionality would be:
I use reStructuredText as the format of my doc strings in my python files, and so I'd like to enable the reStructuredText snippets, macros, etc. to fire in my python """ ... """ strings.
The scope of these strings in the Python files are: string.quoted.double.block.python
Should I just add this scope to all of the commands in the reStructuredText bundle, so all of the scopes for those commands would be changed to: text.restructuredtext, string.quoted.double.block.python
Or should I change the Python grammar to somehow set those two scopes for the """ ... """ string matching pattern (I'm not sure if you can do that, though).
Thanks, -steve
Steve Lianoglou <lists@...> writes:
I was wondering what the best approach to enable this functionality would be:
I use reStructuredText as the format of my doc strings in my python files, and so I'd like to enable the reStructuredText snippets, macros, etc. to fire in my python """ ... """ strings.
The scope of these strings in the Python files are: string.quoted.double.block.python
Should I just add this scope to all of the commands in the reStructuredText bundle, so all of the scopes for those commands would be changed to: text.restructuredtext, string.quoted.double.block.python
Or should I change the Python grammar to somehow set those two scopes for the """ ... """ string matching pattern (I'm not sure if you can do that, though).
At the moment, the best way is probably to just edit the python grammar, adding the text.restructuredtext scope to the strings. Then you'll also get niceties like syntax highlighting for reST inside your python strings, etc.
This is far from ideal though, and Allan's scope injection system for textmate 2 should provide a much more elegant method.
* * *
Incidentally, are any other python users bothered by the decision to use reST as the de facto format for docstrings? reST really clashes with python's clean aesthetic for me.
-Jacob
Or should I change the Python grammar to somehow set those two scopes for the """ ... """ string matching pattern (I'm not sure if you can do that, though).
At the moment, the best way is probably to just edit the python grammar, adding the text.restructuredtext scope to the strings. Then you'll also get niceties like syntax highlighting for reST inside your python strings, etc.
I see ... so how would that look like, exactly?
In the Python grammar, I guess this would be the right place:
{ name = 'string.quoted.double.block.python'; comment = 'double quoted string'; begin = '(""")'; end = '((?<=""")(")""|""")'; beginCaptures = { 1 = { name = 'punctuation.definition.string.begin.python'; }; }; endCaptures = { 1 = { name = 'punctuation.definition.string.end.python'; }; 2 = { name = 'meta.empty-string.double.python'; }; }; patterns = ( { include = '#constant_placeholder'; }, { include = '#escaped_char'; }, ); },
Do I just fiddle with the first name = string.quoted.double.block.python to add test.reStructuredText to it (what's the right way to do that)?
Incidentally, are any other python users bothered by the decision to use reST as the de facto format for docstrings? reST really clashes with python's clean aesthetic for me.
There was a bit of a (long) discussion on the NumPy / SciPy list about this very same issue a while back over the same issue (reST looking too noisy). I think they settled on using reST with a bit of tweaking via some epydoc magic to make it *just a bit* cleaner.
To be honest, however, I don't find reST all that bad ... I kinda like it.
That said, though, I look forward to v2.0 when (I think) we'll be able to fold away the docstrings a bit more cleanly/robustly so I don't have to look at them all day :-)
-steve
On Feb 12, 2007, at 1:29 AM, Steve Lianoglou wrote:
patterns = ( { include = '#constant_placeholder'; }, { include = '#escaped_char'; }, ); },
Do I just fiddle with the first name = string.quoted.double.block.python to add test.reStructuredText to it (what's the right way to do that)?
Just add after or before those include lines another include line like:
{ include = 'text.restructuredtext';},
Haris
Hmm ..
On Feb 12, 2007, at 1:29 AM, Steve Lianoglou wrote:
patterns = ( { include = '#constant_placeholder'; }, { include = '#escaped_char'; }, ); },
Do I just fiddle with the first name = string.quoted.double.block.python to add test.reStructuredText to it (what's the right way to do that)?
Just add after or before those include lines another include line like:
{ include = 'text.restructuredtext';},
I changed that to look like: patterns = ( { include = '#constant_placeholder'; }, { include = '#escaped_char'; }, { include = 'text.restructuredtext'; }, );
When I hit the Text button (to activate it), it blows hoses the Python source ... it's all colored as if it were one long string.
Lines with text, however, (not just whitespace) now all get an addition scope: meta.paragraph.restructuredtext
which I guess is why its coloring everything like a string, but I wonder why it doesn't stop doing that outside of the double quoted blocks """ """, where I do the include = 'text.restructuredtext'?
-steve
On Feb 12, 2007, at 2:00 AM, Steve Lianoglou wrote:
When I hit the Text button (to activate it), it blows hoses the Python source ... it's all colored as if it were one long string.
All of it, or everything starting from the first """ ?
Lines with text, however, (not just whitespace) now all get an addition scope: meta.paragraph.restructuredtext
which I guess is why its coloring everything like a string, but I wonder why it doesn't stop doing that outside of the double quoted blocks """ """, where I do the include = 'text.restructuredtext'?
Presumably the rules in text.restructuredtext are such that they absorb the closing """ . I would venture to guess (though perhaps I am wrong) that the restructuredtext grammar is not ready for inclusion to Python. Go to the closing """ and see what the scope is there. It might include: markup.heading.restructuredtext, which would mean that it would be absorbed by the restructuredtext rule, instead of being considered as losing the first """.
Is any restructuredtext text allowed in python's """ """ ? If not, then perhaps you need to first break the restructuredtext grammar in two parts, a root grammar and an extension grammar, and then include only the root one in python.
-steve
Haris
Yes, ReST is pretty ugly. Markdown would have been a better choice.
- Alex
On Feb 11, 2007, at 9:54 PM, Jacob Rus wrote:
Steve Lianoglou <lists@...> writes:
I was wondering what the best approach to enable this functionality would be:
I use reStructuredText as the format of my doc strings in my python files, and so I'd like to enable the reStructuredText snippets, macros, etc. to fire in my python """ ... """ strings.
The scope of these strings in the Python files are: string.quoted.double.block.python
Should I just add this scope to all of the commands in the reStructuredText bundle, so all of the scopes for those commands would be changed to: text.restructuredtext, string.quoted.double.block.python
Or should I change the Python grammar to somehow set those two scopes for the """ ... """ string matching pattern (I'm not sure if you can do that, though).
At the moment, the best way is probably to just edit the python grammar, adding the text.restructuredtext scope to the strings. Then you'll also get niceties like syntax highlighting for reST inside your python strings, etc.
This is far from ideal though, and Allan's scope injection system for textmate 2 should provide a much more elegant method.
Incidentally, are any other python users bothered by the decision to use reST as the de facto format for docstrings? reST really clashes with python's clean aesthetic for me.
-Jacob
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate