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 20:39:52 +0000 Message-ID: <87cyllg57r.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> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18359"; mail-complaints-to="usenet@ciao.gmane.io" Cc: rms@gnu.org, 69097@debbugs.gnu.org, juri@linkov.net, Stefan Kangas , Andrea Corallo , spwhitton@spwhitton.name To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Sep 02 22:41:18 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 1slDrS-0004dE-Ie for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 02 Sep 2024 22:41:18 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1slDrE-0006Ls-B3; Mon, 02 Sep 2024 16:41:04 -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 1slDrC-0006Li-6D for bug-gnu-emacs@gnu.org; Mon, 02 Sep 2024 16:41:02 -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 1slDrA-0002Uk-Nn for bug-gnu-emacs@gnu.org; Mon, 02 Sep 2024 16:41: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=ubc+0QFu25K3RMZUY6bJKhpu6+prpj8PSpE6jy4T+DQ=; b=H+sAjQFwA8XK9YoHM5Q/xRrId9gUiybML3u5gcE7VkL0XrSE9XL1aCpfT8eRnfWEGflfi6Zjg7ANLLPWABLmNafN/7n7uwRsi92YEHYpPLU+D7p3atc7WZcb6afLdFAhc/vN0sKVRSkuOwVdyGrL7XY16gc3rCacmV4n4FW3DAGtv0L9Y/JVlzYJBxh1CMOXtNqbPoQ6kWqZw9f0OFSB8ltNvAMEMnT8qPcwU1YFdHhXgEX45DkkCjJruyVWh4bMXEEtKCN7pYqfxEwetIi/DeOYgp/cRLEDHY2KmQiiSVOMOPTnqlIYiXpXUq+wMlydoiMqYTTbhWTckFaygcA7tA==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1slDs9-0005Lc-OK for bug-gnu-emacs@gnu.org; Mon, 02 Sep 2024 16:42:01 -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 20:42:01 +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.172530966620463 (code B ref 69097); Mon, 02 Sep 2024 20:42:01 +0000 Original-Received: (at 69097) by debbugs.gnu.org; 2 Sep 2024 20:41:06 +0000 Original-Received: from localhost ([127.0.0.1]:52722 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1slDrF-0005Jy-Kx for submit@debbugs.gnu.org; Mon, 02 Sep 2024 16:41:06 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:60403) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1slDrC-0005JF-Fy for 69097@debbugs.gnu.org; Mon, 02 Sep 2024 16:41:04 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id EB367240029 for <69097@debbugs.gnu.org>; Mon, 2 Sep 2024 22:39:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1725309595; bh=ebfm2m/Bq/DujcvKKvohYxhWHPqFzL9CBGi/VPSJXNU=; h=From:To:Cc:Subject:Autocrypt:OpenPGP:Date:Message-ID:MIME-Version: Content-Type:From; b=asLY0QYsWskAjpZDtgXWQbIlLLibQNUkHftq4JHGB0EMH+Tqr1W9MGLYLNFpLRfpc r2FtCIYrGZYyViqrLHD+0nRUXxV99fJ/7e7+weu3y20gLq7CusyX8dw8n/p7Boo6KM u6oe+k902FlBAqxJc9Ej89NO5wZusu8syehhCnAV7QVArb3ciibNYdQTp6vItKmym7 rYq8XDIPM/kFAEIB1Nqrtk4AjF8dzi4X89CVZNMpszbQRq73QjWjJj7o5TjGHUCEjF HyaAQg620j5zMenviX4VqgBYt6CZR4Mb86NAOC80WaHjdTUg7E+KhgZPen6n0kY8hk J1SJZFZjZnUyg== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4WyLGd0w1Hz9rxF; Mon, 2 Sep 2024 22:39:53 +0200 (CEST) In-Reply-To: <867cbu9uce.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 02 Sep 2024 14:18:57 +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:291122 Archived-At: Stefan Kangas writes: > Eli Zaretskii writes: > >>> From: Philip Kaludercic >>> Cc: Sean Whitton , juri@linkov.net, rms@gnu.org, >>> 69097@debbugs.gnu.org >>> Date: Sun, 01 Sep 2024 20:06:00 +0000 >>> >>> Ping. I am not sure how to proceed on this patch. IIRC the issue was >>> that the notion of a word differs in Emacs and in Bash. I am still in >>> favour of utilising Emacs's definition, as it remains more useful >>> for some given major mode and the fact that it is easier to implement. >> >> Or you could make the defcustom a tristate, and implement both >> behaviors... >> >> As for how to proceed: Stefan and Andrea, do you have an opinion on >> this? > > Binding C-w to backward-kill-word, or some version thereof, is an old > Emacs power user trick that has been recommended in many places over the > years. See, for example: > https://sites.google.com/site/steveyegge2/effective-emacs#h.p_ID_193 > https://emacs-fu.blogspot.com/2009/11/copying-lines-without-selecting-them.html > > So I think this command would be a good addition. Making the word > boundary behaviour into a tristate option sounds like a reasonable way > forward, which should make everyone happy and let people experiment with > what works best for them. 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. Sean Whitton writes: > Hello, > > On Mon 02 Sep 2024 at 11:30am -07, Stefan Kangas wrote: > >> Binding C-w to backward-kill-word, or some version thereof, is an old >> Emacs power user trick that has been recommended in many places over the >> years. See, for example: >> https://sites.google.com/site/steveyegge2/effective-emacs#h.p_ID_193 >> https://emacs-fu.blogspot.com/2009/11/copying-lines-without-selecting-them.html >> >> So I think this command would be a good addition. Making the word >> boundary behaviour into a tristate option sounds like a reasonable way >> forward, which should make everyone happy and let people experiment with >> what works best for them. > > For reference purposes while implementing the tristate, here is my > implementation of the Unix behaviour from my init. > Should be helpful, though there is lots of room for improvement :) > > (defun spw/unix-word-rubout (arg &optional pos neg) > (interactive "p") > ;; Do skip over \n because `backward-kill-word' does. > (unless pos (setq pos "[:space:]\n")) > (unless neg (setq neg "^[:space:]\n")) > (undo-boundary) > (let ((start (point))) > ;; Go only backwards. > (dotimes (_ (abs arg)) > (skip-chars-backward pos) > (skip-chars-backward neg)) > ;; Skip forward over any read-only text (e.g. an Eshell or comint prompt). > (when-let ((beg (and (get-char-property (point) 'read-only) > (next-single-char-property-change > (point) 'read-only nil start)))) > (goto-char beg)) > (kill-region start (point)))) FWIW I don't have any suggestions on how to improve the function either. I wonder if it would make sense to have a minor mode like subword-mode that would enforce a understanding of words like implemented here. -- Philip Kaludercic on peregrine