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: Tue, 31 May 2022 16:14:55 +0530 Message-ID: <87v8tmouag.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> <87mtf075ky.fsf@gmail.com> <83r14cjmdj.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="40767"; 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 Tue May 31 13:19:21 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 1nvzuC-000ASs-1F for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 31 May 2022 13:19:20 +0200 Original-Received: from localhost ([::1]:58076 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nvzuB-0004H2-1b for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 31 May 2022 07:19:19 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47054) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nvzNy-0006Ce-5Y for bug-gnu-emacs@gnu.org; Tue, 31 May 2022 06:46:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:52850) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nvzNx-0005Bb-TJ for bug-gnu-emacs@gnu.org; Tue, 31 May 2022 06:46:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nvzNx-00014R-OA for bug-gnu-emacs@gnu.org; Tue, 31 May 2022 06:46:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Visuwesh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 31 May 2022 10:46: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.16539939164053 (code B ref 55692); Tue, 31 May 2022 10:46:01 +0000 Original-Received: (at 55692) by debbugs.gnu.org; 31 May 2022 10:45:16 +0000 Original-Received: from localhost ([127.0.0.1]:46747 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nvzND-00013G-Eo for submit@debbugs.gnu.org; Tue, 31 May 2022 06:45:16 -0400 Original-Received: from mail-pf1-f195.google.com ([209.85.210.195]:37884) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nvzNB-00012z-AN for 55692@debbugs.gnu.org; Tue, 31 May 2022 06:45:14 -0400 Original-Received: by mail-pf1-f195.google.com with SMTP id bo5so12846321pfb.4 for <55692@debbugs.gnu.org>; Tue, 31 May 2022 03:45:13 -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=o9KCGFWh9p9IYPAPlv5sD+iM56mn8pvf98Iiyq3Ryps=; b=GDuHV1NVXhdgI11GD+dbGUx6nW9lnmstD8hEIScfA4SRAjRCczfwFzVcz010l4/zB1 DECPydLnoYL8ot+O0bFmecKh9mSPoCMWohnKuC242LsH160F+p3RfIFP3Rt6bR+PY2lp erq3/Cgl0QrrwqdogKP4VkA0uydOC8oneqqWExE1AIzlZKC3jRptMPlyX3nLwziNzTIz iGfcFxSJ0l8NCXeFkk6tM+pipcYB/9o5b/0xKyTJ946noMWpauyLr6OOX3IoKcMRE/qA rES/goXbdzLhV56gFyC1IJUHQNBgxTQeLT+zjqS+Oz4LK4SNso3FS/8j2A+uS5rP8H0K ZClA== 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=o9KCGFWh9p9IYPAPlv5sD+iM56mn8pvf98Iiyq3Ryps=; b=jY9nB2oKii6d1acHnZAgS70vRrjx5ZN4AGfimDd51IpHwRq/pl1aHolBFCvul4ek7Z dV1xKlip9Ytn7LLdP/rl8rY+XcFGvm1gfCuVw+bjckR17sOAg1PFbq21It49S8nkXMLL Gd1EFMb5/e4wozdVV8bLy1ezdj3Ye19KgRbbozuxwDXj2A6tZka3beXLebn87SYvfp/R FV0w5RFySSuP8XRyQ0OD3+6m0mxjSdxzzoxyosBDXjjDC3gg/3k18pDcpaty3gBkPfRp HlgL0C+SEi9EqKG2AjANWLrTM9ecKVNnf/wrBB0klD+ERgK4SgVynGrFRUgtRJbi0q8j uq+A== X-Gm-Message-State: AOAM53016z0D66BFmZ5IruakNT1WT+1Dfic3juTZZk7T+uCDC3mOgJS5 O9OV/uw3zNxSVT5BYRgTjAc= X-Google-Smtp-Source: ABdhPJy36QBKcYRdLxsPcyDE1lo7g7wHsr8d/bIQw9svHYUwLls+MIlEr2y3fIRQZv+f79IMyN/ybw== X-Received: by 2002:a63:524d:0:b0:3fb:ee61:82cd with SMTP id s13-20020a63524d000000b003fbee6182cdmr11061966pgl.528.1653993907308; Tue, 31 May 2022 03:45:07 -0700 (PDT) Original-Received: from localhost ([49.204.143.162]) by smtp.gmail.com with ESMTPSA id e23-20020a62ee17000000b0050dc76281e4sm10349499pfi.190.2022.05.31.03.45.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 May 2022 03:45:06 -0700 (PDT) In-Reply-To: <83r14cjmdj.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 29 May 2022 20:10:16 +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:233420 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 20:23:49 +0530 >>=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. >>=20 >> I don't think I fully understood what you meant but I took a shot at it >> anyway. Please review updated patch. > > Well, that uses double negation, which IME is a sign that it can be > clarified. Is the following condition correct? > > [...] > > If not, why not? > For some reason, it completely crossed my mind that I could check for the null value of delete-selection-temporary-region explicitly, thanks for pointing out. The condition is now, (when (and delete-selection-mode (use-region-p) (not buffer-read-only) (or (null delete-selection-temporary-region) (and delete-selection-temporary-region (consp transient-mark-mode) (eq (car transient-mark-mode) 'only)) (and (not (eq delete-selection-temporary-region 'selec= tion)) (eq transient-mark-mode 'lambda)))) >> -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}. > > This text is now too complex and thus confusing. (You can only keep > using that style for boolean options.) I would rephrase: > > Normally, inserting text deletes any active region, replacing it > with the text you insert. However, you can tune this behavior by > customizing the @code{delete-selection-temporary-region} option. > Its default value is @code{nil}, but you can set it to @code{t}, in > which case only temporarily-active regions will be replaced: those > which are set by dragging the mouse (@pxref{Setting Mark}) or by > shift-selection (@pxref{Shift Selection}), as well as by @kbd{C-u > C-x C-x} when Transient Mark mode is disabled. You can further tune > the behavior by setting @code{delete-selection-temporary-region} to > @code{selection}: then temporary regions activated by @kbd{C-u C-x > C-x} won't be replaced, only the ones activated by dragging the > mouse or shift-selection. > > OK? Indeed, that is more clear. Thanks for teaching. The paragraph now says, By default, text insertion occurs normally even if the mark is active=E2=80=94for example, typing =E2=80=98a=E2=80=99 inserts the char= acter =E2=80=98a=E2=80=99, 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. However, you can tune this behavior by customizing the =E2=80=98delete-selection-temporary-region=E2=80=99 option. Its defaul= t value is =E2=80=98nil=E2=80=99, but you can set it to =E2=80=98t=E2=80=99, in which case only temporari= ly-active regions will be replaced: those which are set by dragging the mouse (*note Setting Mark) or by shift-selection (*note Shift Selection), as well as by =E2=80=98C-u C-x C-x=E2=80=99 when Transient Mark Mode is disable= d. You can further tune the behavior by setting =E2=80=98delete-selection-temporar= y-region=E2=80=99 to =E2=80=98selection=E2=80=99: then temporary regions by =E2=80=98C-u = C-x C-x=E2=80=99 won=E2=80=99t be replaced, only the ones activated by dragging the mouse or shift-selection. To toggle Delete Selection mode on or off, type =E2= =80=98M-x delete-selection-mode=E2=80=99. Is this fine? Improved patch attached. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-delete-selection-mode-Add-user-option-to-delete-temp.patch >From 6bdf6dbf4525ef6db2e04897b4d6d23488ac2efe 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 | 13 ++++++++++++- etc/NEWS | 5 +++++ lisp/delsel.el | 21 ++++++++++++++++++++- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/doc/emacs/mark.texi b/doc/emacs/mark.texi index 91c44d527b..ad25ed6a8a 100644 --- a/doc/emacs/mark.texi +++ b/doc/emacs/mark.texi @@ -291,12 +291,23 @@ 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 +first. However, you can tune this behavior by customizing the +@code{delete-selection-temporary-region} option. Its default value is +@code{nil}, but you can set it to @code{t}, in which case only +temporarily-active regions will be replaced: those which are set by +dragging the mouse (@pxref{Setting Mark}) or by shift-selection +(@pxref{Shift Selection}), as well as by @kbd{C-u C-x C-x} when +Transient Mark Mode is disabled. You can further tune the behavior by +setting @code{delete-selection-temporary-region} to @code{selection}: +then temporary regions by @kbd{C-u C-x C-x} won't be replaced, only +the ones activated by dragging the mouse or shift-selection. To +toggle Delete Selection mode on or off, type @kbd{M-x delete-selection-mode}. @node 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..c9d3cf269b 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,7 +264,13 @@ 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 buffer-read-only)) + (not buffer-read-only) + (or (null delete-selection-temporary-region) + (and delete-selection-temporary-region + (consp transient-mark-mode) + (eq (car transient-mark-mode) 'only)) + (and (not (eq delete-selection-temporary-region 'selection)) + (eq transient-mark-mode 'lambda)))) (delete-selection-helper (and (symbolp this-command) (get this-command 'delete-selection))))) -- 2.33.1 --=-=-=--