Fix bug with mispositioned cursor

The call to setline at the end of the update_vars look can shift the
cursor if the cursor would be positioned past the end of the line. This
messes up the cursor repositioning, so we store the cursor column before
any call to setline.