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

From: Eli Zaretskii <[email-masked]>
Date: Sat, 04 May 2024 09:20:13 +0300

> From: Philip Kaludercic <[email-masked]>
> Cc: [email-masked],  [email-masked]
> Date: Fri, 03 May 2024 19:41:43 +0000
> 
> Eli Zaretskii <[email-masked]> 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.