Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2..../idlelib
File: RstripExtension.py
'Provides "Strip trailing whitespace" under the "Format" menu.'
[0] Fix | Delete
[1] Fix | Delete
class RstripExtension:
[2] Fix | Delete
[3] Fix | Delete
menudefs = [
[4] Fix | Delete
('format', [None, ('Strip trailing whitespace', '<<do-rstrip>>'), ] ), ]
[5] Fix | Delete
[6] Fix | Delete
def __init__(self, editwin):
[7] Fix | Delete
self.editwin = editwin
[8] Fix | Delete
self.editwin.text.bind("<<do-rstrip>>", self.do_rstrip)
[9] Fix | Delete
[10] Fix | Delete
def do_rstrip(self, event=None):
[11] Fix | Delete
[12] Fix | Delete
text = self.editwin.text
[13] Fix | Delete
undo = self.editwin.undo
[14] Fix | Delete
[15] Fix | Delete
undo.undo_block_start()
[16] Fix | Delete
[17] Fix | Delete
end_line = int(float(text.index('end')))
[18] Fix | Delete
for cur in range(1, end_line):
[19] Fix | Delete
txt = text.get('%i.0' % cur, '%i.end' % cur)
[20] Fix | Delete
raw = len(txt)
[21] Fix | Delete
cut = len(txt.rstrip())
[22] Fix | Delete
# Since text.delete() marks file as changed, even if not,
[23] Fix | Delete
# only call it when needed to actually delete something.
[24] Fix | Delete
if cut < raw:
[25] Fix | Delete
text.delete('%i.%i' % (cur, cut), '%i.end' % cur)
[26] Fix | Delete
[27] Fix | Delete
undo.undo_block_stop()
[28] Fix | Delete
[29] Fix | Delete
if __name__ == "__main__":
[30] Fix | Delete
import unittest
[31] Fix | Delete
unittest.main('idlelib.idle_test.test_rstrip', verbosity=2, exit=False)
[32] Fix | Delete
[33] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function