all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Visuwesh <visuweshm@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 55692@debbugs.gnu.org
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	[thread overview]
Message-ID: <87v8tmouag.fsf@gmail.com> (raw)
In-Reply-To: <83r14cjmdj.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 29 May 2022 20:10:16 +0300")

[-- Attachment #1: Type: text/plain, Size: 4411 bytes --]

[ஞாயிறு மே 29, 2022] Eli Zaretskii wrote:

>> From: Visuwesh <visuweshm@gmail.com>
>> Cc: 55692@debbugs.gnu.org
>> Date: Sun, 29 May 2022 20:23:49 +0530
>> 
>> >> 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.
>
> 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 'selection))
                          (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—for example, typing ‘a’ inserts the character ‘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.
    However, you can tune this behavior by customizing the
    ‘delete-selection-temporary-region’ option.  Its default value is ‘nil’,
    but you can set it to ‘t’, in which case only temporarily-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 ‘C-u C-x C-x’ when Transient Mark Mode is disabled.  You can
    further tune the behavior by setting ‘delete-selection-temporary-region’
    to ‘selection’: then temporary regions by ‘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 ‘M-x
    delete-selection-mode’.

Is this fine?

Improved patch attached.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-delete-selection-mode-Add-user-option-to-delete-temp.patch --]
[-- Type: text/x-patch, Size: 4486 bytes --]

From 6bdf6dbf4525ef6db2e04897b4d6d23488ac2efe Mon Sep 17 00:00:00 2001
From: Visuwesh <visuweshm@gmail.com>
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
 \f
 * 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


  reply	other threads:[~2022-05-31 10:44 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-28 17:33 bug#55692: 29.0.50; delete-selection-mode: Replace region only if set using the mouse Visuwesh
2022-05-28 19:10 ` Eli Zaretskii
2022-05-29  6:17   ` Visuwesh
2022-05-29  6:52     ` Eli Zaretskii
2022-05-29  8:10       ` Visuwesh
2022-05-29  9:04         ` Eli Zaretskii
2022-05-29 14:53           ` Visuwesh
2022-05-29 17:10             ` Eli Zaretskii
2022-05-31 10:44               ` Visuwesh [this message]
2022-05-31 14:33                 ` Drew Adams
2022-06-01 16:04                 ` Eli Zaretskii
2022-06-01 17:03                   ` Visuwesh
2022-09-06 10:59                     ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87v8tmouag.fsf@gmail.com \
    --to=visuweshm@gmail.com \
    --cc=55692@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.