mirror of
https://github.com/python/cpython.git
synced 2025-08-02 08:02:56 +00:00

About 10 IDLE features were implemented as supposedly optional extensions. Their different behavior could be confusing or worse for users and not good for maintenance. Hence the conversion. The main difference for users is that user configurable key bindings for builtin features are now handled uniformly. Now, editing a binding in a keyset only affects its value in the keyset. All bindings are defined together in the system-specific default keysets in config- extensions.def. All custom keysets are saved as a whole in config- extension.cfg. All take effect as soon as one clicks Apply or Ok. The affected events are '<<force-open-completions>>', '<<expand-word>>', '<<force-open-calltip>>', '<<flash-paren>>', '<<format-paragraph>>', '<<run-module>>', '<<check-module>>', and '<<zoom-height>>'. Any (global) customizations made before 3.6.3 will not affect their keyset- specific customization after 3.6.3. and vice versa. Inital patch by Charles Wohlganger, revised by Terry Jan Reedy.
29 lines
887 B
Python
29 lines
887 B
Python
'Provides "Strip trailing whitespace" under the "Format" menu.'
|
|
|
|
class RstripExtension:
|
|
|
|
def __init__(self, editwin):
|
|
self.editwin = editwin
|
|
|
|
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')))
|
|
for cur in range(1, end_line):
|
|
txt = text.get('%i.0' % cur, '%i.end' % cur)
|
|
raw = len(txt)
|
|
cut = len(txt.rstrip())
|
|
# Since text.delete() marks file as changed, even if not,
|
|
# only call it when needed to actually delete something.
|
|
if cut < raw:
|
|
text.delete('%i.%i' % (cur, cut), '%i.end' % cur)
|
|
|
|
undo.undo_block_stop()
|
|
|
|
if __name__ == "__main__":
|
|
import unittest
|
|
unittest.main('idlelib.idle_test.test_rstrip', verbosity=2, exit=False)
|