Subject: Re: bug#56662: 29.0.50; Funny region highlights when highlight-nonselected-windows is t

From: Eli Zaretskii <[email-masked]>
Date: Sun, 24 Jul 2022 20:32:11 +0300

> From: Juri Linkov <[email-masked]>
> Cc: Visuwesh <[email-masked]>,  Eli Zaretskii <[email-masked]>,
>   [email-masked]
> Date: Sun, 24 Jul 2022 19:41:20 +0300
> 
> It's very easy to make region highlighting window-local with just
> 
> diff --git a/lisp/simple.el b/lisp/simple.el
> index 5443d961e1..04002073bd 100644
> --- a/lisp/simple.el
> +++ b/lisp/simple.el
> @@ -6944,7 +6944,7 @@ redisplay--update-region-highlight
>                             (eq window (minibuffer-selected-window))))))
>          (funcall redisplay-unhighlight-region-function rol)
>        (let* ((pt (window-point window))
> -             (mark (mark))
> +             (mark (or (window-parameter window 'mark) (mark)))
>               (start (min pt mark))
>               (end   (max pt mark))
>               (new
> 
> Then the main task would be to find the right logic of setting
> the window-local mark.  Since this feature request is closed,
> here is a possible starting point for anyone who wants to experiment
> with the prototype trying different use cases:
> 
>   (add-hook 'activate-mark-hook
>             (lambda () (set-window-parameter nil 'mark (mark))))
>   (add-hook 'deactivate-mark-hook
>             (lambda () (set-window-parameter nil 'mark nil)))
>   (add-hook 'window-selection-change-functions
>             (lambda (window)
>               (when (eq window (selected-window))
>                 (set-marker (mark-marker) (window-parameter window 'mark)))))
> 

Don't forget that this must only happen if
highlight-nonselected-windows is non-nil.