Subject: bug#69097: [PATCH] Add 'kill-region-or-word' command

From: Sean Whitton <[email-masked]>
Date: Mon, 06 May 2024 17:46:20 +0100

Hello,

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

>> From: Juri Linkov <[email-masked]>
>> Cc: Eli Zaretskii <[email-masked]>,  [email-masked],  [email-masked]
>> 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