From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#56530: 29.0.50; mouse-2 cut selected text when cua-mode is enabled Date: Fri, 15 Jul 2022 21:53:33 +0300 Organization: LINKOV.NET Message-ID: <86edym1a36.fsf@mail.linkov.net> References: <3c83c124-95a9-9dc6-a7a6-6e357c7574e4@orange.fr> <877d4hmjdh.fsf@gmail.com> <87lesxtivx.fsf@gnus.org> <87wnchl1fm.fsf@gmail.com> <86mtdcg6qr.fsf@mail.linkov.net> <87edyna9wy.fsf@gnus.org> <867d4fa9p7.fsf@mail.linkov.net> <87h73j7epu.fsf@gnus.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36882"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu) Cc: David Ponce , 56530@debbugs.gnu.org, Visuwesh To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Jul 15 20:57:18 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oCQV4-0009VF-6b for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 15 Jul 2022 20:57:18 +0200 Original-Received: from localhost ([::1]:34098 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oCQV2-0003Uv-Vo for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 15 Jul 2022 14:57:17 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40720) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oCQUp-0003T7-5C for bug-gnu-emacs@gnu.org; Fri, 15 Jul 2022 14:57:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:44387) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oCQUo-0005V7-QY for bug-gnu-emacs@gnu.org; Fri, 15 Jul 2022 14:57:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oCQUo-00040C-Gs for bug-gnu-emacs@gnu.org; Fri, 15 Jul 2022 14:57:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 15 Jul 2022 18:57:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 56530 X-GNU-PR-Package: emacs Original-Received: via spool by 56530-submit@debbugs.gnu.org id=B56530.165791140515359 (code B ref 56530); Fri, 15 Jul 2022 18:57:02 +0000 Original-Received: (at 56530) by debbugs.gnu.org; 15 Jul 2022 18:56:45 +0000 Original-Received: from localhost ([127.0.0.1]:42146 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oCQUX-0003zd-Ft for submit@debbugs.gnu.org; Fri, 15 Jul 2022 14:56:45 -0400 Original-Received: from relay11.mail.gandi.net ([217.70.178.231]:57903) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oCQUU-0003zM-GO for 56530@debbugs.gnu.org; Fri, 15 Jul 2022 14:56:44 -0400 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id 15855100004; Fri, 15 Jul 2022 18:56:31 +0000 (UTC) In-Reply-To: <87h73j7epu.fsf@gnus.org> (Lars Ingebrigtsen's message of "Thu, 14 Jul 2022 20:04:45 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:237124 Archived-At: --=-=-= Content-Type: text/plain >> There is already the minor mode: delete-selection-mode >> that is configured by symbol properties. >> Supporting a descriptive symbol name would allow to easily >> configure the desired behavior with just: >> >> (put 'mouse-yank-at-click 'delete-selection 'yank-on-region) > > The problem is that you have to `put' on three symbols, which isn't > optimal. (My proposed mode does just that.) The default settings should be suitable for all users, but modes for groups of settings could be added too. This patch works well but only like Visuwesh pointed out when mouse-yank-at-point is set to t. This is because mouse-yank-primary has such line: (or mouse-yank-at-point (mouse-set-point event)) When delete-selection deletes the region where the mouse is clicked, mouse-set-point loses track and sets point to a random position, because the event contains fixed positions, not markers. I wonder why? --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=yank-on-region.patch diff --git a/lisp/delsel.el b/lisp/delsel.el index 5310328e5f..d9e0141d90 100644 --- a/lisp/delsel.el +++ b/lisp/delsel.el @@ -39,6 +39,8 @@ ;; For commands which do a yank; ensures the region about to be ;; deleted isn't immediately yanked back, which would make the ;; command a no-op. +;; `yank-on-region' +;; Like `yank' but applied only when clicked on the region. ;; `supersede' ;; Delete the active region and ignore the current command, ;; i.e. the command will just delete the region. This is for @@ -176,6 +178,8 @@ delete-selection-helper For commands which do a yank; ensures the region about to be deleted isn't immediately yanked back, which would make the command a no-op. + `yank-on-region' + Like `yank' but applied only when clicked on the region. `supersede' Delete the active region and ignore the current command, i.e. the command will just delete the region. This is for @@ -220,6 +224,11 @@ delete-selection-helper ;; If the region was, say, rectangular, make sure we yank ;; from the top, to "replace". (goto-char pos))) + ((eq type 'yank-on-region) + (let ((pos (posn-point (event-end last-nonmenu-event)))) + (when (and (>= pos (region-beginning)) + (<= pos (region-end))) + (delete-selection-helper 'yank)))) ((eq type 'supersede) (let ((empty-region (= (point) (mark)))) (delete-active-region) @@ -300,6 +309,12 @@ 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-on-region) +(put 'mouse-yank-secondary 'delete-selection 'yank-on-region) +(put 'mouse-yank-at-click 'delete-selection 'yank-on-region) +(put 'menu-bar-select-yank 'delete-selection 'yank-on-region) + (put 'insert-register 'delete-selection t) ;; delete-backward-char and delete-forward-char already delete the selection by ;; default, but not delete-char. --=-=-=--