MCPcopy Index your code
hub / github.com/python/cpython / do_rstrip

Method do_rstrip

Lib/idlelib/format.py:396–421  ·  view source on GitHub ↗
(self, event=None)

Source from the content-addressed store, hash-verified

394 self.editwin = editwin
395
396 def do_rstrip(self, event=None):
397 text = self.editwin.text
398 undo = self.editwin.undo
399 undo.undo_block_start()
400
401 end_line = int(float(text.index('end')))
402 for cur in range(1, end_line):
403 txt = text.get('%i.0' % cur, '%i.end' % cur)
404 raw = len(txt)
405 cut = len(txt.rstrip())
406 # Since text.delete() marks file as changed, even if not,
407 # only call it when needed to actually delete something.
408 if cut < raw:
409 text.delete('%i.%i' % (cur, cut), '%i.end' % cur)
410
411 if (text.get('end-2c') == '\n' # File ends with at least 1 newline;
412 and not hasattr(self.editwin, 'interp')): # & is not Shell.
413 # Delete extra user endlines.
414 while (text.index('end-1c') > '1.0' # Stop if file empty.
415 and text.get('end-3c') == '\n'):
416 text.delete('end-3c')
417 # Because tk indexes are slice indexes and never raise,
418 # a file with only newlines will be emptied.
419 # patchcheck.py does the same.
420
421 undo.undo_block_stop()
422
423
424if __name__ == "__main__":

Callers 2

test_rstrip_linesMethod · 0.80
test_rstrip_endMethod · 0.80

Calls 6

undo_block_startMethod · 0.45
indexMethod · 0.45
getMethod · 0.45
rstripMethod · 0.45
deleteMethod · 0.45
undo_block_stopMethod · 0.45

Tested by 2

test_rstrip_linesMethod · 0.64
test_rstrip_endMethod · 0.64