Subject: Re: bug#35177: 27.0.50; Binding deactivate-mark to nil unexpectedly deactivates the mark

From: Markus Triska <[email-masked]>
Date: Mon, 08 Apr 2019 12:03:11 +0200

Eli Zaretskii <[email-masked]> writes:

> None of your additional test cases do what I said I thought you should
> do, though, do they?

In emacs -Q, please evaluate the following form with C-x C-e:

    (let (deactivate-mark)
      (switch-to-buffer (get-buffer-create "t"))
      (insert "hello")
      (set-mark-command nil)
      (move-beginning-of-line nil))

This does what you say. However, the mark is deactivated after the form
is executed, which is the opposite of what I expect from this snippet.

> I don't think it's something in your code that deactivates the mark,
> it's what Emacs does internally when a command finishes.

I noticed that the mark stays activate (as expected), when I add a
"redisplay" after switch-to-buffer:

    (let (deactivate-mark)
      (switch-to-buffer (get-buffer-create "t"))
      (redisplay)
      (insert "hello")
      (set-mark-command nil)
      (move-beginning-of-line nil))

After I evaluate this, the first form also consistently retains the
active mark when I evaluate it. It is expected that the mark stays
active, but it is unexpected that it does so after I evaluate the second
form, yet is deactivated if I only evaluate the first form.

Please also note that the documentation of deactivate-mark states
"around the code that does the modification". If other preconditions are
necessary to consistently retain the active mark, could you please
document them? Thank you.