From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Visuwesh Newsgroups: gmane.emacs.bugs Subject: bug#55692: 29.0.50; delete-selection-mode: Replace region only if set using the mouse Date: Sun, 29 May 2022 20:23:49 +0530 Message-ID: <87mtf075ky.fsf@gmail.com> References: <87zgj1v9xc.fsf@gmail.com> <83ilpplbhr.fsf@gnu.org> <8735gs9819.fsf@gmail.com> <837d64ltka.fsf@gnu.org> <87y1yk7o9f.fsf@gmail.com> <831qwclnf0.fsf@gnu.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="15242"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: 55692@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun May 29 16:55:11 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 1nvKJy-0003nm-Gb for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 29 May 2022 16:55:10 +0200 Original-Received: from localhost ([::1]:41178 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nvKJx-00034W-8Z for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 29 May 2022 10:55:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53538) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nvKJq-00034C-2N for bug-gnu-emacs@gnu.org; Sun, 29 May 2022 10:55:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:47704) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nvKJp-0004j8-PS for bug-gnu-emacs@gnu.org; Sun, 29 May 2022 10:55:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nvKJp-0003xN-Mu for bug-gnu-emacs@gnu.org; Sun, 29 May 2022 10:55:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Visuwesh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 29 May 2022 14:55:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 55692 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 55692-submit@debbugs.gnu.org id=B55692.165383604215133 (code B ref 55692); Sun, 29 May 2022 14:55:01 +0000 Original-Received: (at 55692) by debbugs.gnu.org; 29 May 2022 14:54:02 +0000 Original-Received: from localhost ([127.0.0.1]:41601 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nvKIr-0003w1-Ug for submit@debbugs.gnu.org; Sun, 29 May 2022 10:54:02 -0400 Original-Received: from mail-pl1-f196.google.com ([209.85.214.196]:34679) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nvKIp-0003vV-RA for 55692@debbugs.gnu.org; Sun, 29 May 2022 10:54:00 -0400 Original-Received: by mail-pl1-f196.google.com with SMTP id n8so8207120plh.1 for <55692@debbugs.gnu.org>; Sun, 29 May 2022 07:53:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=R4nSRcW4zwZAdH5OLfsn9BY7nzgRHvqdFoE8tKbj/MQ=; b=cNuc3t1JOK+rco7TuhGuQStR2+Juq6bVczozW/ZuGLQFZnH2TtfxBCTQ6P9LRn0kWN Lxtj0SqizGrzeujsA2TWo0MawU6YyF58JyRNhLxWd8wlENPcYSxYuScyxmis9l9NlXbY yKU/l/pFZhmiRPHCZNKOOysPWlgpg6qy4BmGBPF4IlRpTjs2GcvSxtXBDJN2OqgmRgZH 3SuQH9DNa9R1CGuLh/2yezDCf79l1HQG3waOtUFokKTlsDmRZQfi2NKXFy1WWamE5UcF G+ZgFvH3SqkALqDeSCwWnFyKILWseGKXKFVyPDJNc6CvdO2gC5B91+8vXxMA2lY8jo3S pzoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=R4nSRcW4zwZAdH5OLfsn9BY7nzgRHvqdFoE8tKbj/MQ=; b=oFzBCMxqesdOmmJ8RMTQD+LT5tBg2sx+LAu3q3F20DJkcbhWoZL/QfqGvyEZWIm9VY qsVI7Zq9nFTaYHI0gDsySerbfcKiau1LffThrChiHyWtuK22lCbUqZuTQ0l6nthb9ZPB qC02mBpF9sTQT7xR0f96roZmTCPoHnk8vEvWd9cXBdF6MDpcCzCTnb9f2yXpNFMjUCLV zEXasn239xgSzPjKNPAU8MDjBmjzh8TKql1L3El+gtl5+RQe++S5fHwFoYwZ9IDC1Dx/ 0pX4ZUJ9mR0GwYgG1S+DdI/VkwCKLYz/BgiWIyG0PgjtHVjD9Z8i89JzDy74El8zgubH tn+A== X-Gm-Message-State: AOAM533Hc6N/+xy5h9Rg/UIqdthRuraYYd/MuC+EPXgP/AFCzC0k5PdH HN55F3c+5MvMo/0yGxU5tEk= X-Google-Smtp-Source: ABdhPJygtf1wl4lMQFHqbegvsKzuY4h4JbV3vS3xNUMbQ9WkmRfwKEj+1dfalU7QbuEsNQavgGXThQ== X-Received: by 2002:a17:902:9349:b0:158:a6f7:e280 with SMTP id g9-20020a170902934900b00158a6f7e280mr51978994plp.155.1653836033767; Sun, 29 May 2022 07:53:53 -0700 (PDT) Original-Received: from localhost ([49.205.87.32]) by smtp.gmail.com with ESMTPSA id hg22-20020a17090b301600b001d97fc5a544sm4939109pjb.2.2022.05.29.07.53.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 May 2022 07:53:52 -0700 (PDT) In-Reply-To: <831qwclnf0.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 29 May 2022 12:04:51 +0300") 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:233325 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable [=E0=AE=9E=E0=AE=BE=E0=AE=AF=E0=AE=BF=E0=AE=B1=E0=AF=81 =E0=AE=AE=E0=AF=87 = 29, 2022] Eli Zaretskii wrote: >> From: Visuwesh >> Cc: 55692@debbugs.gnu.org >> Date: Sun, 29 May 2022 13:40:20 +0530 >>=20 >> >> By default, text insertion occurs normally even if the mark is >> >> active---for example, typing @kbd{a} inserts the character @samp{a}, >> >> then deactivates the mark. Delete Selection mode, a minor mode, >> >> modifies this behavior: if you enable that mode, then inserting text >> >> while the mark is active causes the text in the region to be deleted >> >> -first. To toggle Delete Selection mode on or off, type @kbd{M-x >> >> -delete-selection-mode}. >> >> +first. If you want to replace only temporary regions, set by >> >> +mouse-dragging or shift-selection, then change the variable >> > >> > There should be cross-references here to where these methods are >> > described in the manual. >> > >>=20 >> These methods as in "mouse-dragging" or "shift-selection". I'm afraid I >> don't fully understand what you mean. > > I mean to add @xref or @pxref to the places in the manual where mouse > selection and shift-selection are described. Those places are, > respectively, the nodes "Setting Mark" and "Shift Selection". > Done. >> >> @@ -251,6 +259,10 @@ delete-selection-pre-hook >> >> have this property won't delete the selection. >> >> See `delete-selection-helper'." >> >> (when (and delete-selection-mode (use-region-p) >> >> + (if delete-selection-temporary-regions-only >> >> + (and (consp transient-mark-mode) >> >> + (eq (car transient-mark-mode) 'only)) >> >> + t) >> > >> > I wonder whether we should also optionally allow replacing text in >> > regions activated by "C-u C-x C-x" when transient-mark-mode is off. >> > Those cause transient-mark-mode to have the value 'lambda', not >> > '(only...)'. So maybe the new defcustom should be a tristate, not a >> > boolean? >> > >>=20 >> Sure, that could be useful. But I have transient-mark-mode turned on >> always so I can't comment much on it. However, what would the third >> state be? > > Some symbol. > >> When the defcustom is t, we could have it check for '(only . ...)' >> and the value 'lambda', no? > > Yes, we could have: > > . nil - always replace the region > . t - replace region from mouse, shift-selection, and "C-u C-x C-x" > . selection - only replace region from mouse and shift-selection > Done. >> > Also, can we have the above condition in a more elegant form? In >> > general, whenever you have something like >> > >> > (if SOMETHING foo t) >> > >> > it begs to be rewritten so the "t" part is not needed, because 'if' >> > itself already returns a boolean value. >>=20 >> Sure. I will factor out the condition into a separate function. Is >> that more elegant? > > No, that's overkill. I meant that if you need an 'if' to return t or > something else, you could instead make it return nil or something > else, as in > > (if SOMETHING foo) > > and reverse the condition. > > But if you still don't understand, just forget this comment. I don't think I fully understood what you meant but I took a shot at it anyway. Please review updated patch. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-delete-selection-mode-Add-user-option-to-delete-temp.patch >From 4649ff74c384fa22edb19234928df6322efd6099 Mon Sep 17 00:00:00 2001 From: Visuwesh Date: Sun, 29 May 2022 11:45:19 +0530 Subject: [PATCH] delete-selection-mode: Add user option to delete temporary regions only * lisp/delsel.el (delete-selection-temporary-region): Add new user option. (delete-selection-pre-hook): Respect it. * doc/emacs/mark.texi (Using Region): Document the new user option. * etc/NEWS: Announce the new user option. (bug#55692) --- doc/emacs/mark.texi | 11 +++++++++-- etc/NEWS | 5 +++++ lisp/delsel.el | 18 ++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/doc/emacs/mark.texi b/doc/emacs/mark.texi index 91c44d527b..397f941b2d 100644 --- a/doc/emacs/mark.texi +++ b/doc/emacs/mark.texi @@ -291,13 +291,20 @@ Using Region @cindex Delete Selection mode @cindex mode, Delete Selection @findex delete-selection-mode +@vindex delete-selection-temporary-region By default, text insertion occurs normally even if the mark is active---for example, typing @kbd{a} inserts the character @samp{a}, then deactivates the mark. Delete Selection mode, a minor mode, modifies this behavior: if you enable that mode, then inserting text while the mark is active causes the text in the region to be deleted -first. To toggle Delete Selection mode on or off, type @kbd{M-x -delete-selection-mode}. +first. If you want to replace only temporary regions, set by +mouse-dragging or shift-selection (@pxref{Setting Mark}) or @kbd{C-u +C-x C-x}, then change the variable +@code{delete-selection-temporary-region} to @code{t}. But if you do +not want to consider the region made active by @kbd{C-u C-x C-x} +(@pxref{Disabled Transient Mark}), then set the variable to +@code{selection}. To toggle Delete Selection mode on or off, type +@kbd{M-x delete-selection-mode}. @node Mark Ring @section The Mark Ring diff --git a/etc/NEWS b/etc/NEWS index 85a0ee44b9..43a0e1aaab 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -271,6 +271,11 @@ startup. Previously, these functions ignored * Changes in Emacs 29.1 ++++ +** New user option 'delete-selection-temporary-region'. +When non-nil, 'delete-selection-mode' will only delete the temporary +regions (usually set by mouse-dragging or shift-selection). + +++ ** New user option 'switch-to-prev-buffer-skip-regexp'. This should be a regexp or a list of regexps; buffers whose names diff --git a/lisp/delsel.el b/lisp/delsel.el index f5fe7cf793..8691f4720b 100644 --- a/lisp/delsel.el +++ b/lisp/delsel.el @@ -64,6 +64,19 @@ delete-selection-save-to-register "If non-nil, deleted region text is stored in this register. Value must be the register (key) to use.") +(defcustom delete-selection-temporary-region nil + "Whether to delete only temporary regions. +When non-nil, typed text replaces only the regions set by +mouse-dragging, shift-selection, and \"\\[universal-argument] \\[exchange-point-and-mark]\" when +`transient-mark-mode' is turned off. If the value is the symbol +`selection', then replace only the regions set by mouse-dragging +and shift-selection." + :version "29.1" + :group 'editing-basics + :type '(choice (const :tag "Replace all regions" nil) + (const :tag "Replace region from mouse, shift-selection, and \"C-u C-x C-x\"" t) + (const :tag "Replace region from mouse and shift-selection" selection))) + ;;;###autoload (defalias 'pending-delete-mode 'delete-selection-mode) @@ -251,6 +264,11 @@ delete-selection-pre-hook have this property won't delete the selection. See `delete-selection-helper'." (when (and delete-selection-mode (use-region-p) + (not (when delete-selection-temporary-region + (not (or (and (consp transient-mark-mode) + (eq (car transient-mark-mode) 'only)) + (and (not (eq delete-selection-temporary-region 'selection)) + (eq transient-mark-mode 'lambda)))))) (not buffer-read-only)) (delete-selection-helper (and (symbolp this-command) (get this-command 'delete-selection))))) -- 2.33.1 --=-=-=--