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

From: [email-masked] (GNU bug Tracking System)
Date: Sat, 14 Sep 2024 16:11:02 +0000

Your bug report

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

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
69097: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=69097
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#69097: [PATCH] Add 'kill-region-or-word' command
From: Sean Whitton <[email-masked]>
To: Philip Kaludercic <[email-masked]>
Cc: [email-masked]
Date: Sat, 14 Sep 2024 17:10:04 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

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

Subject: [PATCH] Add 'kill-region-or-word' command
From: Philip Kaludercic <[email-masked]>
To: [email-masked]
Date: Tue, 13 Feb 2024 09:55:39 +0000
List-Id: <debbugs-submit.debbugs.gnu.org>

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.

>From b08b5cca09e1534b7ec28f516c891065eff80a9f Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <[email-masked]>
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