Home | History | Annotate | Download | only in idlelib
      1 'Provides "Strip trailing whitespace" under the "Format" menu.'
      2 
      3 class Rstrip:
      4 
      5     def __init__(self, editwin):
      6         self.editwin = editwin
      7 
      8     def do_rstrip(self, event=None):
      9 
     10         text = self.editwin.text
     11         undo = self.editwin.undo
     12 
     13         undo.undo_block_start()
     14 
     15         end_line = int(float(text.index('end')))
     16         for cur in range(1, end_line):
     17             txt = text.get('%i.0' % cur, '%i.end' % cur)
     18             raw = len(txt)
     19             cut = len(txt.rstrip())
     20             # Since text.delete() marks file as changed, even if not,
     21             # only call it when needed to actually delete something.
     22             if cut < raw:
     23                 text.delete('%i.%i' % (cur, cut), '%i.end' % cur)
     24 
     25         undo.undo_block_stop()
     26 
     27 if __name__ == "__main__":
     28     from unittest import main
     29     main('idlelib.idle_test.test_rstrip', verbosity=2,)
     30