I have a question about editing python in TextMate. Is it possible to change the folding rules so that class/function definitions don't stop folding when they encounter a blank line?
Thanks, Jordan
On 17-08-2005 02:49, Jordan Breeding wrote:
I have a question about editing python in TextMate. Is it possible to change the folding rules so that class/function definitions don't stop folding when they encounter a blank line?
Only if you use sufficient indentation on that blank line.
TextMate parses files mostly line by line and makes syntax highlight and folding decisions based on that. This means that the only way to know if a blank line is for readability or delimiting a function or class is based on indentation.
Jeroen.
On 8/17/05, Jeroen van der Ham jeroen@je-ju.net wrote:
On 17-08-2005 02:49, Jordan Breeding wrote:
I have a question about editing python in TextMate. Is it possible to change the folding rules so that class/function definitions don't stop folding when they encounter a blank line?
Only if you use sufficient indentation on that blank line.
TextMate parses files mostly line by line and makes syntax highlight and folding decisions based on that. This means that the only way to know if a blank line is for readability or delimiting a function or class is based on indentation.
On a quick glance at the Python.plist file it seems that the foldingStopMarker looks for a blank line (for def|class entities). It should be possible to use captures to find the indentation level, no?
in english: foldingStartMarker: (captures preceding_whitespace_pattern) foldingStopMarker: when line is not blank and not matching {preceding_whitespace_pattern} + anything
I haven't decided if that will still work for dicts, lists, and tuples ... but this should fix defs and classes so they don't fold on blank lines within the entity. I think the last entity in the file would not get folded correctly though.
On 17-08-2005 21:04, Kumar McMillan wrote:
On a quick glance at the Python.plist file it seems that the foldingStopMarker looks for a blank line (for def|class entities). It should be possible to use captures to find the indentation level, no?
TextMate already does this, consider the following situation:
class someClass: def someFunction(args): pass . .
I use periods here to show how much indentation there should be for the stop marker to show up. Usually, TM guesses the amount of indentation correctly and you just have to press backspace once on a blank line for the stopMarker to show up.
Is this not what you want?
Jeroen.
On 8/17/05, Jeroen van der Ham jeroen@je-ju.net wrote:
Usually, TM guesses the amount of indentation correctly and you just have to press backspace once on a blank line for the stopMarker to show up.
Is this not what you want?
That's nice for new files, but doesn't help with old files created with other editors.
On Wed, 17 Aug 2005 22:40:03 +0200, Jeroen van der Ham wrote:
TextMate already does this, consider the following situation:
class someClass: def someFunction(args): pass . .
I use periods here to show how much indentation there should be for the stop marker to show up.
This works properly as I write every python codes with TextMate keeping in mind the indentation behavior. But some editors, at least two popular vim and emacs, strips white spaces and such files doesn't match TextMate's indentation rule.
TextMate: 1: class someClass: 2: def func(self): 3: self.doSomethingA() 4: . 5: self.doSomethingB() 6: . 7: . 8: class nextClass: pass
vim, emacs: 1: class someClass: 2: def func(self): 3: self.doSomethingA() 4: . 5: self.doSomethingB() 6: . 7: . 8: class nextClass: pass
In this case, I think Kumar's indentation rule works well.
On 8/17/05, Jeroen van der Ham jeroen@je-ju.net wrote:
TextMate already does this, consider the following situation:
class someClass: def someFunction(args): pass . .
Is this not what you want?
What about this code, folding should still work for the classes, not just the functions:
class someClass: def someFunction(args): pass . class someOtherClass: def someOtherFunction(args): pass
Again using your dot notation.
Regards, Douglas
On 19-08-2005 01:47, Douglas Livingstone wrote:
What about this code, folding should still work for the classes, not just the functions:
class someClass: def someFunction(args): pass . class someOtherClass: def someOtherFunction(args): pass
I understand that that should work, but it doesn't because it's pretty difficult to define what the closing folding match would be. And as far as I know, there's no way to have both a closing and an opening folding on the same line (so matching "class" wouldn't work) and multiline matches are not supported in TextMate, so you can't do a look ahead search for class either.
Jeroen.
Interesting. Well, I tried putting my money where my mouth was and my pattern doesn't seem to work :) Here is what I tried ....
foldingStartMarker: (^\s*)(def|class)\s+([.a-zA-Z0-9_ b]+)\s*(((.*)))?\s*: foldingEndMarker: ^(?!\s*$)(?!\1\s+.*$)
which was trying to accomplish:
foldingStartMarker: (captures indent_level) foldingStopMarker: when line is not blank and not matching {indent_level} + indent + anything
(obviously I stripped out the list, dict, and tuple patterns just for testing)
_
any ideas?
On 8/19/05, Jeroen van der Ham jeroen@je-ju.net wrote:
On 19-08-2005 01:47, Douglas Livingstone wrote:
What about this code, folding should still work for the classes, not just the functions:
class someClass: def someFunction(args): pass . class someOtherClass: def someOtherFunction(args): pass
I understand that that should work, but it doesn't because it's pretty difficult to define what the closing folding match would be. And as far as I know, there's no way to have both a closing and an opening folding on the same line (so matching "class" wouldn't work) and multiline matches are not supported in TextMate, so you can't do a look ahead search for class either.
Jeroen.
<http://www.je-ju.net/~jeroen/blog/>
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 19-08-2005 17:49, Kumar McMillan wrote:
foldingStartMarker: (^\s*)(def|class)\s+([.a-zA-Z0-9_ b]+)\s*(((.*)))?\s*: foldingEndMarker: ^(?!\s*$)(?!\1\s+.*$)
Note that the \1 in the foldingEnd Marker refers to the first match of the foldingEndMarker pattern, which contains itself... You can't refer to the first pattern of the foldingStartMarker there.
Jeroen.
On 8/19/05, Jeroen van der Ham jeroen@je-ju.net wrote:
On 19-08-2005 17:49, Kumar McMillan wrote:
foldingStartMarker: (^\s*)(def|class)\s+([.a-zA-Z0-9_ b]+)\s*(((.*)))?\s*: foldingEndMarker: ^(?!\s*$)(?!\1\s+.*$)
Note that the \1 in the foldingEnd Marker refers to the first match of the foldingEndMarker pattern, which contains itself... You can't refer to the first pattern of the foldingStartMarker there.
hmm... I thought this was changed a couple betas ago (\1 to reference the first match of a starting pattern). At least, if you look at Perl.plist this is how Here-Doc strings are matches. But perhaps this support only exists for begin/end pairs and not foldingStartMarker/foldingEndMarker pairs. Allan, if you are reading, would it be possible to add this for folding start/end ? Or does it exist and I am going about it wrong?
Jeroen.
-- http://www.je-ju.net/~jeroen/blog/ ______________________________________________________________________ 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