Implement priority based clearsnippets.

Implement priority-based clearsnippets and add corresponding test cases (#335).
It will be rewritten in the following CLs.  Tell me if it is still not understandable.