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 13:39:43 +0000 Message-ID: <87ttei2w2o.fsf@posteo.net> References: <871q9g8z8k.fsf@posteo.net> <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> <87bk0wmy17.fsf@posteo.net> <86plp6ha3y.fsf@gnu.org> <87r09m8ogh.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="20020"; 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 Sat Sep 14 15:41:09 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 1spT1Q-00052L-Ba for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 14 Sep 2024 15:41:08 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1spT1E-0006A1-3S; Sat, 14 Sep 2024 09:40:56 -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 1spT1B-00069T-1c for bug-gnu-emacs@gnu.org; Sat, 14 Sep 2024 09:40:53 -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 1spT19-0005BL-Va for bug-gnu-emacs@gnu.org; Sat, 14 Sep 2024 09:40:52 -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=2J/rE0NBTxTJJp6r8mqhFW8ja7A+CfwBOqaUrSjFTqw=; b=ddRXTxa0QxWURB7e3u3sPXsK1hf84mOiBcADHPadSSnTI7tPYWquadTEuRC/caO7IOcqjEKVxOQ7Hi/KQrtcUaiQgaLI37PFzLKC2rGkR3i6QC230PJCAOgkS3QuXBpoSlZmD13ryxL8XFYM7RWpUItgdUm+WxAmkL6tfJKAzx3uxFIG4E3Q7BkBnX+XQkcVf5yOZ4FanOcn1tW8sOolPqsrF3rqNihd5ggmFgJoFTxhcV8jts6pdfavlLAEVMJBrS4bCPnGb+8jDPIXxh7MZ1JxZ04FZgJRt1Q8cCVs6p3M0ppg/mCsceDx1BP3vt4D+3DEzns0DrWkCYfgHQdHOQ==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1spT1K-0006vO-Es for bug-gnu-emacs@gnu.org; Sat, 14 Sep 2024 09:41: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 13:41: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.172632120626037 (code B ref 69097); Sat, 14 Sep 2024 13:41:02 +0000 Original-Received: (at 69097) by debbugs.gnu.org; 14 Sep 2024 13:40:06 +0000 Original-Received: from localhost ([127.0.0.1]:45139 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1spT0Q-0006lr-4U for submit@debbugs.gnu.org; Sat, 14 Sep 2024 09:40:06 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]:49177) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1spT0N-0006l8-7z for 69097@debbugs.gnu.org; Sat, 14 Sep 2024 09:40:04 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id C6A5E240103 for <69097@debbugs.gnu.org>; Sat, 14 Sep 2024 15:39:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1726321185; bh=D1veLSlZinL6R/VamlOOXiqb+fxqdnFl6MCkLWO8cCM=; h=From:To:Cc:Subject:Autocrypt:OpenPGP:Date:Message-ID:MIME-Version: Content-Type:From; b=V6nyM8iWC0GGsXVzLfQAuVL3EUQqezu2kPF28dUTeQApju/PW1v9jXEfy0V3+2wgI drWp9O2SOrOWz0Jld82gv2WrK1fETG44D427o3QrRvWS0Sr8tWcT5pySMTFZ6/t3MW r730hax3bJplEGDjOKLIPIrQ4AqWD6k0E6dbImrsNNIhHETzmeJnH/gBMF+/e8JLP/ on/D5K+apGCNNMRD33ftVDGHEK6b5mnzUC4r/h9gL8FlzjjjkPUVSVI03aNs+hgLDx 4hgbcEqItZGsFaB7cl8/n03oWyTGWSGGS5VhrWL/rbeOiRgvulwHfmXAMDhU1Nzndb JUT5V3/hjBRKQ== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4X5XNJ0QKGz6tsg; Sat, 14 Sep 2024 15:39:43 +0200 (CEST) In-Reply-To: <87r09m8ogh.fsf@zephyr.silentflame.com> (Sean Whitton's message of "Sat, 14 Sep 2024 12:27:42 +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:291746 Archived-At: --=-=-= Content-Type: text/plain Sean Whitton writes: > Hello, > > Thanks for the re-review, Eli. I've pushed my patch. > >> This should also say explicitly that users who turn off Transient Mark >> mode will need to either activate the region ("C-x C-x" etc.) or >> invoke the new word-rubout commands by hand, since otherwise the >> region is never active for them. > > 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 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Allow-kill-region-kill-the-last-word-when-there-is-n.patch >From 2fb36ab68eb177e232b9ee4b0d5ea105b9aa9f16 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..f01c6e2b3cd 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 behaviour 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..f05ded36c22 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), 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 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 And I think that you can already push your change, and I can follow on later. -- Philip Kaludercic on siskin --=-=-=--