5 ms·
I was trying to choose a Mac text editor recently; got it down to Atom and Sublime, and then discovered that both of them do code folding wrong. They think it's
by PhasmaFelis 11y ago
I was trying to choose a Mac text editor recently; got it down to Atom and Sublime, and then discovered that both of them do code folding wrong. They think it's based on indentation, not syntax, so if you try to fold something like:
if (something) {
some code
//commented-out code
more code
}
It folds everything from the opening bracket to the comment, then stops.
Both editors have had issues filed over this bug for years, which have been ignored. (https://github.com/atom/atom/issues/3442 https://github.com/atom/atom/issues/3442, https://github.com/SublimeTextIssues/Core/issues/101 https://github.com/SublimeTextIssues/Core/issues/101)
I eventually decided to go with Atom; it's open-source, so I can at least aspire to fix the damn thing myself when I get annoyed enough.
- coldtea 11y agoAnd why start the comment ahead of the indentation level?
- frou_dh 11y agoIf such commenting is being done using the generic comment/uncomment keyboard shortcut, whether that happens is influenced by TM_COMMENT_DISABLE_INDENT in the language package's Comments.tmPreferences file.
- PhasmaFelis 11y agoI didn't write the code in question, but I've done the same thing before. Usually it's because I'm cursoring up and down a file, see some lines I want to comment out, and don't bother moving over to the start of the text first. Syntax highlighting greys out the comment, so it's not visually obtrusive. (Which is another reason I'm baffled that Atom and Sublime both misbehave this way--they've got syntax highlighting! They're already aware of block delimiters! Why don't they apply that knowledge to code folding?) And I understand there are other reasons to not indent. In some languages, it's conventional to have certain kinds of declarations come at the beginning of a line, even if they're inside a block. (I think C++ does this, but I haven't used it since college--anyone want to comment?)
- oneeyedpigeon 11y agoReally? That's my comment style, so I'd be affected by that if I ever used code-folding. I don't want this to come across as 'blame-the-user', I'm just genuinely interested - what does code-folding help you with?
- wingerlang 11y agoI regularly fold all methods to get an overview of the class and its flow. Or if I quickly want to scan the class to maybe find something. Or even just to go into "zen mode" to feel that I can focus in on one method while the other ones are "gone".
- PhasmaFelis 11y agoAt the time, I was attempting to modify a very large, nonbranching clusterfuck of a function, and there wasn't time to properly refactor it, so I wanted to examine each chunk and then fold it away once I'd determined that it wasn't related to what I was looking for. (And the code I was looking for turned out to be scattered across three different parts of the greater monolith, so I was glad I could fold away the bits in between.) But yeah, generally it helps me get a high-level overview of the code without getting lost in the details.
- ball_of_lint 11y agoIn lisp, if you have a let with a variable declared on the same line and another below, it only folds the variable parts of the let, and leaves the body unfolded. Super frustrating. So like: (( ) ) Folds into ((.. ) And it's just wrong.
- swznd 11y agoyou should try TextMate, it folds correctly