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

Previous Next

Package: emacs;

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

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

Severity: normal

Tags: patch

Done: Sean Whitton <spwhitton <at> spwhitton.name>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Philip Kaludercic <philipk <at> posteo.net>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: rms <at> gnu.org, 69097 <at> debbugs.gnu.org, juri <at> linkov.net, Stefan Kangas <stefankangas <at> gmail.com>, Andrea Corallo <acorallo <at> gnu.org>, spwhitton <at> spwhitton.name
Subject: bug#69097: [PATCH] Add 'kill-region-or-word' command
Date: Mon, 02 Sep 2024 20:39:52 +0000
Stefan Kangas <stefankangas <at> gmail.com> writes:

> Eli Zaretskii <eliz <at> gnu.org> writes:
>
>>> From: Philip Kaludercic <philipk <at> posteo.net>
>>> Cc: Sean Whitton <spwhitton <at> spwhitton.name>,  juri <at> linkov.net,  rms <at> gnu.org,
>>>   69097 <at> 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 <at> 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




This bug report was last modified 243 days ago.

Previous Next


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