Regarding the question of "control lines that take up only one line", first addressing it from the perspective of not having to add more newlines to the template source than is necessary. As I got to your issue #3 I realized you might be concerned about output only, which we have covered already so just skip to the bottom for that, but since I put all this thought in already for the other case, here's that too.
For non-newline control statements, the issue is that parsing in Mako is gets involved in situations when we're essentially scanning along Python and have to figure out "where the Python ends". Issues like quoting and such, for example, and a : can appear inside a dictionary literal too. In the case of control statements, the newline is a pretty big anchor for us. Patches here would need to be proposed for lexer.py:
parsing a ternary if / else would likely be it's own parse target (like def match_ternary_statement()), since it's pretty different than a traditional control line. In which case we might as well pick a great syntax for it. But then I checked the aforementioned jinja2. For a ternary, they don't seem to do any better than us:
http://jinja.pocoo.org/docs/templates/#if-expression as you can see the HTML is quoted there as an expression too.
However, if the case is that Jinja2's (% if <expr> %}, because it has a closing %} allows it to be inlined like {% if <expr> %} <html> {% else %} <html> {% endif %}, then I'd want to think a bit bigger here. I'd want to go into match_control_line() as we did and just find some way to make the newline optional:
% if <expr>:\n
<html>\n
% else:\n
<html>\n
% endif\n
we could perhaps just co-opt the { } verbosity:
{% if <expr>:} <html> {% else:} <html> {% endif}
or just rip them off totally:
{% if <expr> %} <html> {% else %} <html> {% endif %}
either of the above would require a rewritten (either in-place or additional version of) match_control_line(), as we'd be doing the same kind of matching which we do in match_expression(), which is that we need to make use of parse_until_text() so that we properly skip over anything that might be Python code. I'd want the two formats to be completely interchangeable:
% if expr:
<html> {% else %} <html>
% endif
{% if <expr> %} <html>
% elif <expr>:
<html>
% else:
<html> {% endif %}
just some ideas but I'd need someone to be motivated to help patch out lexer.py and add new tests as well.