There could be a 3rd problem, when saving/restoring buffer-local mappings. Because, between the moment when youwe saved the mappings, and the moment when youwe try to restore them, the current buffer may have changed.
And then, Restore_mappings()
would use this info to restore the buffer-local mappings in the right buffer. OneWe could probably use the :bufdo
command, prefix the latter with a count (matching the buffer number previously saved), and suffix it with the mapping command.
We would have to check first if the buffer still exists, using the bufexists()
function, because it could have been deleted in the meantime.