]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue 5150: Add rstrip() menu option to IDLE.
authorRaymond Hettinger <python@rcn.com>
Fri, 29 May 2009 01:22:18 +0000 (01:22 +0000)
committerRaymond Hettinger <python@rcn.com>
Fri, 29 May 2009 01:22:18 +0000 (01:22 +0000)
Doc/whatsnew/3.1.rst
Lib/idlelib/RstripExtension.py [new file with mode: 0644]
Lib/idlelib/config-extensions.def
Misc/ACKS
Misc/NEWS

index ace8c3ff92f7f6611c96e52a05d709183f20aba1..c34a91c7153317fbe7c03587ccc9ed307955dbb1 100644 (file)
@@ -470,6 +470,14 @@ Major performance enhancements have been added:
 
   (Contributed by Jake McGuire and Antoine Pitrou; :issue:`5084`.)
 
+IDLE
+====
+
+* IDLE's format menu now provides an option to strip trailing whitespace
+  from a source file.
+
+  (Contributed by Roger D. Serwy; :issue:`5150`.)
+
 Build and C API Changes
 =======================
 
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 e6b9469bda815d475e4f12bd7eedcf830beea578..4813083249010b82459c56069f173478e01406d8 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -658,6 +658,7 @@ Nick Seidenman
 Žiga Seilnach
 Fred Sells
 Jiwon Seo
+Roger D, Serwy
 Jerry Seutter
 Denis Severson
 Ian Seyer
index 12dfbac99a1c8d98e51f8544de65308ac38cb9a9..7d3a2370328633733c723cf3dc29d3ead2e97e8c 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -262,6 +262,9 @@ Library
 - Issue #5311: bdist_msi can now build packages that do not depend on a
   specific Python version.
 
+- Issue #5150: IDLE's format menu now has an option to strip trailing
+  whitespace.
+
 - Issue #5940: distutils.command.build_clib.check_library_list was not doing 
   the right type checkings anymore.