Subject: Re: bug#50067: Context menus

From: Juri Linkov <[email-masked]>
Date: Tue, 31 Aug 2021 20:37:54 +0300

>>>> On paste when there is a region and delete-selection-mode is t, the
>>>> region should be replaced by the text.
>>>
>>> Please explain how the region should be replaced by the text,
>>> when mouse-yank-at-click or mouse-yank-primary is used
>>> to paste where the mouse is clicked.  Should it delete the region
>>> and paste where mouse is clicked on another part of the buffer?
>>> What if the mouse is clicked in another window?
>>
>> When there is a region and yank text by `C-y’, the text would
>> be replaced.
>>
>> I think when there is a region and point in on region, region
>> should be replaced by text.  No?
>
> mouse-yank-at-click is intended to paste where you click.
> So when there is a region, and you click mouse-3 at some other position
> where you want to paste, and select "Paste" from the context-menu,
> it's unclear what to do with the region.  It makes no sense
> to delete the region, when you paste at the clicked position
> outside of the region, but not on the region.
>
> Please see more in mouse-yank-at-click and mouse-yank-primary
> that contain such comment about the need to deactivate the region:
>
>   ;; Without this, confusing things happen upon e.g. inserting into
>   ;; the middle of an active region.
>   (when select-active-regions
>     (let (select-active-regions)
>       (deactivate-mark)))

But maybe still it should delete the region before yanking?
I suggest to try these settings:

  (put 'mouse-yank-primary 'delete-selection 'yank)
  (put 'mouse-yank-at-click 'delete-selection 'yank)
  (put 'menu-bar-select-yank 'delete-selection 'yank)

Then maybe they should be added to delsel.el.