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

This commit is contained in:
Raymond Hettinger 2009-05-29 01:36:26 +00:00
parent 8de212bd4f
commit b4d2d31874
3 changed files with 38 additions and 0 deletions

View file

@ -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()

View file

@ -86,3 +86,9 @@ bgcolor=LightGray
fgcolor=Black fgcolor=Black
[CodeContext_bindings] [CodeContext_bindings]
toggle-code-context= toggle-code-context=
[RstripExtension]
enable=1
enable_shell=0
enable_editor=1

View file

@ -309,6 +309,9 @@ Library
- Issue #6048: Now Distutils uses the tarfile module in archive_util. - 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 - Issue #6121: pydoc now ignores leading and trailing spaces in the
argument to the 'help' function. argument to the 'help' function.