Subject: bug#49999: 27.2; save-mark-and-excursion does not save mark-active

From: Lars Ingebrigtsen <[email-masked]>
Date: Wed, 11 Aug 2021 17:46:57 +0200

Lars Ingebrigtsen <[email-masked]> writes:

> I can reproduce this, but I'm not quite sure what's going on.  I tweaked
> your function:
>
> (defun my-test-func ()
>   "Test if save-mark-and-excursion is working."
>   (interactive)
>   (save-mark-and-excursion
>     (goto-char (point-min))
>     (add-face-text-property
>      (point) (1+ (point)) (list :background "orange")))
>   (message "%s" mark-active))
>
> This messages t -- but evaling mark-active afterwards shows that it's
> nil.  So something is deactivating the mark after the command has run,
> apparently?  Hm...  this sounds vaguely familiar to me...  Anybody know
> what could be going on here?

Oh, right -- it's transient mark mode that does this stuff?  That is, if
you run a command that inserts something in the buffer, then it'll
switch the region off?

So `save-mark-and-excursion' works exactly as it should.  But if you
don't want transient-mark-mode to switch itself off, you have to say
something like:

(defun my-test-func ()
  "Test if save-mark-and-excursion is working."
  (interactive)
  (save-mark-and-excursion
    (goto-char (point-min))
    (with-silent-modifications
      (add-face-text-property
       (point) (1+ (point)) (list :background "orange")))))

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no