| 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 | |
| 424 | if __name__ == "__main__": |