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, 02 Sep 2024 21:12:01 +0000 Message-ID: <87zfopep5q.fsf@posteo.net> References: <871q9g8z8k.fsf@posteo.net> <87wmob73ds.fsf@posteo.net> <861q6jji0i.fsf@gnu.org> <87o79n6uj6.fsf@posteo.net> <86v83vi2kr.fsf@gnu.org> <86seyzi2by.fsf@gnu.org> <87cyq26bt8.fsf@posteo.net> <864jbeixkt.fsf@gnu.org> <874jbe65u0.fsf@posteo.net> <8634qwkbtc.fsf@mail.linkov.net> <86h6fceij2.fsf@gnu.org> <87edaeevmr.fsf@zephyr.silentflame.com> <87a5l2evdn.fsf@zephyr.silentflame.com> <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> 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="13158"; mail-complaints-to="usenet@ciao.gmane.io" Cc: rms@gnu.org, 69097@debbugs.gnu.org, juri@linkov.net, Stefan Kangas , Eli Zaretskii , Andrea Corallo To: Sean Whitton Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Sep 02 23:13:17 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 1slEMP-0003FA-AM for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 02 Sep 2024 23:13:17 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1slEMB-00027S-HA; Mon, 02 Sep 2024 17:13:03 -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 1slEM9-000278-EQ for bug-gnu-emacs@gnu.org; Mon, 02 Sep 2024 17:13:01 -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 1slEM9-0005Q0-4k for bug-gnu-emacs@gnu.org; Mon, 02 Sep 2024 17:13:01 -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=RfZNundIdn70HSM+OyZ23ZLEfY4icTFbQpxvshzlpD0=; b=u/xeFrhBHCO8R8hiI8+t5cuInya6Ln4b690HNL1u2PnMTDTN4IjaMdO/fevzUGw2/QpUm5armX9ZhUcJ0rimaDc/yJeP8amcFQyDB35uvAEFfEirLMJ7oKPTt71WhyTnWPhaKaFLuQdxnysIJzrZ7XvMdl05imB51VISaaYBARNG7Wmjo/icayN27C9vvtufUPLT4b9hl1oVes2daj5KRKPgea7dbVHMbq1p+pkZOOozeCxpreTUMBw+qHxYLqAffTVM9BOi9BmZDuxisJfB5lhS/WAn2RIpaiYEfl5Py+IlhvvAvVgGvk3bECHqWeMXxqiQ7bUaW0Lfz5ReRcm+Ww==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1slEN8-0006Ry-3L for bug-gnu-emacs@gnu.org; Mon, 02 Sep 2024 17: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: Mon, 02 Sep 2024 21: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.172531159224692 (code B ref 69097); Mon, 02 Sep 2024 21:14:02 +0000 Original-Received: (at 69097) by debbugs.gnu.org; 2 Sep 2024 21:13:12 +0000 Original-Received: from localhost ([127.0.0.1]:52777 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1slEMK-0006QC-5G for submit@debbugs.gnu.org; Mon, 02 Sep 2024 17:13:12 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:33057) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1slEMI-0006Pz-9A for 69097@debbugs.gnu.org; Mon, 02 Sep 2024 17:13:11 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 3F91624002A for <69097@debbugs.gnu.org>; Mon, 2 Sep 2024 23:12:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1725311523; bh=mGhptGdpERKZUFrTZHfBrZ4fhcfZR/kPyuUA3CeNxCI=; h=From:To:Cc:Subject:Autocrypt:OpenPGP:Date:Message-ID:MIME-Version: Content-Type:From; b=NdhSUmZkQ+SuWhjpK5A9y0U2oqUM1pILi+RVqfRereJRj0AIlV9lPEQAsRmdehxVG vBNWGM6v8qayDqCMP/5xXC2ECXLcTfpbGRRL5Fcwt8hf1vyM5bknuxJyFllzMvSx1l FU0ZpiWPfDy5QM4jLNK7VQpKoMMj9tgRrCIDnT5DpB5DBcbljZ3zbGf3SKgaIbztVm VY3juwr069oZdJnOXwD1qW7c5BM5uHSjrGWz7pBlIVxDelb8XSpNiwrRrLJVbwdAGy cFpipjt1SGlKeuJCJHG0LrXe7DgUDTCBG4fxwPKDbv/WpdsTgyJ9iuOQWXl9XTaBpi TFjaw5juxEFiQ== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4WyLzk2D7Rz9rxF; Mon, 2 Sep 2024 23:12:02 +0200 (CEST) In-Reply-To: <87seuhbx87.fsf@zephyr.silentflame.com> (Sean Whitton's message of "Mon, 02 Sep 2024 21:46:00 +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:291127 Archived-At: --=-=-= Content-Type: text/plain Sean Whitton writes: > Hello, > > On Mon 02 Sep 2024 at 09:42pm +01, Sean Whitton wrote: > >> Hello, >> >> On Mon 02 Sep 2024 at 08:39pm GMT, Philip Kaludercic wrote: >> >>> How about this suggestion: We add a generic kill-region-or-word >>> command, and a user option for a function (set to either >>> `backward-kill-word' or Sean's `unix-word-rubout'). I can prepare a >>> patch with the simpler version, and then Sean can add his behaviour in a >>> second patch so that the attribution remains correct. >> >> I think a tristate option is preferable to this. >> >> If the user wants something of their own they can just write their own >> command. > > Sorry, I wrote this too quickly, I don't think I actually understand > your new proposal. > > Could you sketch it out? > > Thank you for your patience on this one. I had misremembered the last state of this patch. It is easier to just have a tristate option. Here is the updated proposal: --=-=-= Content-Type: text/plain Content-Disposition: inline diff --git a/lisp/simple.el b/lisp/simple.el index eedc5768fe2..9ce108089e7 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -5817,6 +5817,17 @@ kill-read-only-ok :type 'boolean :group 'killing) +(defcustom kill-word-if-no-region nil + "Behaviour when `kill-region' is invoked without an active region. +If set to nil (default), then an error occurs and nothing is killed. If +set to `emacs-word', then kill a 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." + :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) + (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. @@ -5839,25 +5850,47 @@ kill-region the text, but put the text in the kill ring anyway. This means that you can use the killing commands to copy text from a read-only buffer. -Lisp programs should use this function for killing text. - (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 instead. Interactively, REGION is always non-nil, and so - this command always kills the current region." +Lisp programs should use this function for killing text. (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 instead. If REGION has the special value +`kill-word', then it will kill the previous word, as with +`backward-kill-word'. Interactively, REGION is always non-nil, and so +this command always kills the current region." ;; Pass mark first, then point, because the order matters when ;; calling `kill-append'. (interactive (progn (let ((beg (mark)) (end (point))) - (unless (and beg end) - (user-error "The mark is not set now, so there is no region")) - (list beg end 'region)))) + (cond + ((and beg end (use-region-p)) + (list beg end 'region)) + (kill-word-if-no-region + (list beg end kill-word-if-no-region)) + ((user-error "The mark is not set now, so there is no region")))))) + (condition-case nil - (let ((string (if region - (funcall region-extract-function 'delete) - (filter-buffer-substring beg end 'delete)))) + (let ((string (cond + ((eq region 'emacs-word) + (let ((end (point))) + (save-excursion + (forward-word -1) + (filter-buffer-substring (point) end 'delete)))) + ((eq region 'unix-word) + (let ((end (point))) + (save-excursion + (skip-chars-backward "[:space:]") + (skip-chars-backward "^[:space:]") + (filter-buffer-substring + (if (get-char-property (point) 'read-only) + (next-single-char-property-change + (point) 'read-only nil end) + (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) --=-=-= Content-Type: text/plain -- Philip Kaludercic on peregrine --=-=-=--