Rewrite nano functions, move more code to nano.py

Beginnings of a rewrite of the old nanoWhatever functions to make the
code cleaner and more easily understood. The new functions are not yet
actually used anywhere, but they are starting to exist.
Almost all remaining nano code is now moved to nano.py, and kalpana.py3
and terminal.py should only get to call the functions directly  without
fiddling about with nano variables and stuff.