summaryrefslogtreecommitdiff
path: root/cleanup-whitespace.sed
blob: cfbf0037b69705fdea24ffb75f186e20b7d81792 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# only modify new lines
/^+/ {

# remove diff-style + line prefix
s/^+//

# remove trailing whitespace
s/[[:space:]]*$//

# replace 8 spaces at the beginning of a line with a single tab
s/^        /	/

# remove 1-7 spaces at the beginning of a line if they are followed by
# a tab (which would hide them in the resulting layout)
s/^ \{1,7\}	/	/

:spacestotab
# replace 8 tab-aligned spaces with a single tab
s/	        /		/
t spacestotab

:removespaces
# remove 1-7 tab-aligned spaces if they are followed by a tab (which
# would hide them in the resulting layout)
s/	 \{1,7\}	/		/
t removespaces

:tabtospaces
# replace non-leading tabs with spaces (except for trailing tabs in
# macros) to make reindentation easier
s/^\(	*\([^	]\{8\}\)*[^	]\{8\}\)	\(.*[^\\]\)$/\1        \3/
s/^\(	*\([^	]\{8\}\)*[^	]\{1\}\)	\(.*[^\\]\)$/\1       \3/
s/^\(	*\([^	]\{8\}\)*[^	]\{2\}\)	\(.*[^\\]\)$/\1      \3/
s/^\(	*\([^	]\{8\}\)*[^	]\{3\}\)	\(.*[^\\]\)$/\1     \3/
s/^\(	*\([^	]\{8\}\)*[^	]\{4\}\)	\(.*[^\\]\)$/\1    \3/
s/^\(	*\([^	]\{8\}\)*[^	]\{5\}\)	\(.*[^\\]\)$/\1   \3/
s/^\(	*\([^	]\{8\}\)*[^	]\{6\}\)	\(.*[^\\]\)$/\1  \3/
s/^\(	*\([^	]\{8\}\)*[^	]\{7\}\)	\(.*[^\\]\)$/\1 \3/

s/^\(	*\([^	]\{8\}\)*[^	]\{8\}\)	\(.*[^	].*\\\)$/\1        \3/
s/^\(	*\([^	]\{8\}\)*[^	]\{1\}\)	\(.*[^	].*\\\)$/\1       \3/
s/^\(	*\([^	]\{8\}\)*[^	]\{2\}\)	\(.*[^	].*\\\)$/\1      \3/
s/^\(	*\([^	]\{8\}\)*[^	]\{3\}\)	\(.*[^	].*\\\)$/\1     \3/
s/^\(	*\([^	]\{8\}\)*[^	]\{4\}\)	\(.*[^	].*\\\)$/\1    \3/
s/^\(	*\([^	]\{8\}\)*[^	]\{5\}\)	\(.*[^	].*\\\)$/\1   \3/
s/^\(	*\([^	]\{8\}\)*[^	]\{6\}\)	\(.*[^	].*\\\)$/\1  \3/
s/^\(	*\([^	]\{8\}\)*[^	]\{7\}\)	\(.*[^	].*\\\)$/\1 \3/

t tabtospaces

# restore diff-style + line prefix
s/^/+/
}