Folding for functions with parameters over multiple lines#84
Open
tungol wants to merge 2 commits intotextmate:masterfrom
Open
Folding for functions with parameters over multiple lines#84tungol wants to merge 2 commits intotextmate:masterfrom
tungol wants to merge 2 commits intotextmate:masterfrom
Conversation
The default configuration fails to fold functions if the parameters are defined over multiple lines. Due to typing, this is more likely to happen these days than it used to be. Three things here: - a new regex for foldingIndentedBlockStart. The existing expression only matches when the final : is on the same line as the 'def'. We don't want to lose that requirement for the other keywords that start a block, so I added a totally separate expression that matches only functions definitions with a open-parenthesis as the final non-whitespace non-comment character on the line. `^\s*def\b.*\(\s*(#.*)?$` - adding a foldingIndentedBlockIgnore expression This is needed so that the closing parenthesis of the parameter declaration can be on a lower indent level, like black likes to do. It should match a closing parenthesis and colon with optional return type. `^\s*\)(\s*->\s*\w.*)?:\s*(#.*)?$` - modifying foldingStartMarker Still not done, because Textmate also matches `def foo(\n` as the start of marker-based folding due to the parenthesis, and then it gets confused. I added a negative lookbehind to prevent it from matching when we're making a def statement. `(?<!\bdef\s+\w+\s*)` With those three changes in place, Textmate can now fold all functions, not just those with `def` and `):` on the same line!
Author
|
I jumped the gun here - I didn't realize that variable length negative-lookbehinds were unsupported, so I actually broke folding for all braces. Working around this limitation so I can match |
Negative look-behinds with varaible lengths aren't supported, which I didn't realize. This fixes the issue using a negative-lookahead instead.
Author
|
I think I got it working now and the MR has been updated. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The default configuration fails to fold functions if the parameters are defined over multiple lines. Due to typing, this is more likely to happen these days than it used to be.
Three things here:
The existing expression only matches when the final : is on the same line as the 'def'. We don't want to lose that requirement for the other keywords that start a block, so I added a totally separate expression that matches only functions definitions with a open-parenthesis as the final non-whitespace non-comment character on the line.
^\s*def\b.*\(\s*(#.*)?$This is needed so that the closing parenthesis of the parameter declaration can be on a lower indent level, like black likes to do. It should match a closing parenthesis and colon with optional return type.
^\s*\)(\s*->\s*\w.*)?:\s*(#.*)?$Still not done, because Textmate also matches
def foo(\nas the start of marker-based folding due to the parenthesis, and then it gets confused. The new foldingStartMarkerexpression uses a negative-lookahead to match
(only if it's not preceded by a def statement.^(?!\s*def\s+\w+\s*).*\(\s*(#.*)?$With those three changes in place, Textmate can now fold all functions, not just those with
defand):on the same line!The exact expressions can probably be fine-tuned a little further - I didn't fuss with them too much. I'm creating this MR more so anyone with the same issue might find it than in any expectation it'll get merged.