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

From: Lars Ingebrigtsen <[email-masked]>
Date: Wed, 11 Aug 2021 14:19:43 +0200

Peter Münster <[email-masked]> writes:

> It seems, that save-mark-and-excursion does not restore the mark state.
>
> Here is a test function:
>
> (defun my-test-func ()
>   "Test if save-mark-and-excursion is working."
>   (interactive)
>   (with-current-buffer "test-buf"
>     (save-mark-and-excursion
>       (goto-char (point-min))
>       (add-face-text-property
>        (point) (1+ (point)) (list :background "orange")))))
>
> Test case:
> - "emacs -Q"
> - evaluate my-test-func
> - open a new buffer "test-buf"
> - type some characters
> - mark a region somewhere
> - M-x my-test-func
>
> Result: point is restored, but mark-active is nil.

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?

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