""" Rstrip Extension: Provides "Do rstrip()" under the "Format" menu. Author: Roger D. Serwy roger.serwy@gmail.com Date: 2009-05-28 Add these lines to config-extensions.def [RstripExtension] enable=1 enable_shell=0 enable_editor=1 """ class RstripExtension: menudefs = [ ('format', [None, ('Do rstrip()', '<>'), ]),] 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()