an attempt to generalize and improve `magit-key-mode'