Else block always runs
@mcaceresb
This is because we run other commands after the if clause gets sent. Not really sure the best way to fix this. In Jupyter Notebook/Atom you can just be careful to only send the entire if/else block. In Jupyter console, you can fix this by wrapping the entire block in a pair of braces.

Console workaround:

If there is more than one line of code, simply require two blank lines instead of one for the chunk to be considered complete.
(i.e. two <CR> from the user)
Brilliant!
This is helpful for the console, but the behavior is still suboptimal in Hydrogen, since it doesn't use is_complete messages at all..

The only way to get around this in hydrogen right now is to manually select the if/else block. For now I should at least put this in the limitations page in the docs.

Wait, how does it do it for python, then?
It doesn't. Since Hydrogen is 100% language-agnostic, it uses only general syntax elements like indentation and the foldEndMarker designated by the language's syntax highlighting package.
Recently a separate python-specific add-on package was developed to expand code lines. See https://github.com/nikitakit/hydrogen-python/pull/10 for the difficulty of correctly implementing this feature.
This is something Hydrogen struggles with in general because of its language-independentness... Here's the same issue in Javascript.

I think it's something that could be improved in Hydrogen... If you had a suggestion I might mention it to the other maintainers and try to create a PR for it.
and the foldEndMarker designated by the language's syntax highlighting package.
I thought you were in charge of that, or is it too much of a pain to implement? You can nest if/else in an ifelse fold if if is followed by else in the next line?
I am. And I edited it recently to include the ending } in Hydrogen.
But it's just a plain regex setting (that a core Atom package then implements) and Atom can't do regexes across lines anyways. So I don't think it's possible to say "} ends folds except when else { or else if { appears on the following line"
In Javascript, you could put }(?!\s* else) as the regex and plausibly get the whole if/else clause. But not sure how to do it when they're always on separate lines.
Multi-line regex?
Atom can't do regexes across lines anyways
At least not for syntax highlighting. I doubt it allows it here, though I could try it out.
Wait, this is odd. Python has multi-line strings. Doesn't it highlight them?
Conceptually, if should start an if-else environment ended by a blank line after } or an else block, right? I reckon that's not how it's written?
Wait, this is odd. Python has multi-line strings. Doesn't it highlight them?
Yes, but the token that it looks for in the regular expression never spans a newline. I.e. the """ will be on one line and another, and Atom can create regions between the lines, but the token can never span lines.
That's why it's impossible, for example, to highlight Setext headers in Markdown https://github.com/burodepeper/language-markdown/issues/192
Actually, it is ended by an else block or a line containing anything that doesn't start with else
But that is not the same, tho, right? Because you can look for environment delimiters...at least that is what I'm assuming.
The markdown example has no delimiter to start the header, just to end it.
With the syntax highlighting yes. But not the fold end marker to my knowledge. I haven't tried but I'd be surprised.
What's a simple regex to try?
}(?!\s*\n\s*else)
Something like that, yeah. Remember that you can have if w/o brackets and else with brackets after afaik
It actually works when not using brackets:

I suppose the main reason is that when there are brackets I run the code with include
So include must break Stata's record of if/else somehow
The only case in which it doesn't work is when if uses brackets.
Why did we end up using include anyways?

Oh right we use include so that commands will stop running after one creates an error. Which is good...