add preserve cursor and history function and use it for a remove whitespace function.