Subject: [PATCH] Make mouse-2 respect delete-selection mode

From: Visuwesh <[email-masked]>
Date: Wed, 06 Jul 2022 20:28:48 +0530

Tags: patch

Yanking with the mouse (i.e., mouse-2) does not replace the selected
region if delete-selection-mode is turned on.  Attached patch makes the
mouse yank commands delete-selection-mode aware.

>From 699b0b80648cb4b3d926937bf259442ccc1612a5 Mon Sep 17 00:00:00 2001
From: Visuwesh <[email-masked]>
Date: Wed, 6 Jul 2022 20:27:16 +0530
Subject: [PATCH] Make mouse-2 respect delete-selection mode

* lisp/delsel.el: Make the mouse yank commands delete-selection-mode
aware.
---
 lisp/delsel.el | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lisp/delsel.el b/lisp/delsel.el
index 5310328e5f..723a52b17d 100644
--- a/lisp/delsel.el
+++ b/lisp/delsel.el
@@ -300,6 +300,9 @@ delete-selection-uses-region-p
 (put 'yank-pop 'delete-selection 'yank)
 (put 'yank-from-kill-ring 'delete-selection 'yank)
 (put 'clipboard-yank 'delete-selection 'yank)
+(put 'mouse-yank-primary 'delete-selection 'yank)
+(put 'mouse-yank-secondary 'delete-selection 'yank)
+(put 'mouse-yank-at-click 'delete-selection 'yank)
 (put 'insert-register 'delete-selection t)
 ;; delete-backward-char and delete-forward-char already delete the selection by
 ;; default, but not delete-char.
--
2.35.1

In GNU Emacs 29.0.50 (build 3, x86_64-pc-linux-gnu, X toolkit, Xaw scroll bars)
 of 2022-07-03 built on astatine
Repository revision: c4930e938b6f9f21b4a9c37912d2b6ce4796b9a2
Repository branch: tamil-phonetic2
Windowing system distributor 'The X.Org Foundation', version 11.0.12101003
System Description: Debian GNU/Linux 11 (bullseye)

Configured using:
 'configure --with-modules --with-sound=alsa --with-x-toolkit=lucid
 --with-json --without-xaw3d --without-gconf --without-libsystemd
 --with-x --without-cairo'