Skip to content

Commit 4a15c03

Browse files
committed
Add script for removing trailing whitespaces in a file.
1 parent e3b5876 commit 4a15c03

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

trim_trailing_whitespace.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)