It turns out that all editing commands set var deactivate-mark , which does this only after the command completes.
To avoid this behavior, you should wrap the buffer change functions in let -statement, preventing the global deactivate-mark var from changing.
(let (deactivate-mark) (...))
I spent more than an hour on this problem, because I just skipped the deactivate-mark in the manual, believing that this is a description of the function. Of course, as I already knew, but now I understand correctly: emacs lisp has a different namespace for functions and variables.
source share