# 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/^/+/ }