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-mark
which 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 global deactivate-mark
var.
(let (deactivate-mark)
(...))
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With