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: Sat, 14 Sep 2024 14:13:06 +0000 Message-ID: <87plp62uj1.fsf@posteo.net> References: <871q9g8z8k.fsf@posteo.net> <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> <87bk0wmy17.fsf@posteo.net> <86plp6ha3y.fsf@gnu.org> <87r09m8ogh.fsf@zephyr.silentflame.com> <87ttei2w2o.fsf@posteo.net> <86seu2fi07.fsf@gnu.org> 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="18625"; mail-complaints-to="usenet@ciao.gmane.io" Cc: rms@gnu.org, 69097@debbugs.gnu.org, juri@linkov.net, stefankangas@gmail.com, acorallo@gnu.org, spwhitton@spwhitton.name To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Sep 14 16:14:02 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 1spTXF-0004il-B2 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 14 Sep 2024 16:14:01 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1spTX8-0007u2-BM; Sat, 14 Sep 2024 10:13:55 -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 1spTX5-0007ts-Ta for bug-gnu-emacs@gnu.org; Sat, 14 Sep 2024 10:13:51 -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 1spTX5-0001W6-KQ for bug-gnu-emacs@gnu.org; Sat, 14 Sep 2024 10:13:51 -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=gkVoL1TrgDDmm7RmcP+gXg93+33NskR51PCI0TbJYgY=; b=E9Uvo4Ft+rgLBwi+cjqKH3L+B1vCRdPKOa3Kc/ckSnMnWm7iCAbpR3k9nzlmCIWOnR0nd7PjyQvsULYq3ufPueZuQceD6un62hhBDNn6b+RXLzhTPDIGFmrGvgxftjgyN6Gfg7oCXox+XDi8LP93qq89Zgtp1RZhedGiD7o36+IbDr9CUlyjdAQrWdN/HFFnXWO7UUZcyaVTR6zfReXZWEkKqKTJVtMZl3bc6MmFEnSEoaejzujAsZMV2aJ06VPo7KC/t3M5i7dakcdI6h5FLjnATx8UM7RJOFbabZiL34Yoq2k4kuYrQcn+LrG0hx19ij3xY58yOiOLF9eNGwRQkg==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1spTXG-0000yB-4l for bug-gnu-emacs@gnu.org; Sat, 14 Sep 2024 10:14: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: Sat, 14 Sep 2024 14:14: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.17263232073653 (code B ref 69097); Sat, 14 Sep 2024 14:14:02 +0000 Original-Received: (at 69097) by debbugs.gnu.org; 14 Sep 2024 14:13:27 +0000 Original-Received: from localhost ([127.0.0.1]:47477 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1spTWh-0000wq-2W for submit@debbugs.gnu.org; Sat, 14 Sep 2024 10:13:27 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:43147) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1spTWe-0000wZ-R7 for 69097@debbugs.gnu.org; Sat, 14 Sep 2024 10:13:25 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id BAD99240027 for <69097@debbugs.gnu.org>; Sat, 14 Sep 2024 16:13:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1726323188; bh=6byuGrDFCjAnupN69X7SZY192cXZXOo/u0tQijIOFyM=; h=From:To:Cc:Subject:Autocrypt:OpenPGP:Date:Message-ID:MIME-Version: Content-Type:From; b=NDssdAo25YvzqHw7ljcveXjrMjT45PsB4jhOaoncdzEFUWkuMRkHwUuRh0u8wIPeF CKTyruzhb0WVC2B4XNOduz6rWHzVkxg3+GRYUbtzSRN5Xe91NfQ5+V7M7hgVB/+Tdd 33/7g0KmlGmaAHdjIM29IlWINRGmwGtCClA0yXrJx8WPljTj7zJDwUZ9FYHywyDZCa ru+YSSwdeRG9AZkSFZEZmyHmFmMBmJG7P8aGc0JBj3+2t72eu08JIUgIMQSSNCvFDk FaaqDQqBQnI3ZtaPgWT+T2ehYLYVoEpAzoVZMspuzCVHln8J1+XfT8kJkbWqSgBUEQ GqahQsI5qHa1A== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4X5Y6p6Jtwz6tw1; Sat, 14 Sep 2024 16:13:06 +0200 (CEST) In-Reply-To: <86seu2fi07.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 14 Sep 2024 17:05:12 +0300") 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:291761 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> From: Philip Kaludercic >> Cc: Eli Zaretskii , rms@gnu.org, 69097@debbugs.gnu.org, >> juri@linkov.net, stefankangas@gmail.com, acorallo@gnu.org >> Date: Sat, 14 Sep 2024 13:39:43 +0000 >> >> > This seems like Philip might want to think a bit about what it is more >> > helpful to say, so I'll hold off on editing and pushing his patch >> > myself. >> >> How about > > LGTM, but there's still a "behaviour" there... Eh, sorry! I double checked the patch this time: --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Allow-kill-region-kill-the-last-word-when-there-is-n.patch >From 2b92dcb771646f5ff5b7f574c9ebeada9e8593a5 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 | 9 +++++++++ lisp/simple.el | 41 ++++++++++++++++++++++++++++++++++------- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index add438e8b6a..3984670bff7 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -129,6 +129,15 @@ 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, if non-nil, modifies the fall-back behavior of +'kill-region' if no region is active, and will kill the last word +instead of raising an error. Note that if you have disabled Transient +Mark mode you might prefer to use 'unix-word-rubout', as this feature +relies on there being an active region. + * Changes in Specialized Modes and Packages in Emacs 31.1 diff --git a/lisp/simple.el b/lisp/simple.el index bbb13c1b471..fb7dad50a13 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 + "Behavior when `kill-region' is invoked without an active region. +If set to nil (default), then the behavior `kill-region' will not +change. 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 behavior 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 If there is nothing left, then Sean can push both changes at once. -- Philip Kaludercic on siskin --=-=-=--