I've just attempted to add folding for POD to TM's Perl language definition - forgetting that I've already tried it previously. POD looks like this:
=head1 A heading
=head2 A sub heading
=cut
The =cut always ends the POD. So my patterns look like ^=(?!cut) and ^=cut\s*$ respectively. That doesn't work because the folding mechanism expects a recursive syntax - each opening 'thing' requires its own closing 'thing'.
So I was thinking about how the problem could be solved and it occurred to me that it'd be interesting to have an extension to regular expression syntax that allowed an assertion to be made about the matching scope.
Assuming the assertion was called ?^ you could match the text 'foo' only in storage.type.sub.perl or entity.name.function.perl with something like this:
(?^storage.type.sub.perl|entity.name.function.perl:foo)
Generally (?^ <scope re> : <re> ) would allow <re> to match only if the current scope name matched <scope re>.
To solve my folding problem the code that scans for folds would have to be scope aware - which may not be feasible architecturally.
And I realise that extending RE semantics to grok rich text is a bit of a big undertaking - but I thought it was a cute idea :)
On 23 Nov 2007, at 19:39, Andy Armstrong wrote:
[...] And I realise that extending RE semantics to grok rich text is a bit of a big undertaking - but I thought it was a cute idea :)
It’s actually been brought up a few times in the past, but yeah, it is quite an undertaking.
On 24 Nov 2007, at 12:09, Allan Odgaard wrote:
[...] And I realise that extending RE semantics to grok rich text is a bit of a big undertaking - but I thought it was a cute idea :)
It’s actually been brought up a few times in the past, but yeah, it is quite an undertaking.
I've just checked out the Oniguruma sources. I guess that adding new assertion types is probably beyond the scope of its pluggable syntax mechanism. And I imagine that's just the first, small hurdle...
So, more prosaically: support for folding where a language supports a mix of recursive and non-recursive syntaxes please :)
Just out of curiosity, where would you want the folding markers in your example? It looks like your regex will give you a start-folding- arrow at '=head2' and a stop-folding-arrow at '=cut' but it sounds like you want folds that start at each '=head' section and end at the following section. The problem is, a line can't be both a beginning and an ending. For example:
if (thing) { doStuff(); } else { doOtherStuff(); }
That will only give you one large folding section. You have to separate the second half from the first if you want two. You could also try to end each fold at the line before each '=head' section, but I don't know how you would go about that.
-- Ian Potter
On Nov 23, 2007, at 1:39 PM, Andy Armstrong wrote:
I've just attempted to add folding for POD to TM's Perl language definition - forgetting that I've already tried it previously. POD looks like this:
=head1 A heading
=head2 A sub heading
=cut
The =cut always ends the POD. So my patterns look like ^=(?!cut) and ^=cut\s*$ respectively. That doesn't work because the folding mechanism expects a recursive syntax - each opening 'thing' requires its own closing 'thing'.
So I was thinking about how the problem could be solved and it occurred to me that it'd be interesting to have an extension to regular expression syntax that allowed an assertion to be made about the matching scope.
Assuming the assertion was called ?^ you could match the text 'foo' only in storage.type.sub.perl or entity.name.function.perl with something like this:
(?^storage.type.sub.perl|entity.name.function.perl:foo)
Generally (?^ <scope re> : <re> ) would allow <re> to match only if the current scope name matched <scope re>.
To solve my folding problem the code that scans for folds would have to be scope aware - which may not be feasible architecturally.
And I realise that extending RE semantics to grok rich text is a bit of a big undertaking - but I thought it was a cute idea :)
-- Andy Armstrong, Hexten
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
On 24 Nov 2007, at 16:09, Ian Potter wrote:
Just out of curiosity, where would you want the folding markers in your example?
I wanted to be able to fold an entire chunk of POD as a single entity. So that would be
v =head1 A heading
=head2
^ =cut
Folding to
=head A heading ...
POD starts with any line that commences with =whatever apart from =cut - which marks the end of POD. So it's no good just to fold at '=head1'.
It looks like your regex will give you a start-folding-arrow at '=head2' and a stop-folding-arrow at '=cut' but it sounds like you want folds that start at each '=head' section and end at the following section. The problem is, a line can't be both a beginning and an ending. For example:
if (thing) { doStuff(); } else { doOtherStuff(); }
That will only give you one large folding section. You have to separate the second half from the first if you want two. You could also try to end each fold at the line before each '=head' section, but I don't know how you would go about that.
I don't think you can with the current folding mechanism. My idea was that if I could add assertions to the regexen I could make the start- of-POD pattern match only in a non-POD scope - so it'd only match the first POD directive.
For that use it doesn't have to integrated into the regex engine - it'd be enough to have a scope based condition that a folding pattern could depend upon:
foldingStartMarker = '(^=(?!cut)|/*|({|[|()\s*$)'; foldingStartIfScope = '! markup.directive.comment.block.documentation.perl'; foldingStopMarker = '(^=cut|*/|^\s*(}|]|)))';
But that got me to thinking about regexen for rich text and how a more general mechanism to allow scope assertions in regexen would be a fun thing to have. It'd allow you to do things like searching and replacing only within string literals - for example.
On 24 Nov 2007, at 16:24, Andy Armstrong wrote:
For that use it doesn't have to integrated into the regex engine - it'd be enough to have a scope based condition that a folding pattern could depend upon:
foldingStartMarker = '(^=(?!cut)|/*|({|[|()\s*$)'; foldingStartIfScope = '! markup.directive.comment.block.documentation.perl'; foldingStopMarker = '(^=cut|*/|^\s*(}|]|)))';
Unrelated: I wonder why the Perl language definition supports C style / * */ comments - which aren't legal in Perl?
On Nov 24, 2007, at 10:26 AM, Andy Armstrong wrote:
For that use it doesn't have to integrated into the regex engine - it'd be enough to have a scope based condition that a folding pattern could depend upon:
foldingStartMarker = '(^=(?!cut)|/*|({|[|()\s*$)'; foldingStartIfScope = '! markup.directive.comment.block.documentation.perl'; foldingStopMarker = '(^=cut|*/|^\s*(}|]|)))';
Unrelated: I wonder why the Perl language definition supports C style /* */ comments - which aren't legal in Perl?
Early on there was a lot of copy and pasting between the languages, and then people added the features they wanted to them. Since they aren't used as comments they also never caused problems so nobody removed them. ;)