diff options
author | Raymond Hettinger <python@rcn.com> | 2009-05-29 01:22:18 +0000 |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2009-05-29 01:22:18 +0000 |
commit | eb816954fb5795e10669edb4db29cf12f6b32ab0 (patch) | |
tree | a8b3b6a0bea08524140bd01d9951e9e8438d1c2c /Lib/idlelib/RstripExtension.py | |
parent | 323ee0cc21e360b105e34c07b80ec670703ee213 (diff) | |
download | cpython-git-eb816954fb5795e10669edb4db29cf12f6b32ab0.tar.gz |
Issue 5150: Add rstrip() menu option to IDLE.
Diffstat (limited to 'Lib/idlelib/RstripExtension.py')
-rw-r--r-- | Lib/idlelib/RstripExtension.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Lib/idlelib/RstripExtension.py b/Lib/idlelib/RstripExtension.py new file mode 100644 index 0000000000..19e35d4d48 --- /dev/null +++ b/Lib/idlelib/RstripExtension.py @@ -0,0 +1,29 @@ +'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() |