Improve =mode_name and add a test for it.

It's convenient to let modes fail, in which case we should pop out of
them if they didn't pop out themselves. It might be worth thinking about
ways to keep the mental model easy for popping out of modes.