unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#69097: [PATCH] Add 'kill-region-or-word' command
@ 2024-02-13  9:55 Philip Kaludercic
  2024-02-17  3:53 ` Richard Stallman
  2024-05-03  7:37 ` Philip Kaludercic
  0 siblings, 2 replies; 33+ messages in thread
From: Philip Kaludercic @ 2024-02-13  9:55 UTC (permalink / raw)
  To: 69097

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

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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: [PATCH] Add 'kill-region-or-word' command --]
[-- Type: text/x-patch, Size: 1532 bytes --]

From b08b5cca09e1534b7ec28f516c891065eff80a9f Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <philipk@posteo.net>
Date: Tue, 13 Feb 2024 10:51:22 +0100
Subject: [PATCH] Add 'kill-region-or-word' command

* lisp/simple.el (kill-region-or-word): Add it.
* etc/NEWS: Document it.
---
 etc/NEWS       | 6 ++++++
 lisp/simple.el | 9 +++++++++
 2 files changed, 15 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index 6fae64728f2..e7e516d61a1 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -223,6 +223,12 @@ executable, if it exists.  This should remove the need to change its
 value when installing GNU coreutils using something like ports or
 Homebrew.
 
+---
+** New command 'kill-region-or-word'.
+This command will kill a region, if it is active, or delete the last
+word.  As such, it is a convenient alternative binding for C-w,
+providing a DWIM behaviour for both Emacs and Unix users.
+
 +++
 ** cl-print
 
diff --git a/lisp/simple.el b/lisp/simple.el
index 9a33049f4ca..bf4080fcf2d 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -8798,6 +8798,15 @@ backward-kill-word
   (interactive "p")
   (kill-word (- arg)))
 
+(defun kill-region-or-word ()
+  "Call `kill-region' if there is an active region.
+Otherwise kill the last word, just like Unix."
+  (interactive)
+  (call-interactively
+   (if (use-region-p)
+       #'kill-region
+     #'backward-kill-word)))
+
 (defun current-word (&optional strict really-word)
   "Return the word at or near point, as a string.
 The return value includes no text properties.
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* bug#69097: [PATCH] Add 'kill-region-or-word' command
  2024-02-13  9:55 bug#69097: [PATCH] Add 'kill-region-or-word' command Philip Kaludercic
@ 2024-02-17  3:53 ` Richard Stallman
       [not found]   ` <87ttm7gi9i.fsf@posteo.net>
  2024-05-03  7:37 ` Philip Kaludercic
  1 sibling, 1 reply; 33+ messages in thread
From: Richard Stallman @ 2024-02-17  3:53 UTC (permalink / raw)
  To: Philip Kaludercic; +Cc: 69097

[[[ 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)







^ permalink raw reply	[flat|nested] 33+ messages in thread

* bug#69097: [PATCH] Add 'kill-region-or-word' command
       [not found]   ` <87ttm7gi9i.fsf@posteo.net>
@ 2024-02-19  3:44     ` Richard Stallman
       [not found]       ` <87sf1obkw9.fsf@posteo.net>
  0 siblings, 1 reply; 33+ messages in thread
From: Richard Stallman @ 2024-02-19  3:44 UTC (permalink / raw)
  To: Philip Kaludercic; +Cc: 69097

[[[ 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)







^ permalink raw reply	[flat|nested] 33+ messages in thread

* bug#69097: [PATCH] Add 'kill-region-or-word' command
       [not found]       ` <87sf1obkw9.fsf@posteo.net>
@ 2024-02-23  3:04         ` Richard Stallman
       [not found]           ` <871q93rzv8.fsf@posteo.net>
  0 siblings, 1 reply; 33+ messages in thread
From: Richard Stallman @ 2024-02-23  3:04 UTC (permalink / raw)
  To: Philip Kaludercic; +Cc: 69097

[[[ 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)







^ permalink raw reply	[flat|nested] 33+ messages in thread

* bug#69097: [PATCH] Add 'kill-region-or-word' command
       [not found]           ` <871q93rzv8.fsf@posteo.net>
@ 2024-02-25  3:16             ` Richard Stallman
       [not found]               ` <87frxgn73g.fsf@posteo.net>
  0 siblings, 1 reply; 33+ messages in thread
From: Richard Stallman @ 2024-02-25  3:16 UTC (permalink / raw)
  To: Philip Kaludercic; +Cc: 69097

[[[ 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)







^ permalink raw reply	[flat|nested] 33+ messages in thread

* bug#69097: [PATCH] Add 'kill-region-or-word' command
       [not found]               ` <87frxgn73g.fsf@posteo.net>
@ 2024-02-27  3:12                 ` Richard Stallman
  0 siblings, 0 replies; 33+ messages in thread
From: Richard Stallman @ 2024-02-27  3:12 UTC (permalink / raw)
  To: Philip Kaludercic; +Cc: 69097

[[[ 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)







^ permalink raw reply	[flat|nested] 33+ messages in thread

* bug#69097: [PATCH] Add 'kill-region-or-word' command
  2024-02-13  9:55 bug#69097: [PATCH] Add 'kill-region-or-word' command Philip Kaludercic
  2024-02-17  3:53 ` Richard Stallman
@ 2024-05-03  7:37 ` Philip Kaludercic
  2024-05-03 10:40   ` Eli Zaretskii
  1 sibling, 1 reply; 33+ messages in thread
From: Philip Kaludercic @ 2024-05-03  7:37 UTC (permalink / raw)
  To: 69097

Philip Kaludercic <philipk@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





^ permalink raw reply	[flat|nested] 33+ messages in thread

* bug#69097: [PATCH] Add 'kill-region-or-word' command
  2024-05-03  7:37 ` Philip Kaludercic
@ 2024-05-03 10:40   ` Eli Zaretskii
  2024-05-03 10:48     ` Philip Kaludercic
  0 siblings, 1 reply; 33+ messages in thread
From: Eli Zaretskii @ 2024-05-03 10:40 UTC (permalink / raw)
  To: Philip Kaludercic; +Cc: Richard Stallman, 69097

> From: Philip Kaludercic <philipk@posteo.net>
> Date: Fri, 03 May 2024 07:37:03 +0000
> 
> Philip Kaludercic <philipk@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?





^ permalink raw reply	[flat|nested] 33+ messages in thread

* bug#69097: [PATCH] Add 'kill-region-or-word' command
  2024-05-03 10:40   ` Eli Zaretskii
@ 2024-05-03 10:48     ` Philip Kaludercic
  2024-05-03 10:59       ` Eli Zaretskii
  0 siblings, 1 reply; 33+ messages in thread
From: Philip Kaludercic @ 2024-05-03 10:48 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Richard Stallman, 69097

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Philip Kaludercic <philipk@posteo.net>
>> Date: Fri, 03 May 2024 07:37:03 +0000
>> 
>> Philip Kaludercic <philipk@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





^ permalink raw reply	[flat|nested] 33+ messages in thread

* bug#69097: [PATCH] Add 'kill-region-or-word' command
  2024-05-03 10:48     ` Philip Kaludercic
@ 2024-05-03 10:59       ` Eli Zaretskii
  2024-05-03 11:04         ` Eli Zaretskii
  2024-05-03 16:20         ` Philip Kaludercic
  0 siblings, 2 replies; 33+ messages in thread
From: Eli Zaretskii @ 2024-05-03 10:59 UTC (permalink / raw)
  To: Philip Kaludercic; +Cc: rms, 69097

> From: Philip Kaludercic <philipk@posteo.net>
> Cc: 69097@debbugs.gnu.org,  Richard Stallman <rms@gnu.org>
> Date: Fri, 03 May 2024 10:48:13 +0000
> 
> Eli Zaretskii <eliz@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?





^ permalink raw reply	[flat|nested] 33+ messages in thread

* bug#69097: [PATCH] Add 'kill-region-or-word' command
  2024-05-03 10:59       ` Eli Zaretskii
@ 2024-05-03 11:04         ` Eli Zaretskii
  2024-05-03 17:32           ` Philip Kaludercic
  2024-05-03 16:20         ` Philip Kaludercic
  1 sibling, 1 reply; 33+ messages in thread
From: Eli Zaretskii @ 2024-05-03 11:04 UTC (permalink / raw)
  To: philipk; +Cc: rms, 69097

> Cc: rms@gnu.org, 69097@debbugs.gnu.org
> Date: Fri, 03 May 2024 13:59:00 +0300
> From: Eli Zaretskii <eliz@gnu.org>
> 
> > From: Philip Kaludercic <philipk@posteo.net>
> > Cc: 69097@debbugs.gnu.org,  Richard Stallman <rms@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").





^ permalink raw reply	[flat|nested] 33+ messages in thread

* bug#69097: [PATCH] Add 'kill-region-or-word' command
  2024-05-03 10:59       ` Eli Zaretskii
  2024-05-03 11:04         ` Eli Zaretskii
@ 2024-05-03 16:20         ` Philip Kaludercic
  1 sibling, 0 replies; 33+ messages in thread
From: Philip Kaludercic @ 2024-05-03 16:20 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: rms, 69097

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Philip Kaludercic <philipk@posteo.net>
>> Cc: 69097@debbugs.gnu.org,  Richard Stallman <rms@gnu.org>
>> Date: Fri, 03 May 2024 10:48:13 +0000
>> 
>> Eli Zaretskii <eliz@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





^ permalink raw reply	[flat|nested] 33+ messages in thread

* bug#69097: [PATCH] Add 'kill-region-or-word' command
  2024-05-03 11:04         ` Eli Zaretskii
@ 2024-05-03 17:32           ` Philip Kaludercic
  2024-05-03 18:01             ` Eli Zaretskii
  0 siblings, 1 reply; 33+ messages in thread
From: Philip Kaludercic @ 2024-05-03 17:32 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: rms, 69097

Eli Zaretskii <eliz@gnu.org> writes:

>> Cc: rms@gnu.org, 69097@debbugs.gnu.org
>> Date: Fri, 03 May 2024 13:59:00 +0300
>> From: Eli Zaretskii <eliz@gnu.org>
>> 
>> > From: Philip Kaludercic <philipk@posteo.net>
>> > Cc: 69097@debbugs.gnu.org,  Richard Stallman <rms@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





^ permalink raw reply	[flat|nested] 33+ messages in thread

* bug#69097: [PATCH] Add 'kill-region-or-word' command
  2024-05-03 17:32           ` Philip Kaludercic
@ 2024-05-03 18:01             ` Eli Zaretskii
  2024-05-03 19:41               ` Philip Kaludercic
  0 siblings, 1 reply; 33+ messages in thread
From: Eli Zaretskii @ 2024-05-03 18:01 UTC (permalink / raw)
  To: Philip Kaludercic; +Cc: rms, 69097

> From: Philip Kaludercic <philipk@posteo.net>
> Cc: rms@gnu.org,  69097@debbugs.gnu.org
> Date: Fri, 03 May 2024 17:32:35 +0000
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> >> Cc: rms@gnu.org, 69097@debbugs.gnu.org
> >> Date: Fri, 03 May 2024 13:59:00 +0300
> >> From: Eli Zaretskii <eliz@gnu.org>
> >> 
> >> > From: Philip Kaludercic <philipk@posteo.net>
> >> > Cc: 69097@debbugs.gnu.org,  Richard Stallman <rms@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.





^ permalink raw reply	[flat|nested] 33+ messages in thread

* bug#69097: [PATCH] Add 'kill-region-or-word' command
  2024-05-03 18:01             ` Eli Zaretskii
@ 2024-05-03 19:41               ` Philip Kaludercic
  2024-05-04  6:20                 ` Eli Zaretskii
  2024-05-05  6:53                 ` Juri Linkov
  0 siblings, 2 replies; 33+ messages in thread
From: Philip Kaludercic @ 2024-05-03 19:41 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: rms, 69097

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

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Philip Kaludercic <philipk@posteo.net>
>> Cc: rms@gnu.org,  69097@debbugs.gnu.org
>> Date: Fri, 03 May 2024 17:32:35 +0000
>> 
>> Eli Zaretskii <eliz@gnu.org> writes:
>> 
>> >> Cc: rms@gnu.org, 69097@debbugs.gnu.org
>> >> Date: Fri, 03 May 2024 13:59:00 +0300
>> >> From: Eli Zaretskii <eliz@gnu.org>
>> >> 
>> >> > From: Philip Kaludercic <philipk@posteo.net>
>> >> > Cc: 69097@debbugs.gnu.org,  Richard Stallman <rms@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:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Allow-kill-region-to-delete-the-last-word.patch --]
[-- Type: text/x-patch, Size: 4702 bytes --]

From c64fa2065e88c4e4848bf8a15161c82ae6d1c2bd Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <philipk@posteo.net>
Date: Fri, 3 May 2024 21:38:51 +0200
Subject: [PATCH] Allow 'kill-region' to delete the last word

* lisp/simple.el (kill-word-if-no-region): Add new user option
to allow 'kill-region' to kill the last word if no region is
active.  The intention is to mirror the conventional C-w binding
found in many Unix shells.
(kill-region): Respect 'kill-word-if-no-region'.
* etc/NEWS: Mention the change.  (Bug#69097)
---
 etc/NEWS       |  6 ++++++
 lisp/simple.el | 43 ++++++++++++++++++++++++++++++-------------
 2 files changed, 36 insertions(+), 13 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index d4177d759f3..a0f2472ab67 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -416,6 +416,12 @@ When visiting a script that invokes 'env -S INTERPRETER ARGS...' in
 its shebang line, Emacs will now skip over 'env -S' and deduce the
 major mode based on the interpreter after 'env -S'.
 
+---
+*** 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.
+
 ** Emacs Server and Client
 
 ---
diff --git a/lisp/simple.el b/lisp/simple.el
index a459f6ecfd2..7fade562909 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -5790,6 +5790,11 @@ kill-read-only-ok
   :type 'boolean
   :group 'killing)
 
+(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)
+
 (defun kill-region (beg end &optional region)
   "Kill (\"cut\") text between point and mark.
 This deletes the text from the buffer and saves it in the kill ring.
@@ -5812,25 +5817,36 @@ kill-region
 the text, but put the text in the kill ring anyway.  This means that
 you can use the killing commands to copy text from a read-only buffer.
 
-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.  Interactively, REGION is always non-nil, and so
- this command always kills the current region."
+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'.  Interactively, REGION is always non-nil, and so
+this command always kills the current region."
   ;; Pass mark first, then point, because the order matters when
   ;; calling `kill-append'.
   (interactive (progn
                  (let ((beg (mark))
                        (end (point)))
-                   (unless (and beg end)
-                     (user-error "The mark is not set now, so there is no region"))
-                   (list beg end 'region))))
+                   (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"))))))
+
   (condition-case nil
-      (let ((string (if region
-                        (funcall region-extract-function 'delete)
-                      (filter-buffer-substring beg end 'delete))))
+      (let ((string (cond
+                     ((eq region 'kill-word)
+                      (let ((end (point)))
+                        (save-excursion
+                          (forward-word -1)
+                          (filter-buffer-substring (point) end 'delete))))
+                     (region
+                      (funcall region-extract-function 'delete))
+                     ((filter-buffer-substring beg end 'delete)))))
 	(when string			;STRING is nil if BEG = END
 	  ;; Add that string to the kill ring, one way or another.
 	  (if (eq last-command 'kill-region)
@@ -5857,6 +5873,7 @@ kill-region
        ;; If the buffer isn't read-only, the text is.
        (signal 'text-read-only (list (current-buffer)))))))
 
+
 ;; copy-region-as-kill no longer sets this-command, because it's confusing
 ;; to get two copies of the text when the user accidentally types M-w and
 ;; then corrects it with the intended C-w.
-- 
2.44.0


[-- Attachment #3: Type: text/plain, Size: 38 bytes --]



-- 
	Philip Kaludercic on peregrine

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* bug#69097: [PATCH] Add 'kill-region-or-word' command
  2024-05-03 19:41               ` Philip Kaludercic
@ 2024-05-04  6:20                 ` Eli Zaretskii
  2024-05-05  6:53                 ` Juri Linkov
  1 sibling, 0 replies; 33+ messages in thread
From: Eli Zaretskii @ 2024-05-04  6:20 UTC (permalink / raw)
  To: Philip Kaludercic; +Cc: rms, 69097

> From: Philip Kaludercic <philipk@posteo.net>
> Cc: rms@gnu.org,  69097@debbugs.gnu.org
> Date: Fri, 03 May 2024 19:41:43 +0000
> 
> Eli Zaretskii <eliz@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.





^ permalink raw reply	[flat|nested] 33+ messages in thread

* bug#69097: [PATCH] Add 'kill-region-or-word' command
  2024-05-03 19:41               ` Philip Kaludercic
  2024-05-04  6:20                 ` Eli Zaretskii
@ 2024-05-05  6:53                 ` Juri Linkov
  2024-05-05  9:04                   ` Eli Zaretskii
  2024-05-05 16:47                   ` Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors
  1 sibling, 2 replies; 33+ messages in thread
From: Juri Linkov @ 2024-05-05  6:53 UTC (permalink / raw)
  To: Philip Kaludercic; +Cc: Eli Zaretskii, rms, 69097

> +(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)

What a strange thing.  `kill-region' is not related to word commands
in no way.  Why not kill a sentence?  Why not kill a line?  Why just word?
All existing commands handle an active region.  But there is no commands
that do in the opposite direction where a general command handles
one random specific case.  This is because the region is a more
general concept.





^ permalink raw reply	[flat|nested] 33+ messages in thread

* bug#69097: [PATCH] Add 'kill-region-or-word' command
  2024-05-05  6:53                 ` Juri Linkov
@ 2024-05-05  9:04                   ` Eli Zaretskii
  2024-05-05 16:29                     ` Juri Linkov
  2024-05-06 16:46                     ` Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-05-05 16:47                   ` Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors
  1 sibling, 2 replies; 33+ messages in thread
From: Eli Zaretskii @ 2024-05-05  9:04 UTC (permalink / raw)
  To: Juri Linkov; +Cc: philipk, rms, 69097

> From: Juri Linkov <juri@linkov.net>
> Cc: Eli Zaretskii <eliz@gnu.org>,  rms@gnu.org,  69097@debbugs.gnu.org
> Date: Sun, 05 May 2024 09:53:19 +0300
> 
> > +(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)
> 
> What a strange thing.  `kill-region' is not related to word commands
> in no way.  Why not kill a sentence?  Why not kill a line?  Why just word?
> All existing commands handle an active region.  But there is no commands
> that do in the opposite direction where a general command handles
> one random specific case.  This is because the region is a more
> general concept.

https://debbugs.gnu.org/cgi/bugreport.cgi?bug=69097#14 is supposed to
provide the rationale (consistency with what C-w does in a terminal,
which I presume means in Bash or similar programs which use
Readline?).





^ permalink raw reply	[flat|nested] 33+ messages in thread

* bug#69097: [PATCH] Add 'kill-region-or-word' command
  2024-05-05  9:04                   ` Eli Zaretskii
@ 2024-05-05 16:29                     ` Juri Linkov
  2024-05-05 16:54                       ` Philip Kaludercic
  2024-05-06  0:21                       ` Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-05-06 16:46                     ` Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors
  1 sibling, 2 replies; 33+ messages in thread
From: Juri Linkov @ 2024-05-05 16:29 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: philipk, rms, 69097

>> > +(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)
>>
>> What a strange thing.  `kill-region' is not related to word commands
>> in no way.  Why not kill a sentence?  Why not kill a line?  Why just word?
>> All existing commands handle an active region.  But there is no commands
>> that do in the opposite direction where a general command handles
>> one random specific case.  This is because the region is a more
>> general concept.
>
> https://debbugs.gnu.org/cgi/bugreport.cgi?bug=69097#14 is supposed to
> provide the rationale (consistency with what C-w does in a terminal,
> which I presume means in Bash or similar programs which use
> Readline?).

So this is for Readline compatibility:

  unix-word-rubout (C-w)
    Kill the word behind point, using white space as a word boundary.
    The killed text is saved on the kill-ring.

Then I have no opinion, since 'backward-kill-word' (C-<backspace>, M-DEL).
already does this just fine.





^ permalink raw reply	[flat|nested] 33+ messages in thread

* bug#69097: [PATCH] Add 'kill-region-or-word' command
  2024-05-05  6:53                 ` Juri Linkov
  2024-05-05  9:04                   ` Eli Zaretskii
@ 2024-05-05 16:47                   ` Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors
  1 sibling, 0 replies; 33+ messages in thread
From: Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-05-05 16:47 UTC (permalink / raw)
  To: Juri Linkov, Philip Kaludercic
  Cc: Eli Zaretskii, rms@gnu.org, 69097@debbugs.gnu.org

> > +(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)
> 
> What a strange thing.  `kill-region' is not related to word commands
> in no way.  Why not kill a sentence?  Why not kill a line?  Why just
> word?
>
> All existing commands handle an active region.  But there is no commands
> that do in the opposite direction where a general command handles
> one random specific case.  This is because the region is a more
> general concept.

+1.  Finally some sense in this thread.

If there's no mark in a buffer when you use C-w
the logical behavior is to raise an error telling
you exactly that.  Emacs was wise to do this.

No mark means no region, which means no region to
kill.  (And how often does anyone see this error
when using C-w?)
___

Just as bad as giving C-w this unhelpful behavior
was redefining `kill-region' to give it the new
behavior, instead of binding C-w to a new command.
___

Having no mark is different from having an empty
region (whether or not transient-mark-mode is on).
An empty region is a bona fide region.  Killing
an empty region works; as does yanking it.  An
empty string on the kill ring affects yanking
just as one would expect.  Code can depend on it.





^ permalink raw reply	[flat|nested] 33+ messages in thread

* bug#69097: [PATCH] Add 'kill-region-or-word' command
  2024-05-05 16:29                     ` Juri Linkov
@ 2024-05-05 16:54                       ` Philip Kaludercic
  2024-05-05 16:59                         ` Juri Linkov
  2024-05-05 17:05                         ` Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-05-06  0:21                       ` Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors
  1 sibling, 2 replies; 33+ messages in thread
From: Philip Kaludercic @ 2024-05-05 16:54 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Eli Zaretskii, rms, 69097

Juri Linkov <juri@linkov.net> writes:

>>> > +(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)
>>>
>>> What a strange thing.  `kill-region' is not related to word commands
>>> in no way.  Why not kill a sentence?  Why not kill a line?  Why just word?
>>> All existing commands handle an active region.  But there is no commands
>>> that do in the opposite direction where a general command handles
>>> one random specific case.  This is because the region is a more
>>> general concept.
>>
>> https://debbugs.gnu.org/cgi/bugreport.cgi?bug=69097#14 is supposed to
>> provide the rationale (consistency with what C-w does in a terminal,
>> which I presume means in Bash or similar programs which use
>> Readline?).
>
> So this is for Readline compatibility:
>
>   unix-word-rubout (C-w)
>     Kill the word behind point, using white space as a word boundary.
>     The killed text is saved on the kill-ring.
>
> Then I have no opinion, since 'backward-kill-word' (C-<backspace>, M-DEL).
> already does this just fine.

Right, the initial command just merges `backward-kill-word' and
`kill-region' into one.

-- 
	Philip Kaludercic on icterid





^ permalink raw reply	[flat|nested] 33+ messages in thread

* bug#69097: [PATCH] Add 'kill-region-or-word' command
  2024-05-05 16:54                       ` Philip Kaludercic
@ 2024-05-05 16:59                         ` Juri Linkov
  2024-05-05 17:08                           ` Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-05-05 18:27                           ` Philip Kaludercic
  2024-05-05 17:05                         ` Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors
  1 sibling, 2 replies; 33+ messages in thread
From: Juri Linkov @ 2024-05-05 16:59 UTC (permalink / raw)
  To: Philip Kaludercic; +Cc: Eli Zaretskii, rms, 69097

>>>> > +(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)
>>>>
>>>> What a strange thing.  `kill-region' is not related to word commands
>>>> in no way.  Why not kill a sentence?  Why not kill a line?  Why just word?
>>>> All existing commands handle an active region.  But there is no commands
>>>> that do in the opposite direction where a general command handles
>>>> one random specific case.  This is because the region is a more
>>>> general concept.
>>>
>>> https://debbugs.gnu.org/cgi/bugreport.cgi?bug=69097#14 is supposed to
>>> provide the rationale (consistency with what C-w does in a terminal,
>>> which I presume means in Bash or similar programs which use
>>> Readline?).
>>
>> So this is for Readline compatibility:
>>
>>   unix-word-rubout (C-w)
>>     Kill the word behind point, using white space as a word boundary.
>>     The killed text is saved on the kill-ring.
>>
>> Then I have no opinion, since 'backward-kill-word' (C-<backspace>, M-DEL).
>> already does this just fine.
>
> Right, the initial command just merges `backward-kill-word' and
> `kill-region' into one.

There are two ways to merge:
1. `backward-kill-word' into `kill-region'
2. `kill-region' into `backward-kill-word'

I don't know why prefer one over another.





^ permalink raw reply	[flat|nested] 33+ messages in thread

* bug#69097: [PATCH] Add 'kill-region-or-word' command
  2024-05-05 16:54                       ` Philip Kaludercic
  2024-05-05 16:59                         ` Juri Linkov
@ 2024-05-05 17:05                         ` Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-05-05 17:13                           ` Eli Zaretskii
  1 sibling, 1 reply; 33+ messages in thread
From: Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-05-05 17:05 UTC (permalink / raw)
  To: Philip Kaludercic, Juri Linkov
  Cc: Eli Zaretskii, rms@gnu.org, 69097@debbugs.gnu.org

> Right, the initial command just merges `backward-kill-word' and
> `kill-region' into one.

`kill-region-or-backward-word', then.  And the
open question then should be whether to bind that
new command to C-w _by default_.  (My vote: no.)

If you like, just suggest to users, somewhere, to
start using that binding.  See if its use becomes
popular, THEN revisit the question here of giving
it `kill-region's longstanding default binding.

Just one opinion.





^ permalink raw reply	[flat|nested] 33+ messages in thread

* bug#69097: [PATCH] Add 'kill-region-or-word' command
  2024-05-05 16:59                         ` Juri Linkov
@ 2024-05-05 17:08                           ` Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-05-05 18:27                           ` Philip Kaludercic
  1 sibling, 0 replies; 33+ messages in thread
From: Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-05-05 17:08 UTC (permalink / raw)
  To: Juri Linkov, Philip Kaludercic
  Cc: Eli Zaretskii, rms@gnu.org, 69097@debbugs.gnu.org

> > Right, the initial command just merges `backward-kill-word' and
> > `kill-region' into one.
> 
> There are two ways to merge:
> 1. `backward-kill-word' into `kill-region'
> 2. `kill-region' into `backward-kill-word'
> 
> I don't know why prefer one over another.

Just please make the merge a _new_ command,
and don't give it the longstanding key for
either `kill-region' or `backward-kill-word'.
Don't give it any key binding by default.

That's the Emacs way, IMO.  If people tend
to bind it to some normally-taken key, such
as `C-w' or `M-DEL' THEN raise the question
of whether Emacs should change that binding
by default.





^ permalink raw reply	[flat|nested] 33+ messages in thread

* bug#69097: [PATCH] Add 'kill-region-or-word' command
  2024-05-05 17:05                         ` Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-05-05 17:13                           ` Eli Zaretskii
  2024-05-05 17:53                             ` Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 33+ messages in thread
From: Eli Zaretskii @ 2024-05-05 17:13 UTC (permalink / raw)
  To: Drew Adams; +Cc: philipk, rms, 69097, juri

> From: Drew Adams <drew.adams@oracle.com>
> CC: Eli Zaretskii <eliz@gnu.org>, "rms@gnu.org" <rms@gnu.org>,
>         "69097@debbugs.gnu.org" <69097@debbugs.gnu.org>
> Date: Sun, 5 May 2024 17:05:12 +0000
> 
> > Right, the initial command just merges `backward-kill-word' and
> > `kill-region' into one.
> 
> `kill-region-or-backward-word', then.  And the
> open question then should be whether to bind that
> new command to C-w _by default_.  (My vote: no.)
> 
> If you like, just suggest to users, somewhere, to
> start using that binding.  See if its use becomes
> popular, THEN revisit the question here of giving
> it `kill-region's longstanding default binding.
> 
> Just one opinion.

Did you notice that this behavior is off by default?





^ permalink raw reply	[flat|nested] 33+ messages in thread

* bug#69097: [PATCH] Add 'kill-region-or-word' command
  2024-05-05 17:13                           ` Eli Zaretskii
@ 2024-05-05 17:53                             ` Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 0 replies; 33+ messages in thread
From: Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-05-05 17:53 UTC (permalink / raw)
  To: Eli Zaretskii
  Cc: philipk@posteo.net, rms@gnu.org, 69097@debbugs.gnu.org,
	juri@linkov.net

> Did you notice that this behavior is off by default?

Good.





^ permalink raw reply	[flat|nested] 33+ messages in thread

* bug#69097: [PATCH] Add 'kill-region-or-word' command
  2024-05-05 16:59                         ` Juri Linkov
  2024-05-05 17:08                           ` Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-05-05 18:27                           ` Philip Kaludercic
  1 sibling, 0 replies; 33+ messages in thread
From: Philip Kaludercic @ 2024-05-05 18:27 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Eli Zaretskii, rms, 69097

Juri Linkov <juri@linkov.net> writes:

>>>>> > +(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)
>>>>>
>>>>> What a strange thing.  `kill-region' is not related to word commands
>>>>> in no way.  Why not kill a sentence?  Why not kill a line?  Why just word?
>>>>> All existing commands handle an active region.  But there is no commands
>>>>> that do in the opposite direction where a general command handles
>>>>> one random specific case.  This is because the region is a more
>>>>> general concept.
>>>>
>>>> https://debbugs.gnu.org/cgi/bugreport.cgi?bug=69097#14 is supposed to
>>>> provide the rationale (consistency with what C-w does in a terminal,
>>>> which I presume means in Bash or similar programs which use
>>>> Readline?).
>>>
>>> So this is for Readline compatibility:
>>>
>>>   unix-word-rubout (C-w)
>>>     Kill the word behind point, using white space as a word boundary.
>>>     The killed text is saved on the kill-ring.
>>>
>>> Then I have no opinion, since 'backward-kill-word' (C-<backspace>, M-DEL).
>>> already does this just fine.
>>
>> Right, the initial command just merges `backward-kill-word' and
>> `kill-region' into one.
>
> There are two ways to merge:
> 1. `backward-kill-word' into `kill-region'
> 2. `kill-region' into `backward-kill-word'

And

3. a separate command, like `kill-region-or-word'

> I don't know why prefer one over another.

-- 
	Philip Kaludercic on peregrine





^ permalink raw reply	[flat|nested] 33+ messages in thread

* bug#69097: [PATCH] Add 'kill-region-or-word' command
  2024-05-05 16:29                     ` Juri Linkov
  2024-05-05 16:54                       ` Philip Kaludercic
@ 2024-05-06  0:21                       ` Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors
  1 sibling, 0 replies; 33+ messages in thread
From: Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-05-06  0:21 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 69097

M-DEL and unix-word-rubout have different word boundaries though. I have bindings for both.
-- 
Sean Whitton

Please excuse top-posting and brevity. I am writing to you from a mobile phone.

> On 5 May 2024, at 17:45, Juri Linkov <juri@linkov.net> wrote:
> 
> 
>> 
>>>> +(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)
>>> 
>>> What a strange thing.  `kill-region' is not related to word commands
>>> in no way.  Why not kill a sentence?  Why not kill a line?  Why just word?
>>> All existing commands handle an active region.  But there is no commands
>>> that do in the opposite direction where a general command handles
>>> one random specific case.  This is because the region is a more
>>> general concept.
>> 
>> https://debbugs.gnu.org/cgi/bugreport.cgi?bug=69097#14 is supposed to
>> provide the rationale (consistency with what C-w does in a terminal,
>> which I presume means in Bash or similar programs which use
>> Readline?).
> 
> So this is for Readline compatibility:
> 
>  unix-word-rubout (C-w)
>    Kill the word behind point, using white space as a word boundary.
>    The killed text is saved on the kill-ring.
> 
> Then I have no opinion, since 'backward-kill-word' (C-<backspace>, M-DEL).
> already does this just fine.
> 
> 
> 






^ permalink raw reply	[flat|nested] 33+ messages in thread

* bug#69097: [PATCH] Add 'kill-region-or-word' command
  2024-05-05  9:04                   ` Eli Zaretskii
  2024-05-05 16:29                     ` Juri Linkov
@ 2024-05-06 16:46                     ` Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-05-06 16:51                       ` Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors
  1 sibling, 1 reply; 33+ messages in thread
From: Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-05-06 16:46 UTC (permalink / raw)
  To: Eli Zaretskii, Juri Linkov, philipk, rms, 69097

Hello,

On Sun 05 May 2024 at 12:04pm +03, Eli Zaretskii wrote:

>> From: Juri Linkov <juri@linkov.net>
>> Cc: Eli Zaretskii <eliz@gnu.org>,  rms@gnu.org,  69097@debbugs.gnu.org
>> Date: Sun, 05 May 2024 09:53:19 +0300
>>
>> > +(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)
>>
>> What a strange thing.  `kill-region' is not related to word commands
>> in no way.  Why not kill a sentence?  Why not kill a line?  Why just word?
>> All existing commands handle an active region.  But there is no commands
>> that do in the opposite direction where a general command handles
>> one random specific case.  This is because the region is a more
>> general concept.
>
> https://debbugs.gnu.org/cgi/bugreport.cgi?bug=69097#14 is supposed to
> provide the rationale (consistency with what C-w does in a terminal,
> which I presume means in Bash or similar programs which use
> Readline?).

I am concerned that the difference between Emacs's backward-kill-word
and the tty unix-word-rubout is not being taken into account with this
change proposal.

In bash on Linux there is actually both M-DEL and C-w, and they do
different things, and it's useful to have both.
E.g. if you have a half-entered command

    % foo bar/baz/quux

with point at the end of the line, then M-DEL can be used to delete
individual path components, e.g. M-DEL M-DEL will get you

    % foo bar/

which is nice if you need to correct some path components.
But C-w always deletes back to whitespace, in this case leaving just
'foo', so you can replace the whole argument, or several arguments, with
C-w, instead of having to type M-DEL lots of times.

So if what we're aiming for here is concordance with the terminal, then
the fallback behaviour should not be Emacs's backward-kill-word, but a
new command that's more like unix-word-rubout.

But then, I'm not sure introducing something that funadmental to Emacs's
basic command set is appropriate in the context of thinking about
fallback behaviour.

(I have C-w in Emacs be like unix-word-rubout, keep M-DEL as the
default, and move kill-region elsewhere.)

-- 
Sean Whitton





^ permalink raw reply	[flat|nested] 33+ messages in thread

* bug#69097: [PATCH] Add 'kill-region-or-word' command
  2024-05-06 16:46                     ` Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-05-06 16:51                       ` Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-05-06 17:55                         ` Eli Zaretskii
  0 siblings, 1 reply; 33+ messages in thread
From: Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-05-06 16:51 UTC (permalink / raw)
  To: Eli Zaretskii, Juri Linkov, philipk, rms, 69097

Hello,

On Mon 06 May 2024 at 05:46pm +01, Sean Whitton wrote:
>
> In bash on Linux [...]

I specifically called out Linux because while GNU readline has a
unix-word-rubout command, C-w in the Linux tty is actually implemented
in the Linux-specific tty layer, below readline.

-- 
Sean Whitton





^ permalink raw reply	[flat|nested] 33+ messages in thread

* bug#69097: [PATCH] Add 'kill-region-or-word' command
  2024-05-06 16:51                       ` Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-05-06 17:55                         ` Eli Zaretskii
  2024-05-07  8:47                           ` Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 33+ messages in thread
From: Eli Zaretskii @ 2024-05-06 17:55 UTC (permalink / raw)
  To: Sean Whitton; +Cc: philipk, rms, 69097, juri

> From: Sean Whitton <spwhitton@spwhitton.name>
> Date: Mon, 06 May 2024 17:51:48 +0100
> 
> On Mon 06 May 2024 at 05:46pm +01, Sean Whitton wrote:
> >
> > In bash on Linux [...]
> 
> I specifically called out Linux because while GNU readline has a
> unix-word-rubout command, C-w in the Linux tty is actually implemented
> in the Linux-specific tty layer, below readline.

Evidently, the above is inaccurate, because I see the same behavior in
Bash on MS-Windows.





^ permalink raw reply	[flat|nested] 33+ messages in thread

* bug#69097: [PATCH] Add 'kill-region-or-word' command
  2024-05-06 17:55                         ` Eli Zaretskii
@ 2024-05-07  8:47                           ` Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-05-07  8:47                             ` Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 33+ messages in thread
From: Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-05-07  8:47 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: philipk, rms, 69097, juri

Hello,

On Mon 06 May 2024 at 08:55pm +03, Eli Zaretskii wrote:

>> From: Sean Whitton <spwhitton@spwhitton.name>
>> Date: Mon, 06 May 2024 17:51:48 +0100
>>
>> On Mon 06 May 2024 at 05:46pm +01, Sean Whitton wrote:
>> >
>> > In bash on Linux [...]
>>
>> I specifically called out Linux because while GNU readline has a
>> unix-word-rubout command, C-w in the Linux tty is actually implemented
>> in the Linux-specific tty layer, below readline.
>
> Evidently, the above is inaccurate, because I see the same behavior in
> Bash on MS-Windows.

I believe that this is why readline has the unix-word-rubout command, to
ensure that terminal emulators work the same as the tty.  Anyway, this
is just implementation and not relevant to Jim's patch.

-- 
Sean Whitton





^ permalink raw reply	[flat|nested] 33+ messages in thread

* bug#69097: [PATCH] Add 'kill-region-or-word' command
  2024-05-07  8:47                           ` Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-05-07  8:47                             ` Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 0 replies; 33+ messages in thread
From: Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-05-07  8:47 UTC (permalink / raw)
  To: Eli Zaretskii, juri, philipk, rms, 69097

On Tue 07 May 2024 at 09:47am +01, Sean Whitton wrote:

>
> I believe that this is why readline has the unix-word-rubout command, to
> ensure that terminal emulators work the same as the tty.  Anyway, this
> is just implementation and not relevant to Jim's patch.

Phil's patch*


-- 
Sean Whitton





^ permalink raw reply	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2024-05-07  8:47 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-13  9:55 bug#69097: [PATCH] Add 'kill-region-or-word' command Philip Kaludercic
2024-02-17  3:53 ` Richard Stallman
     [not found]   ` <87ttm7gi9i.fsf@posteo.net>
2024-02-19  3:44     ` Richard Stallman
     [not found]       ` <87sf1obkw9.fsf@posteo.net>
2024-02-23  3:04         ` Richard Stallman
     [not found]           ` <871q93rzv8.fsf@posteo.net>
2024-02-25  3:16             ` Richard Stallman
     [not found]               ` <87frxgn73g.fsf@posteo.net>
2024-02-27  3:12                 ` Richard Stallman
2024-05-03  7:37 ` Philip Kaludercic
2024-05-03 10:40   ` Eli Zaretskii
2024-05-03 10:48     ` Philip Kaludercic
2024-05-03 10:59       ` Eli Zaretskii
2024-05-03 11:04         ` Eli Zaretskii
2024-05-03 17:32           ` Philip Kaludercic
2024-05-03 18:01             ` Eli Zaretskii
2024-05-03 19:41               ` Philip Kaludercic
2024-05-04  6:20                 ` Eli Zaretskii
2024-05-05  6:53                 ` Juri Linkov
2024-05-05  9:04                   ` Eli Zaretskii
2024-05-05 16:29                     ` Juri Linkov
2024-05-05 16:54                       ` Philip Kaludercic
2024-05-05 16:59                         ` Juri Linkov
2024-05-05 17:08                           ` Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-05 18:27                           ` Philip Kaludercic
2024-05-05 17:05                         ` Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-05 17:13                           ` Eli Zaretskii
2024-05-05 17:53                             ` Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-06  0:21                       ` Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-06 16:46                     ` Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-06 16:51                       ` Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-06 17:55                         ` Eli Zaretskii
2024-05-07  8:47                           ` Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-07  8:47                             ` Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-05 16:47                   ` Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-03 16:20         ` Philip Kaludercic

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).