PyWin editor modification

C

C or L Smith

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top