Dave wrote:
>
> Yes, moving the "else" back to column zero works fine. But as you
> say,
> it is much clearer if one starts a block at column zero. It just seems
> like the whole indentation scheme is breaking down at this point: I've
> got to watch out for mixing spaces and tabs and as soon as I start
> nesting blocks and mixing with HTML, I can no longer have that good
> old
> pythonic indented blocks feeling (or can I?) Is there a better way to
> represent this (attached) code?
This is a "common" complaint, and ver 0.4 will have a fix for this.
(Actually, I just committed it to CVS)
Basically, I think what I'm going to go with is:
if you end a script block with " $%> ", then PSP will pick up the amount
of indentation that the last script line was using, and add it to the
indentation level. That level of indentation will exist until the next
script block.
This is IN ADDITION to the auto indentation that comes from ending a
script block wth a ":". The auto indentation still has to be ended with
a <% end %>, but, that <% end %>, because it is a script block, will
also end the $%> indentation level.
So your code would look like this:
-------------------------------------------
<%@ page method="writeHTML" %>
PSP Test
<% q=0 %>
<%
if q:
self.writeln("We have Q")
else:
for i in range(10):$%>
Sorry! No Q !!!
<% end %>
-------------------------------------------------
How does that strike you?
Can I indent my nested "for: loop
> somehow? (Of course, the argument could be made that PSP pages are for
> display and shouldn't have a lot of nested blocks and that complex
> code
> should be moved to a Can or Servlet.)
I'm the one who will make that argument (for a Can or Servlet). BUt the
blocks are so common and necessary that they are a special case. I
think the solution above will work well.
Jay
|