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

From: Sean Whitton <[email-masked]>
Date: Mon, 02 Sep 2024 19:45:25 +0100

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