diff options
author | Raymond Hettinger <python@rcn.com> | 2009-05-29 01:36:26 +0000 |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2009-05-29 01:36:26 +0000 |
commit | b4d2d3187419c3674b18b04b0208f456440b5c26 (patch) | |
tree | 0cc3697808a62072d2107b6643c4910930861893 /Lib/idlelib | |
parent | 8de212bd4f0c7d87e51758e92c6ba8f54e444b93 (diff) | |
download | cpython-git-b4d2d3187419c3674b18b04b0208f456440b5c26.tar.gz |
Issue 5150: Add rstrip() option to IDLE's format menu.
Diffstat (limited to 'Lib/idlelib')
-rw-r--r-- | Lib/idlelib/RstripExtension.py | 29 | ||||
-rw-r--r-- | Lib/idlelib/config-extensions.def | 6 |
2 files changed, 35 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() diff --git a/Lib/idlelib/config-extensions.def b/Lib/idlelib/config-extensions.def index 2d5cf6822e..78b68f6b56 100644 --- a/Lib/idlelib/config-extensions.def +++ b/Lib/idlelib/config-extensions.def @@ -86,3 +86,9 @@ bgcolor=LightGray fgcolor=Black [CodeContext_bindings] toggle-code-context= + +[RstripExtension] +enable=1 +enable_shell=0 +enable_editor=1 + |