A simple macroscript to delete all unused materials from the Compact Editor Material Slots AND the Slate Material Editor Views.
The Compact Editor Code is from the existing Macro found under the Compact Material Editor "Utilities" menu.
I have added the code to also purge the SME at the same time.
You might want to check out the "Purge Empty Layers" macroscript as well. There are some awesome scene management tools out there but these are both small, simple tools without a lot of overhead for doing a little housekeeping before saving your file.