I'd love to be able to fold comment blocks. (I'm thinking ruby, but really, any language)
I suppose it'd be possible with a simple modification somewhere in the language bundle. Any pointers?
On 04/10/2005, at 22.32, Caio Chassot wrote:
I'd love to be able to fold comment blocks. (I'm thinking ruby, but really, any language)
I suppose it'd be possible with a simple modification somewhere in the language bundle. Any pointers?
It's the foldingStartMarker and foldingStopMarker (for each language grammar in the bundle editor). These are regular expressions matched against each line, and those lines which match one (but not both) of them, becomes a start or stop marker.
One caveat being that start and stop markers must have the same indent to be foldable.
So for Ruby comments you'd have to make up some convention, like using + on first comment line and - on last, e.g.:
#+ # This is a comment block # which automatically folds #-
Which would be foldable by using these patterns:
foldingStartMarker = '#+'; foldingStopMarker = '#-';
On Oct 04, 2005, at 18:26, Allan Odgaard wrote:
So for Ruby comments you'd have to make up some convention, like using
on first comment line and - on last, e.g.:
#+ # This is a comment block # which automatically folds #-
That's ok for code that I write, but I need it most when reading heavily documented code like, say, active_record. Can anything be done to fold standard ruby comments automatically?
If not, given that this comment style is common to so many languages, would you consider implementing a solution that makes it possible?
One idea: you could implement an alternative way of specifying foldings that would address this and hopefully other situations (eg. paragraphs, lists and blockquotes in markdown). Basically what we need is a way to fold a group of consecutive lines that match a pattern, so:
foldingGroupMarker = "#"
On 05/10/2005, at 3.09, Caio Chassot wrote:
That's ok for code that I write, but I need it most when reading heavily documented code like, say, active_record. Can anything be done to fold standard ruby comments automatically?
If not, given that this comment style is common to so many languages, would you consider implementing a solution that makes it possible?
Foldings will be revisited in 1.3, I'm still not entirely decided on how it should be handled, but definitely something involving scopes.
And if there's nothing unique to the first and last line in the block you want to fold, you'll have to select and fold it manually.
You can find the command block by regexp searching for: (^[[^\n]&&\s] *#.*$\n)+ -- currently though, “fold selection” is not a recordable action (for a macro), but I can add it to the list for next build.
You can find the command block by regexp searching for: (^[[^\n]&&\s]*#.*$\n)+ -- currently though, “fold selection” is not a recordable action (for a macro), but I can add it to the list for next build.
That would be great. But is it possible to create a macro that folds all comments? I mean, is there flow control for macros along the lines of "while find comment regexp, fold selection"?
On 05/10/2005, at 16.40, Caio Chassot wrote:
You can find the command block by regexp searching for: (^[[^\n]&& \s]*#.*$\n)+ -- currently though, “fold selection” is not a recordable action (for a macro), but I can add it to the list for next build.
That would be great. But is it possible to create a macro that folds all comments? I mean, is there flow control for macros along the lines of "while find comment regexp, fold selection"?
No, macros are just replaying your actions.
On 04/10/2005, at 23.26, Allan Odgaard wrote:
Which would be foldable by using these patterns:
foldingStartMarker = '#\+'; foldingStopMarker = '#-';
What about a start marker that is all the lines to be folded, and an endmarker that is the space just after the block but before the next block.
So something like
foldingStartMarker = '(?: beginning of line, #, chars in line, end of line )+' foldingStopMarker = ''
...
If the marker is placed at the outer edge of the block, then prehaps the same regex can be used for both start and stop marker, providing the marker matches the whole block.
So the markers would match the whole block and be placed like this:
M # code # code # code # code
# code # code # code M # code
On Oct 5, 2005, at 7:19 AM, David Jack Olrik wrote:
On 04/10/2005, at 23.26, Allan Odgaard wrote:
Which would be foldable by using these patterns: foldingStartMarker = '#+'; foldingStopMarker = '#-';
Out of curiosity, why doesn't this work (latest version of TextMate):
foldingStartMarker = '^\s*#.+\n(?=\s*#)'; foldingStopMarker = '^\s*#.+\n(?!\s*#)';
The regexp work in the Find dialog, finding the desired lines. If it did, I should get folding starts on all lines of a multi-line comment save for the last; as it is, I don't get any folding markers at all using those regexp on the following document:
module Foo #Just a single-line # Another lone single-line - no need to fold def foo
end
# Here's more than one line comment # carried on and on # until the end def bar
end end
On Oct 5, 2005, at 7:55 AM, Gavin Kistner wrote:
On Oct 5, 2005, at 7:19 AM, David Jack Olrik wrote:
On 04/10/2005, at 23.26, Allan Odgaard wrote:
Which would be foldable by using these patterns: foldingStartMarker = '#+'; foldingStopMarker = '#-';
Out of curiosity, why doesn't this work (latest version of TextMate):
foldingStartMarker = '^\s*#.+\n(?=\s*#)'; foldingStopMarker = '^\s*#.+\n(?!\s*#)';
To begin to answer my own question, it looks like it's the \n. That sort of makes sense, I suppose - how can TM know what line to fold on when the RegExp matches over multiple lines?
However, even placing that inside a lookahead doesn't work.
foldingStartMarker = '^\s*#.+' # This properly starts a fold foldingStartMarker = '^\s*#.+(?=\n)' # This does not
As the lookahead assertion doesn't consume characters, I'm not sure why that fails...is it perhaps because each line is passed into the folding detector, with no context for the lines around it?
On 05/10/2005, at 16.03, Gavin Kistner wrote:
As the lookahead assertion doesn't consume characters, I'm not sure why that fails...is it perhaps because each line is passed into the folding detector, with no context for the lines around it?
Yes -- the same is the case for the syntax highlight patterns.
If the patterns were allowed to match multiple lines, it would be possible to craft patterns so that changing last line in the document would affect syntax highlight or folding markers on the first line -- so very bad for performance.