blob: 19e35d4d4815233709f38b53eb056e5b8ee5b033 [file] [log] [blame]
Raymond Hettingereb816952009-05-29 01:22:18 +00001'Provides "Strip trailing whitespace" under the "Format" menu.'
2
3__author__ = "Roger D. Serwy <roger.serwy at gmail.com>"
4
5class 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()