Ignore empty parts when calculating cursor part.

Fixes #389.
Don't filter completion parts if there's only one.

This fixes a regression (completion not showing with :) introduced in
b1501a691db43b99bf10c78bf1c85507904d4caa.
Rewrite keymode handling to use only one mode.

Fixes #417.
Fixes #418.
See 4ab5d2df28f7f999882034442d3a8f1b1dce0fce.