GNU bug report logs - #55692
29.0.50; delete-selection-mode: Replace region only if set using the mouse

Previous Next

Package: emacs;

Reported by: Visuwesh <visuweshm <at> gmail.com>

Date: Sat, 28 May 2022 17:34:01 UTC

Severity: normal

Tags: patch

Found in version 29.0.50

Fixed in version 29.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 55692 in the body.
You can then email your comments to 55692 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#55692; Package emacs. (Sat, 28 May 2022 17:34:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Visuwesh <visuweshm <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sat, 28 May 2022 17:34:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Visuwesh <visuweshm <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 29.0.50; delete-selection-mode: Replace region only if set using
 the mouse
Date: Sat, 28 May 2022 23:03:51 +0530
[Message part 1 (text/plain, inline)]
Tags: patch

Motivation: I often find myself annoyed by `delete-selection-mode' when
using the keyboard since the region in Emacs does not translate to text
selections in other applications.  On the contrary, I find myself
wanting the behaviour of `delete-selection-mode' for regions set using
the mouse.  Attached patch adds an user option to do that.

[0001-delete-selection-mode-Add-user-option-to-delete-mous.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#55692; Package emacs. (Sat, 28 May 2022 19:11:01 GMT) Full text and rfc822 format available.

Message #8 received at 55692 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Visuwesh <visuweshm <at> gmail.com>
Cc: 55692 <at> debbugs.gnu.org
Subject: Re: bug#55692: 29.0.50;
 delete-selection-mode: Replace region only if set using the mouse
Date: Sat, 28 May 2022 22:10:08 +0300
> From: Visuwesh <visuweshm <at> gmail.com>
> Date: Sat, 28 May 2022 23:03:51 +0530
> 
> Motivation: I often find myself annoyed by `delete-selection-mode' when
> using the keyboard since the region in Emacs does not translate to text
> selections in other applications.  On the contrary, I find myself
> wanting the behaviour of `delete-selection-mode' for regions set using
> the mouse.  Attached patch adds an user option to do that.

IMO, we shouldn't distinguish between the mouse and shift-selection
methods of defining the region.  So this feature, if accepted, should
also treat both methods of defining the region the same.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#55692; Package emacs. (Sun, 29 May 2022 06:19:02 GMT) Full text and rfc822 format available.

Message #11 received at 55692 <at> debbugs.gnu.org (full text, mbox):

From: Visuwesh <visuweshm <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 55692 <at> debbugs.gnu.org
Subject: Re: bug#55692: 29.0.50; delete-selection-mode: Replace region only
 if set using the mouse
Date: Sun, 29 May 2022 11:47:32 +0530
[Message part 1 (text/plain, inline)]
[சனி மே 28, 2022] Eli Zaretskii wrote:

>> From: Visuwesh <visuweshm <at> gmail.com>
>> Date: Sat, 28 May 2022 23:03:51 +0530
>> 
>> Motivation: I often find myself annoyed by `delete-selection-mode' when
>> using the keyboard since the region in Emacs does not translate to text
>> selections in other applications.  On the contrary, I find myself
>> wanting the behaviour of `delete-selection-mode' for regions set using
>> the mouse.  Attached patch adds an user option to do that.
>
> IMO, we shouldn't distinguish between the mouse and shift-selection
> methods of defining the region.  So this feature, if accepted, should
> also treat both methods of defining the region the same.

Considering shift-selection would be convenient as well.  Please check
attached patch.

[0001-delete-selection-mode-Add-user-option-to-delete-temp.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#55692; Package emacs. (Sun, 29 May 2022 06:53:01 GMT) Full text and rfc822 format available.

Message #14 received at 55692 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Visuwesh <visuweshm <at> gmail.com>
Cc: 55692 <at> debbugs.gnu.org
Subject: Re: bug#55692: 29.0.50; delete-selection-mode: Replace region only
 if set using the mouse
Date: Sun, 29 May 2022 09:52:05 +0300
> From: Visuwesh <visuweshm <at> gmail.com>
> Cc: 55692 <at> debbugs.gnu.org
> Date: Sun, 29 May 2022 11:47:32 +0530
> 
> [சனி மே 28, 2022] Eli Zaretskii wrote:
> 
> > IMO, we shouldn't distinguish between the mouse and shift-selection
> > methods of defining the region.  So this feature, if accepted, should
> > also treat both methods of defining the region the same.
> 
> Considering shift-selection would be convenient as well.  Please check
> attached patch.

Thanks.

> +@vindex delete-selection-temporary-regions-only

I'd drop the "-only" part: it is not necessary, and makes the variable
name longer.

>    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.

> @@ -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?

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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#55692; Package emacs. (Sun, 29 May 2022 08:11:02 GMT) Full text and rfc822 format available.

Message #17 received at 55692 <at> debbugs.gnu.org (full text, mbox):

From: Visuwesh <visuweshm <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 55692 <at> debbugs.gnu.org
Subject: Re: bug#55692: 29.0.50; delete-selection-mode: Replace region only
 if set using the mouse
Date: Sun, 29 May 2022 13:40:20 +0530
[ஞாயிறு மே 29, 2022] Eli Zaretskii wrote:

>> From: Visuwesh <visuweshm <at> gmail.com>
>> Cc: 55692 <at> debbugs.gnu.org
>> Date: Sun, 29 May 2022 11:47:32 +0530
>> 
>> [சனி மே 28, 2022] Eli Zaretskii wrote:
>> 
>> > IMO, we shouldn't distinguish between the mouse and shift-selection
>> > methods of defining the region.  So this feature, if accepted, should
>> > also treat both methods of defining the region the same.
>> 
>> Considering shift-selection would be convenient as well.  Please check
>> attached patch.
>
> Thanks.
>
>> +@vindex delete-selection-temporary-regions-only
>
> I'd drop the "-only" part: it is not necessary, and makes the variable
> name longer.
>

Okay, will do.

>>    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.
>

These methods as in "mouse-dragging" or "shift-selection".  I'm afraid I
don't fully understand what you mean.

>> @@ -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?
>

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?  When the defcustom is t, we could have it check for '(only
. ...)' and the value 'lambda', no?

> 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.

Sure.  I will factor out the condition into a separate function.  Is
that more elegant?

I will send an updated patch a bit later.  Thanks.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#55692; Package emacs. (Sun, 29 May 2022 09:06:02 GMT) Full text and rfc822 format available.

Message #20 received at 55692 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Visuwesh <visuweshm <at> gmail.com>
Cc: 55692 <at> debbugs.gnu.org
Subject: Re: bug#55692: 29.0.50; delete-selection-mode: Replace region only
 if set using the mouse
Date: Sun, 29 May 2022 12:04:51 +0300
> From: Visuwesh <visuweshm <at> gmail.com>
> Cc: 55692 <at> debbugs.gnu.org
> Date: Sun, 29 May 2022 13:40:20 +0530
> 
> >>    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.
> >
> 
> 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".

> >> @@ -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?
> >
> 
> 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

> > 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.
> 
> 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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#55692; Package emacs. (Sun, 29 May 2022 14:55:01 GMT) Full text and rfc822 format available.

Message #23 received at 55692 <at> debbugs.gnu.org (full text, mbox):

From: Visuwesh <visuweshm <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 55692 <at> debbugs.gnu.org
Subject: Re: 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 part 1 (text/plain, inline)]
[ஞாயிறு மே 29, 2022] Eli Zaretskii wrote:

