Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eb81695

Browse files
committed
Issue 5150: Add rstrip() menu option to IDLE.
1 parent 323ee0c commit eb81695

5 files changed

Lines changed: 47 additions & 0 deletions

File tree

Doc/whatsnew/3.1.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,14 @@ Major performance enhancements have been added:
470470

471471
(Contributed by Jake McGuire and Antoine Pitrou; :issue:`5084`.)
472472

473+
IDLE
474+
====
475+
476+
* IDLE's format menu now provides an option to strip trailing whitespace
477+
from a source file.
478+
479+
(Contributed by Roger D. Serwy; :issue:`5150`.)
480+
473481
Build and C API Changes
474482
=======================
475483

Lib/idlelib/RstripExtension.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'Provides "Strip trailing whitespace" under the "Format" menu.'
2+
3+
__author__ = "Roger D. Serwy <roger.serwy at gmail.com>"
4+
5+
class RstripExtension:
6+
7+
menudefs = [
8+
('format', [None,
9+
('Strip trailing whitespace', '<<do-rstrip>>'),
10+
]),]
11+
12+
def __init__(self, editwin):
13+
self.editwin = editwin
14+
self.editwin.text.bind("<<do-rstrip>>", self.do_rstrip)
15+
16+
def do_rstrip(self, event=None):
17+
18+
text = self.editwin.text
19+
undo = self.editwin.undo
20+
21+
undo.undo_block_start()
22+
23+
end_line = int(float(text.index('end'))) + 1
24+
for cur in range(1, end_line):
25+
txt = text.get('%i.0' % cur, '%i.0 lineend' % cur)
26+
cut = len(txt.rstrip())
27+
text.delete('%i.%i' % (cur, cut), '%i.0 lineend' % cur)
28+
29+
undo.undo_block_stop()

Lib/idlelib/config-extensions.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,9 @@ bgcolor=LightGray
8686
fgcolor=Black
8787
[CodeContext_bindings]
8888
toggle-code-context=
89+
90+
[RstripExtension]
91+
enable=1
92+
enable_shell=0
93+
enable_editor=1
94+

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ Nick Seidenman
658658
Žiga Seilnach
659659
Fred Sells
660660
Jiwon Seo
661+
Roger D, Serwy
661662
Jerry Seutter
662663
Denis Severson
663664
Ian Seyer

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ Library
262262
- Issue #5311: bdist_msi can now build packages that do not depend on a
263263
specific Python version.
264264

265+
- Issue #5150: IDLE's format menu now has an option to strip trailing
266+
whitespace.
267+
265268
- Issue #5940: distutils.command.build_clib.check_library_list was not doing
266269
the right type checkings anymore.
267270

0 commit comments

Comments
 (0)