Closed peter-b closed 8 years ago
I've worked this out.. It seems you can't have two settings blocks for the same grammars. I'll merge them. Will need to submit one PR for this and #18 now. I'm also looking at how to improve with switch indenting. At the moment break decreases indent so break and case are at the same indent level. With case indenting it means when you want continuation you end up with case indenting again.. not good.
I've tried case both increasing and decreasing and it works OK apart from the fact that case and switch are at the same indent. Not ideal but better than the increasing indentation with continuation bug. What are your thoughts? What we really need is a way to force the precedence of the switch increase in indent over the case decrease, however, I'm not sure if that is possible. I'm off to investigate some other languages to see how they handle it.
I've also added support for default which was missing. After thinking on the switch handling I don't think (unless I'm missing something) that we can do much better than case and default being both indent increasers and decreasers. If they aren't then then we rely on break too much to decrease our indent which is clearly unacceptable when you consider continuation or the fact that break is redundant on the last case.
So... I'm going to run with my changes. The quirk will be that switch, case and default are on the same indent but that compromise is better than the bugs of cases with continuation indenting again and ending the control structure not returning to the correct indent level. Even if we can think of a way to indent the cases the end switch wouldn't return us correctly to the right indent so I don't think there's any other options unless there's a way to script the behavior...
One extra thing I'll note about switch indenting is that after reviewing a number of other languages I have found that they don't indent cases so what they do is the equivalent of this:
switch thing
case thing1
/* code */
break
case thing2
/* code */
break
end switch
I find the lack of indentation on the cases unhelpful. What I have done will result in this which I prefer:
switch thing
case thing1
/* code */
break
case thing2
/* code */
break
end switch
It does not appear to be possible to implement both indentation after switch and after case AND fix the bugs I found and outlined earlier. As seen here:
switch thing
case thing1
/* code */
case thing2
/* code */
break
end switch
and here:
switch thing
case thing1
/* code */
break
case thing2
/* code */
end switch
@montegoulding What does Atom's C language mode do? I think the best thing to do is to copy that. If it does what you describe, then that sounds like a win to me. I agree that what you've done looks the best out of the options that you've described...
I looked at c, php and JavaScript. All have no indentation for case. I'd rather not follow the crowd if we can do better. You can obviously manually indent though. I wonder what atom would need for proper support... I guess some way to link the indent of the first block to subsequent blocks that should have that level???
For LiveCode Builder source code, the "Edit->Auto Indent" command ("Editor: Auto Indent" via the command palette) properly re-indents source code, including
if
/repeat
/handler
etc.This doesn't seem to work properly for LiveCode Script source code (
.livecodescript
files).