From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philip Kaludercic Newsgroups: gmane.emacs.bugs Subject: bug#69097: [PATCH] Add 'kill-region-or-word' command Date: Tue, 13 Feb 2024 09:55:39 +0000 Message-ID: <871q9g8z8k.fsf@posteo.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10098"; mail-complaints-to="usenet@ciao.gmane.io" To: 69097@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Feb 13 10:57:06 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rZpXF-0002Ot-R1 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 13 Feb 2024 10:57:05 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rZpWw-00016i-JM; Tue, 13 Feb 2024 04:56:46 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rZpWv-00015m-Dy for bug-gnu-emacs@gnu.org; Tue, 13 Feb 2024 04:56:45 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rZpWv-000345-62 for bug-gnu-emacs@gnu.org; Tue, 13 Feb 2024 04:56:45 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rZpXC-0004H6-GW for bug-gnu-emacs@gnu.org; Tue, 13 Feb 2024 04:57:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Philip Kaludercic Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 13 Feb 2024 09:57:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 69097 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.170781818316365 (code B ref -1); Tue, 13 Feb 2024 09:57:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 13 Feb 2024 09:56:23 +0000 Original-Received: from localhost ([127.0.0.1]:41655 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rZpWW-0004Fq-AL for submit@debbugs.gnu.org; Tue, 13 Feb 2024 04:56:23 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:49158) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rZpWR-0004FV-6L for submit@debbugs.gnu.org; Tue, 13 Feb 2024 04:56:19 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rZpW9-00011k-Hi for bug-gnu-emacs@gnu.org; Tue, 13 Feb 2024 04:55:57 -0500 Original-Received: from mout02.posteo.de ([185.67.36.66]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rZpVu-0002yL-Jx for bug-gnu-emacs@gnu.org; Tue, 13 Feb 2024 04:55:57 -0500 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id AB1BA240104 for ; Tue, 13 Feb 2024 10:55:40 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1707818140; bh=AGhS5fAlCwcWwOhEzjbDQ5xuFmfJZUCEcTzYryQO7Yc=; h=From:To:Subject:OpenPGP:Date:Message-ID:MIME-Version:Content-Type: From; b=mOiebyWuJ85kWAlRrae3f+KBZIOo4AXo/rQ+yrllPCMk41NiiGqTZXMIW3yUCv1eK FoGBzp3gASpwMAmDRr2uPk/UOalhhedhb00z9uvEhXGIiWM8zyGmxajvHEEE9Zkhe1 g9CeBU2U4d8u2RFoPHo2sZ6YKy1/oYIK8/by0Z/m9nqwo27N6N+Haa0CzfGDHLU4Tk SidGn0kwfoOilxz5UyHEYrrxj6bYHYNwN1xeT66Rm3lfcq6395Mx1/n7JqbEG2mJ/r 1f43U0Q+cFAIvQJfJSD9BiPWYFU10qF3gZzbCJbYa/NeSRoVv/I3e1uur24fgSnIob +7hg12V2iplqQ== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4TYxXX2gzYz9rxR for ; Tue, 13 Feb 2024 10:55:40 +0100 (CET) OpenPGP: id=7126E1DE2F0CE35C770BED01F2C3CC513DB89F66; url="https://keys.openpgp.org/vks/v1/by-fingerprint/7126E1DE2F0CE35C770BED01F2C3CC513DB89F66"; preference=signencrypt Received-SPF: pass client-ip=185.67.36.66; envelope-from=philipk@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:279950 Archived-At: --=-=-= Content-Type: text/plain 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. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Add-'kill-region-or-word'-command.patch Content-Description: [PATCH] Add 'kill-region-or-word' command >From b08b5cca09e1534b7ec28f516c891065eff80a9f Mon Sep 17 00:00:00 2001 From: Philip Kaludercic 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 --=-=-=--