Commits

Anonymous committed 618e46a

Issue 5150: Add rstrip() menu option to IDLE.

  • Participants
  • Parent commits a0a25de

Comments (0)

Files changed (5)

Doc/whatsnew/3.1.rst

 
   (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
 =======================
 

Lib/idlelib/RstripExtension.py

+'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()

Lib/idlelib/config-extensions.def

 fgcolor=Black
 [CodeContext_bindings]
 toggle-code-context=
+
+[RstripExtension]
+enable=1
+enable_shell=0
+enable_editor=1
+
 Žiga Seilnach
 Fred Sells
 Jiwon Seo
+Roger D, Serwy
 Jerry Seutter
 Denis Severson
 Ian Seyer
 - 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.