all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Philip Kaludercic <philipk@posteo.net>
To: 69097@debbugs.gnu.org
Subject: bug#69097: [PATCH] Add 'kill-region-or-word' command
Date: Tue, 13 Feb 2024 09:55:39 +0000	[thread overview]
Message-ID: <871q9g8z8k.fsf@posteo.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 196 bytes --]

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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: [PATCH] Add 'kill-region-or-word' command --]
[-- Type: text/x-patch, Size: 1532 bytes --]

From b08b5cca09e1534b7ec28f516c891065eff80a9f Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <philipk@posteo.net>
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


             reply	other threads:[~2024-02-13  9:55 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-13  9:55 Philip Kaludercic [this message]
2024-02-17  3:53 ` bug#69097: [PATCH] Add 'kill-region-or-word' command Richard Stallman
     [not found]   ` <87ttm7gi9i.fsf@posteo.net>
2024-02-19  3:44     ` Richard Stallman
     [not found]       ` <87sf1obkw9.fsf@posteo.net>
2024-02-23  3:04         ` Richard Stallman
     [not found]           ` <871q93rzv8.fsf@posteo.net>
2024-02-25  3:16             ` Richard Stallman
     [not found]               ` <87frxgn73g.fsf@posteo.net>
2024-02-27  3:12                 ` Richard Stallman
2024-05-03  7:37 ` Philip Kaludercic
2024-05-03 10:40   ` Eli Zaretskii
2024-05-03 10:48     ` Philip Kaludercic
2024-05-03 10:59       ` Eli Zaretskii
2024-05-03 11:04         ` Eli Zaretskii
2024-05-03 17:32           ` Philip Kaludercic
2024-05-03 18:01             ` Eli Zaretskii
2024-05-03 19:41               ` Philip Kaludercic
2024-05-04  6:20                 ` Eli Zaretskii
2024-05-05  6:53                 ` Juri Linkov
2024-05-05  9:04                   ` Eli Zaretskii
2024-05-05 16:29                     ` Juri Linkov
2024-05-05 16:54                       ` Philip Kaludercic
2024-05-05 16:59                         ` Juri Linkov
2024-05-05 17:08                           ` Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-05 18:27                           ` Philip Kaludercic
2024-05-05 17:05                         ` Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-05 17:13                           ` Eli Zaretskii
2024-05-05 17:53                             ` Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-06  0:21                       ` Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-06 16:46                     ` Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-06 16:51                       ` Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-06 17:55                         ` Eli Zaretskii
2024-05-07  8:47                           ` Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-07  8:47                             ` Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-05 16:47                   ` Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-03 16:20         ` Philip Kaludercic

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871q9g8z8k.fsf@posteo.net \
    --to=philipk@posteo.net \
    --cc=69097@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.