All Downloads are FREE. Search and download functionalities are using the official Maven repository.

lib-python.2.7.idlelib.RstripExtension.py Maven / Gradle / Ivy

Go to download

Jython is an implementation of the high-level, dynamic, object-oriented language Python written in 100% Pure Java, and seamlessly integrated with the Java platform. It thus allows you to run Python on any Java platform.

The newest version!
'Provides "Strip trailing whitespace" under the "Format" menu.'

__author__ = "Roger D. Serwy "

class RstripExtension:

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

    def __init__(self, editwin):
        self.editwin = editwin
        self.editwin.text.bind("<>", 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()




© 2015 - 2025 Weber Informatics LLC | Privacy Policy