GNU bug report logs - #69097
[PATCH] Add 'kill-region-or-word' command

Previous Next

Package: emacs;

Reported by: Philip Kaludercic <philipk <at> posteo.net>

Date: Tue, 13 Feb 2024 09:57:02 UTC

Severity: normal

Tags: patch

To reply to this bug, email your comments to 69097 AT debbugs.gnu.org.

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#69097; Package emacs. (Tue, 13 Feb 2024 09:57:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Philip Kaludercic <philipk <at> posteo.net>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 13 Feb 2024 09:57:02 GMT) Full text and rfc822 format available.

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

From: Philip Kaludercic <philipk <at> posteo.net>
To: bug-gnu-emacs <at> gnu.org
Subject: [PATCH] Add 'kill-region-or-word' command
Date: Tue, 13 Feb 2024 09:55:39 +0000
[Message part 1 (text/plain, inline)]
This is another useful command I find myself re-implementing every time
I use an unmodified Emacs, that I think would provide some nice
convenience for people used to classical Unix keybindings.

[0001-Add-'kill-region-or-word'-command.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69097; Package emacs. (Fri, 03 May 2024 07:38:02 GMT) Full text and rfc822 format available.

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

From: Philip Kaludercic <philipk <at> posteo.net>
To: 69097 <at> debbugs.gnu.org
Subject: Re: bug#69097: [PATCH] Add 'kill-region-or-word' command
Date: Fri, 03 May 2024 07:37:03 +0000
Philip Kaludercic <philipk <at> posteo.net> writes:

> This is another useful command I find myself re-implementing every time
> I use an unmodified Emacs, that I think would provide some nice
> convenience for people used to classical Unix keybindings.

ping?  I had a discussion with RMS off-list and he seemed to be
supportive of the change.

-- 
	Philip Kaludercic on peregrine




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69097; Package emacs. (Fri, 03 May 2024 10:42:01 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Philip Kaludercic <philipk <at> posteo.net>
Cc: Richard Stallman <rms <at> gnu.org>, 69097 <at> debbugs.gnu.org
Subject: Re: bug#69097: [PATCH] Add 'kill-region-or-word' command
Date: Fri, 03 May 2024 13:40:13 +0300
> From: Philip Kaludercic <philipk <at> posteo.net>
> Date: Fri, 03 May 2024 07:37:03 +0000
> 
> Philip Kaludercic <philipk <at> posteo.net> writes:
> 
> > This is another useful command I find myself re-implementing every time
> > I use an unmodified Emacs, that I think would provide some nice
> > convenience for people used to classical Unix keybindings.
> 
> ping?  I had a discussion with RMS off-list and he seemed to be
> supportive of the change.

That's a problem with off-list discussions: no one knows about them.

More to the point, can you explain why we need this, given the
existence of kill-word?

Also, this kills backward, something that is not evident, neither from
the name of the command nor from the doc string (and the obscure
reference to Unix doesn't help, IMO).

Finally, having another command that kills the region doesn't seem
justified, or is it?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69097; Package emacs. (Fri, 03 May 2024 10:49:01 GMT) Full text and rfc822 format available.

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

From: Philip Kaludercic <philipk <at> posteo.net>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Richard Stallman <rms <at> gnu.org>, 69097 <at> debbugs.gnu.org
Subject: Re: bug#69097: [PATCH] Add 'kill-region-or-word' command
Date: Fri, 03 May 2024 10:48:13 +0000
Eli Zaretskii <eliz <at> gnu.org> writes:

>> From: Philip Kaludercic <philipk <at> posteo.net>
>> Date: Fri, 03 May 2024 07:37:03 +0000
>> 
>> Philip Kaludercic <philipk <at> posteo.net> writes:
>> 
>> > This is another useful command I find myself re-implementing every time
>> > I use an unmodified Emacs, that I think would provide some nice
>> > convenience for people used to classical Unix keybindings.
>> 
>> ping?  I had a discussion with RMS off-list and he seemed to be
>> supportive of the change.
>
> That's a problem with off-list discussions: no one knows about them.

I also realised this too late, if you want to I can resend the messages.

> More to the point, can you explain why we need this, given the
> existence of kill-word?
>
> Also, this kills backward, something that is not evident, neither from
> the name of the command nor from the doc string (and the obscure
> reference to Unix doesn't help, IMO).
>
> Finally, having another command that kills the region doesn't seem
> justified, or is it?

The motivation is sort of the same as with generalising `upcase-word' to
`upcase-dwim'.  If there is no active region, it behaves like
`backward-kill-word' (which is what C-w does in a terminal as well), but
if there is an active region it reverts to `kill-ring-save'.  I have
this in my personal configuration for ages, and it is always one of the
first things I re-implement when using an Emacs without a custom init.el.

-- 
	Philip Kaludercic on peregrine




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69097; Package emacs. (Fri, 03 May 2024 11:01:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Philip Kaludercic <philipk <at> posteo.net>
Cc: rms <at> gnu.org, 69097 <at> debbugs.gnu.org
Subject: Re: bug#69097: [PATCH] Add 'kill-region-or-word' command
Date: Fri, 03 May 2024 13:59:00 +0300
> From: Philip Kaludercic <philipk <at> posteo.net>
> Cc: 69097 <at> debbugs.gnu.org,  Richard Stallman <rms <at> gnu.org>
> Date: Fri, 03 May 2024 10:48:13 +0000
> 
> Eli Zaretskii <eliz <at> gnu.org> writes:
> 
> >> ping?  I had a discussion with RMS off-list and he seemed to be
> >> supportive of the change.
> >
> > That's a problem with off-list discussions: no one knows about them.
> 
> I also realised this too late, if you want to I can resend the messages.

I think that would be a good idea, at least for posterity.  So please
do.

> > More to the point, can you explain why we need this, given the
> > existence of kill-word?
> >
> > Also, this kills backward, something that is not evident, neither from
> > the name of the command nor from the doc string (and the obscure
> > reference to Unix doesn't help, IMO).
> >
> > Finally, having another command that kills the region doesn't seem
> > justified, or is it?
> 
> The motivation is sort of the same as with generalising `upcase-word' to
> `upcase-dwim'.  If there is no active region, it behaves like
> `backward-kill-word' (which is what C-w does in a terminal as well), but
> if there is an active region it reverts to `kill-ring-save'.

If so, then (assuming we decide to accept this change), the name of
the command should be something like kill-word-dwim, and the doc
string should mention the two commands you refer to above.

> I have this in my personal configuration for ages, and it is always
> one of the first things I re-implement when using an Emacs without a
> custom init.el.

Any reason why you need this command and cannot settle for the two
commands it replaces heuristically?  Are you using Emacs with
transient-mark-mode on or off?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69097; Package emacs. (Fri, 03 May 2024 11:06:01 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: philipk <at> posteo.net
Cc: rms <at> gnu.org, 69097 <at> debbugs.gnu.org
Subject: Re: bug#69097: [PATCH] Add 'kill-region-or-word' command
Date: Fri, 03 May 2024 14:04:17 +0300
> Cc: rms <at> gnu.org, 69097 <at> debbugs.gnu.org
> Date: Fri, 03 May 2024 13:59:00 +0300
> From: Eli Zaretskii <eliz <at> gnu.org>
> 
> > From: Philip Kaludercic <philipk <at> posteo.net>
> > Cc: 69097 <at> debbugs.gnu.org,  Richard Stallman <rms <at> gnu.org>
> > Date: Fri, 03 May 2024 10:48:13 +0000
> > 
> > > More to the point, can you explain why we need this, given the
> > > existence of kill-word?
> > >
> > > Also, this kills backward, something that is not evident, neither from
> > > the name of the command nor from the doc string (and the obscure
> > > reference to Unix doesn't help, IMO).
> > >
> > > Finally, having another command that kills the region doesn't seem
> > > justified, or is it?
> > 
> > The motivation is sort of the same as with generalising `upcase-word' to
> > `upcase-dwim'.  If there is no active region, it behaves like
> > `backward-kill-word' (which is what C-w does in a terminal as well), but
> > if there is an active region it reverts to `kill-ring-save'.
> 
> If so, then (assuming we decide to accept this change), the name of
> the command should be something like kill-word-dwim, and the doc
> string should mention the two commands you refer to above.
> 
> > I have this in my personal configuration for ages, and it is always
> > one of the first things I re-implement when using an Emacs without a
> > custom init.el.
> 
> Any reason why you need this command and cannot settle for the two
> commands it replaces heuristically?  Are you using Emacs with
> transient-mark-mode on or off?

And one more question: currently C-w signals an error if there's no
region.  So another idea is to extend C-w to delete the word at point
if there's no region (where "no region" means "no active region" if
transient-mark-mode is ON, otherwise it means "no mark set").




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69097; Package emacs. (Fri, 03 May 2024 16:16:02 GMT) Full text and rfc822 format available.

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

From: Richard Stallman <rms <at> gnu.org>
To: Philip Kaludercic <philipk <at> posteo.net>
Cc: 69097 <at> debbugs.gnu.org
Subject: Re: bug#69097: [PATCH] Add 'kill-region-or-word' command
Date: Fri, 23 Feb 2024 03:04:25 +0000
[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

  > My command boils down to using `use-region-p'.  This makes usage
  > together with `transient-mark-mode' intuitive, because if you can see
  > the selection, you kill a region, otherwise a word is deleted.

That seems natural.

Have you tried putting this on M-d?  It could be convenient but it
could instead be disturbing and surprising.

-- 
Dr Richard Stallman (https://stallman.org)
Chief GNUisance of the GNU Project (https://gnu.org)
Founder, Free Software Foundation (https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)






Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69097; Package emacs. (Fri, 03 May 2024 16:16:02 GMT) Full text and rfc822 format available.

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

From: Richard Stallman <rms <at> gnu.org>
To: Philip Kaludercic <philipk <at> posteo.net>
Cc: 69097 <at> debbugs.gnu.org
Subject: Re: bug#69097: [PATCH] Add 'kill-region-or-word' command
Date: Sun, 25 Feb 2024 03:16:01 +0000
[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

  > > Have you tried putting this on M-d?  It could be convenient but it
  > > could instead be disturbing and surprising.

  > I would expect it to be weird, as long as the proposed command uses
  > backward-kill-word, and not kill-word.

I did not see in the email that it kills a word _backwards_.  That
being so, the natural binding for it would be M-DEL.

Do people find this changed behavior for M-DEL natural?
I am not presuming either yes or no.

-- 
Dr Richard Stallman (https://stallman.org)
Chief GNUisance of the GNU Project (https://gnu.org)
Founder, Free Software Foundation (https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)






Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69097; Package emacs. (Fri, 03 May 2024 16:16:02 GMT) Full text and rfc822 format available.

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

From: Richard Stallman <rms <at> gnu.org>
To: Philip Kaludercic <philipk <at> posteo.net>
Cc: 69097 <at> debbugs.gnu.org
Subject: Re: bug#69097: [PATCH] Add 'kill-region-or-word' command
Date: Sat, 17 Feb 2024 03:53:06 +0000
[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

  > This is another useful command I find myself re-implementing every time
  > I use an unmodified Emacs, that I think would provide some nice
  > convenience for people used to classical Unix keybindings.

Do you bind this to a key?  If so, which key is convenient?

-- 
Dr Richard Stallman (https://stallman.org)
Chief GNUisance of the GNU Project (https://gnu.org)
Founder, Free Software Foundation (https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)






Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69097; Package emacs. (Fri, 03 May 2024 16:16:03 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69097; Package emacs. (Fri, 03 May 2024 16:16:03 GMT) Full text and rfc822 format available.

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

From: Richard Stallman <rms <at> gnu.org>
To: Philip Kaludercic <philipk <at> posteo.net>
Cc: 69097 <at> debbugs.gnu.org
Subject: Re: bug#69097: [PATCH] Add 'kill-region-or-word' command
Date: Tue, 27 Feb 2024 03:12:27 +0000
[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

  > I don't think this command should be bound by default at all.  Just like
  > by default M-u is bound to `upcase-word', but the user might decide to
  > rebind the key to the more powerful (or more confusing) DWIM command
  > `upcase-dwim', here too, I just want to propose offering an opt-in
  > alternative that the user can bind wherever they please.  Making the
  > decision for them would be too invasive IMO.

Maybe you're right -- but let's find out what users think of it.
It may turn out that users will love having this command on M-DEL.

-- 
Dr Richard Stallman (https://stallman.org)
Chief GNUisance of the GNU Project (https://gnu.org)
Founder, Free Software Foundation (https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)






Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69097; Package emacs. (Fri, 03 May 2024 16:16:04 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69097; Package emacs. (Fri, 03 May 2024 16:16:04 GMT) Full text and rfc822 format available.

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

From: Richard Stallman <rms <at> gnu.org>
To: Philip Kaludercic <philipk <at> posteo.net>
Cc: 69097 <at> debbugs.gnu.org
Subject: Re: bug#69097: [PATCH] Add 'kill-region-or-word' command
Date: Mon, 19 Feb 2024 03:44:44 +0000
[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

How does it decide whether to kill a region or a word?

-- 
Dr Richard Stallman (https://stallman.org)
Chief GNUisance of the GNU Project (https://gnu.org)
Founder, Free Software Foundation (https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)






Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69097; Package emacs. (Fri, 03 May 2024 16:21:02 GMT) Full text and rfc822 format available.

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

From: Philip Kaludercic <philipk <at> posteo.net>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: rms <at> gnu.org, 69097 <at> debbugs.gnu.org
Subject: Re: bug#69097: [PATCH] Add 'kill-region-or-word' command
Date: Fri, 03 May 2024 16:20:18 +0000
Eli Zaretskii <eliz <at> gnu.org> writes:

>> From: Philip Kaludercic <philipk <at> posteo.net>
>> Cc: 69097 <at> debbugs.gnu.org,  Richard Stallman <rms <at> gnu.org>
>> Date: Fri, 03 May 2024 10:48:13 +0000
>> 
>> Eli Zaretskii <eliz <at> gnu.org> writes:
>> 
>> >> ping?  I had a discussion with RMS off-list and he seemed to be
>> >> supportive of the change.
>> >
>> > That's a problem with off-list discussions: no one knows about them.
>> 
>> I also realised this too late, if you want to I can resend the messages.
>
> I think that would be a good idea, at least for posterity.  So please
> do.

Done, let's see if my mail server allows it.

>> > More to the point, can you explain why we need this, given the
>> > existence of kill-word?
>> >
>> > Also, this kills backward, something that is not evident, neither from
>> > the name of the command nor from the doc string (and the obscure
>> > reference to Unix doesn't help, IMO).
>> >
>> > Finally, having another command that kills the region doesn't seem
>> > justified, or is it?
>> 
>> The motivation is sort of the same as with generalising `upcase-word' to
>> `upcase-dwim'.  If there is no active region, it behaves like
>> `backward-kill-word' (which is what C-w does in a terminal as well), but
>> if there is an active region it reverts to `kill-ring-save'.
>
> If so, then (assuming we decide to accept this change), the name of
> the command should be something like kill-word-dwim, and the doc
> string should mention the two commands you refer to above.

I am not sure if the analogy is that perfect, but I certainly can
mention `backward-kill-word' and `kill-ring-save'.

>> I have this in my personal configuration for ages, and it is always
>> one of the first things I re-implement when using an Emacs without a
>> custom init.el.
>
> Any reason why you need this command and cannot settle for the two
> commands it replaces heuristically?  Are you using Emacs with
> transient-mark-mode on or off?

With transient-mark-mode on.  I have a mixed habit of using C-w in
terminals and in Emacs, and which one I want to use correlates pretty
well with there being an active region.

-- 
	Philip Kaludercic on peregrine




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69097; Package emacs. (Fri, 03 May 2024 17:34:01 GMT) Full text and rfc822 format available.

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

From: Philip Kaludercic <philipk <at> posteo.net>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: rms <at> gnu.org, 69097 <at> debbugs.gnu.org
Subject: Re: bug#69097: [PATCH] Add 'kill-region-or-word' command
Date: Fri, 03 May 2024 17:32:35 +0000
Eli Zaretskii <eliz <at> gnu.org> writes:

>> Cc: rms <at> gnu.org, 69097 <at> debbugs.gnu.org
>> Date: Fri, 03 May 2024 13:59:00 +0300
>> From: Eli Zaretskii <eliz <at> gnu.org>
>> 
>> > From: Philip Kaludercic <philipk <at> posteo.net>
>> > Cc: 69097 <at> debbugs.gnu.org,  Richard Stallman <rms <at> gnu.org>
>> > Date: Fri, 03 May 2024 10:48:13 +0000
>> > 
>> > > More to the point, can you explain why we need this, given the
>> > > existence of kill-word?
>> > >
>> > > Also, this kills backward, something that is not evident, neither from
>> > > the name of the command nor from the doc string (and the obscure
>> > > reference to Unix doesn't help, IMO).
>> > >
>> > > Finally, having another command that kills the region doesn't seem
>> > > justified, or is it?
>> > 
>> > The motivation is sort of the same as with generalising `upcase-word' to
>> > `upcase-dwim'.  If there is no active region, it behaves like
>> > `backward-kill-word' (which is what C-w does in a terminal as well), but
>> > if there is an active region it reverts to `kill-ring-save'.
>> 
>> If so, then (assuming we decide to accept this change), the name of
>> the command should be something like kill-word-dwim, and the doc
>> string should mention the two commands you refer to above.
>> 
>> > I have this in my personal configuration for ages, and it is always
>> > one of the first things I re-implement when using an Emacs without a
>> > custom init.el.
>> 
>> Any reason why you need this command and cannot settle for the two
>> commands it replaces heuristically?  Are you using Emacs with
>> transient-mark-mode on or off?
>
> And one more question: currently C-w signals an error if there's no
> region.  So another idea is to extend C-w to delete the word at point
> if there's no region (where "no region" means "no active region" if
> transient-mark-mode is ON, otherwise it means "no mark set").

That is basically what my command does (with the difference that I don't
just check if (mark) is non-nil but also if (use-region-p) is non-nil),
just not part of kill-region.  I don't know if this is too invasive, if
users are used to this error being signalled.  Perhaps it can be
protected by a user option?

-- 
	Philip Kaludercic on peregrine




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69097; Package emacs. (Fri, 03 May 2024 18:03:01 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Philip Kaludercic <philipk <at> posteo.net>
Cc: rms <at> gnu.org, 69097 <at> debbugs.gnu.org
Subject: Re: bug#69097: [PATCH] Add 'kill-region-or-word' command
Date: Fri, 03 May 2024 21:01:38 +0300
> From: Philip Kaludercic <philipk <at> posteo.net>
> Cc: rms <at> gnu.org,  69097 <at> debbugs.gnu.org
> Date: Fri, 03 May 2024 17:32:35 +0000
> 
> Eli Zaretskii <eliz <at> gnu.org> writes:
> 
> >> Cc: rms <at> gnu.org, 69097 <at> debbugs.gnu.org
> >> Date: Fri, 03 May 2024 13:59:00 +0300
> >> From: Eli Zaretskii <eliz <at> gnu.org>
> >> 
> >> > From: Philip Kaludercic <philipk <at> posteo.net>
> >> > Cc: 69097 <at> debbugs.gnu.org,  Richard Stallman <rms <at> gnu.org>
> >> > Date: Fri, 03 May 2024 10:48:13 +0000
> >> > 
> >> > > More to the point, can you explain why we need this, given the
> >> > > existence of kill-word?
> >> > >
> >> > > Also, this kills backward, something that is not evident, neither from
> >> > > the name of the command nor from the doc string (and the obscure
> >> > > reference to Unix doesn't help, IMO).
> >> > >
> >> > > Finally, having another command that kills the region doesn't seem
> >> > > justified, or is it?
> >> > 
> >> > The motivation is sort of the same as with generalising `upcase-word' to
> >> > `upcase-dwim'.  If there is no active region, it behaves like
> >> > `backward-kill-word' (which is what C-w does in a terminal as well), but
> >> > if there is an active region it reverts to `kill-ring-save'.
> >> 
> >> If so, then (assuming we decide to accept this change), the name of
> >> the command should be something like kill-word-dwim, and the doc
> >> string should mention the two commands you refer to above.
> >> 
> >> > I have this in my personal configuration for ages, and it is always
> >> > one of the first things I re-implement when using an Emacs without a
> >> > custom init.el.
> >> 
> >> Any reason why you need this command and cannot settle for the two
> >> commands it replaces heuristically?  Are you using Emacs with
> >> transient-mark-mode on or off?
> >
> > And one more question: currently C-w signals an error if there's no
> > region.  So another idea is to extend C-w to delete the word at point
> > if there's no region (where "no region" means "no active region" if
> > transient-mark-mode is ON, otherwise it means "no mark set").
> 
> That is basically what my command does (with the difference that I don't
> just check if (mark) is non-nil but also if (use-region-p) is non-nil),
> just not part of kill-region.  I don't know if this is too invasive, if
> users are used to this error being signalled.  Perhaps it can be
> protected by a user option?

I don't think anyone wants the error, so doing something useful in
that case should be a no-brainer.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69097; Package emacs. (Fri, 03 May 2024 19:43:02 GMT) Full text and rfc822 format available.

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

From: Philip Kaludercic <philipk <at> posteo.net>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: rms <at> gnu.org, 69097 <at> debbugs.gnu.org
Subject: Re: bug#69097: [PATCH] Add 'kill-region-or-word' command
Date: Fri, 03 May 2024 19:41:43 +0000
[Message part 1 (text/plain, inline)]
Eli Zaretskii <eliz <at> gnu.org> writes:

>> From: Philip Kaludercic <philipk <at> posteo.net>
>> Cc: rms <at> gnu.org,  69097 <at> debbugs.gnu.org
>> Date: Fri, 03 May 2024 17:32:35 +0000
>> 
>> Eli Zaretskii <eliz <at> gnu.org> writes:
>> 
>> >> Cc: rms <at> gnu.org, 69097 <at> debbugs.gnu.org
>> >> Date: Fri, 03 May 2024 13:59:00 +0300
>> >> From: Eli Zaretskii <eliz <at> gnu.org>
>> >> 
>> >> > From: Philip Kaludercic <philipk <at> posteo.net>
>> >> > Cc: 69097 <at> debbugs.gnu.org,  Richard Stallman <rms <at> gnu.org>
>> >> > Date: Fri, 03 May 2024 10:48:13 +0000
>> >> > 
>> >> > > More to the point, can you explain why we need this, given the
>> >> > > existence of kill-word?
>> >> > >
>> >> > > Also, this kills backward, something that is not evident, neither from
>> >> > > the name of the command nor from the doc string (and the obscure
>> >> > > reference to Unix doesn't help, IMO).
>> >> > >
>> >> > > Finally, having another command that kills the region doesn't seem
>> >> > > justified, or is it?
>> >> > 
>> >> > The motivation is sort of the same as with generalising `upcase-word' to
>> >> > `upcase-dwim'.  If there is no active region, it behaves like
>> >> > `backward-kill-word' (which is what C-w does in a terminal as well), but
>> >> > if there is an active region it reverts to `kill-ring-save'.
>> >> 
>> >> If so, then (assuming we decide to accept this change), the name of
>> >> the command should be something like kill-word-dwim, and the doc
>> >> string should mention the two commands you refer to above.
>> >> 
>> >> > I have this in my personal configuration for ages, and it is always
>> >> > one of the first things I re-implement when using an Emacs without a
>> >> > custom init.el.
>> >> 
>> >> Any reason why you need this command and cannot settle for the two
>> >> commands it replaces heuristically?  Are you using Emacs with
>> >> transient-mark-mode on or off?
>> >
>> > And one more question: currently C-w signals an error if there's no
>> > region.  So another idea is to extend C-w to delete the word at point
>> > if there's no region (where "no region" means "no active region" if
>> > transient-mark-mode is ON, otherwise it means "no mark set").
>> 
>> That is basically what my command does (with the difference that I don't
>> just check if (mark) is non-nil but also if (use-region-p) is non-nil),
>> just not part of kill-region.  I don't know if this is too invasive, if
>> users are used to this error being signalled.  Perhaps it can be
>> protected by a user option?
>
> I don't think anyone wants the error, so doing something useful in
> that case should be a no-brainer.

How does this look like:

[0001-Allow-kill-region-to-delete-the-last-word.patch (text/x-patch, attachment)]
[Message part 3 (text/plain, inline)]

-- 
	Philip Kaludercic on peregrine

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69097; Package emacs. (Sat, 04 May 2024 06:22:01 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Philip Kaludercic <philipk <at> posteo.net>
Cc: rms <at> gnu.org, 69097 <at> debbugs.gnu.org
Subject: Re: bug#69097: [PATCH] Add 'kill-region-or-word' command
Date: Sat, 04 May 2024 09:20:13 +0300
> From: Philip Kaludercic <philipk <at> posteo.net>
> Cc: rms <at> gnu.org,  69097 <at> debbugs.gnu.org
> Date: Fri, 03 May 2024 19:41:43 +0000
> 
> Eli Zaretskii <eliz <at> gnu.org> writes:
> 
> > I don't think anyone wants the error, so doing something useful in
> > that case should be a no-brainer.
> 
> How does this look like:

Looks good, but it needs some polish, I think:

> +---
> +*** New user option 'kill-word-if-no-region'.
> +This option will modify the fall-back behaviour of 'kill-region' if no
> +region is active, and will kill the last word instead of raising an
> +error.

This should be modified according to comments below, and also should
say what is the default of this option.

> +(defcustom kill-word-if-no-region nil
> +  "Non-nil means that `kill-region' without a region will kill the last word."
> +  :type 'boolean
> +  :group 'killing)

This lacks the :version tag.

> +Lisp programs should use this function for killing text.  (To delete
> +text, use `delete-region'.)  Supply two arguments, character positions
> +BEG and END indicating the stretch of text to be killed.  If the
> +optional argument REGION is non-nil, the function ignores BEG and END,
> +and kills the current region instead.  If REGION has the special value
> +`kill-word', then it will kill the previous word, as with
> +`backward-kill-word'.

Instead of "the previous word", I would say "word characters before
point", since we don't kill the entire word if point is inside a word.

>                        Interactively, REGION is always non-nil, and so
> +this command always kills the current region."

This is not accurate, is it?  If you invoke C-w immediately after
starting "emacs -Q", C-w currently signals an error.  Also, the new
user option should be mentioned here with its effect on what happens
in that case.

> +                   (cond
> +                    ((and beg end (use-region-p))
> +                     (list beg end 'region))
> +                    (kill-word-if-no-region
> +                     (list beg end 'kill-word))
> +                    ((user-error "The mark is not set now, so there is no region"))))))
> +

If transient-mark-mode is OFF and kill-word-if-no-region is non-nil,
this will always kill the previous word, right?  I think this is not
what we want, so I think the above should work specially if
transient-mark-mode is turned OFF.

Finally, this needs the suitable changes in the manuals.

Thanks.




This bug report was last modified today.

Previous Next


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