move mode expansion logic into single function

plus a couple bug fixes to expansion and invis char counting logic
need to set actual prompt string
save orig prompt and always use it when expanding
save orig prompt and update primary with expanded

copy orig prompt to _rl_orig_prompt
replace rl_prompt with expanded prompt if they're different

doesn't support multiline terms yet