The PyWin editor that comes with the Windows distribution is a great little 
workhorse. If you have used it you perhaps notice how it intelligently works 
with spaces and indentation, e.g. after typing the word 'pass' and pressing 
enter it dedents one level as you would probably desire. It also strips 
trailing space from every line that you enter...unless that line contains ONLY 
space.

The following modification to the AutoIndent.py file in the 
pythonwin\pywin\idle directory makes the editor strip all trailing space, even 
if that's all a line contains. With this modification, no line that you enter 
with the PyWin editor will ever contain trailing space (unless you purposely 
add it to the end of a line but then don't press <enter>).

Search for the word "inject" which appears only once in the file and add the 
line as indicated below:

if i == n:
    # the cursor is in or at leading indentation; just inject
    # an empty line at the start
    text.delete("insert - %d chars" % i, "insert")  <== add this line
    text.insert("insert linestart", '\n')
    return "break"

This little modification is going to make my editing life less error prone as I 
work on a project that checks for trailing whitespace. Maybe it will be useful 
to someone else.

/c

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to