There was an error while loading. Please reload this page.
1 parent e3b5876 commit 4a15c03Copy full SHA for 4a15c03
trim_trailing_whitespace.py
@@ -0,0 +1,22 @@
1
+import editor
2
+import re
3
+
4
5
+def main():
6
+ """Trim trailing whitespaces in each line of the currently opened document
7
+ in editor.
8
+ """
9
+ contents = editor.get_text()
10
+ # split editor content by trailing whitespaces
11
+ contents = re.split(' +\n', contents)
12
+ # join again with newlines and remove last character, because otherwise
13
+ # there would be an additional newline
14
+ contents = '\n'.join(contents)[:-1]
15
+ editor.replace_text(0, len(editor.get_text()), contents)
16
17
+ return
18
19
20
+if __name__ == '__main__':
21
+ main()
22
0 commit comments