>> From: Visuwesh <visuweshm <at> gmail.com>
>> Cc: 55692 <at> debbugs.gnu.org
>> Date: Sun, 29 May 2022 13:40:20 +0530
>> 
>> >>    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.
>> >
>> 
>> 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?
>> >
>> 
>> 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.
>> 
>> 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.

[0001-delete-selection-mode-Add-user-option-to-delete-temp.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#55692; Package emacs. (Sun, 29 May 2022 17:11:02 GMT) Full text and rfc822 format available.

Message #26 received at 55692 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Visuwesh <visuweshm <at> gmail.com>
Cc: 55692 <at> debbugs.gnu.org
Subject: Re: bug#55692: 29.0.50; delete-selection-mode: Replace region only
 if set using the mouse
Date: Sun, 29 May 2022 20:10:16 +0300
> From: Visuwesh <visuweshm <at> gmail.com>
> Cc: 55692 <at> 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?

  (when (and delete-selection-mode
             (use-region-p)
	     (not buffer-read-only)
	     (or (null delete-selection-temporary-region)
		 (and (eq delete-selection-temporary-region 'selection)
		      (consp transient-mark-mode)
		      (eq (car transient-mark-mode) 'only))
	         (and delete-selection-temporary-region
	              (or (eq transient-mark-mode 'lambda)
		          (and (consp transient-mark-mode)
		               (eq (car transient-mark-mode) 'only))))))

If not, why not?

> -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?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#55692; Package emacs. (Tue, 31 May 2022 10:46:01 GMT) Full text and rfc822 format available.

Message #29 received at 55692 <at> debbugs.gnu.org (full text, mbox):

From: Visuwesh <visuweshm <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 55692 <at> debbugs.gnu.org
Subject: Re: 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 part 1 (text/plain, inline)]
[ஞாயிறு மே 29, 2022] Eli Zaretskii wrote:

>> From: Visuwesh <visuweshm <at> gmail.com>
>> Cc: 55692 <at> 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.

[0001-delete-selection-mode-Add-user-option-to-delete-temp.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#55692; Package emacs. (Tue, 31 May 2022 14:34:01 GMT) Full text and rfc822 format available.

Message #32 received at 55692 <at> debbugs.gnu.org (full text, mbox):

From: Drew Adams <drew.adams <at> oracle.com>
To: Visuwesh <visuweshm <at> gmail.com>, Eli Zaretskii <eliz <at> gnu.org>
Cc: "55692 <at> debbugs.gnu.org" <55692 <at> debbugs.gnu.org>
Subject: RE: [External] : bug#55692: 29.0.50; delete-selection-mode: Replace
 region only if set using the mouse
Date: Tue, 31 May 2022 14:33:40 +0000
This has long been the text in the manual: 

>        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.

But this, or similar, is apparently being added now:

>     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’.

FWIW, I disagree with this doc change.

If you're going to do something like that (let
alone say _more_ about this minor new feature than
about `delete-selection-mode' itself), then at
least tell users about the _real_ way to customize
d-s-mode - the part that's _basic_ to its design
and purpose.

I'm talking about the fact that d-s-mode does _not_
just replace selected text - even by _default_ for
some commands.

The design of d-s-mode - its features that are
useful for both end users and Lisp coders - isn't
even hinted at in the doc.

What is that design?  The mode behaves differently
for different commands.  Both by default and by
easy-peasy customization.

The doc says nothing about this, and yet it's so
simple, general, elegant, and powerful.  Just put
the kind of action you want on a command symbol
as property `delete-selection'.  There are basic,
predefined actions, and you can define any other
action you like.

From the delsel.el Commentary - which is the real
doc, IMO:

;; Commands which will delete the selection need a 'delete-selection
;; property on their symbols; commands which insert text but don't
;; have this property won't delete the selection.  It can be one of
;; the values:
;;
;;  `yank'
;;      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.
;;  `supersede'
;;      Delete the active region and ignore the current command,
;;      i.e. the command will just delete the region.  This is for
;;      commands that normally delete small amounts of text, like
;;      a single character -- they will instead delete the whole
;;      active region.
;;  `kill'
;;      `kill-region' is used on the selection, rather than
;;      `delete-region'.  (Text selected with the mouse will typically
;;      be yankable anyhow.)
;;  t
;;      The normal case: delete the active region prior to executing
;;      the command which will insert replacement text.
;;  FUNCTION
;;      For commands which need to dynamically determine this behavior.
;;      FUNCTION should take no argument and return one of the above
;;      values, or nil.  In the latter case, FUNCTION should itself
;;      do with the active region whatever is appropriate."

Note the first sentence, BTW.  You don't get _any_
`delete-selection-mode' behavior at all for a
command unless it has property `delete-selection'.

Yes, most insertion of regular text falls into the
default case.  And yes, that's the main idea behind
the mode.  But that's not a reason for the manual
to speak _only_ of that behavior.  d-s-mode doesn't
have as its aim only to replicate behavior that you
might be used to outside Emacs.

If you're going to start mentioning non-replacement
behavior, please prioritize the basic design of
d-s-mode, not the changes proposed in this thread.

Mention the latter if you like, but please don't
overwhelm the description of d-s-mode itself, and
(especially) please prioritize its essential means
of customization - the basic design.

Emphasize what's important.  The proposed new
feature isn't what's important about being able to
"tune this behavior".  Not IMO.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#55692; Package emacs. (Wed, 01 Jun 2022 16:05:02 GMT) Full text and rfc822 format available.

Message #35 received at 55692 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Visuwesh <visuweshm <at> gmail.com>
Cc: 55692 <at> debbugs.gnu.org
Subject: Re: bug#55692: 29.0.50; delete-selection-mode: Replace region only
 if set using the mouse
Date: Wed, 01 Jun 2022 19:04:10 +0300
> From: Visuwesh <visuweshm <at> gmail.com>
> Cc: 55692 <at> debbugs.gnu.org
> Date: Tue, 31 May 2022 16:14:55 +0530
> 
> Improved patch attached.

Thanks, installed.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#55692; Package emacs. (Wed, 01 Jun 2022 17:04:01 GMT) Full text and rfc822 format available.

Message #38 received at 55692 <at> debbugs.gnu.org (full text, mbox):

From: Visuwesh <visuweshm <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 55692 <at> debbugs.gnu.org
Subject: Re: bug#55692: 29.0.50; delete-selection-mode: Replace region only
 if set using the mouse
Date: Wed, 01 Jun 2022 22:33:45 +0530
[Wednesday June 01, 2022] Eli Zaretskii wrote:

>> From: Visuwesh <visuweshm <at> gmail.com>
>> Cc: 55692 <at> debbugs.gnu.org
>> Date: Tue, 31 May 2022 16:14:55 +0530
>> 
>> Improved patch attached.
>
> Thanks, installed.

Great, thanks.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#55692; Package emacs. (Tue, 06 Sep 2022 11:00:01 GMT) Full text and rfc822 format available.

Message #41 received at 55692 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Visuwesh <visuweshm <at> gmail.com>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 55692 <at> debbugs.gnu.org
Subject: Re: bug#55692: 29.0.50; delete-selection-mode: Replace region only
 if set using the mouse
Date: Tue, 06 Sep 2022 12:59:31 +0200
Visuwesh <visuweshm <at> gmail.com> writes:

>>> Improved patch attached.
>>
>> Thanks, installed.
>
> Great, thanks.

But the bug report was left open, so I'm closing it now.  (I quickly
skimmed the bug report to see if there was anything else to be done
here, but didn't see anything.  If this is a mistake, please respond to
the debbugs address and we'll reopen.)




bug marked as fixed in version 29.1, send any further explanations to 55692 <at> debbugs.gnu.org and Visuwesh <visuweshm <at> gmail.com> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Tue, 06 Sep 2022 11:00:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 04 Oct 2022 11:24:09 GMT) Full text and rfc822 format available.

This bug report was last modified 1 year and 198 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.