]> granicus.if.org Git - python/commitdiff
Issue 5150: Add rstrip() option to IDLE's format menu.
authorRaymond Hettinger <python@rcn.com>
Fri, 29 May 2009 01:36:26 +0000 (01:36 +0000)
committerRaymond Hettinger <python@rcn.com>
Fri, 29 May 2009 01:36:26 +0000 (01:36 +0000)
Lib/idlelib/RstripExtension.py [new file with mode: 0644]
Lib/idlelib/config-extensions.def
Misc/NEWS

diff --git a/Lib/idlelib/RstripExtension.py b/Lib/idlelib/RstripExtension.py
new file mode 100644 (file)
index 0000000..19e35d4
--- /dev/null
@@ -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()
index 2d5cf6822e8edf845cbf2f9b4d46778f56cabe79..78b68f6b56f24e5501a9ed5983c40343e8ab390c 100644 (file)
@@ -86,3 +86,9 @@ bgcolor=LightGray
 fgcolor=Black
 [CodeContext_bindings]
 toggle-code-context=
+
+[RstripExtension]
+enable=1
+enable_shell=0
+enable_editor=1
+
index e8b5e182735cf9c5a72ba779443c75f2f51e98d1..e622cb411ed6f6829a51a4088caacc597384d61d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -309,6 +309,9 @@ Library
 
 - Issue #6048: Now Distutils uses the tarfile module in archive_util.
 
+- Issue #5150: IDLE's format menu now has an option to strip trailing
+  whitespace.
+
 - Issue #6121: pydoc now ignores leading and trailing spaces in the
   argument to the 'help' function.