complete rewrite of insert_at_cursor()

It now writes the characters into the file buffer immediately after
reading them. This will make some things much easier in the future,
though it's less efficient than reading into a temporary buffer first.