Staging
v0.5.1
https://github.com/python/cpython
Raw File
Tip revision: 08e544e27bcc26fd82d218ea0676da42c8b8b9f7 authored by Antoine Pitrou on 25 August 2011, 16:32:02 UTC
Issue #12333: fix test_distutils failures under Solaris and derivatives
Tip revision: 08e544e
RstripExtension.py
'Provides "Strip trailing whitespace" under the "Format" menu.'

__author__ = "Roger D. Serwy <roger.serwy at gmail.com>"

class RstripExtension:

    menudefs = [
        ('format', [None,
               ('Strip trailing whitespace', '<<do-rstrip>>'),
       ]),]

    def __init__(self, editwin):
        self.editwin = editwin
        self.editwin.text.bind("<<do-rstrip>>", self.do_rstrip)

    def do_rstrip(self, event=None):

        text = self.editwin.text
        undo = self.editwin.undo

        undo.undo_block_start()

        end_line = int(float(text.index('end'))) + 1
        for cur in range(1, end_line):
            txt = text.get('%i.0' % cur, '%i.0 lineend' % cur)
            cut = len(txt.rstrip())
            text.delete('%i.%i' % (cur, cut), '%i.0 lineend' % cur)

        undo.undo_block_stop()
back to top