I attached a patch which adds support for completion boundaries to the sorting by history position. Tests are included. Daniel