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: Mon, 09 Sep 2024 19:23:32 +0000 Message-ID: <87bk0wmy17.fsf@posteo.net> References: <871q9g8z8k.fsf@posteo.net> <86ikzqbzac.fsf@gnu.org> <87seujf8bb.fsf@posteo.net> <867cbu9uce.fsf@gnu.org> <87cyllg57r.fsf@posteo.net> <87zfopbxdk.fsf@zephyr.silentflame.com> <87seuhbx87.fsf@zephyr.silentflame.com> <87zfopep5q.fsf@posteo.net> <86r0a16i71.fsf@gnu.org> <877cbshf4h.fsf@posteo.net> <87a5gnzf5f.fsf@zephyr.silentflame.com> <87y146jv6z.fsf@posteo.net> <87ikvaxmbm.fsf@zephyr.silentflame.com> <871q1yw4fz.fsf@posteo.net> <877cbpvzkm.fsf@zephyr.silentflame.com> <86frqd10k1.fsf@gnu.org> <87r09wvqdp.fsf@zephyr.silentflame.com> <86frqbyemw.fsf@gnu.org> <871q1vuq7y.fsf@zephyr.silentflame.com> <87wmjntb7x.fsf@zephyr.silentflame.com> <87h6aosofr.fsf@zephyr.silentflame.com> 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="5418"; mail-complaints-to="usenet@ciao.gmane.io" Cc: rms@gnu.org, 69097@debbugs.gnu.org, juri@linkov.net, stefankangas@gmail.com, Eli Zaretskii , acorallo@gnu.org To: Sean Whitton Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Sep 09 21:24:31 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 1snjzy-0001FS-Fp for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 09 Sep 2024 21:24:30 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1snjzV-0004XO-Jn; Mon, 09 Sep 2024 15:24:01 -0400 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 1snjzT-0004X2-0l for bug-gnu-emacs@gnu.org; Mon, 09 Sep 2024 15:23:59 -0400 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 1snjzS-0000aK-N6 for bug-gnu-emacs@gnu.org; Mon, 09 Sep 2024 15:23:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=5wcb83OAnXsDRRRVRPuc5uPiCdlvXkcxSBIIhTwSTKI=; b=dxXXoLuwfF9f5s00NugpDqBjHThCQf1dvF+CkGhmf0fFZekbF0JfQvgPqzgWgeqjbsRoUmDpJ2Ypx0lqjIhMaQOqwmt+L9AM460UHTlyvOdE40NxnJ5+0x/yZBbFgP1v2Lj0H31ITAcij+PXQSTWZc+jFnSkDdPwnEQHYYN7T2/A3c0qn2WW9P5+dUKY98jfZB2w2fFa/+2yuc3P1alH86Hqe9ea+G0htROz/JQyEqT0X4Hx6bpvtWjl54Dm/oRnpeG/qtp6oc1lW746GPlI1xniirX1vZj8BswGLcJxMyE3mE4iwId2NeXE8l92C4NB5KoGR9zZpJg0GLDDCCIdEg==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1snjzW-00080X-EK for bug-gnu-emacs@gnu.org; Mon, 09 Sep 2024 15:24:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Philip Kaludercic Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 09 Sep 2024 19:24:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 69097 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 69097-submit@debbugs.gnu.org id=B69097.172590982830761 (code B ref 69097); Mon, 09 Sep 2024 19:24:02 +0000 Original-Received: (at 69097) by debbugs.gnu.org; 9 Sep 2024 19:23:48 +0000 Original-Received: from localhost ([127.0.0.1]:34203 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1snjzH-000805-Db for submit@debbugs.gnu.org; Mon, 09 Sep 2024 15:23:47 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]:56615) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1snjzF-0007zr-0f for 69097@debbugs.gnu.org; Mon, 09 Sep 2024 15:23:45 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id B09F7240103 for <69097@debbugs.gnu.org>; Mon, 9 Sep 2024 21:23:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1725909814; bh=e1Bnc/b3DuDyDICSEG65sTsgBsjz23BNadbjj4tlK2s=; h=From:To:Cc:Subject:Autocrypt:OpenPGP:Date:Message-ID:MIME-Version: Content-Type:From; b=pU5zSHdZeJt2p8mHRH8QgHuB4AXO/JvYyvlh4uJclEO3iunUH47uzHoOBv4aLPecZ ZoMS0u2H2T4V2qgx68y5OS0ZfiB2jUr6sEZ1aXMkz47GIFy8K5i333rznHYjfnp8V1 KWsxCLcsGbjr+3zhhjj4e9WhtdGKMvEp2hLXKEoc2gkwTO+iItwS/bjXwlPuqyTXsN aHx1gmsKU0/AO1Xe+/hDkoVdiVqv2oZAfH+p5L0qArsLitfi3AtPXxaYGUKGpDXlx+ 3qBxxkivg+oTQ8rzBTFHM4ww+ceXp9Wf00r6bynzNBNmW0WEcbpMly89ZIQZgZGbVc Arlc1s/i3cbsw== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4X2cFK3ksSz9rxD; Mon, 9 Sep 2024 21:23:33 +0200 (CEST) In-Reply-To: <87h6aosofr.fsf@zephyr.silentflame.com> (Sean Whitton's message of "Mon, 09 Sep 2024 18:54:16 +0100") Autocrypt: addr=philipk@posteo.net; keydata= mDMEZBBQQhYJKwYBBAHaRw8BAQdAHJuofBrfqFh12uQu0Yi7mrl525F28eTmwUDflFNmdui0QlBo aWxpcCBLYWx1ZGVyY2ljIChnZW5lcmF0ZWQgYnkgYXV0b2NyeXB0LmVsKSA8cGhpbGlwa0Bwb3N0 ZW8ubmV0PoiWBBMWCAA+FiEEDg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwMFCQHhM4AFCwkI BwIGFQoJCAsCBBYCAwECHgECF4AACgkQ8xYDWXahwulikAEA77hloUiSrXgFkUVJhlKBpLCHUjA0 mWZ9j9w5d08+jVwBAK6c4iGP7j+/PhbkxaEKa4V3MzIl7zJkcNNjHCXmvFcEuDgEZBBQQhIKKwYB BAGXVQEFAQEHQI5NLiLRjZy3OfSt1dhCmFyn+fN/QKELUYQetiaoe+MMAwEIB4h+BBgWCAAmFiEE Dg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwwFCQHhM4AACgkQ8xYDWXahwukm+wEA8cml4JpK NeAu65rg+auKrPOP6TP/4YWRCTIvuYDm0joBALw98AMz7/qMHvSCeU/hw9PL6u6R2EScxtpKnWof z4oM OpenPGP: id=philipk@posteo.net; url="https://keys.openpgp.org/vks/v1/by-email/philipk@posteo.net"; preference=signencrypt 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:291528 Archived-At: --=-=-= Content-Type: text/plain Sean Whitton writes: > Hello Eli, > > Any comments on v4? I'd like to commit to unblock Philip. Thanks! Here is my updated patch. If you want to, you can push both at once so that we can close the issue more quickly as soon as Eli has time to take a look: --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Allow-kill-region-kill-the-last-word-when-there-is-n.patch >From 0f19dadb75a01873cb3f40a6addd825e63c266ce Mon Sep 17 00:00:00 2001 From: Philip Kaludercic Date: Tue, 3 Sep 2024 18:29:56 +0200 Subject: [PATCH] Allow 'kill-region' kill the last word when there is no region * etc/NEWS: Document the new user option. * lisp/simple.el (kill-region-dwim): Add new option. (kill-region): Respect 'kill-region-dwim'. (Bug#69097) --- etc/NEWS | 7 +++++++ lisp/simple.el | 41 ++++++++++++++++++++++++++++++++++------- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index add438e8b6a..8cde2c294a9 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -129,6 +129,13 @@ Unix-words are words separated by whitespace regardless of the buffer's syntax table. In a Unix terminal or shell, C-w kills by Unix-word. The new commands 'unix-word-rubout' and 'unix-filename-rubout' allow you to bind keys to operate more similarly to the terminal. + +--- +** New user option 'kill-word-dwim'. +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. + * Changes in Specialized Modes and Packages in Emacs 31.1 diff --git a/lisp/simple.el b/lisp/simple.el index bbb13c1b471..d1be33ce87d 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -5817,6 +5817,19 @@ kill-read-only-ok :type 'boolean :group 'killing) +(defcustom kill-region-dwim nil + "Behaviour when `kill-region' is invoked without an active region. +If set to nil (default), the behaviour of `kill-region' stays the same. +If set to `emacs-word', then kill the last word as defined by the +current major mode. If set to `unix-word', then kill the last word in +the style of a shell like Bash, disregarding the major mode like with +`unix-word-rubout'." + :type '(choice (const :tag "Kill a word like `backward-kill-word'" emacs-word) + (const :tag "Kill a word like Bash would" unix-word) + (const :tag "Do not kill anything" nil)) + :group 'killing + :version "31.1") + (defun kill-region (beg end &optional region) "Kill (\"cut\") text between point and mark. This deletes the text from the buffer and saves it in the kill ring. @@ -5843,21 +5856,35 @@ kill-region (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', the function ignores BEG and END, and kills the current region instead. Interactively, REGION is always non-nil, and so - this command always kills the current region." + this command always kills the current region. It is possible to + override this behaviour by customising the user option + `kill-region-dwim'." ;; Pass mark first, then point, because the order matters when ;; calling `kill-append'. (interactive (progn (let ((beg (mark)) (end (point))) - (unless (and beg end) + (cond + ((and kill-region-dwim (not (use-region-p))) + (list beg end kill-region-dwim)) + ((not (or beg end)) (user-error "The mark is not set now, so there is no region")) - (list beg end 'region)))) + ((list beg end 'region)))))) + (condition-case nil - (let ((string (if region - (funcall region-extract-function 'delete) - (filter-buffer-substring beg end 'delete)))) + (let ((string (cond + ((memq region '(unix-word emacs-word)) + (let ((end (point))) + (save-excursion + (if (eq region 'emacs-word) + (forward-word -1) + (forward-unix-word -1)) + (filter-buffer-substring (point) end 'delete)))) + (region + (funcall region-extract-function 'delete)) + ((filter-buffer-substring beg end 'delete))))) (when string ;STRING is nil if BEG = END ;; Add that string to the kill ring, one way or another. (if (eq last-command 'kill-region) -- 2.45.2 --=-=-= Content-Type: text/plain -- Philip Kaludercic on siskin --=-=-=--