V6 of this patch applies, builds and checks against the current HEAD. The areas below could use some attention.
In explain.c:
malloc() should not be called directly here. palloc() would be the correct call, I believe, but the functions in stringinfo.h are probably your best choice as they remove the necessity for dealing with buffer size and overflow.
There is leftover commented out code from the previous patch version in the T_Sort case.
In show_sort_group_keys(), the splitting of the existing declaration and initialization of the keyresno and target seems unnecessary and against the style of surrounding code.
Multi-line comments should follow the existing format.
There are no tests for the "... is LC_COLLATE" and "COLLATE..." cases.
Section 14.1 of the documentation may need to be updated.
Mike.