# replace tags with number (for sorting) and shortcut
s,	kMandarin,	1 M,
s,	kCantonese,	2 C,
s,	kJapaneseKun,	3 J,
s,	kJapaneseOn,	4 S,
s,	kKorean,	5 K,
s,	kVietnamese,	6 V,
s,	kDefinition,	9 D,
t cont
d

: cont
# format code value to uniform length for subsequent sorting
s,U+\(....\)	,U+0\1	,

# fix missing space around parentheses
s,\([^	 (]\)(\([^)]* [^)]* \),\1 (\2,g
s,)\([^ ]\),) \1,g
# fix incorrect ((
s,((\([^)]*)[^)]*\)$,(\1,
# fix superfluous blanks before , or ;
s/ ,/,/g
s/ ;/;/g
