It seems like altering the buffer in any way, stops the defun from activating mark:
(defun mark-five-next ()
"Marks the next five chars as expected"
(interactive)
(push-mark (+ 5 (point)) t t))
(defun insert-an-a-then-mark-five-next ()
"Does not mark the next five chars"
(interactive)
(insert "a")
(push-mark (+ 5 (point)) t t))
I’d prefer a way to fix it, but just an explanation is good too.
It turns out that all editing commands set the var
deactivate-markwhich does just that after the command has finished.To avoid this behavior, you have to wrap the buffer-altering functions in a
let-statement, preventing the change of the globaldeactivate-markvar.I spent more than an hour on this problem, because I just skipped over deactivate-mark in the manual, thinking it was a description of the function. Of course, as I already knew, but have now properly learned: emacs lisp has a different namespace for functions and variables.