Skip to content

Instantly share code, notes, and snippets.

@magnars
Created January 30, 2012 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magnars/1705973 to your computer and use it in GitHub Desktop.
Save magnars/1705973 to your computer and use it in GitHub Desktop.
push-mark not behaving as expected
(defun mark-five-next ()
"Marks the next five chars as expected"
(interactive)
(push-mark (+ 5 (point)) t t))
(defun delete-region-then-mark-five-next (start end)
"Does not mark the next five chars"
(interactive "r")
(delete-region start end)
(push-mark (+ 5 (point)) t t))
@magnars
Copy link
Author

magnars commented Jan 30, 2012

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment