* 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; 90+ 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] 90+ 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; 90+ 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] 90+ 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; 90+ 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] 90+ 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; 90+ 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] 90+ 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; 90+ 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] 90+ 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; 90+ 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] 90+ 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; 90+ 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] 90+ 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; 90+ 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] 90+ 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; 90+ 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] 90+ 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; 90+ 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] 90+ 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; 90+ 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] 90+ 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; 90+ 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] 90+ 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; 90+ 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] 90+ 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; 90+ 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] 90+ 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; 90+ 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] 90+ 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; 90+ 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] 90+ 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; 90+ 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] 90+ 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; 90+ 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] 90+ 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; 90+ 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] 90+ 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; 90+ 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] 90+ 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; 90+ 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] 90+ 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; 90+ 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] 90+ 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; 90+ 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] 90+ 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; 90+ 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] 90+ 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; 90+ 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] 90+ 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; 90+ 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] 90+ 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; 90+ 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] 90+ 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; 90+ 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] 90+ 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; 90+ 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] 90+ 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; 90+ 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] 90+ 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
2024-09-01 20:06 ` Philip Kaludercic
0 siblings, 2 replies; 90+ 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] 90+ 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
2024-09-01 20:06 ` Philip Kaludercic
1 sibling, 1 reply; 90+ 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] 90+ 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; 90+ 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] 90+ 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-09-01 20:06 ` Philip Kaludercic
2024-09-02 6:36 ` Sean Whitton
2024-09-02 11:18 ` Eli Zaretskii
1 sibling, 2 replies; 90+ messages in thread
From: Philip Kaludercic @ 2024-09-01 20:06 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: juri, rms, 69097, Sean Whitton
Eli Zaretskii <eliz@gnu.org> writes:
>> 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.
Ping. I am not sure how to proceed on this patch. IIRC the issue was
that the notion of a word differs in Emacs and in Bash. I am still in
favour of utilising Emacs's definition, as it remains more useful
for some given major mode and the fact that it is easier to implement.
--
Philip Kaludercic on peregrine
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-01 20:06 ` Philip Kaludercic
@ 2024-09-02 6:36 ` Sean Whitton
2024-09-02 11:18 ` Eli Zaretskii
1 sibling, 0 replies; 90+ messages in thread
From: Sean Whitton @ 2024-09-02 6:36 UTC (permalink / raw)
To: Philip Kaludercic; +Cc: Eli Zaretskii, rms, 69097, juri
Hello,
On Sun 01 Sep 2024 at 08:06pm GMT, Philip Kaludercic wrote:
> Ping. I am not sure how to proceed on this patch. IIRC the issue was
> that the notion of a word differs in Emacs and in Bash. I am still in
> favour of utilising Emacs's definition, as it remains more useful
> for some given major mode and the fact that it is easier to implement.
Please take a look at my longer message. I don't think it has been
addressed.
--
Sean Whitton
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-01 20:06 ` Philip Kaludercic
2024-09-02 6:36 ` Sean Whitton
@ 2024-09-02 11:18 ` Eli Zaretskii
2024-09-02 18:30 ` Stefan Kangas
2024-09-02 20:39 ` Philip Kaludercic
1 sibling, 2 replies; 90+ messages in thread
From: Eli Zaretskii @ 2024-09-02 11:18 UTC (permalink / raw)
To: Philip Kaludercic, Stefan Kangas, Andrea Corallo
Cc: juri, rms, 69097, spwhitton
> From: Philip Kaludercic <philipk@posteo.net>
> Cc: Sean Whitton <spwhitton@spwhitton.name>, juri@linkov.net, rms@gnu.org,
> 69097@debbugs.gnu.org
> Date: Sun, 01 Sep 2024 20:06:00 +0000
>
> Eli Zaretskii <eliz@gnu.org> writes:
>
> >> 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.
>
> Ping. I am not sure how to proceed on this patch. IIRC the issue was
> that the notion of a word differs in Emacs and in Bash. I am still in
> favour of utilising Emacs's definition, as it remains more useful
> for some given major mode and the fact that it is easier to implement.
Or you could make the defcustom a tristate, and implement both
behaviors...
As for how to proceed: Stefan and Andrea, do you have an opinion on
this?
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-02 11:18 ` Eli Zaretskii
@ 2024-09-02 18:30 ` Stefan Kangas
2024-09-02 18:45 ` Sean Whitton
2024-09-02 20:39 ` Philip Kaludercic
1 sibling, 1 reply; 90+ messages in thread
From: Stefan Kangas @ 2024-09-02 18:30 UTC (permalink / raw)
To: Eli Zaretskii, Philip Kaludercic, Andrea Corallo
Cc: juri, rms, 69097, spwhitton
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Philip Kaludercic <philipk@posteo.net>
>> Cc: Sean Whitton <spwhitton@spwhitton.name>, juri@linkov.net, rms@gnu.org,
>> 69097@debbugs.gnu.org
>> Date: Sun, 01 Sep 2024 20:06:00 +0000
>>
>> Ping. I am not sure how to proceed on this patch. IIRC the issue was
>> that the notion of a word differs in Emacs and in Bash. I am still in
>> favour of utilising Emacs's definition, as it remains more useful
>> for some given major mode and the fact that it is easier to implement.
>
> Or you could make the defcustom a tristate, and implement both
> behaviors...
>
> As for how to proceed: Stefan and Andrea, do you have an opinion on
> this?
Binding C-w to backward-kill-word, or some version thereof, is an old
Emacs power user trick that has been recommended in many places over the
years. See, for example:
https://sites.google.com/site/steveyegge2/effective-emacs#h.p_ID_193
https://emacs-fu.blogspot.com/2009/11/copying-lines-without-selecting-them.html
So I think this command would be a good addition. Making the word
boundary behaviour into a tristate option sounds like a reasonable way
forward, which should make everyone happy and let people experiment with
what works best for them.
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-02 18:30 ` Stefan Kangas
@ 2024-09-02 18:45 ` Sean Whitton
0 siblings, 0 replies; 90+ messages in thread
From: Sean Whitton @ 2024-09-02 18:45 UTC (permalink / raw)
To: Stefan Kangas, Eli Zaretskii, Philip Kaludercic, Andrea Corallo,
juri, rms, 69097
Hello,
On Mon 02 Sep 2024 at 11:30am -07, Stefan Kangas wrote:
> Binding C-w to backward-kill-word, or some version thereof, is an old
> Emacs power user trick that has been recommended in many places over the
> years. See, for example:
> https://sites.google.com/site/steveyegge2/effective-emacs#h.p_ID_193
> https://emacs-fu.blogspot.com/2009/11/copying-lines-without-selecting-them.html
>
> So I think this command would be a good addition. Making the word
> boundary behaviour into a tristate option sounds like a reasonable way
> forward, which should make everyone happy and let people experiment with
> what works best for them.
For reference purposes while implementing the tristate, here is my
implementation of the Unix behaviour from my init.
Should be helpful, though there is lots of room for improvement :)
(defun spw/unix-word-rubout (arg &optional pos neg)
(interactive "p")
;; Do skip over \n because `backward-kill-word' does.
(unless pos (setq pos "[:space:]\n"))
(unless neg (setq neg "^[:space:]\n"))
(undo-boundary)
(let ((start (point)))
;; Go only backwards.
(dotimes (_ (abs arg))
(skip-chars-backward pos)
(skip-chars-backward neg))
;; Skip forward over any read-only text (e.g. an Eshell or comint prompt).
(when-let ((beg (and (get-char-property (point) 'read-only)
(next-single-char-property-change
(point) 'read-only nil start))))
(goto-char beg))
(kill-region start (point))))
--
Sean Whitton
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-02 11:18 ` Eli Zaretskii
2024-09-02 18:30 ` Stefan Kangas
@ 2024-09-02 20:39 ` Philip Kaludercic
2024-09-02 20:42 ` Sean Whitton
1 sibling, 1 reply; 90+ messages in thread
From: Philip Kaludercic @ 2024-09-02 20:39 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: rms, 69097, juri, Stefan Kangas, Andrea Corallo, spwhitton
Stefan Kangas <stefankangas@gmail.com> writes:
> Eli Zaretskii <eliz@gnu.org> writes:
>
>>> From: Philip Kaludercic <philipk@posteo.net>
>>> Cc: Sean Whitton <spwhitton@spwhitton.name>, juri@linkov.net, rms@gnu.org,
>>> 69097@debbugs.gnu.org
>>> Date: Sun, 01 Sep 2024 20:06:00 +0000
>>>
>>> Ping. I am not sure how to proceed on this patch. IIRC the issue was
>>> that the notion of a word differs in Emacs and in Bash. I am still in
>>> favour of utilising Emacs's definition, as it remains more useful
>>> for some given major mode and the fact that it is easier to implement.
>>
>> Or you could make the defcustom a tristate, and implement both
>> behaviors...
>>
>> As for how to proceed: Stefan and Andrea, do you have an opinion on
>> this?
>
> Binding C-w to backward-kill-word, or some version thereof, is an old
> Emacs power user trick that has been recommended in many places over the
> years. See, for example:
> https://sites.google.com/site/steveyegge2/effective-emacs#h.p_ID_193
> https://emacs-fu.blogspot.com/2009/11/copying-lines-without-selecting-them.html
>
> So I think this command would be a good addition. Making the word
> boundary behaviour into a tristate option sounds like a reasonable way
> forward, which should make everyone happy and let people experiment with
> what works best for them.
How about this suggestion: We add a generic kill-region-or-word
command, and a user option for a function (set to either
`backward-kill-word' or Sean's `unix-word-rubout'). I can prepare a
patch with the simpler version, and then Sean can add his behaviour in a
second patch so that the attribution remains correct.
Sean Whitton <spwhitton@spwhitton.name> writes:
> Hello,
>
> On Mon 02 Sep 2024 at 11:30am -07, Stefan Kangas wrote:
>
>> Binding C-w to backward-kill-word, or some version thereof, is an old
>> Emacs power user trick that has been recommended in many places over the
>> years. See, for example:
>> https://sites.google.com/site/steveyegge2/effective-emacs#h.p_ID_193
>> https://emacs-fu.blogspot.com/2009/11/copying-lines-without-selecting-them.html
>>
>> So I think this command would be a good addition. Making the word
>> boundary behaviour into a tristate option sounds like a reasonable way
>> forward, which should make everyone happy and let people experiment with
>> what works best for them.
>
> For reference purposes while implementing the tristate, here is my
> implementation of the Unix behaviour from my init.
> Should be helpful, though there is lots of room for improvement :)
>
> (defun spw/unix-word-rubout (arg &optional pos neg)
> (interactive "p")
> ;; Do skip over \n because `backward-kill-word' does.
> (unless pos (setq pos "[:space:]\n"))
> (unless neg (setq neg "^[:space:]\n"))
> (undo-boundary)
> (let ((start (point)))
> ;; Go only backwards.
> (dotimes (_ (abs arg))
> (skip-chars-backward pos)
> (skip-chars-backward neg))
> ;; Skip forward over any read-only text (e.g. an Eshell or comint prompt).
> (when-let ((beg (and (get-char-property (point) 'read-only)
> (next-single-char-property-change
> (point) 'read-only nil start))))
> (goto-char beg))
> (kill-region start (point))))
FWIW I don't have any suggestions on how to improve the function either.
I wonder if it would make sense to have a minor mode like subword-mode
that would enforce a understanding of words like implemented here.
--
Philip Kaludercic on peregrine
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-02 20:39 ` Philip Kaludercic
@ 2024-09-02 20:42 ` Sean Whitton
2024-09-02 20:45 ` Philip Kaludercic
2024-09-02 20:46 ` Sean Whitton
0 siblings, 2 replies; 90+ messages in thread
From: Sean Whitton @ 2024-09-02 20:42 UTC (permalink / raw)
To: Philip Kaludercic
Cc: rms, 69097, juri, Stefan Kangas, Eli Zaretskii, Andrea Corallo
Hello,
On Mon 02 Sep 2024 at 08:39pm GMT, Philip Kaludercic wrote:
> How about this suggestion: We add a generic kill-region-or-word
> command, and a user option for a function (set to either
> `backward-kill-word' or Sean's `unix-word-rubout'). I can prepare a
> patch with the simpler version, and then Sean can add his behaviour in a
> second patch so that the attribution remains correct.
I think a tristate option is preferable to this.
If the user wants something of their own they can just write their own
command.
--
Sean Whitton
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-02 20:42 ` Sean Whitton
@ 2024-09-02 20:45 ` Philip Kaludercic
2024-09-02 20:46 ` Sean Whitton
1 sibling, 0 replies; 90+ messages in thread
From: Philip Kaludercic @ 2024-09-02 20:45 UTC (permalink / raw)
To: Sean Whitton
Cc: rms, 69097, juri, Stefan Kangas, Eli Zaretskii, Andrea Corallo
Sean Whitton <spwhitton@spwhitton.name> writes:
> Hello,
>
> On Mon 02 Sep 2024 at 08:39pm GMT, Philip Kaludercic wrote:
>
>> How about this suggestion: We add a generic kill-region-or-word
>> command, and a user option for a function (set to either
>> `backward-kill-word' or Sean's `unix-word-rubout'). I can prepare a
>> patch with the simpler version, and then Sean can add his behaviour in a
>> second patch so that the attribution remains correct.
>
> I think a tristate option is preferable to this.
It would still be a user options with three states:
- nil (default, don't delete a word)
- #'backward-kill-word
- #'unix-word-rubout
> If the user wants something of their own they can just write their own
> command.
Sure, but going by that logic we don't need this change at all.
--
Philip Kaludercic on peregrine
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-02 20:42 ` Sean Whitton
2024-09-02 20:45 ` Philip Kaludercic
@ 2024-09-02 20:46 ` Sean Whitton
2024-09-02 21:12 ` Philip Kaludercic
1 sibling, 1 reply; 90+ messages in thread
From: Sean Whitton @ 2024-09-02 20:46 UTC (permalink / raw)
To: Philip Kaludercic
Cc: rms, 69097, juri, Stefan Kangas, Eli Zaretskii, Andrea Corallo
Hello,
On Mon 02 Sep 2024 at 09:42pm +01, Sean Whitton wrote:
> Hello,
>
> On Mon 02 Sep 2024 at 08:39pm GMT, Philip Kaludercic wrote:
>
>> How about this suggestion: We add a generic kill-region-or-word
>> command, and a user option for a function (set to either
>> `backward-kill-word' or Sean's `unix-word-rubout'). I can prepare a
>> patch with the simpler version, and then Sean can add his behaviour in a
>> second patch so that the attribution remains correct.
>
> I think a tristate option is preferable to this.
>
> If the user wants something of their own they can just write their own
> command.
Sorry, I wrote this too quickly, I don't think I actually understand
your new proposal.
Could you sketch it out?
Thank you for your patience on this one.
--
Sean Whitton
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-02 20:46 ` Sean Whitton
@ 2024-09-02 21:12 ` Philip Kaludercic
2024-09-03 12:21 ` Eli Zaretskii
0 siblings, 1 reply; 90+ messages in thread
From: Philip Kaludercic @ 2024-09-02 21:12 UTC (permalink / raw)
To: Sean Whitton
Cc: rms, 69097, juri, Stefan Kangas, Eli Zaretskii, Andrea Corallo
[-- Attachment #1: Type: text/plain, Size: 977 bytes --]
Sean Whitton <spwhitton@spwhitton.name> writes:
> Hello,
>
> On Mon 02 Sep 2024 at 09:42pm +01, Sean Whitton wrote:
>
>> Hello,
>>
>> On Mon 02 Sep 2024 at 08:39pm GMT, Philip Kaludercic wrote:
>>
>>> How about this suggestion: We add a generic kill-region-or-word
>>> command, and a user option for a function (set to either
>>> `backward-kill-word' or Sean's `unix-word-rubout'). I can prepare a
>>> patch with the simpler version, and then Sean can add his behaviour in a
>>> second patch so that the attribution remains correct.
>>
>> I think a tristate option is preferable to this.
>>
>> If the user wants something of their own they can just write their own
>> command.
>
> Sorry, I wrote this too quickly, I don't think I actually understand
> your new proposal.
>
> Could you sketch it out?
>
> Thank you for your patience on this one.
I had misremembered the last state of this patch. It is easier to just
have a tristate option. Here is the updated proposal:
[-- Attachment #2: Type: text/plain, Size: 4174 bytes --]
diff --git a/lisp/simple.el b/lisp/simple.el
index eedc5768fe2..9ce108089e7 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -5817,6 +5817,17 @@ kill-read-only-ok
:type 'boolean
:group 'killing)
+(defcustom kill-word-if-no-region nil
+ "Behaviour when `kill-region' is invoked without an active region.
+If set to nil (default), then an error occurs and nothing is killed. If
+set to `emacs-word', then kill a the last word as defined by the current
+major mode. If set to `unix-word', then kill the last word in the style
+of a shell like Bash, disregarding the major mode."
+ :type '(choice (const :tag "Kill a word like `backward-kill-word'" emacs-word)
+ (const :tag "Kill a word like Bash would" unix-word)
+ (const :tag "Do not kill anything" nil))
+ :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.
@@ -5839,25 +5850,47 @@ 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-if-no-region))
+ ((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 'emacs-word)
+ (let ((end (point)))
+ (save-excursion
+ (forward-word -1)
+ (filter-buffer-substring (point) end 'delete))))
+ ((eq region 'unix-word)
+ (let ((end (point)))
+ (save-excursion
+ (skip-chars-backward "[:space:]")
+ (skip-chars-backward "^[:space:]")
+ (filter-buffer-substring
+ (if (get-char-property (point) 'read-only)
+ (next-single-char-property-change
+ (point) 'read-only nil end)
+ (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)
[-- Attachment #3: Type: text/plain, Size: 37 bytes --]
--
Philip Kaludercic on peregrine
^ permalink raw reply related [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-02 21:12 ` Philip Kaludercic
@ 2024-09-03 12:21 ` Eli Zaretskii
2024-09-03 13:53 ` Robert Pluim
2024-09-03 16:32 ` Philip Kaludercic
0 siblings, 2 replies; 90+ messages in thread
From: Eli Zaretskii @ 2024-09-03 12:21 UTC (permalink / raw)
To: Philip Kaludercic; +Cc: rms, 69097, juri, stefankangas, acorallo, spwhitton
> From: Philip Kaludercic <philipk@posteo.net>
> Cc: Eli Zaretskii <eliz@gnu.org>, Stefan Kangas <stefankangas@gmail.com>,
> Andrea Corallo <acorallo@gnu.org>, juri@linkov.net, rms@gnu.org,
> 69097@debbugs.gnu.org
> Date: Mon, 02 Sep 2024 21:12:01 +0000
>
> I had misremembered the last state of this patch. It is easier to just
> have a tristate option. Here is the updated proposal:
Thanks.
> +(defcustom kill-word-if-no-region nil
I would call this 'kill-region-dwim' instead.
> + "Behaviour when `kill-region' is invoked without an active region.
> +If set to nil (default), then an error occurs and nothing is killed. If
> +set to `emacs-word', then kill a the last word as defined by the current
> +major mode. If set to `unix-word', then kill the last word in the style
> +of a shell like Bash, disregarding the major mode."
> + :type '(choice (const :tag "Kill a word like `backward-kill-word'" emacs-word)
> + (const :tag "Kill a word like Bash would" unix-word)
> + (const :tag "Do not kill anything" nil))
> + :group 'killing)
:version tag is missing.
> -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
Not sure why you decided to reformat this part. Its formatting was
not random.
This also needs a NEWS entry.
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-03 12:21 ` Eli Zaretskii
@ 2024-09-03 13:53 ` Robert Pluim
2024-09-03 14:27 ` Eli Zaretskii
2024-09-03 16:32 ` Philip Kaludercic
1 sibling, 1 reply; 90+ messages in thread
From: Robert Pluim @ 2024-09-03 13:53 UTC (permalink / raw)
To: Eli Zaretskii
Cc: Philip Kaludercic, rms, 69097, juri, stefankangas, acorallo,
spwhitton
>>>>> On Tue, 03 Sep 2024 15:21:54 +0300, Eli Zaretskii <eliz@gnu.org> said:
>> From: Philip Kaludercic <philipk@posteo.net>
>> Cc: Eli Zaretskii <eliz@gnu.org>, Stefan Kangas <stefankangas@gmail.com>,
>> Andrea Corallo <acorallo@gnu.org>, juri@linkov.net, rms@gnu.org,
>> 69097@debbugs.gnu.org
>> Date: Mon, 02 Sep 2024 21:12:01 +0000
>>
>> I had misremembered the last state of this patch. It is easier to just
>> have a tristate option. Here is the updated proposal:
Eli> Thanks.
>> +(defcustom kill-word-if-no-region nil
Eli> I would call this 'kill-region-dwim' instead.
>> + "Behaviour when `kill-region' is invoked without an active region.
>> +If set to nil (default), then an error occurs and nothing is killed. If
>> +set to `emacs-word', then kill a the last word as defined by the current
>> +major mode. If set to `unix-word', then kill the last word in the style
>> +of a shell like Bash, disregarding the major mode."
>> + :type '(choice (const :tag "Kill a word like `backward-kill-word'" emacs-word)
>> + (const :tag "Kill a word like Bash would" unix-word)
>> + (const :tag "Do not kill anything" nil))
>> + :group 'killing)
Eli> :version tag is missing.
Is it worth allowing a user-specified function?
Robert
--
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-03 13:53 ` Robert Pluim
@ 2024-09-03 14:27 ` Eli Zaretskii
2024-09-03 14:55 ` Robert Pluim
0 siblings, 1 reply; 90+ messages in thread
From: Eli Zaretskii @ 2024-09-03 14:27 UTC (permalink / raw)
To: Robert Pluim; +Cc: philipk, rms, 69097, juri, stefankangas, acorallo, spwhitton
> From: Robert Pluim <rpluim@gmail.com>
> Cc: Philip Kaludercic <philipk@posteo.net>, rms@gnu.org,
> 69097@debbugs.gnu.org, juri@linkov.net, stefankangas@gmail.com,
> acorallo@gnu.org, spwhitton@spwhitton.name
> Date: Tue, 03 Sep 2024 15:53:39 +0200
>
> >>>>> On Tue, 03 Sep 2024 15:21:54 +0300, Eli Zaretskii <eliz@gnu.org> said:
>
> >> From: Philip Kaludercic <philipk@posteo.net>
> >> Cc: Eli Zaretskii <eliz@gnu.org>, Stefan Kangas <stefankangas@gmail.com>,
> >> Andrea Corallo <acorallo@gnu.org>, juri@linkov.net, rms@gnu.org,
> >> 69097@debbugs.gnu.org
> >> Date: Mon, 02 Sep 2024 21:12:01 +0000
> >>
> >> I had misremembered the last state of this patch. It is easier to just
> >> have a tristate option. Here is the updated proposal:
>
> Eli> Thanks.
>
> >> +(defcustom kill-word-if-no-region nil
>
> Eli> I would call this 'kill-region-dwim' instead.
>
> >> + "Behaviour when `kill-region' is invoked without an active region.
> >> +If set to nil (default), then an error occurs and nothing is killed. If
> >> +set to `emacs-word', then kill a the last word as defined by the current
> >> +major mode. If set to `unix-word', then kill the last word in the style
> >> +of a shell like Bash, disregarding the major mode."
> >> + :type '(choice (const :tag "Kill a word like `backward-kill-word'" emacs-word)
> >> + (const :tag "Kill a word like Bash would" unix-word)
> >> + (const :tag "Do not kill anything" nil))
> >> + :group 'killing)
>
> Eli> :version tag is missing.
>
> Is it worth allowing a user-specified function?
I don't understand what you are asking, sorry. Allow a function where
and to do what?
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-03 14:27 ` Eli Zaretskii
@ 2024-09-03 14:55 ` Robert Pluim
2024-09-03 15:32 ` Eli Zaretskii
0 siblings, 1 reply; 90+ messages in thread
From: Robert Pluim @ 2024-09-03 14:55 UTC (permalink / raw)
To: Eli Zaretskii
Cc: philipk, rms, 69097, juri, stefankangas, acorallo, spwhitton
>>>>> On Tue, 03 Sep 2024 17:27:59 +0300, Eli Zaretskii <eliz@gnu.org> said:
>> >> + "Behaviour when `kill-region' is invoked without an active region.
>> >> +If set to nil (default), then an error occurs and nothing is killed. If
>> >> +set to `emacs-word', then kill a the last word as defined by the current
>> >> +major mode. If set to `unix-word', then kill the last word in the style
>> >> +of a shell like Bash, disregarding the major mode."
>> >> + :type '(choice (const :tag "Kill a word like `backward-kill-word'" emacs-word)
>> >> + (const :tag "Kill a word like Bash would" unix-word)
>> >> + (const :tag "Do not kill anything" nil))
>> >> + :group 'killing)
>>
Eli> :version tag is missing.
>>
>> Is it worth allowing a user-specified function?
Eli> I don't understand what you are asking, sorry. Allow a function where
Eli> and to do what?
The current proposal offers three fixed behaviours. Iʼm wondering if
it makes sense for the user option to be allowed to be a user-defined
function, in case someone wants a different behaviour, ie
+(defcustom kill-word-if-no-region nil
+ "Behaviour when `kill-region' is invoked without an active region.
+If set to nil (default), then an error occurs and nothing is killed. If
+set to `emacs-word', then kill a the last word as defined by the current
+major mode. If set to `unix-word', then kill the last word in the style
+of a shell like Bash, disregarding the major mode. If set to a
+function, call that function."
+ :type '(choice (const :tag "Kill a word like `backward-kill-word'" emacs-word)
+ (const :tag "Kill a word like Bash would" unix-word)
+ (const :tag "Do not kill anything" nil)
+ (symbol :tag "User function")
+ :group 'killing)
Robert
--
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-03 14:55 ` Robert Pluim
@ 2024-09-03 15:32 ` Eli Zaretskii
0 siblings, 0 replies; 90+ messages in thread
From: Eli Zaretskii @ 2024-09-03 15:32 UTC (permalink / raw)
To: Robert Pluim; +Cc: philipk, rms, 69097, juri, stefankangas, acorallo, spwhitton
> From: Robert Pluim <rpluim@gmail.com>
> Cc: philipk@posteo.net, rms@gnu.org, 69097@debbugs.gnu.org,
> juri@linkov.net, stefankangas@gmail.com, acorallo@gnu.org,
> spwhitton@spwhitton.name
> Date: Tue, 03 Sep 2024 16:55:29 +0200
>
> +(defcustom kill-word-if-no-region nil
> + "Behaviour when `kill-region' is invoked without an active region.
> +If set to nil (default), then an error occurs and nothing is killed. If
> +set to `emacs-word', then kill a the last word as defined by the current
> +major mode. If set to `unix-word', then kill the last word in the style
> +of a shell like Bash, disregarding the major mode. If set to a
> +function, call that function."
> + :type '(choice (const :tag "Kill a word like `backward-kill-word'" emacs-word)
> + (const :tag "Kill a word like Bash would" unix-word)
> + (const :tag "Do not kill anything" nil)
> + (symbol :tag "User function")
> + :group 'killing)
When and why would this be useful?
Since kill-region cannot be customized in this way, I wonder why this
new functionality should. If someone wants to replace kill-region
with their own function, they can always redefine it or advise it, no?
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-03 12:21 ` Eli Zaretskii
2024-09-03 13:53 ` Robert Pluim
@ 2024-09-03 16:32 ` Philip Kaludercic
2024-09-03 16:47 ` Robert Pluim
` (2 more replies)
1 sibling, 3 replies; 90+ messages in thread
From: Philip Kaludercic @ 2024-09-03 16:32 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: rms, 69097, juri, stefankangas, acorallo, spwhitton
[-- Attachment #1: Type: text/plain, Size: 2288 bytes --]
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Philip Kaludercic <philipk@posteo.net>
>> Cc: Eli Zaretskii <eliz@gnu.org>, Stefan Kangas <stefankangas@gmail.com>,
>> Andrea Corallo <acorallo@gnu.org>, juri@linkov.net, rms@gnu.org,
>> 69097@debbugs.gnu.org
>> Date: Mon, 02 Sep 2024 21:12:01 +0000
>>
>> I had misremembered the last state of this patch. It is easier to just
>> have a tristate option. Here is the updated proposal:
>
> Thanks.
>
>> +(defcustom kill-word-if-no-region nil
>
> I would call this 'kill-region-dwim' instead.
Can do.
>> + "Behaviour when `kill-region' is invoked without an active region.
>> +If set to nil (default), then an error occurs and nothing is killed. If
>> +set to `emacs-word', then kill a the last word as defined by the current
>> +major mode. If set to `unix-word', then kill the last word in the style
>> +of a shell like Bash, disregarding the major mode."
>> + :type '(choice (const :tag "Kill a word like `backward-kill-word'" emacs-word)
>> + (const :tag "Kill a word like Bash would" unix-word)
>> + (const :tag "Do not kill anything" nil))
>> + :group 'killing)
>
> :version tag is missing.
Whoops, added it.
>> -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
>
> Not sure why you decided to reformat this part. Its formatting was
> not random.
I think this was just an accidental M-q.
> This also needs a NEWS entry.
I've added the NEWS entry from the last iteration of the patch (now
actually as a patch, not just a diff):
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Allow-kill-region-kill-the-last-word-when-there-is-n.patch --]
[-- Type: text/x-patch, Size: 4779 bytes --]
From 981331cfe0757b21f529be02d848a3ef7bcc4295 Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <philipk@posteo.net>
Date: Tue, 3 Sep 2024 18:29:56 +0200
Subject: [PATCH] Allow 'kill-region' kill the last word when there is no
region
* etc/NEWS: Document the new user option.
* lisp/simple.el (kill-region-dwim): Add new option.
(kill-region): Respect 'kill-region-dwim'. (Bug#69097)
---
etc/NEWS | 6 ++++++
lisp/simple.el | 50 ++++++++++++++++++++++++++++++++++++++++++--------
2 files changed, 48 insertions(+), 8 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index 1e66f084117..7fadf52a6cf 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -123,6 +123,12 @@ When using 'visual-wrap-prefix-mode' in buffers with variable-pitch
fonts, the wrapped text will now be lined up correctly so that it's
exactly below the text after the prefix on the first line.
+---
+** 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.
+
\f
* Changes in Specialized Modes and Packages in Emacs 31.1
diff --git a/lisp/simple.el b/lisp/simple.el
index eedc5768fe2..3b4453c7a8f 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -5817,6 +5817,17 @@ kill-read-only-ok
:type 'boolean
:group 'killing)
+(defcustom kill-region-dwim nil
+ "Behaviour when `kill-region' is invoked without an active region.
+If set to nil (default), then an error occurs and nothing is killed. If
+set to `emacs-word', then kill a the last word as defined by the current
+major mode. If set to `unix-word', then kill the last word in the style
+of a shell like Bash, disregarding the major mode."
+ :type '(choice (const :tag "Kill a word like `backward-kill-word'" emacs-word)
+ (const :tag "Kill a word like Bash would" unix-word)
+ (const :tag "Do not kill anything" nil))
+ :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.
@@ -5843,21 +5854,44 @@ kill-region
(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', 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."
+ this command always kills the current region. It is possible to
+ override this behaviour by customising the user option
+ `kill-region-dwim'."
;; 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-region-dwim
+ (list beg end kill-region-dwim))
+ ((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 'emacs-word)
+ (let ((end (point)))
+ (save-excursion
+ (forward-word -1)
+ (filter-buffer-substring (point) end 'delete))))
+ ((eq region 'unix-word)
+ (let ((end (point)))
+ (save-excursion
+ (skip-chars-backward "[:space:]")
+ (skip-chars-backward "^[:space:]")
+ (filter-buffer-substring
+ (if (get-char-property (point) 'read-only)
+ (next-single-char-property-change
+ (point) 'read-only nil end)
+ (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)
--
2.46.0
[-- Attachment #3: Type: text/plain, Size: 1882 bytes --]
Robert Pluim <rpluim@gmail.com> writes:
>>>>>> On Tue, 03 Sep 2024 15:21:54 +0300, Eli Zaretskii <eliz@gnu.org> said:
>
> >> From: Philip Kaludercic <philipk@posteo.net>
> >> Cc: Eli Zaretskii <eliz@gnu.org>, Stefan Kangas <stefankangas@gmail.com>,
> >> Andrea Corallo <acorallo@gnu.org>, juri@linkov.net, rms@gnu.org,
> >> 69097@debbugs.gnu.org
> >> Date: Mon, 02 Sep 2024 21:12:01 +0000
> >>
> >> I had misremembered the last state of this patch. It is easier to just
> >> have a tristate option. Here is the updated proposal:
>
> Eli> Thanks.
>
> >> +(defcustom kill-word-if-no-region nil
>
> Eli> I would call this 'kill-region-dwim' instead.
>
> >> + "Behaviour when `kill-region' is invoked without an active region.
> >> +If set to nil (default), then an error occurs and nothing is killed. If
> >> +set to `emacs-word', then kill a the last word as defined by the current
> >> +major mode. If set to `unix-word', then kill the last word in the style
> >> +of a shell like Bash, disregarding the major mode."
> >> + :type '(choice (const :tag "Kill a word like `backward-kill-word'" emacs-word)
> >> + (const :tag "Kill a word like Bash would" unix-word)
> >> + (const :tag "Do not kill anything" nil))
> >> + :group 'killing)
>
> Eli> :version tag is missing.
>
> Is it worth allowing a user-specified function?
That would be possible as well, but to make it manageable with the
current approach the function would have to be one that moves the point.
So we could rewrite the patch with two default options `backward-word'
and `unix-backward-word' (which we would have to add), but I am not sure
it would have much use. Perhaps killing the current word, instead of
just killing to the beginning?
> Robert
--
Philip Kaludercic on peregrine
^ permalink raw reply related [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-03 16:32 ` Philip Kaludercic
@ 2024-09-03 16:47 ` Robert Pluim
2024-09-04 11:08 ` Eli Zaretskii
2024-09-04 14:07 ` Sean Whitton
2 siblings, 0 replies; 90+ messages in thread
From: Robert Pluim @ 2024-09-03 16:47 UTC (permalink / raw)
To: Philip Kaludercic
Cc: rms, 69097, juri, stefankangas, Eli Zaretskii, acorallo,
spwhitton
>>>>> On Tue, 03 Sep 2024 16:32:46 +0000, Philip Kaludercic <philipk@posteo.net> said:
>>
>> Is it worth allowing a user-specified function?
Philip> That would be possible as well, but to make it manageable with the
Philip> current approach the function would have to be one that moves the point.
Philip> So we could rewrite the patch with two default options `backward-word'
Philip> and `unix-backward-word' (which we would have to add), but I am not sure
Philip> it would have much use. Perhaps killing the current word, instead of
Philip> just killing to the beginning?
You mean having all the option values be functions? That would work as
well, but was not what I was suggesting.
In any case, I canʼt find a strong justification for such
configurability. We can always add it in later if people ask for it.
Robert
--
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-03 16:32 ` Philip Kaludercic
2024-09-03 16:47 ` Robert Pluim
@ 2024-09-04 11:08 ` Eli Zaretskii
2024-09-04 14:07 ` Sean Whitton
2 siblings, 0 replies; 90+ messages in thread
From: Eli Zaretskii @ 2024-09-04 11:08 UTC (permalink / raw)
To: Philip Kaludercic; +Cc: rms, 69097, juri, stefankangas, acorallo, spwhitton
> From: Philip Kaludercic <philipk@posteo.net>
> Cc: spwhitton@spwhitton.name, stefankangas@gmail.com, acorallo@gnu.org,
> juri@linkov.net, rms@gnu.org, 69097@debbugs.gnu.org
> Date: Tue, 03 Sep 2024 16:32:46 +0000
>
> I've added the NEWS entry from the last iteration of the patch (now
> actually as a patch, not just a diff):
Thanks.
> +---
> +** New user option 'kill-word-if-no-region'.
^^^^^^^^^^^^^^^^^^^^^^
This is not the right name...
> +(defcustom kill-region-dwim nil
> + "Behaviour when `kill-region' is invoked without an active region.
> +If set to nil (default), then an error occurs and nothing is killed. If
> +set to `emacs-word', then kill a the last word as defined by the current
^^^^^^^^^^
The "a" part should be removed.
> +major mode. If set to `unix-word', then kill the last word in the style
> +of a shell like Bash, disregarding the major mode."
> + :type '(choice (const :tag "Kill a word like `backward-kill-word'" emacs-word)
> + (const :tag "Kill a word like Bash would" unix-word)
> + (const :tag "Do not kill anything" nil))
> + :group 'killing)
:version still missing.
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-03 16:32 ` Philip Kaludercic
2024-09-03 16:47 ` Robert Pluim
2024-09-04 11:08 ` Eli Zaretskii
@ 2024-09-04 14:07 ` Sean Whitton
2024-09-04 14:21 ` Eli Zaretskii
2024-09-05 9:39 ` Philip Kaludercic
2 siblings, 2 replies; 90+ messages in thread
From: Sean Whitton @ 2024-09-04 14:07 UTC (permalink / raw)
To: Philip Kaludercic; +Cc: rms, 69097, juri, stefankangas, Eli Zaretskii, acorallo
Hello,
On Tue 03 Sep 2024 at 04:32pm GMT, Philip Kaludercic wrote:
>
> +(defcustom kill-region-dwim nil
> + "Behaviour when `kill-region' is invoked without an active region.
> +If set to nil (default), then an error occurs and nothing is killed. If
> +set to `emacs-word', then kill a the last word as defined by the current
> +major mode. If set to `unix-word', then kill the last word in the style
> +of a shell like Bash, disregarding the major mode."
> + :type '(choice (const :tag "Kill a word like `backward-kill-word'" emacs-word)
> + (const :tag "Kill a word like Bash would" unix-word)
> + (const :tag "Do not kill anything" nil))
> + :group 'killing)
I think I'm missing something here. When it's nil and there is no
*active* region, but there is a region, it should kill that, surely?
With or without TMM.
I very regularly kill inactive regions (e.g. after M->).
> + ((eq region 'unix-word)
> + (let ((end (point)))
> + (save-excursion
> + (skip-chars-backward "[:space:]")
> + (skip-chars-backward "^[:space:]")
> + (filter-buffer-substring
> + (if (get-char-property (point) 'read-only)
> + (next-single-char-property-change
> + (point) 'read-only nil end)
> + (point))
> + end 'delete))))
> + (region
> + (funcall region-extract-function 'delete))
> + ((filter-buffer-substring beg end 'delete)))))
Shall I rather commit this as an independent unix-word-rubout?
Improves attribution, and it's independently useful.
--
Sean Whitton
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-04 14:07 ` Sean Whitton
@ 2024-09-04 14:21 ` Eli Zaretskii
2024-09-05 9:39 ` Philip Kaludercic
1 sibling, 0 replies; 90+ messages in thread
From: Eli Zaretskii @ 2024-09-04 14:21 UTC (permalink / raw)
To: Sean Whitton; +Cc: philipk, rms, 69097, juri, stefankangas, acorallo
> From: Sean Whitton <spwhitton@spwhitton.name>
> Cc: Eli Zaretskii <eliz@gnu.org>, stefankangas@gmail.com,
> acorallo@gnu.org, juri@linkov.net, rms@gnu.org, 69097@debbugs.gnu.org
> Date: Wed, 04 Sep 2024 15:07:08 +0100
>
> > +(defcustom kill-region-dwim nil
> > + "Behaviour when `kill-region' is invoked without an active region.
> > +If set to nil (default), then an error occurs and nothing is killed. If
> > +set to `emacs-word', then kill a the last word as defined by the current
> > +major mode. If set to `unix-word', then kill the last word in the style
> > +of a shell like Bash, disregarding the major mode."
> > + :type '(choice (const :tag "Kill a word like `backward-kill-word'" emacs-word)
> > + (const :tag "Kill a word like Bash would" unix-word)
> > + (const :tag "Do not kill anything" nil))
> > + :group 'killing)
>
> I think I'm missing something here. When it's nil and there is no
> *active* region, but there is a region, it should kill that, surely?
> With or without TMM.
Yes, you are right. It sounds like we made wrong assumptions about
what happens in that case, and should rethink this.
C-w signals an error only if there's no mark in the buffer.
So I guess we need a new command after all.
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-04 14:07 ` Sean Whitton
2024-09-04 14:21 ` Eli Zaretskii
@ 2024-09-05 9:39 ` Philip Kaludercic
2024-09-05 9:52 ` Eli Zaretskii
2024-09-05 13:27 ` Sean Whitton
1 sibling, 2 replies; 90+ messages in thread
From: Philip Kaludercic @ 2024-09-05 9:39 UTC (permalink / raw)
To: Sean Whitton; +Cc: rms, 69097, juri, stefankangas, Eli Zaretskii, acorallo
[-- Attachment #1: Type: text/plain, Size: 1053 bytes --]
Sean Whitton <spwhitton@spwhitton.name> writes:
> Hello,
>
> On Tue 03 Sep 2024 at 04:32pm GMT, Philip Kaludercic wrote:
>
>>
>> +(defcustom kill-region-dwim nil
>> + "Behaviour when `kill-region' is invoked without an active region.
>> +If set to nil (default), then an error occurs and nothing is killed. If
>> +set to `emacs-word', then kill a the last word as defined by the current
>> +major mode. If set to `unix-word', then kill the last word in the style
>> +of a shell like Bash, disregarding the major mode."
>> + :type '(choice (const :tag "Kill a word like `backward-kill-word'" emacs-word)
>> + (const :tag "Kill a word like Bash would" unix-word)
>> + (const :tag "Do not kill anything" nil))
>> + :group 'killing)
>
> I think I'm missing something here. When it's nil and there is no
> *active* region, but there is a region, it should kill that, surely?
> With or without TMM.
> I very regularly kill inactive regions (e.g. after M->).
That is not an inherent problem, we can adjust the patch by
[-- Attachment #2: Type: text/plain, Size: 837 bytes --]
diff --git a/lisp/simple.el b/lisp/simple.el
index 3b4453c7a8f..9d4d5bcd10c 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -5865,11 +5865,11 @@ kill-region
(let ((beg (mark))
(end (point)))
(cond
- ((and beg end (use-region-p))
- (list beg end 'region))
- (kill-region-dwim
+ ((and kill-region-dwim (not (use-region-p)))
(list beg end kill-region-dwim))
- ((user-error "The mark is not set now, so there is no region"))))))
+ ((not (or beg end))
+ (user-error "The mark is not set now, so there is no region"))
+ ((list beg end 'region))))))
(condition-case nil
(let ((string (cond
[-- Attachment #3: Type: text/plain, Size: 2422 bytes --]
to fix that issue.
>> + ((eq region 'unix-word)
>> + (let ((end (point)))
>> + (save-excursion
>> + (skip-chars-backward "[:space:]")
>> + (skip-chars-backward "^[:space:]")
>> + (filter-buffer-substring
>> + (if (get-char-property (point) 'read-only)
>> + (next-single-char-property-change
>> + (point) 'read-only nil end)
>> + (point))
>> + end 'delete))))
>> + (region
>> + (funcall region-extract-function 'delete))
>> + ((filter-buffer-substring beg end 'delete)))))
>
> Shall I rather commit this as an independent unix-word-rubout?
>
> Improves attribution, and it's independently useful.
As a standalone command?
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Sean Whitton <spwhitton@spwhitton.name>
>> Cc: Eli Zaretskii <eliz@gnu.org>, stefankangas@gmail.com,
>> acorallo@gnu.org, juri@linkov.net, rms@gnu.org, 69097@debbugs.gnu.org
>> Date: Wed, 04 Sep 2024 15:07:08 +0100
>>
>> > +(defcustom kill-region-dwim nil
>> > + "Behaviour when `kill-region' is invoked without an active region.
>> > +If set to nil (default), then an error occurs and nothing is killed. If
>> > +set to `emacs-word', then kill a the last word as defined by the current
>> > +major mode. If set to `unix-word', then kill the last word in the style
>> > +of a shell like Bash, disregarding the major mode."
>> > + :type '(choice (const :tag "Kill a word like `backward-kill-word'" emacs-word)
>> > + (const :tag "Kill a word like Bash would" unix-word)
>> > + (const :tag "Do not kill anything" nil))
>> > + :group 'killing)
>>
>> I think I'm missing something here. When it's nil and there is no
>> *active* region, but there is a region, it should kill that, surely?
>> With or without TMM.
>
> Yes, you are right. It sounds like we made wrong assumptions about
> what happens in that case, and should rethink this.
>
> C-w signals an error only if there's no mark in the buffer.
>
> So I guess we need a new command after all.
Not necessarily (unless I am mistaken above), but I am not opposed to it either.
--
Philip Kaludercic on siskin
^ permalink raw reply related [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-05 9:39 ` Philip Kaludercic
@ 2024-09-05 9:52 ` Eli Zaretskii
2024-09-05 10:02 ` Philip Kaludercic
2024-09-05 13:27 ` Sean Whitton
1 sibling, 1 reply; 90+ messages in thread
From: Eli Zaretskii @ 2024-09-05 9:52 UTC (permalink / raw)
To: Philip Kaludercic; +Cc: rms, 69097, juri, stefankangas, acorallo, spwhitton
> From: Philip Kaludercic <philipk@posteo.net>
> Cc: Eli Zaretskii <eliz@gnu.org>, stefankangas@gmail.com,
> acorallo@gnu.org, juri@linkov.net, rms@gnu.org, 69097@debbugs.gnu.org
> Date: Thu, 05 Sep 2024 09:39:32 +0000
>
> >> I think I'm missing something here. When it's nil and there is no
> >> *active* region, but there is a region, it should kill that, surely?
> >> With or without TMM.
> >
> > Yes, you are right. It sounds like we made wrong assumptions about
> > what happens in that case, and should rethink this.
> >
> > C-w signals an error only if there's no mark in the buffer.
> >
> > So I guess we need a new command after all.
>
> Not necessarily (unless I am mistaken above), but I am not opposed to it either.
If we don't introduce a new command, then what will be the modified
behavior of kill-region? Specifically, when will it delete the last
word? In Emacs buffers, it is very rare not to have the mark, so it
sounds like the Bash-like behavior will very rarely if ever available,
no?
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-05 9:52 ` Eli Zaretskii
@ 2024-09-05 10:02 ` Philip Kaludercic
2024-09-05 10:19 ` Eli Zaretskii
0 siblings, 1 reply; 90+ messages in thread
From: Philip Kaludercic @ 2024-09-05 10:02 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: rms, 69097, juri, stefankangas, acorallo, spwhitton
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Philip Kaludercic <philipk@posteo.net>
>> Cc: Eli Zaretskii <eliz@gnu.org>, stefankangas@gmail.com,
>> acorallo@gnu.org, juri@linkov.net, rms@gnu.org, 69097@debbugs.gnu.org
>> Date: Thu, 05 Sep 2024 09:39:32 +0000
>>
>> >> I think I'm missing something here. When it's nil and there is no
>> >> *active* region, but there is a region, it should kill that, surely?
>> >> With or without TMM.
>> >
>> > Yes, you are right. It sounds like we made wrong assumptions about
>> > what happens in that case, and should rethink this.
>> >
>> > C-w signals an error only if there's no mark in the buffer.
>> >
>> > So I guess we need a new command after all.
>>
>> Not necessarily (unless I am mistaken above), but I am not opposed to it either.
>
> If we don't introduce a new command, then what will be the modified
> behavior of kill-region? Specifically, when will it delete the last
> word?
If the new user option is non-nil /and/ there is no region. If
`kill-region-dwim' is nil (default), then nothing should change.
>
> In Emacs buffers, it is very rare not to have the mark, so it
> sounds like the Bash-like behavior will very rarely if ever available,
> no?
It will kick-in whenever `use-region-p' returns a non-nil value. I
recognise that this isn't useful for people who don't rely on transient
mark mode, but in that case we'll need to commands anyway, as I don't
want to use the behaviour that Sean describes.
--
Philip Kaludercic on siskin
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-05 10:02 ` Philip Kaludercic
@ 2024-09-05 10:19 ` Eli Zaretskii
2024-09-05 10:23 ` Philip Kaludercic
0 siblings, 1 reply; 90+ messages in thread
From: Eli Zaretskii @ 2024-09-05 10:19 UTC (permalink / raw)
To: Philip Kaludercic; +Cc: rms, 69097, juri, stefankangas, acorallo, spwhitton
> From: Philip Kaludercic <philipk@posteo.net>
> Cc: spwhitton@spwhitton.name, stefankangas@gmail.com, acorallo@gnu.org,
> juri@linkov.net, rms@gnu.org, 69097@debbugs.gnu.org
> Date: Thu, 05 Sep 2024 10:02:45 +0000
>
> Eli Zaretskii <eliz@gnu.org> writes:
>
> > If we don't introduce a new command, then what will be the modified
> > behavior of kill-region? Specifically, when will it delete the last
> > word?
>
> If the new user option is non-nil /and/ there is no region. If
> `kill-region-dwim' is nil (default), then nothing should change.
>
> >
> > In Emacs buffers, it is very rare not to have the mark, so it
> > sounds like the Bash-like behavior will very rarely if ever available,
> > no?
>
> It will kick-in whenever `use-region-p' returns a non-nil value.
Non-nil or nil? Above you say "there's no region", which AFAIU means
use-region-p returns nil.
> I recognise that this isn't useful for people who don't rely on
> transient mark mode, but in that case we'll need to commands anyway,
> as I don't want to use the behaviour that Sean describes.
Which is why I think we will need a separate command after all.
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-05 10:19 ` Eli Zaretskii
@ 2024-09-05 10:23 ` Philip Kaludercic
0 siblings, 0 replies; 90+ messages in thread
From: Philip Kaludercic @ 2024-09-05 10:23 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: rms, 69097, juri, stefankangas, acorallo, spwhitton
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Philip Kaludercic <philipk@posteo.net>
>> Cc: spwhitton@spwhitton.name, stefankangas@gmail.com, acorallo@gnu.org,
>> juri@linkov.net, rms@gnu.org, 69097@debbugs.gnu.org
>> Date: Thu, 05 Sep 2024 10:02:45 +0000
>>
>> Eli Zaretskii <eliz@gnu.org> writes:
>>
>> > If we don't introduce a new command, then what will be the modified
>> > behavior of kill-region? Specifically, when will it delete the last
>> > word?
>>
>> If the new user option is non-nil /and/ there is no region. If
>> `kill-region-dwim' is nil (default), then nothing should change.
>>
>> >
>> > In Emacs buffers, it is very rare not to have the mark, so it
>> > sounds like the Bash-like behavior will very rarely if ever available,
>> > no?
>>
>> It will kick-in whenever `use-region-p' returns a non-nil value.
>
> Non-nil or nil? Above you say "there's no region", which AFAIU means
> use-region-p returns nil.
Right, my bad.
>> I recognise that this isn't useful for people who don't rely on
>> transient mark mode, but in that case we'll need to commands anyway,
>> as I don't want to use the behaviour that Sean describes.
>
> Which is why I think we will need a separate command after all.
OK, but we can add that independently of this patch.
--
Philip Kaludercic on siskin
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-05 9:39 ` Philip Kaludercic
2024-09-05 9:52 ` Eli Zaretskii
@ 2024-09-05 13:27 ` Sean Whitton
2024-09-05 14:38 ` Philip Kaludercic
1 sibling, 1 reply; 90+ messages in thread
From: Sean Whitton @ 2024-09-05 13:27 UTC (permalink / raw)
To: Philip Kaludercic; +Cc: rms, 69097, juri, stefankangas, Eli Zaretskii, acorallo
Hello,
On Thu 05 Sep 2024 at 09:39am GMT, Philip Kaludercic wrote:
>>> + ((eq region 'unix-word)
>>> + (let ((end (point)))
>>> + (save-excursion
>>> + (skip-chars-backward "[:space:]")
>>> + (skip-chars-backward "^[:space:]")
>>> + (filter-buffer-substring
>>> + (if (get-char-property (point) 'read-only)
>>> + (next-single-char-property-change
>>> + (point) 'read-only nil end)
>>> + (point))
>>> + end 'delete))))
>>> + (region
>>> + (funcall region-extract-function 'delete))
>>> + ((filter-buffer-substring beg end 'delete)))))
>>
>> Shall I rather commit this as an independent unix-word-rubout?
>>
>> Improves attribution, and it's independently useful.
>
> As a standalone command?
I mean, yeah, I have had it on my C-w for years. Probably some other
people have implementations too.
--
Sean Whitton
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-05 13:27 ` Sean Whitton
@ 2024-09-05 14:38 ` Philip Kaludercic
2024-09-06 10:36 ` Sean Whitton
0 siblings, 1 reply; 90+ messages in thread
From: Philip Kaludercic @ 2024-09-05 14:38 UTC (permalink / raw)
To: Sean Whitton; +Cc: rms, 69097, juri, stefankangas, Eli Zaretskii, acorallo
[-- Attachment #1: Type: text/plain, Size: 1734 bytes --]
Sean Whitton <spwhitton@spwhitton.name> writes:
> Hello,
>
> On Thu 05 Sep 2024 at 09:39am GMT, Philip Kaludercic wrote:
>
>>>> + ((eq region 'unix-word)
>>>> + (let ((end (point)))
>>>> + (save-excursion
>>>> + (skip-chars-backward "[:space:]")
>>>> + (skip-chars-backward "^[:space:]")
>>>> + (filter-buffer-substring
>>>> + (if (get-char-property (point) 'read-only)
>>>> + (next-single-char-property-change
>>>> + (point) 'read-only nil end)
>>>> + (point))
>>>> + end 'delete))))
>>>> + (region
>>>> + (funcall region-extract-function 'delete))
>>>> + ((filter-buffer-substring beg end 'delete)))))
>>>
>>> Shall I rather commit this as an independent unix-word-rubout?
>>>
>>> Improves attribution, and it's independently useful.
>>
>> As a standalone command?
>
> I mean, yeah, I have had it on my C-w for years. Probably some other
> people have implementations too.
In that case, it would be difficult to use it directly in this
implementation, as kill-region needs a command that just moves the
point. I guess it would be possible to hack something together with
atomic change groups, but the cleanest strategy would probably be to
have a unix-word-forward command that goes in both directions, and use
that both in a standalone unix-word-rubout and this patch. But we can
do that after merging this patch -- assuming there are no more blocking
issues with the latest version:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Allow-kill-region-kill-the-last-word-when-there-is-n.patch --]
[-- Type: text/x-diff, Size: 5053 bytes --]
From fa7b5158fb1507db32a7b537137418afa024cfad Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <philipk@posteo.net>
Date: Tue, 3 Sep 2024 18:29:56 +0200
Subject: [PATCH] Allow 'kill-region' kill the last word when there is no
region
* etc/NEWS: Document the new user option.
* lisp/simple.el (kill-region-dwim): Add new option.
(kill-region): Respect 'kill-region-dwim'. (Bug#69097)
---
etc/NEWS | 8 +++++++-
lisp/simple.el | 49 ++++++++++++++++++++++++++++++++++++++++++-------
2 files changed, 49 insertions(+), 8 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index 1e66f084117..60efbfb43d8 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -123,6 +123,12 @@ When using 'visual-wrap-prefix-mode' in buffers with variable-pitch
fonts, the wrapped text will now be lined up correctly so that it's
exactly below the text after the prefix on the first line.
+---
+** 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.
+
\f
* Changes in Specialized Modes and Packages in Emacs 31.1
@@ -268,7 +274,7 @@ any.
** Diff
---
-*** New command 'diff-kill-ring-save'.
+*** New command 'diff-kill-dwim'.
This command copies to the 'kill-ring' a region of text modified
according to diffs in the current buffer, but without applying the diffs
to the original text. If the selected range extends a hunk, the
diff --git a/lisp/simple.el b/lisp/simple.el
index eedc5768fe2..efa338f0b0d 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -5817,6 +5817,18 @@ kill-read-only-ok
:type 'boolean
:group 'killing)
+(defcustom kill-region-dwim nil
+ "Behaviour when `kill-region' is invoked without an active region.
+If set to nil (default), the behaviour of `kill-region' stays the same.
+If set to `emacs-word', then kill the last word as defined by the
+current major mode. If set to `unix-word', then kill the last word in
+the style of a shell like Bash, disregarding the major mode."
+ :type '(choice (const :tag "Kill a word like `backward-kill-word'" emacs-word)
+ (const :tag "Kill a word like Bash would" unix-word)
+ (const :tag "Do not kill anything" nil))
+ :group 'killing
+ :version "31.1")
+
(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.
@@ -5843,21 +5855,44 @@ kill-region
(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', 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."
+ this command always kills the current region. It is possible to
+ override this behaviour by customising the user option
+ `kill-region-dwim'."
;; Pass mark first, then point, because the order matters when
;; calling `kill-append'.
(interactive (progn
(let ((beg (mark))
(end (point)))
- (unless (and beg end)
+ (cond
+ ((and kill-region-dwim (not (use-region-p)))
+ (list beg end kill-region-dwim))
+ ((not (or beg end))
(user-error "The mark is not set now, so there is no region"))
- (list beg end 'region))))
+ ((list beg end 'region))))))
+
(condition-case nil
- (let ((string (if region
- (funcall region-extract-function 'delete)
- (filter-buffer-substring beg end 'delete))))
+ (let ((string (cond
+ ((eq region 'emacs-word)
+ (let ((end (point)))
+ (save-excursion
+ (forward-word -1)
+ (filter-buffer-substring (point) end 'delete))))
+ ((eq region 'unix-word)
+ (let ((end (point)))
+ (save-excursion
+ (skip-chars-backward "[:space:]")
+ (skip-chars-backward "^[:space:]")
+ (filter-buffer-substring
+ (if (get-char-property (point) 'read-only)
+ (next-single-char-property-change
+ (point) 'read-only nil end)
+ (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)
--
2.45.2
[-- Attachment #3: Type: text/plain, Size: 35 bytes --]
--
Philip Kaludercic on siskin
^ permalink raw reply related [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-05 14:38 ` Philip Kaludercic
@ 2024-09-06 10:36 ` Sean Whitton
2024-09-06 11:06 ` Sean Whitton
2024-09-06 11:30 ` Eli Zaretskii
0 siblings, 2 replies; 90+ messages in thread
From: Sean Whitton @ 2024-09-06 10:36 UTC (permalink / raw)
To: Philip Kaludercic; +Cc: rms, 69097, juri, stefankangas, Eli Zaretskii, acorallo
[-- Attachment #1: Type: text/plain, Size: 912 bytes --]
Hello,
On Thu 05 Sep 2024 at 02:38pm GMT, Philip Kaludercic wrote:
> In that case, it would be difficult to use it directly in this
> implementation, as kill-region needs a command that just moves the
> point. I guess it would be possible to hack something together with
> atomic change groups, but the cleanest strategy would probably be to
> have a unix-word-forward command that goes in both directions, and use
> that both in a standalone unix-word-rubout and this patch. But we can
> do that after merging this patch -- assuming there are no more blocking
> issues with the latest version:
I think you're right, but I would like to commit my function first, so
that I get attribution (it did take me some time to figure out what was
useful in this area), and because I think it should be rewritten in
terms of fields.
Please take a look at the attached. unix-word-rubout to follow.
--
Sean Whitton
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-New-command-forward-unix-word.patch --]
[-- Type: text/x-patch, Size: 3847 bytes --]
From 4cb701150976cdb91658a1c82edd6e8270fd26c8 Mon Sep 17 00:00:00 2001
From: Sean Whitton <spwhitton@spwhitton.name>
Date: Fri, 6 Sep 2024 11:35:46 +0100
Subject: [PATCH] New command forward-unix-word
* lisp/simple.el (forward-unix-word): New command.
* doc/lispref/positions.texi (Word Motion):
* etc/NEWS: Document it.
---
doc/lispref/positions.texi | 13 +++++++++++++
etc/NEWS | 5 +++++
lisp/simple.el | 30 ++++++++++++++++++++++++++++++
3 files changed, 48 insertions(+)
diff --git a/doc/lispref/positions.texi b/doc/lispref/positions.texi
index 37cfe264157..b576df82382 100644
--- a/doc/lispref/positions.texi
+++ b/doc/lispref/positions.texi
@@ -275,6 +275,19 @@ Word Motion
syntax tables.
@end defun
+@deffn Command forward-unix-word &optional arg delim
+This function is like @code{forward-word}, except that words are always
+delimited by whitespace, regardless of the buffer's syntax table. This
+emulates how @kbd{C-w} at the Unix terminal or shell identifies words.
+See the @code{unix-word-rubout} command in @xref{(readline)Commands For
+Killing}.
+
+Lisp programs can pass the @var{delim} argument to specify the notion of
+whitespace. This argument is a string listing the characters considered
+whitespace, as might be passed to @code{skip-chars-forward}. The
+default is @code{[:space:]\n}. Do not prefix a `^' character.
+@end deffn
+
@node Buffer End Motion
@subsection Motion to an End of the Buffer
@cindex move to beginning or end of buffer
diff --git a/etc/NEWS b/etc/NEWS
index f3e719a34d3..8037fcfd1af 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -123,6 +123,11 @@ When using 'visual-wrap-prefix-mode' in buffers with variable-pitch
fonts, the wrapped text will now be lined up correctly so that it's
exactly below the text after the prefix on the first line.
++++
+** New command 'forward-unix-word'.
+This command is like 'forward-word', except it always considers words to
+be delimited by whitespace, regardless of the buffer's syntax table.
+It thus emulates how C-w at the Unix terminal or shell identifies words.
\f
* Changes in Specialized Modes and Packages in Emacs 31.1
diff --git a/lisp/simple.el b/lisp/simple.el
index 2453a129d0a..f34eef9ac25 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -8892,6 +8892,36 @@ current-word
;; If we found something nonempty, return it as a string.
(unless (= start end)
(buffer-substring-no-properties start end)))))
+
+(defun forward-unix-word (&optional arg delim)
+ "Move forward to the end of the next whitespace-delimited word.
+With argument ARG, do this that many times; the default is once.
+With negative ARG, go backwards to the beginning of whitespace-delimited
+words.
+DELIM is a string specifying what characters are considered whitespace,
+as might be passed to `skip-chars-forward'.
+The default is \"[:space:]\\n\". Do not prefix a `^' character.
+
+This command is like `forward-word' except that words are always
+delimited by whitespace, regardless of the buffer's syntax table.
+Like `forward-word', this command respects fields.
+
+This emulates how C-w at the Unix terminal or shell identifies words.
+See the `unix-word-rubout' command in Info node `(readline)Commands For
+Killing'."
+ (interactive "^p")
+ (unless (zerop arg)
+ ;; We do skip over \n by default because `backward-word' does.
+ (let* ((delim (or delim "[:space:]\n"))
+ (ndelim (format "^%s" delim))
+ (start (point))
+ (fun (if (> arg 0)
+ #'skip-chars-forward
+ #'skip-chars-backward)))
+ (dotimes (_ (abs arg))
+ (funcall fun delim)
+ (funcall fun ndelim))
+ (constrain-to-field nil start))))
\f
(defcustom fill-prefix nil
"String for filling to insert at front of new line, or nil for none."
--
2.39.2
^ permalink raw reply related [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-06 10:36 ` Sean Whitton
@ 2024-09-06 11:06 ` Sean Whitton
2024-09-06 11:30 ` Eli Zaretskii
1 sibling, 0 replies; 90+ messages in thread
From: Sean Whitton @ 2024-09-06 11:06 UTC (permalink / raw)
To: Philip Kaludercic; +Cc: rms, 69097, juri, stefankangas, Eli Zaretskii, acorallo
Hello,
On Fri 06 Sep 2024 at 11:36am +01, Sean Whitton wrote:
> diff --git a/doc/lispref/positions.texi b/doc/lispref/positions.texi
> index 37cfe264157..b576df82382 100644
> --- a/doc/lispref/positions.texi
> +++ b/doc/lispref/positions.texi
> @@ -275,6 +275,19 @@ Word Motion
> syntax tables.
> @end defun
>
> +@deffn Command forward-unix-word &optional arg delim
> +This function is like @code{forward-word}, except that words are always
> +delimited by whitespace, regardless of the buffer's syntax table. This
> +emulates how @kbd{C-w} at the Unix terminal or shell identifies words.
> +See the @code{unix-word-rubout} command in @xref{(readline)Commands For
> +Killing}.
> +
> +Lisp programs can pass the @var{delim} argument to specify the notion of
> +whitespace. This argument is a string listing the characters considered
> +whitespace, as might be passed to @code{skip-chars-forward}. The
> +default is @code{[:space:]\n}. Do not prefix a `^' character.
> +@end deffn
The `^' should use @code{}.
> diff --git a/lisp/simple.el b/lisp/simple.el
> index 2453a129d0a..f34eef9ac25 100644
> --- a/lisp/simple.el
> +++ b/lisp/simple.el
> @@ -8892,6 +8892,36 @@ current-word
> ;; If we found something nonempty, return it as a string.
> (unless (= start end)
> (buffer-substring-no-properties start end)))))
> +
> +(defun forward-unix-word (&optional arg delim)
> + "Move forward to the end of the next whitespace-delimited word.
ARG is not optional, only DELIM, in fact. I will fix this.
I thought I should also explain this DELIM thing. In addition to
Philip's usage and unix-word-rubout, I would like to add
unix-filename-rubout, which I think is generally useful -- it's also in
(info "(readline)Commands For Killing"). DELIM is needed for that.
It also makes the function more generally useful to Lisp programmers --
you might want to drop \n, for example.
--
Sean Whitton
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-06 10:36 ` Sean Whitton
2024-09-06 11:06 ` Sean Whitton
@ 2024-09-06 11:30 ` Eli Zaretskii
2024-09-06 13:54 ` Sean Whitton
1 sibling, 1 reply; 90+ messages in thread
From: Eli Zaretskii @ 2024-09-06 11:30 UTC (permalink / raw)
To: Sean Whitton; +Cc: philipk, rms, 69097, juri, stefankangas, acorallo
> From: Sean Whitton <spwhitton@spwhitton.name>
> Cc: Eli Zaretskii <eliz@gnu.org>, stefankangas@gmail.com,
> acorallo@gnu.org, juri@linkov.net, rms@gnu.org, 69097@debbugs.gnu.org
> Date: Fri, 06 Sep 2024 11:36:25 +0100
>
> I think you're right, but I would like to commit my function first, so
> that I get attribution (it did take me some time to figure out what was
> useful in this area), and because I think it should be rewritten in
> terms of fields.
>
> Please take a look at the attached. unix-word-rubout to follow.
Thanks, but I see no reason to document this command in the manual,
certainly not in the ELisp reference (it's a command, not a function).
IMO it's obscure enough to be documented only in NEWS.
> +(defun forward-unix-word (&optional arg delim)
> + "Move forward to the end of the next whitespace-delimited word.
> +With argument ARG, do this that many times; the default is once.
> +With negative ARG, go backwards to the beginning of whitespace-delimited
> +words.
> +DELIM is a string specifying what characters are considered whitespace,
> +as might be passed to `skip-chars-forward'.
> +The default is \"[:space:]\\n\". Do not prefix a `^' character.
Should this be "[:space:]\\n\\r" instead? if not, why not?
Also note that [:space:] depends on mode-specific syntax table, so I
question the wisdom of using it in a command that's supposed to be
mode-agnostic.
> +This command is like `forward-word' except that words are always
> +delimited by whitespace, regardless of the buffer's syntax table.
> +Like `forward-word', this command respects fields.
> +
> +This emulates how C-w at the Unix terminal or shell identifies words.
> +See the `unix-word-rubout' command in Info node `(readline)Commands For
> +Killing'."
This should try to be more explicit about what "word" means for this
command. Since it's so different from any notion of "word" in Emacs,
I would even seriously consider not to use that word, or maybe quote
it (in addition to explaining what it means).
Also, since this is a command, its doc string should clearly separate
what happens in interactive invocation from what happens when called
from Lisp. DELIM belongs to the latter. (Is it even useful to
provide that option for Lisp-only calls? what's the use case for
that?)
And finally, I wonder why we need this command? AFAIU, the original
intent was to implement something similar to unix-word-rubout, not a
new movement command. If the plan has changed, I think we need to
discuss the need once again.
Thanks.
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-06 11:30 ` Eli Zaretskii
@ 2024-09-06 13:54 ` Sean Whitton
2024-09-06 16:32 ` Philip Kaludercic
2024-09-07 9:52 ` Eli Zaretskii
0 siblings, 2 replies; 90+ messages in thread
From: Sean Whitton @ 2024-09-06 13:54 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: philipk, rms, 69097, juri, stefankangas, acorallo
[-- Attachment #1: Type: text/plain, Size: 2497 bytes --]
Hello,
On Fri 06 Sep 2024 at 02:30pm +03, Eli Zaretskii wrote:
> Thanks, but I see no reason to document this command in the manual,
> certainly not in the ELisp reference (it's a command, not a function).
> IMO it's obscure enough to be documented only in NEWS.
That's quite fine with me.
> Should this be "[:space:]\\n\\r" instead? if not, why not?
>
> Also note that [:space:] depends on mode-specific syntax table, so I
> question the wisdom of using it in a command that's supposed to be
> mode-agnostic.
Both excellent points, thank you. I looked at the POSIX standard and
came up with a new default value.
>> +This command is like `forward-word' except that words are always
>> +delimited by whitespace, regardless of the buffer's syntax table.
>> +Like `forward-word', this command respects fields.
>> +
>> +This emulates how C-w at the Unix terminal or shell identifies words.
>> +See the `unix-word-rubout' command in Info node `(readline)Commands For
>> +Killing'."
>
> This should try to be more explicit about what "word" means for this
> command. Since it's so different from any notion of "word" in Emacs,
> I would even seriously consider not to use that word, or maybe quote
> it (in addition to explaining what it means).
This is very helpful. You're right. In the attached, I've tried using
"unix-word". Let me know what you think of that.
> Also, since this is a command, its doc string should clearly separate
> what happens in interactive invocation from what happens when called
> from Lisp. DELIM belongs to the latter. (Is it even useful to
> provide that option for Lisp-only calls? what's the use case for
> that?)
>
> And finally, I wonder why we need this command? AFAIU, the original
> intent was to implement something similar to unix-word-rubout, not a
> new movement command. If the plan has changed, I think we need to
> discuss the need once again.
I think it was unhelpful of me to send this in without callers.
I'm sorry about that.
The reason for adding this is that it factors out what is in common
between what Philip is doing, and unix-word-rubout.
So in the attached revised patch, I've included unix-word-rubout.
I've also included a second readline command which I have bound in my
own init. It demonstrates why there is a need for DELIM.
By the way, forward-unix-word could also be a plain function.
I made it a command because, well, why not. Let me know if you think it
should be switched back to a function.
--
Sean Whitton
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-New-commands-for-moving-and-killing-unix-words.patch --]
[-- Type: text/x-patch, Size: 3976 bytes --]
From c047e640399bb923728ed9967e8545d53b22ea5c Mon Sep 17 00:00:00 2001
From: Sean Whitton <spwhitton@spwhitton.name>
Date: Fri, 6 Sep 2024 11:35:46 +0100
Subject: [PATCH] New commands for moving and killing unix-words
* lisp/simple.el (forward-unix-word, unix-word-rubout)
(unix-filename-rubout): New commands.
* etc/NEWS: Document them.
---
etc/NEWS | 7 +++++++
lisp/simple.el | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 64 insertions(+)
diff --git a/etc/NEWS b/etc/NEWS
index f3e719a34d3..54cf0a3df52 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -123,6 +123,13 @@ When using 'visual-wrap-prefix-mode' in buffers with variable-pitch
fonts, the wrapped text will now be lined up correctly so that it's
exactly below the text after the prefix on the first line.
+---
+** New commands for moving and killing unix-words.
+Unix-words are words separated by whitespace regardless of the buffer's
+syntax table. In a Unix terminal or shell, C-w kills by unix-word.
+The new commands 'forward-unix-word', 'unix-word-rubout' and
+'unix-filename-rubout' allow you to bind keys to operate more similarly
+to the terminal.
\f
* Changes in Specialized Modes and Packages in Emacs 31.1
diff --git a/lisp/simple.el b/lisp/simple.el
index 2453a129d0a..0322ac0cd8c 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -8892,6 +8892,63 @@ current-word
;; If we found something nonempty, return it as a string.
(unless (= start end)
(buffer-substring-no-properties start end)))))
+
+(defun forward-unix-word (arg &optional delim)
+ "Move forward ARG unix-words.
+A unix-word is whitespace-delimited.
+Interactively, ARG is the numeric prefix argument, defaulting to 1.
+A negative ARG means go backwards to the beginning of unix-words.
+
+Unix-words differ from Emacs words in that they are always delimited by
+whitespace, regardless of the buffer's syntax table. This command
+emulates how C-w at the Unix terminal or shell identifies words.
+
+When called from Lisp, DELIM specifies what characters are considered
+whitespace. It is a string as might be passed to `skip-chars-forward'.
+The default is \" \\f\\n\\r\\t\\v\". Do not prefix a `^' character."
+ (interactive "^p")
+ (unless (zerop arg)
+ ;; We do skip over newlines by default because `backward-word' does.
+ (let* ((delim (or delim " \f\n\r\t\v"))
+ (ndelim (format "^%s" delim))
+ (start (point))
+ (fun (if (> arg 0)
+ #'skip-chars-forward
+ #'skip-chars-backward)))
+ (dotimes (_ (abs arg))
+ (funcall fun delim)
+ (funcall fun ndelim))
+ (constrain-to-field nil start))))
+
+(defun unix-word-rubout (arg)
+ "Kill ARG unix-words backwards.
+A unix-word is whitespace-delimited.
+Interactively, ARG is the numeric prefix argument, defaulting to 1.
+A negative ARG means to kill forwards.
+
+Unix-words differ from Emacs words in that they are always delimited by
+whitespace, regardless of the buffer's syntax table. Thus, this command
+emulates C-w at the Unix terminal or shell identifies words.
+See also this command's nakesake in Info node
+`(readline)Commands For Killing'."
+ (interactive "^p")
+ (let ((start (point)))
+ (forward-unix-word (- arg))
+ (kill-region start (point))))
+
+(defun unix-filename-rubout (arg)
+ "Kill ARG unix-words backwards, also treating `/' as whitespace.
+A unix-word is whitespace-delimited.
+Interactively, ARG is the numeric prefix argument, defaulting to 1.
+A negative ARG means to kill forwards.
+
+This is like `unix-word-rubout' (which see), but `/' is also considered
+whitespace. See this command's namesake in Info node
+`(readline)Commands For Killing'."
+ (interactive "^p")
+ (let ((start (point)))
+ (forward-unix-word (- arg) "/ \f\n\r\t\v")
+ (kill-region start (point))))
\f
(defcustom fill-prefix nil
"String for filling to insert at front of new line, or nil for none."
--
2.39.2
^ permalink raw reply related [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-06 13:54 ` Sean Whitton
@ 2024-09-06 16:32 ` Philip Kaludercic
2024-09-07 9:52 ` Eli Zaretskii
1 sibling, 0 replies; 90+ messages in thread
From: Philip Kaludercic @ 2024-09-06 16:32 UTC (permalink / raw)
To: Sean Whitton; +Cc: rms, 69097, juri, stefankangas, Eli Zaretskii, acorallo
Sean Whitton <spwhitton@spwhitton.name> writes:
> Hello,
>
> On Fri 06 Sep 2024 at 02:30pm +03, Eli Zaretskii wrote:
>
>> Thanks, but I see no reason to document this command in the manual,
>> certainly not in the ELisp reference (it's a command, not a function).
>> IMO it's obscure enough to be documented only in NEWS.
>
> That's quite fine with me.
>
>> Should this be "[:space:]\\n\\r" instead? if not, why not?
>>
>> Also note that [:space:] depends on mode-specific syntax table, so I
>> question the wisdom of using it in a command that's supposed to be
>> mode-agnostic.
>
> Both excellent points, thank you. I looked at the POSIX standard and
> came up with a new default value.
>
>>> +This command is like `forward-word' except that words are always
>>> +delimited by whitespace, regardless of the buffer's syntax table.
>>> +Like `forward-word', this command respects fields.
>>> +
>>> +This emulates how C-w at the Unix terminal or shell identifies words.
>>> +See the `unix-word-rubout' command in Info node `(readline)Commands For
>>> +Killing'."
>>
>> This should try to be more explicit about what "word" means for this
>> command. Since it's so different from any notion of "word" in Emacs,
>> I would even seriously consider not to use that word, or maybe quote
>> it (in addition to explaining what it means).
>
> This is very helpful. You're right. In the attached, I've tried using
> "unix-word". Let me know what you think of that.
>
>> Also, since this is a command, its doc string should clearly separate
>> what happens in interactive invocation from what happens when called
>> from Lisp. DELIM belongs to the latter. (Is it even useful to
>> provide that option for Lisp-only calls? what's the use case for
>> that?)
>>
>> And finally, I wonder why we need this command? AFAIU, the original
>> intent was to implement something similar to unix-word-rubout, not a
>> new movement command. If the plan has changed, I think we need to
>> discuss the need once again.
>
> I think it was unhelpful of me to send this in without callers.
> I'm sorry about that.
>
> The reason for adding this is that it factors out what is in common
> between what Philip is doing, and unix-word-rubout.
> So in the attached revised patch, I've included unix-word-rubout.
Right, this is the command that we agreed on being necessary to appease
both people who want C-w to kill the region when no transient
region is active or to kill a word.
> I've also included a second readline command which I have bound in my
> own init. It demonstrates why there is a need for DELIM.
>
> By the way, forward-unix-word could also be a plain function.
> I made it a command because, well, why not. Let me know if you think it
> should be switched back to a function.
>
> --
> Sean Whitton
>
> From c047e640399bb923728ed9967e8545d53b22ea5c Mon Sep 17 00:00:00 2001
> From: Sean Whitton <spwhitton@spwhitton.name>
> Date: Fri, 6 Sep 2024 11:35:46 +0100
> Subject: [PATCH] New commands for moving and killing unix-words
>
> * lisp/simple.el (forward-unix-word, unix-word-rubout)
> (unix-filename-rubout): New commands.
> * etc/NEWS: Document them.
> ---
> etc/NEWS | 7 +++++++
> lisp/simple.el | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 64 insertions(+)
>
> diff --git a/etc/NEWS b/etc/NEWS
> index f3e719a34d3..54cf0a3df52 100644
> --- a/etc/NEWS
> +++ b/etc/NEWS
> @@ -123,6 +123,13 @@ When using 'visual-wrap-prefix-mode' in buffers with variable-pitch
> fonts, the wrapped text will now be lined up correctly so that it's
> exactly below the text after the prefix on the first line.
>
> +---
> +** New commands for moving and killing unix-words.
> +Unix-words are words separated by whitespace regardless of the buffer's
> +syntax table. In a Unix terminal or shell, C-w kills by unix-word.
> +The new commands 'forward-unix-word', 'unix-word-rubout' and
> +'unix-filename-rubout' allow you to bind keys to operate more similarly
> +to the terminal.
> \f
> * Changes in Specialized Modes and Packages in Emacs 31.1
>
> diff --git a/lisp/simple.el b/lisp/simple.el
> index 2453a129d0a..0322ac0cd8c 100644
> --- a/lisp/simple.el
> +++ b/lisp/simple.el
> @@ -8892,6 +8892,63 @@ current-word
> ;; If we found something nonempty, return it as a string.
> (unless (= start end)
> (buffer-substring-no-properties start end)))))
> +
> +(defun forward-unix-word (arg &optional delim)
> + "Move forward ARG unix-words.
> +A unix-word is whitespace-delimited.
> +Interactively, ARG is the numeric prefix argument, defaulting to 1.
> +A negative ARG means go backwards to the beginning of unix-words.
> +
> +Unix-words differ from Emacs words in that they are always delimited by
> +whitespace, regardless of the buffer's syntax table. This command
> +emulates how C-w at the Unix terminal or shell identifies words.
Should you mention the ^W notation here as well?
> +
> +When called from Lisp, DELIM specifies what characters are considered
> +whitespace. It is a string as might be passed to `skip-chars-forward'.
> +The default is \" \\f\\n\\r\\t\\v\". Do not prefix a `^' character."
I think it would be worth checking for a ^ and then throwing a user-error.
> + (interactive "^p")
> + (unless (zerop arg)
> + ;; We do skip over newlines by default because `backward-word' does.
> + (let* ((delim (or delim " \f\n\r\t\v"))
^
I'd use "\s" here (and below).
> + (ndelim (format "^%s" delim))
> + (start (point))
> + (fun (if (> arg 0)
> + #'skip-chars-forward
> + #'skip-chars-backward)))
> + (dotimes (_ (abs arg))
> + (funcall fun delim)
> + (funcall fun ndelim))
> + (constrain-to-field nil start))))
> +
> +(defun unix-word-rubout (arg)
> + "Kill ARG unix-words backwards.
> +A unix-word is whitespace-delimited.
> +Interactively, ARG is the numeric prefix argument, defaulting to 1.
> +A negative ARG means to kill forwards.
> +
> +Unix-words differ from Emacs words in that they are always delimited by
> +whitespace, regardless of the buffer's syntax table. Thus, this command
> +emulates C-w at the Unix terminal or shell identifies words.
> +See also this command's nakesake in Info node
> +`(readline)Commands For Killing'."
> + (interactive "^p")
> + (let ((start (point)))
> + (forward-unix-word (- arg))
> + (kill-region start (point))))
Won't there be an error here if the command is invoked with a negative argument?
> +
> +(defun unix-filename-rubout (arg)
> + "Kill ARG unix-words backwards, also treating `/' as whitespace.
> +A unix-word is whitespace-delimited.
> +Interactively, ARG is the numeric prefix argument, defaulting to 1.
> +A negative ARG means to kill forwards.
> +
> +This is like `unix-word-rubout' (which see), but `/' is also considered
> +whitespace. See this command's namesake in Info node
> +`(readline)Commands For Killing'."
> + (interactive "^p")
> + (let ((start (point)))
> + (forward-unix-word (- arg) "/ \f\n\r\t\v")
> + (kill-region start (point))))
> \f
> (defcustom fill-prefix nil
> "String for filling to insert at front of new line, or nil for none."
--
Philip Kaludercic on siskin
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-06 13:54 ` Sean Whitton
2024-09-06 16:32 ` Philip Kaludercic
@ 2024-09-07 9:52 ` Eli Zaretskii
2024-09-07 10:10 ` Philip Kaludercic
2024-09-07 21:08 ` Sean Whitton
1 sibling, 2 replies; 90+ messages in thread
From: Eli Zaretskii @ 2024-09-07 9:52 UTC (permalink / raw)
To: Sean Whitton; +Cc: philipk, rms, 69097, juri, stefankangas, acorallo
> From: Sean Whitton <spwhitton@spwhitton.name>
> Cc: philipk@posteo.net, stefankangas@gmail.com, acorallo@gnu.org,
> juri@linkov.net, rms@gnu.org, 69097@debbugs.gnu.org
> Date: Fri, 06 Sep 2024 14:54:58 +0100
>
> +(defun forward-unix-word (arg &optional delim)
> + "Move forward ARG unix-words.
> +A unix-word is whitespace-delimited.
> +Interactively, ARG is the numeric prefix argument, defaulting to 1.
> +A negative ARG means go backwards to the beginning of unix-words.
I again ask whether we need this command. It is okay to have a
function (perhaps even an internal one) to move by Unix-words, but
what are the use cases for such a command?
> +(defun unix-filename-rubout (arg)
> + "Kill ARG unix-words backwards, also treating `/' as whitespace.
> +A unix-word is whitespace-delimited.
> +Interactively, ARG is the numeric prefix argument, defaulting to 1.
> +A negative ARG means to kill forwards.
> +
> +This is like `unix-word-rubout' (which see), but `/' is also considered
> +whitespace.
I'd say '/' is treated as word delimiter. "Considered whitespace"
sounds strange to me.
Should we also treat a backslash as delimiter, for MS-Windows?
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-07 9:52 ` Eli Zaretskii
@ 2024-09-07 10:10 ` Philip Kaludercic
2024-09-07 21:08 ` Sean Whitton
1 sibling, 0 replies; 90+ messages in thread
From: Philip Kaludercic @ 2024-09-07 10:10 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: rms, 69097, juri, stefankangas, acorallo, Sean Whitton
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Sean Whitton <spwhitton@spwhitton.name>
>> Cc: philipk@posteo.net, stefankangas@gmail.com, acorallo@gnu.org,
>> juri@linkov.net, rms@gnu.org, 69097@debbugs.gnu.org
>> Date: Fri, 06 Sep 2024 14:54:58 +0100
>>
>> +(defun forward-unix-word (arg &optional delim)
>> + "Move forward ARG unix-words.
>> +A unix-word is whitespace-delimited.
>> +Interactively, ARG is the numeric prefix argument, defaulting to 1.
>> +A negative ARG means go backwards to the beginning of unix-words.
>
> I again ask whether we need this command. It is okay to have a
> function (perhaps even an internal one) to move by Unix-words, but
> what are the use cases for such a command?
I think it is conceivable that some users might prefer to have
deterministic word movement that doesn't change depending on the major
mode. But as mention earlier, this is functionality that might be worth
relegating into a subword-mode-like mode, instead of defining new
commands.
>> +(defun unix-filename-rubout (arg)
>> + "Kill ARG unix-words backwards, also treating `/' as whitespace.
>> +A unix-word is whitespace-delimited.
>> +Interactively, ARG is the numeric prefix argument, defaulting to 1.
>> +A negative ARG means to kill forwards.
>> +
>> +This is like `unix-word-rubout' (which see), but `/' is also considered
>> +whitespace.
>
> I'd say '/' is treated as word delimiter. "Considered whitespace"
> sounds strange to me.
>
> Should we also treat a backslash as delimiter, for MS-Windows?
--
Philip Kaludercic on siskin
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-07 9:52 ` Eli Zaretskii
2024-09-07 10:10 ` Philip Kaludercic
@ 2024-09-07 21:08 ` Sean Whitton
2024-09-07 21:17 ` Sean Whitton
2024-09-08 10:38 ` Philip Kaludercic
1 sibling, 2 replies; 90+ messages in thread
From: Sean Whitton @ 2024-09-07 21:08 UTC (permalink / raw)
To: Eli Zaretskii, philipk; +Cc: 69097, acorallo, stefankangas, rms, juri
[-- Attachment #1: Type: text/plain, Size: 729 bytes --]
Hello,
Thank you both for the feedback. Attached is an updated version.
A few replies:
On Fri 06 Sep 2024 at 04:32pm GMT, Philip Kaludercic wrote:
> Won't there be an error here if the command is invoked with a negative
> argument?
Do you mean that you think there should be an error?
I don't see any need for that.
On Sat 07 Sep 2024 at 12:52pm +03, Eli Zaretskii wrote:
> I again ask whether we need this command. It is okay to have a
> function (perhaps even an internal one) to move by Unix-words, but
> what are the use cases for such a command?
That's fine. I've turned it back into a function.
> Should we also treat a backslash as delimiter, for MS-Windows?
Good idea. That's more useful.
--
Sean Whitton
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: v3-0001-New-commands-for-moving-and-killing-unix-words.patch --]
[-- Type: text/x-patch, Size: 3992 bytes --]
From 9163f6ab16816702f8bc6acb6f22734eb57acfc7 Mon Sep 17 00:00:00 2001
From: Sean Whitton <spwhitton@spwhitton.name>
Date: Fri, 6 Sep 2024 11:35:46 +0100
Subject: [PATCH v3] New commands for moving and killing unix-words
* lisp/simple.el (forward-unix-word): New function.
(unix-word-rubout, unix-filename-rubout): New commands.
* etc/NEWS: Announce the new commands.
---
etc/NEWS | 6 ++++++
lisp/simple.el | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 63 insertions(+)
diff --git a/etc/NEWS b/etc/NEWS
index f3e719a34d3..104941425c2 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -123,6 +123,12 @@ When using 'visual-wrap-prefix-mode' in buffers with variable-pitch
fonts, the wrapped text will now be lined up correctly so that it's
exactly below the text after the prefix on the first line.
+---
+** New commands 'unix-word-rubout' and 'unix-filename-rubout'.
+Unix-words are words separated by whitespace regardless of the buffer's
+syntax table. In a Unix terminal or shell, C-w kills by Unix-word.
+The new commands 'unix-word-rubout' and 'unix-filename-rubout' allow
+you to bind keys to operate more similarly to the terminal.
\f
* Changes in Specialized Modes and Packages in Emacs 31.1
diff --git a/lisp/simple.el b/lisp/simple.el
index 2453a129d0a..1b910b0ed22 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -8892,6 +8892,63 @@ current-word
;; If we found something nonempty, return it as a string.
(unless (= start end)
(buffer-substring-no-properties start end)))))
+
+(defun forward-unix-word (n &optional delim)
+ "Move forward N Unix-words.
+A Unix-word is whitespace-delimited.
+A negative N means go backwards to the beginning of Unix-words.
+
+Unix-words differ from Emacs words in that they are always delimited by
+whitespace, regardless of the buffer's syntax table. This function
+emulates how C-w at the Unix terminal or shell identifies words.
+
+Optional argument DELIM specifies what characters are considered
+whitespace. It is a string as might be passed to `skip-chars-forward'.
+The default is \"\\s\\f\\n\\r\\t\\v\". Do not prefix a `^' character."
+ (when (and delim (string-prefix-p "^" delim))
+ (error "DELIM argument must not begin with `^'"))
+ (unless (zerop n)
+ ;; We do skip over newlines by default because `backward-word' does.
+ (let* ((delim (or delim "\s\f\n\r\t\v"))
+ (ndelim (format "^%s" delim))
+ (start (point))
+ (fun (if (> n 0)
+ #'skip-chars-forward
+ #'skip-chars-backward)))
+ (dotimes (_ (abs n))
+ (funcall fun delim)
+ (funcall fun ndelim))
+ (constrain-to-field nil start))))
+
+(defun unix-word-rubout (arg)
+ "Kill ARG Unix-words backwards.
+A Unix-word is whitespace-delimited.
+Interactively, ARG is the numeric prefix argument, defaulting to 1.
+A negative ARG means to kill forwards.
+
+Unix-words differ from Emacs words in that they are always delimited by
+whitespace, regardless of the buffer's syntax table.
+Thus, this command emulates C-w at the Unix terminal or shell.
+See also this command's nakesake in Info node
+`(readline)Commands For Killing'."
+ (interactive "^p")
+ (let ((start (point)))
+ (forward-unix-word (- arg))
+ (kill-region start (point))))
+
+(defun unix-filename-rubout (arg)
+ "Kill ARG Unix-words backwards, also treating `/' as delimiting words.
+A Unix-word is whitespace-delimited.
+Interactively, ARG is the numeric prefix argument, defaulting to 1.
+A negative ARG means to kill forwards.
+
+This is like `unix-word-rubout' (which see), but `/' is also treated as
+a word delimiter. See this command's namesake in Info node
+`(readline)Commands For Killing'."
+ (interactive "^p")
+ (let ((start (point)))
+ (forward-unix-word (- arg) "\\/\s\f\n\r\t\v")
+ (kill-region start (point))))
\f
(defcustom fill-prefix nil
"String for filling to insert at front of new line, or nil for none."
--
2.39.2
^ permalink raw reply related [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-07 21:08 ` Sean Whitton
@ 2024-09-07 21:17 ` Sean Whitton
2024-09-09 17:54 ` Sean Whitton
2024-09-08 10:38 ` Philip Kaludercic
1 sibling, 1 reply; 90+ messages in thread
From: Sean Whitton @ 2024-09-07 21:17 UTC (permalink / raw)
To: Eli Zaretskii, philipk; +Cc: 69097, acorallo, stefankangas, rms, juri
[-- Attachment #1: Type: text/plain, Size: 322 bytes --]
Hello,
On Sat 07 Sep 2024 at 10:08pm +01, Sean Whitton wrote:
> Hello,
>
> Thank you both for the feedback. Attached is an updated version.
I neglected to update the docstring for adding backslashes as delimiters
in unix-filename-rubout. Fixed in the attached, along with a another
few small fixes.
--
Sean Whitton
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: v4-0001-New-commands-unix-word-rubout-unix-filename-rubou.patch --]
[-- Type: text/x-patch, Size: 3998 bytes --]
From 059ca7388494f21d13c87f114965a2ec1fc1cc55 Mon Sep 17 00:00:00 2001
From: Sean Whitton <spwhitton@spwhitton.name>
Date: Fri, 6 Sep 2024 11:35:46 +0100
Subject: [PATCH v4] New commands unix-word-rubout, unix-filename-rubout
* lisp/simple.el (forward-unix-word): New function.
(unix-word-rubout, unix-filename-rubout): New commands.
* etc/NEWS: Announce the new commands.
---
etc/NEWS | 6 ++++++
lisp/simple.el | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 63 insertions(+)
diff --git a/etc/NEWS b/etc/NEWS
index f3e719a34d3..104941425c2 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -123,6 +123,12 @@ When using 'visual-wrap-prefix-mode' in buffers with variable-pitch
fonts, the wrapped text will now be lined up correctly so that it's
exactly below the text after the prefix on the first line.
+---
+** New commands 'unix-word-rubout' and 'unix-filename-rubout'.
+Unix-words are words separated by whitespace regardless of the buffer's
+syntax table. In a Unix terminal or shell, C-w kills by Unix-word.
+The new commands 'unix-word-rubout' and 'unix-filename-rubout' allow
+you to bind keys to operate more similarly to the terminal.
\f
* Changes in Specialized Modes and Packages in Emacs 31.1
diff --git a/lisp/simple.el b/lisp/simple.el
index 2453a129d0a..18cc15f6f5d 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -8892,6 +8892,63 @@ current-word
;; If we found something nonempty, return it as a string.
(unless (= start end)
(buffer-substring-no-properties start end)))))
+
+(defun forward-unix-word (n &optional delim)
+ "Move forward N Unix-words.
+A Unix-word is whitespace-delimited.
+A negative N means go backwards to the beginning of Unix-words.
+
+Unix-words differ from Emacs words in that they are always delimited by
+whitespace, regardless of the buffer's syntax table. This function
+emulates how C-w at the Unix terminal or shell identifies words.
+
+Optional argument DELIM specifies what characters are considered
+whitespace. It is a string as might be passed to `skip-chars-forward'.
+The default is \"\\s\\f\\n\\r\\t\\v\". Do not prefix a `^' character."
+ (when (string-prefix-p "^" delim)
+ (error "DELIM argument must not begin with `^'"))
+ (unless (zerop n)
+ ;; We do skip over newlines by default because `backward-word' does.
+ (let* ((delim (or delim "\s\f\n\r\t\v"))
+ (ndelim (format "^%s" delim))
+ (start (point))
+ (fun (if (> n 0)
+ #'skip-chars-forward
+ #'skip-chars-backward)))
+ (dotimes (_ (abs n))
+ (funcall fun delim)
+ (funcall fun ndelim))
+ (constrain-to-field nil start))))
+
+(defun unix-word-rubout (arg)
+ "Kill ARG Unix-words backwards.
+A Unix-word is whitespace-delimited.
+Interactively, ARG is the numeric prefix argument, defaulting to 1.
+A negative ARG means to kill forwards.
+
+Unix-words differ from Emacs words in that they are always delimited by
+whitespace, regardless of the buffer's syntax table.
+Thus, this command emulates C-w at the Unix terminal or shell.
+See also this command's nakesake in Info node
+`(readline)Commands For Killing'."
+ (interactive "^p")
+ (let ((start (point)))
+ (forward-unix-word (- arg))
+ (kill-region start (point))))
+
+(defun unix-filename-rubout (arg)
+ "Kill ARG Unix-words backwards, also treating slashes as word delimiters.
+A Unix-word is whitespace-delimited.
+Interactively, ARG is the numeric prefix argument, defaulting to 1.
+A negative ARG means to kill forwards.
+
+This is like `unix-word-rubout' (which see), but `/' and `\\' are also
+treated as delimiting words. See this command's namesake in Info node
+`(readline)Commands For Killing'."
+ (interactive "^p")
+ (let ((start (point)))
+ (forward-unix-word (- arg) "\\/\s\f\n\r\t\v")
+ (kill-region start (point))))
\f
(defcustom fill-prefix nil
"String for filling to insert at front of new line, or nil for none."
--
2.39.2
^ permalink raw reply related [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-07 21:08 ` Sean Whitton
2024-09-07 21:17 ` Sean Whitton
@ 2024-09-08 10:38 ` Philip Kaludercic
1 sibling, 0 replies; 90+ messages in thread
From: Philip Kaludercic @ 2024-09-08 10:38 UTC (permalink / raw)
To: Sean Whitton; +Cc: rms, 69097, juri, stefankangas, Eli Zaretskii, acorallo
Sean Whitton <spwhitton@spwhitton.name> writes:
> Hello,
>
> Thank you both for the feedback. Attached is an updated version.
>
> A few replies:
>
> On Fri 06 Sep 2024 at 04:32pm GMT, Philip Kaludercic wrote:
>
>> Won't there be an error here if the command is invoked with a negative
>> argument?
>
> Do you mean that you think there should be an error?
> I don't see any need for that.
I had mistakenly assumed that (kill-region start (point)) would throw an
error if (> start (point)), and that it would be better to catch that
case earlier. But I just checked, and kill-region does the right thing,
so forget about it.
--
Philip Kaludercic on icterid
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-07 21:17 ` Sean Whitton
@ 2024-09-09 17:54 ` Sean Whitton
2024-09-09 19:03 ` Eli Zaretskii
2024-09-09 19:23 ` Philip Kaludercic
0 siblings, 2 replies; 90+ messages in thread
From: Sean Whitton @ 2024-09-09 17:54 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: philipk, rms, 69097, juri, stefankangas, acorallo
Hello Eli,
Any comments on v4? I'd like to commit to unblock Philip. Thanks!
--
Sean Whitton
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-09 17:54 ` Sean Whitton
@ 2024-09-09 19:03 ` Eli Zaretskii
2024-09-09 19:48 ` Sean Whitton
2024-09-09 19:23 ` Philip Kaludercic
1 sibling, 1 reply; 90+ messages in thread
From: Eli Zaretskii @ 2024-09-09 19:03 UTC (permalink / raw)
To: Sean Whitton; +Cc: philipk, rms, 69097, juri, stefankangas, acorallo
> From: Sean Whitton <spwhitton@spwhitton.name>
> Cc: philipk@posteo.net, stefankangas@gmail.com, acorallo@gnu.org,
> juri@linkov.net, rms@gnu.org, 69097@debbugs.gnu.org
> Date: Mon, 09 Sep 2024 18:54:16 +0100
>
> Hello Eli,
>
> Any comments on v4?
When I have time.
> I'd like to commit to unblock Philip.
Sure, but there's no rush.
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-09 17:54 ` Sean Whitton
2024-09-09 19:03 ` Eli Zaretskii
@ 2024-09-09 19:23 ` Philip Kaludercic
2024-09-14 9:12 ` Eli Zaretskii
1 sibling, 1 reply; 90+ messages in thread
From: Philip Kaludercic @ 2024-09-09 19:23 UTC (permalink / raw)
To: Sean Whitton; +Cc: rms, 69097, juri, stefankangas, Eli Zaretskii, acorallo
[-- Attachment #1: Type: text/plain, Size: 289 bytes --]
Sean Whitton <spwhitton@spwhitton.name> writes:
> Hello Eli,
>
> Any comments on v4? I'd like to commit to unblock Philip. Thanks!
Here is my updated patch. If you want to, you can push both at once so
that we can close the issue more quickly as soon as Eli has time to take
a look:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Allow-kill-region-kill-the-last-word-when-there-is-n.patch --]
[-- Type: text/x-diff, Size: 4358 bytes --]
From 0f19dadb75a01873cb3f40a6addd825e63c266ce Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <philipk@posteo.net>
Date: Tue, 3 Sep 2024 18:29:56 +0200
Subject: [PATCH] Allow 'kill-region' kill the last word when there is no
region
* etc/NEWS: Document the new user option.
* lisp/simple.el (kill-region-dwim): Add new option.
(kill-region): Respect 'kill-region-dwim'. (Bug#69097)
---
etc/NEWS | 7 +++++++
lisp/simple.el | 41 ++++++++++++++++++++++++++++++++++-------
2 files changed, 41 insertions(+), 7 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index add438e8b6a..8cde2c294a9 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -129,6 +129,13 @@ Unix-words are words separated by whitespace regardless of the buffer's
syntax table. In a Unix terminal or shell, C-w kills by Unix-word.
The new commands 'unix-word-rubout' and 'unix-filename-rubout' allow
you to bind keys to operate more similarly to the terminal.
+
+---
+** New user option 'kill-word-dwim'.
+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.
+
\f
* Changes in Specialized Modes and Packages in Emacs 31.1
diff --git a/lisp/simple.el b/lisp/simple.el
index bbb13c1b471..d1be33ce87d 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -5817,6 +5817,19 @@ kill-read-only-ok
:type 'boolean
:group 'killing)
+(defcustom kill-region-dwim nil
+ "Behaviour when `kill-region' is invoked without an active region.
+If set to nil (default), the behaviour of `kill-region' stays the same.
+If set to `emacs-word', then kill the last word as defined by the
+current major mode. If set to `unix-word', then kill the last word in
+the style of a shell like Bash, disregarding the major mode like with
+`unix-word-rubout'."
+ :type '(choice (const :tag "Kill a word like `backward-kill-word'" emacs-word)
+ (const :tag "Kill a word like Bash would" unix-word)
+ (const :tag "Do not kill anything" nil))
+ :group 'killing
+ :version "31.1")
+
(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.
@@ -5843,21 +5856,35 @@ kill-region
(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', 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."
+ this command always kills the current region. It is possible to
+ override this behaviour by customising the user option
+ `kill-region-dwim'."
;; Pass mark first, then point, because the order matters when
;; calling `kill-append'.
(interactive (progn
(let ((beg (mark))
(end (point)))
- (unless (and beg end)
+ (cond
+ ((and kill-region-dwim (not (use-region-p)))
+ (list beg end kill-region-dwim))
+ ((not (or beg end))
(user-error "The mark is not set now, so there is no region"))
- (list beg end 'region))))
+ ((list beg end 'region))))))
+
(condition-case nil
- (let ((string (if region
- (funcall region-extract-function 'delete)
- (filter-buffer-substring beg end 'delete))))
+ (let ((string (cond
+ ((memq region '(unix-word emacs-word))
+ (let ((end (point)))
+ (save-excursion
+ (if (eq region 'emacs-word)
+ (forward-word -1)
+ (forward-unix-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)
--
2.45.2
[-- Attachment #3: Type: text/plain, Size: 35 bytes --]
--
Philip Kaludercic on siskin
^ permalink raw reply related [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-09 19:03 ` Eli Zaretskii
@ 2024-09-09 19:48 ` Sean Whitton
0 siblings, 0 replies; 90+ messages in thread
From: Sean Whitton @ 2024-09-09 19:48 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: philipk, rms, 69097, juri, stefankangas, acorallo
Hello,
On Mon 09 Sep 2024 at 10:03pm +03, Eli Zaretskii wrote:
>> From: Sean Whitton <spwhitton@spwhitton.name>
>> Cc: philipk@posteo.net, stefankangas@gmail.com, acorallo@gnu.org,
>> juri@linkov.net, rms@gnu.org, 69097@debbugs.gnu.org
>> Date: Mon, 09 Sep 2024 18:54:16 +0100
>>
>> Hello Eli,
>>
>> Any comments on v4?
>
> When I have time.
Sorry, thought you might have missed it.
--
Sean Whitton
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-09 19:23 ` Philip Kaludercic
@ 2024-09-14 9:12 ` Eli Zaretskii
2024-09-14 11:27 ` Sean Whitton
0 siblings, 1 reply; 90+ messages in thread
From: Eli Zaretskii @ 2024-09-14 9:12 UTC (permalink / raw)
To: Philip Kaludercic; +Cc: rms, 69097, juri, stefankangas, acorallo, spwhitton
> From: Philip Kaludercic <philipk@posteo.net>
> Cc: Eli Zaretskii <eliz@gnu.org>, stefankangas@gmail.com,
> acorallo@gnu.org, juri@linkov.net, rms@gnu.org, 69097@debbugs.gnu.org
> Date: Mon, 09 Sep 2024 19:23:32 +0000
>
> > Hello Eli,
> >
> > Any comments on v4? I'd like to commit to unblock Philip. Thanks!
>
> Here is my updated patch. If you want to, you can push both at once so
> that we can close the issue more quickly as soon as Eli has time to take
> a look:
I'm okay with installing both patches, but please first fix the few
minor nits below:
> +---
> +** New user option 'kill-word-dwim'.
> +This option will modify the fall-back behaviour of 'kill-region' if no
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
"This option, if non-nil, modifies the fall-back behavior..."
> +region is active, and will kill the last word instead of raising an
> +error.
This should also say explicitly that users who turn off Transient Mark
mode will need to either activate the region ("C-x C-x" etc.) or
invoke the new word-rubout commands by hand, since otherwise the
region is never active for them.
> +(defcustom kill-region-dwim nil
> + "Behaviour when `kill-region' is invoked without an active region.
> +If set to nil (default), the behaviour of `kill-region' stays the same.
^^^^^^^^^ ^^^^^^^^^^^^^^
"behavior", US English spelling.
The same as what?
Thanks.
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-14 9:12 ` Eli Zaretskii
@ 2024-09-14 11:27 ` Sean Whitton
2024-09-14 13:39 ` Philip Kaludercic
0 siblings, 1 reply; 90+ messages in thread
From: Sean Whitton @ 2024-09-14 11:27 UTC (permalink / raw)
To: Eli Zaretskii, Philip Kaludercic; +Cc: acorallo, stefankangas, rms, 69097, juri
Hello,
Thanks for the re-review, Eli. I've pushed my patch.
> This should also say explicitly that users who turn off Transient Mark
> mode will need to either activate the region ("C-x C-x" etc.) or
> invoke the new word-rubout commands by hand, since otherwise the
> region is never active for them.
This seems like Philip might want to think a bit about what it is more
helpful to say, so I'll hold off on editing and pushing his patch
myself.
--
Sean Whitton
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-14 11:27 ` Sean Whitton
@ 2024-09-14 13:39 ` Philip Kaludercic
2024-09-14 14:05 ` Eli Zaretskii
0 siblings, 1 reply; 90+ messages in thread
From: Philip Kaludercic @ 2024-09-14 13:39 UTC (permalink / raw)
To: Sean Whitton; +Cc: rms, 69097, juri, stefankangas, Eli Zaretskii, acorallo
[-- Attachment #1: Type: text/plain, Size: 529 bytes --]
Sean Whitton <spwhitton@spwhitton.name> writes:
> Hello,
>
> Thanks for the re-review, Eli. I've pushed my patch.
>
>> This should also say explicitly that users who turn off Transient Mark
>> mode will need to either activate the region ("C-x C-x" etc.) or
>> invoke the new word-rubout commands by hand, since otherwise the
>> region is never active for them.
>
> This seems like Philip might want to think a bit about what it is more
> helpful to say, so I'll hold off on editing and pushing his patch
> myself.
How about
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Allow-kill-region-kill-the-last-word-when-there-is-n.patch --]
[-- Type: text/x-diff, Size: 4527 bytes --]
From 2fb36ab68eb177e232b9ee4b0d5ea105b9aa9f16 Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <philipk@posteo.net>
Date: Tue, 3 Sep 2024 18:29:56 +0200
Subject: [PATCH] Allow 'kill-region' kill the last word when there is no
region
* etc/NEWS: Document the new user option.
* lisp/simple.el (kill-region-dwim): Add new option.
(kill-region): Respect 'kill-region-dwim'. (Bug#69097)
---
etc/NEWS | 9 +++++++++
lisp/simple.el | 41 ++++++++++++++++++++++++++++++++++-------
2 files changed, 43 insertions(+), 7 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index add438e8b6a..f01c6e2b3cd 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -129,6 +129,15 @@ Unix-words are words separated by whitespace regardless of the buffer's
syntax table. In a Unix terminal or shell, C-w kills by Unix-word.
The new commands 'unix-word-rubout' and 'unix-filename-rubout' allow
you to bind keys to operate more similarly to the terminal.
+
+---
+** New user option 'kill-word-dwim'.
+This option, if non-nil, modifies the fall-back behaviour of
+'kill-region' if no region is active, and will kill the last word
+instead of raising an error. Note that if you have disabled Transient
+Mark mode you might prefer to use 'unix-word-rubout', as this feature
+relies on there being an active region.
+
\f
* Changes in Specialized Modes and Packages in Emacs 31.1
diff --git a/lisp/simple.el b/lisp/simple.el
index bbb13c1b471..f05ded36c22 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -5817,6 +5817,19 @@ kill-read-only-ok
:type 'boolean
:group 'killing)
+(defcustom kill-region-dwim nil
+ "Behaviour when `kill-region' is invoked without an active region.
+If set to nil (default), then the behavior `kill-region' will not
+change. If set to `emacs-word', then kill the last word as defined by
+the current major mode. If set to `unix-word', then kill the last word
+in the style of a shell like Bash, disregarding the major mode like with
+`unix-word-rubout'."
+ :type '(choice (const :tag "Kill a word like `backward-kill-word'" emacs-word)
+ (const :tag "Kill a word like Bash would" unix-word)
+ (const :tag "Do not kill anything" nil))
+ :group 'killing
+ :version "31.1")
+
(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.
@@ -5843,21 +5856,35 @@ kill-region
(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', 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."
+ this command always kills the current region. It is possible to
+ override this behaviour by customising the user option
+ `kill-region-dwim'."
;; Pass mark first, then point, because the order matters when
;; calling `kill-append'.
(interactive (progn
(let ((beg (mark))
(end (point)))
- (unless (and beg end)
+ (cond
+ ((and kill-region-dwim (not (use-region-p)))
+ (list beg end kill-region-dwim))
+ ((not (or beg end))
(user-error "The mark is not set now, so there is no region"))
- (list beg end 'region))))
+ ((list beg end 'region))))))
+
(condition-case nil
- (let ((string (if region
- (funcall region-extract-function 'delete)
- (filter-buffer-substring beg end 'delete))))
+ (let ((string (cond
+ ((memq region '(unix-word emacs-word))
+ (let ((end (point)))
+ (save-excursion
+ (if (eq region 'emacs-word)
+ (forward-word -1)
+ (forward-unix-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)
--
2.45.2
[-- Attachment #3: Type: text/plain, Size: 113 bytes --]
And I think that you can already push your change, and I can follow on
later.
--
Philip Kaludercic on siskin
^ permalink raw reply related [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-14 13:39 ` Philip Kaludercic
@ 2024-09-14 14:05 ` Eli Zaretskii
2024-09-14 14:13 ` Philip Kaludercic
0 siblings, 1 reply; 90+ messages in thread
From: Eli Zaretskii @ 2024-09-14 14:05 UTC (permalink / raw)
To: Philip Kaludercic; +Cc: rms, 69097, juri, stefankangas, acorallo, spwhitton
> From: Philip Kaludercic <philipk@posteo.net>
> Cc: Eli Zaretskii <eliz@gnu.org>, rms@gnu.org, 69097@debbugs.gnu.org,
> juri@linkov.net, stefankangas@gmail.com, acorallo@gnu.org
> Date: Sat, 14 Sep 2024 13:39:43 +0000
>
> > This seems like Philip might want to think a bit about what it is more
> > helpful to say, so I'll hold off on editing and pushing his patch
> > myself.
>
> How about
LGTM, but there's still a "behaviour" there...
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-14 14:05 ` Eli Zaretskii
@ 2024-09-14 14:13 ` Philip Kaludercic
2024-09-14 14:24 ` Eli Zaretskii
` (2 more replies)
0 siblings, 3 replies; 90+ messages in thread
From: Philip Kaludercic @ 2024-09-14 14:13 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: rms, 69097, juri, stefankangas, acorallo, spwhitton
[-- Attachment #1: Type: text/plain, Size: 551 bytes --]
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Philip Kaludercic <philipk@posteo.net>
>> Cc: Eli Zaretskii <eliz@gnu.org>, rms@gnu.org, 69097@debbugs.gnu.org,
>> juri@linkov.net, stefankangas@gmail.com, acorallo@gnu.org
>> Date: Sat, 14 Sep 2024 13:39:43 +0000
>>
>> > This seems like Philip might want to think a bit about what it is more
>> > helpful to say, so I'll hold off on editing and pushing his patch
>> > myself.
>>
>> How about
>
> LGTM, but there's still a "behaviour" there...
Eh, sorry! I double checked the patch this time:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Allow-kill-region-kill-the-last-word-when-there-is-n.patch --]
[-- Type: text/x-diff, Size: 4524 bytes --]
From 2b92dcb771646f5ff5b7f574c9ebeada9e8593a5 Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <philipk@posteo.net>
Date: Tue, 3 Sep 2024 18:29:56 +0200
Subject: [PATCH] Allow 'kill-region' kill the last word when there is no
region
* etc/NEWS: Document the new user option.
* lisp/simple.el (kill-region-dwim): Add new option.
(kill-region): Respect 'kill-region-dwim'. (Bug#69097)
---
etc/NEWS | 9 +++++++++
lisp/simple.el | 41 ++++++++++++++++++++++++++++++++++-------
2 files changed, 43 insertions(+), 7 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index add438e8b6a..3984670bff7 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -129,6 +129,15 @@ Unix-words are words separated by whitespace regardless of the buffer's
syntax table. In a Unix terminal or shell, C-w kills by Unix-word.
The new commands 'unix-word-rubout' and 'unix-filename-rubout' allow
you to bind keys to operate more similarly to the terminal.
+
+---
+** New user option 'kill-word-dwim'.
+This option, if non-nil, modifies the fall-back behavior of
+'kill-region' if no region is active, and will kill the last word
+instead of raising an error. Note that if you have disabled Transient
+Mark mode you might prefer to use 'unix-word-rubout', as this feature
+relies on there being an active region.
+
\f
* Changes in Specialized Modes and Packages in Emacs 31.1
diff --git a/lisp/simple.el b/lisp/simple.el
index bbb13c1b471..fb7dad50a13 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -5817,6 +5817,19 @@ kill-read-only-ok
:type 'boolean
:group 'killing)
+(defcustom kill-region-dwim nil
+ "Behavior when `kill-region' is invoked without an active region.
+If set to nil (default), then the behavior `kill-region' will not
+change. If set to `emacs-word', then kill the last word as defined by
+the current major mode. If set to `unix-word', then kill the last word
+in the style of a shell like Bash, disregarding the major mode like with
+`unix-word-rubout'."
+ :type '(choice (const :tag "Kill a word like `backward-kill-word'" emacs-word)
+ (const :tag "Kill a word like Bash would" unix-word)
+ (const :tag "Do not kill anything" nil))
+ :group 'killing
+ :version "31.1")
+
(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.
@@ -5843,21 +5856,35 @@ kill-region
(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', 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."
+ this command always kills the current region. It is possible to
+ override this behavior by customising the user option
+ `kill-region-dwim'."
;; Pass mark first, then point, because the order matters when
;; calling `kill-append'.
(interactive (progn
(let ((beg (mark))
(end (point)))
- (unless (and beg end)
+ (cond
+ ((and kill-region-dwim (not (use-region-p)))
+ (list beg end kill-region-dwim))
+ ((not (or beg end))
(user-error "The mark is not set now, so there is no region"))
- (list beg end 'region))))
+ ((list beg end 'region))))))
+
(condition-case nil
- (let ((string (if region
- (funcall region-extract-function 'delete)
- (filter-buffer-substring beg end 'delete))))
+ (let ((string (cond
+ ((memq region '(unix-word emacs-word))
+ (let ((end (point)))
+ (save-excursion
+ (if (eq region 'emacs-word)
+ (forward-word -1)
+ (forward-unix-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)
--
2.45.2
[-- Attachment #3: Type: text/plain, Size: 102 bytes --]
If there is nothing left, then Sean can push both changes at once.
--
Philip Kaludercic on siskin
^ permalink raw reply related [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-14 14:13 ` Philip Kaludercic
@ 2024-09-14 14:24 ` Eli Zaretskii
2024-09-14 16:10 ` Sean Whitton
2024-09-17 17:58 ` Juri Linkov
2 siblings, 0 replies; 90+ messages in thread
From: Eli Zaretskii @ 2024-09-14 14:24 UTC (permalink / raw)
To: Philip Kaludercic; +Cc: rms, 69097, juri, stefankangas, acorallo, spwhitton
> From: Philip Kaludercic <philipk@posteo.net>
> Cc: spwhitton@spwhitton.name, rms@gnu.org, 69097@debbugs.gnu.org,
> juri@linkov.net, stefankangas@gmail.com, acorallo@gnu.org
> Date: Sat, 14 Sep 2024 14:13:06 +0000
>
> >> How about
> >
> > LGTM, but there's still a "behaviour" there...
>
> Eh, sorry! I double checked the patch this time:
Thanks, feel free to install.
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-14 14:13 ` Philip Kaludercic
2024-09-14 14:24 ` Eli Zaretskii
@ 2024-09-14 16:10 ` Sean Whitton
2024-09-14 16:26 ` German Pacenza
2024-09-14 21:19 ` Philip Kaludercic
2024-09-17 17:58 ` Juri Linkov
2 siblings, 2 replies; 90+ messages in thread
From: Sean Whitton @ 2024-09-14 16:10 UTC (permalink / raw)
To: Philip Kaludercic; +Cc: 69097-done
Hello,
Installed. I fixed a couple of typos in your commit, and pushed another
commit doing some reformatting for readability. Hope you like it!
--
Sean Whitton
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-14 16:10 ` Sean Whitton
@ 2024-09-14 16:26 ` German Pacenza
2024-09-14 16:36 ` Sean Whitton
2024-09-14 21:19 ` Philip Kaludercic
1 sibling, 1 reply; 90+ messages in thread
From: German Pacenza @ 2024-09-14 16:26 UTC (permalink / raw)
To: 69097; +Cc: philipk, spwhitton
News entry mentions kill-word-dwim instead of kill region-dwim
--
German Pacenza
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-14 16:26 ` German Pacenza
@ 2024-09-14 16:36 ` Sean Whitton
0 siblings, 0 replies; 90+ messages in thread
From: Sean Whitton @ 2024-09-14 16:36 UTC (permalink / raw)
To: German Pacenza; +Cc: philipk, 69097
Hello,
On Sat 14 Sep 2024 at 01:26pm -03, German Pacenza wrote:
> News entry mentions kill-word-dwim instead of kill region-dwim
Thanks, fixed!
--
Sean Whitton
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-14 16:10 ` Sean Whitton
2024-09-14 16:26 ` German Pacenza
@ 2024-09-14 21:19 ` Philip Kaludercic
2024-09-14 21:22 ` Sean Whitton
1 sibling, 1 reply; 90+ messages in thread
From: Philip Kaludercic @ 2024-09-14 21:19 UTC (permalink / raw)
To: Sean Whitton; +Cc: 69097-done
Is the "(which see)" at the end intentional?
On 14 September 2024 18:10:04 CEST, Sean Whitton <spwhitton@spwhitton.name> wrote:
>Hello,
>
>Installed. I fixed a couple of typos in your commit, and pushed another
>commit doing some reformatting for readability. Hope you like it!
>
--
Sent from my phone. Please excuse my brevity and bad formatting.
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-14 21:19 ` Philip Kaludercic
@ 2024-09-14 21:22 ` Sean Whitton
0 siblings, 0 replies; 90+ messages in thread
From: Sean Whitton @ 2024-09-14 21:22 UTC (permalink / raw)
To: Philip Kaludercic; +Cc: 69097-done
Hello,
On Sat 14 Sep 2024 at 09:19pm GMT, Philip Kaludercic wrote:
> Is the "(which see)" at the end intentional?
Yeah, not a typo. (It's actually all over the codebase.)
--
Sean Whitton
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-14 14:13 ` Philip Kaludercic
2024-09-14 14:24 ` Eli Zaretskii
2024-09-14 16:10 ` Sean Whitton
@ 2024-09-17 17:58 ` Juri Linkov
2024-09-18 16:08 ` Juri Linkov
2024-09-19 7:19 ` Philip Kaludercic
2 siblings, 2 replies; 90+ messages in thread
From: Juri Linkov @ 2024-09-17 17:58 UTC (permalink / raw)
To: Philip Kaludercic; +Cc: 69097
Thanks for the new command! I'd like to use it, but currently can't
because I have customized 'mark-even-if-inactive' to nil.
> +** New user option 'kill-word-dwim'.
> +This option, if non-nil, modifies the fall-back behavior of
> +'kill-region' if no region is active, and will kill the last word
> +instead of raising an error. Note that if you have disabled Transient
> +Mark mode you might prefer to use 'unix-word-rubout', as this feature
> +relies on there being an active region.
This could mention the default keybindings of 'kill-region' ('C-w').
> +(defcustom kill-region-dwim nil
> + "Behavior when `kill-region' is invoked without an active region.
> +If set to nil (default), then the behavior `kill-region' will not
> +change. If set to `emacs-word', then kill the last word as defined by
> +the current major mode. If set to `unix-word', then kill the last word
> +in the style of a shell like Bash, disregarding the major mode like with
> +`unix-word-rubout'."
> + :type '(choice (const :tag "Kill a word like `backward-kill-word'" emacs-word)
> + (const :tag "Kill a word like Bash would" unix-word)
> + (const :tag "Do not kill anything" nil))
Usually the default value 'nil' comes first.
This helps to disable an option by always selecting 0
from the Customization menu.
> (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.
> @@ -5843,21 +5856,35 @@ kill-region
> (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', 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."
> + this command always kills the current region. It is possible to
> + override this behavior by customising the user option
> + `kill-region-dwim'."
I tried to use this command with `emacs -Q`, and typed 'C-w C-w' twice,
but it fails with
Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p nil)
kill-region(nil 16 emacs-word)
funcall-interactively(kill-region nil 16 emacs-word)
command-execute(kill-region)
because for the second 'C-w' it calls 'kill-append':
(if (eq last-command 'kill-region)
(kill-append string (< end beg))
(kill-new string))
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-17 17:58 ` Juri Linkov
@ 2024-09-18 16:08 ` Juri Linkov
2024-09-19 7:19 ` Philip Kaludercic
1 sibling, 0 replies; 90+ messages in thread
From: Juri Linkov @ 2024-09-18 16:08 UTC (permalink / raw)
To: Philip Kaludercic; +Cc: 69097
> Thanks for the new command!
Sorry, I meant the new option.
> I'd like to use it, but currently can't
> because I have customized 'mark-even-if-inactive' to nil.
This small fix addresses the remaining issues:
diff --git a/lisp/simple.el b/lisp/simple.el
index 9fbd9bfb577..40266f37209 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -5865,7 +5865,7 @@ kill-region
;; Pass mark first, then point, because the order matters when
;; calling `kill-append'.
(interactive (progn
- (let ((beg (mark))
+ (let ((beg (mark kill-region-dwim))
(end (point)))
(cond
((and kill-region-dwim (not (use-region-p)))
@@ -5888,10 +5888,12 @@ kill-region
((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)
+ (if (and (null kill-region-dwim)
+ (eq last-command 'kill-region))
(kill-append string (< end beg))
(kill-new string)))
- (when (or string (eq last-command 'kill-region))
+ (when (and (null kill-region-dwim)
+ (or string (eq last-command 'kill-region)))
(setq this-command 'kill-region))
(setq deactivate-mark t)
nil)
^ permalink raw reply related [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-17 17:58 ` Juri Linkov
2024-09-18 16:08 ` Juri Linkov
@ 2024-09-19 7:19 ` Philip Kaludercic
2024-09-20 6:50 ` Juri Linkov
1 sibling, 1 reply; 90+ messages in thread
From: Philip Kaludercic @ 2024-09-19 7:19 UTC (permalink / raw)
To: Juri Linkov; +Cc: 69097
Juri Linkov <juri@linkov.net> writes:
> Thanks for the new command! I'd like to use it, but currently can't
> because I have customized 'mark-even-if-inactive' to nil.
>
>> +** New user option 'kill-word-dwim'.
>> +This option, if non-nil, modifies the fall-back behavior of
>> +'kill-region' if no region is active, and will kill the last word
>> +instead of raising an error. Note that if you have disabled Transient
>> +Mark mode you might prefer to use 'unix-word-rubout', as this feature
>> +relies on there being an active region.
>
> This could mention the default keybindings of 'kill-region' ('C-w').
>
>> +(defcustom kill-region-dwim nil
>> + "Behavior when `kill-region' is invoked without an active region.
>> +If set to nil (default), then the behavior `kill-region' will not
>> +change. If set to `emacs-word', then kill the last word as defined by
>> +the current major mode. If set to `unix-word', then kill the last word
>> +in the style of a shell like Bash, disregarding the major mode like with
>> +`unix-word-rubout'."
>> + :type '(choice (const :tag "Kill a word like `backward-kill-word'" emacs-word)
>> + (const :tag "Kill a word like Bash would" unix-word)
>> + (const :tag "Do not kill anything" nil))
>
> Usually the default value 'nil' comes first.
> This helps to disable an option by always selecting 0
> from the Customization menu.
Good point, I had no real reason for listing it as the last option
besides that the line length was shorter that way.
>> (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.
>> @@ -5843,21 +5856,35 @@ kill-region
>> (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', 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."
>> + this command always kills the current region. It is possible to
>> + override this behavior by customising the user option
>> + `kill-region-dwim'."
>
> I tried to use this command with `emacs -Q`, and typed 'C-w C-w' twice,
> but it fails with
>
> Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p nil)
> kill-region(nil 16 emacs-word)
> funcall-interactively(kill-region nil 16 emacs-word)
> command-execute(kill-region)
>
> because for the second 'C-w' it calls 'kill-append':
>
> (if (eq last-command 'kill-region)
> (kill-append string (< end beg))
> (kill-new string))
Juri Linkov <juri@linkov.net> writes:
>> Thanks for the new command!
>
> Sorry, I meant the new option.
>
>> I'd like to use it, but currently can't
>> because I have customized 'mark-even-if-inactive' to nil.
>
> This small fix addresses the remaining issues:
>
> diff --git a/lisp/simple.el b/lisp/simple.el
> index 9fbd9bfb577..40266f37209 100644
> --- a/lisp/simple.el
> +++ b/lisp/simple.el
> @@ -5865,7 +5865,7 @@ kill-region
> ;; Pass mark first, then point, because the order matters when
> ;; calling `kill-append'.
> (interactive (progn
> - (let ((beg (mark))
> + (let ((beg (mark kill-region-dwim))
> (end (point)))
> (cond
> ((and kill-region-dwim (not (use-region-p)))
> @@ -5888,10 +5888,12 @@ kill-region
> ((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)
> + (if (and (null kill-region-dwim)
> + (eq last-command 'kill-region))
> (kill-append string (< end beg))
> (kill-new string)))
> - (when (or string (eq last-command 'kill-region))
> + (when (and (null kill-region-dwim)
> + (or string (eq last-command 'kill-region)))
> (setq this-command 'kill-region))
> (setq deactivate-mark t)
> nil)
Do you want to push this fix? I can take care of the other two points.
--
Philip Kaludercic on siskin
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-19 7:19 ` Philip Kaludercic
@ 2024-09-20 6:50 ` Juri Linkov
2024-09-20 16:57 ` Philip Kaludercic
0 siblings, 1 reply; 90+ messages in thread
From: Juri Linkov @ 2024-09-20 6:50 UTC (permalink / raw)
To: Philip Kaludercic; +Cc: 69097
> Do you want to push this fix? I can take care of the other two points.
Everything discussed so far is pushed now, so you can adjust if you want.
^ permalink raw reply [flat|nested] 90+ messages in thread
* bug#69097: [PATCH] Add 'kill-region-or-word' command
2024-09-20 6:50 ` Juri Linkov
@ 2024-09-20 16:57 ` Philip Kaludercic
0 siblings, 0 replies; 90+ messages in thread
From: Philip Kaludercic @ 2024-09-20 16:57 UTC (permalink / raw)
To: Juri Linkov; +Cc: 69097
Juri Linkov <juri@linkov.net> writes:
>> Do you want to push this fix? I can take care of the other two points.
>
> Everything discussed so far is pushed now, so you can adjust if you want.
No, it is fine. Thanks!
--
Philip Kaludercic on siskin
^ permalink raw reply [flat|nested] 90+ messages in thread
end of thread, other threads:[~2024-09-20 16:57 UTC | newest]
Thread overview: 90+ 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-09-01 20:06 ` Philip Kaludercic
2024-09-02 6:36 ` Sean Whitton
2024-09-02 11:18 ` Eli Zaretskii
2024-09-02 18:30 ` Stefan Kangas
2024-09-02 18:45 ` Sean Whitton
2024-09-02 20:39 ` Philip Kaludercic
2024-09-02 20:42 ` Sean Whitton
2024-09-02 20:45 ` Philip Kaludercic
2024-09-02 20:46 ` Sean Whitton
2024-09-02 21:12 ` Philip Kaludercic
2024-09-03 12:21 ` Eli Zaretskii
2024-09-03 13:53 ` Robert Pluim
2024-09-03 14:27 ` Eli Zaretskii
2024-09-03 14:55 ` Robert Pluim
2024-09-03 15:32 ` Eli Zaretskii
2024-09-03 16:32 ` Philip Kaludercic
2024-09-03 16:47 ` Robert Pluim
2024-09-04 11:08 ` Eli Zaretskii
2024-09-04 14:07 ` Sean Whitton
2024-09-04 14:21 ` Eli Zaretskii
2024-09-05 9:39 ` Philip Kaludercic
2024-09-05 9:52 ` Eli Zaretskii
2024-09-05 10:02 ` Philip Kaludercic
2024-09-05 10:19 ` Eli Zaretskii
2024-09-05 10:23 ` Philip Kaludercic
2024-09-05 13:27 ` Sean Whitton
2024-09-05 14:38 ` Philip Kaludercic
2024-09-06 10:36 ` Sean Whitton
2024-09-06 11:06 ` Sean Whitton
2024-09-06 11:30 ` Eli Zaretskii
2024-09-06 13:54 ` Sean Whitton
2024-09-06 16:32 ` Philip Kaludercic
2024-09-07 9:52 ` Eli Zaretskii
2024-09-07 10:10 ` Philip Kaludercic
2024-09-07 21:08 ` Sean Whitton
2024-09-07 21:17 ` Sean Whitton
2024-09-09 17:54 ` Sean Whitton
2024-09-09 19:03 ` Eli Zaretskii
2024-09-09 19:48 ` Sean Whitton
2024-09-09 19:23 ` Philip Kaludercic
2024-09-14 9:12 ` Eli Zaretskii
2024-09-14 11:27 ` Sean Whitton
2024-09-14 13:39 ` Philip Kaludercic
2024-09-14 14:05 ` Eli Zaretskii
2024-09-14 14:13 ` Philip Kaludercic
2024-09-14 14:24 ` Eli Zaretskii
2024-09-14 16:10 ` Sean Whitton
2024-09-14 16:26 ` German Pacenza
2024-09-14 16:36 ` Sean Whitton
2024-09-14 21:19 ` Philip Kaludercic
2024-09-14 21:22 ` Sean Whitton
2024-09-17 17:58 ` Juri Linkov
2024-09-18 16:08 ` Juri Linkov
2024-09-19 7:19 ` Philip Kaludercic
2024-09-20 6:50 ` Juri Linkov
2024-09-20 16:57 ` Philip Kaludercic
2024-09-08 10:38 ` Philip Kaludercic
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).