summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2009-05-29 01:22:18 (GMT)
committerRaymond Hettinger <python@rcn.com>2009-05-29 01:22:18 (GMT)
commiteb816954fb5795e10669edb4db29cf12f6b32ab0 (patch)
treea8b3b6a0bea08524140bd01d9951e9e8438d1c2c
parent323ee0cc21e360b105e34c07b80ec670703ee213 (diff)
downloadcpython-eb816954fb5795e10669edb4db29cf12f6b32ab0.zip
cpython-eb816954fb5795e10669edb4db29cf12f6b32ab0.tar.gz
cpython-eb816954fb5795e10669edb4db29cf12f6b32ab0.tar.bz2
Issue 5150: Add rstrip() menu option to IDLE.
-rw-r--r--Doc/whatsnew/3.1.rst8
-rw-r--r--Lib/idlelib/RstripExtension.py29
-rw-r--r--Lib/idlelib/config-extensions.def6
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS3
5 files changed, 47 insertions, 0 deletions
diff --git a/Doc/whatsnew/3.1.rst b/Doc/whatsnew/3.1.rst
index ace8c3f..c34a91c 100644
--- a/Doc/whatsnew/3.1.rst
+++ b/Doc/whatsnew/3.1.rst
@@ -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
index 0000000..19e35d4
--- /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 2d5cf68..78b68f6 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
+
diff --git a/Misc/ACKS b/Misc/ACKS
index e6b9469..4813083 100644
--- 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
diff --git a/Misc/NEWS b/Misc/NEWS
index 12dfbac..7d3a237 100644
--- 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.