Provide a distance-based sorting of identifiers

Connected with issue #180. Sort near cursor candidates basing on their
distance and frequency in the cursor's neighborhood.