From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#69097: [PATCH] Add 'kill-region-or-word' command Date: Sat, 04 May 2024 09:20:13 +0300 Message-ID: <861q6ihzdu.fsf@gnu.org> 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> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30742"; mail-complaints-to="usenet@ciao.gmane.io" Cc: rms@gnu.org, 69097@debbugs.gnu.org To: Philip Kaludercic Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat May 04 08:21:53 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 1s38mP-0007lB-Pj for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 04 May 2024 08:21:53 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s38mD-0004Ii-DM; Sat, 04 May 2024 02:21:41 -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 1s38mB-0004IQ-6c for bug-gnu-emacs@gnu.org; Sat, 04 May 2024 02:21:39 -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 1s38mA-0002Vz-Ub for bug-gnu-emacs@gnu.org; Sat, 04 May 2024 02:21:38 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1s38mX-0006I1-Nd for bug-gnu-emacs@gnu.org; Sat, 04 May 2024 02:22:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 04 May 2024 06:22: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.171480366324138 (code B ref 69097); Sat, 04 May 2024 06:22:01 +0000 Original-Received: (at 69097) by debbugs.gnu.org; 4 May 2024 06:21:03 +0000 Original-Received: from localhost ([127.0.0.1]:51484 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s38la-0006HG-HS for submit@debbugs.gnu.org; Sat, 04 May 2024 02:21:03 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50992) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s38lY-0006Gj-6W for 69097@debbugs.gnu.org; Sat, 04 May 2024 02:21:00 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s38l5-0002OT-M3; Sat, 04 May 2024 02:20:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=Lx2Qj5kkuovbnBVR+I3lVt85HV474J/R3Ky3YQZ9aPQ=; b=l9HG77M77Mue QdW04KZDh7RkNPgAMRWIsz+t/5HGp/M5qmGnI0hcA9Ui97qzFRKOVq6u/cfuS8+Ckkp6bs18bMdX8 xU9xGwby0wZNheHpasOIkWYkNXNXleF0GnKReAvK68i+5Jf2qQKKzG8cDQkOJNqEsh/XSdLX717SJ o5Y0INsplgq1VqEER+LB2MYL7SEOaWPraoyBo7pJkzwL9r/XDbfyMDHXIN0QAWBo07KTqIz581mfr eOek6Fnnd0l5WOPJjnVOfEeRTjhYx/xI7sp2CxS7zlDhy6LwvURWgSfhIHJs/B0r0whhvG4HCmoQY c5OBUrcT4Qdyk7Yc+5b43Q==; In-Reply-To: <874jbe65u0.fsf@posteo.net> (message from Philip Kaludercic on Fri, 03 May 2024 19:41:43 +0000) 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:284404 Archived-At: > From: Philip Kaludercic > Cc: rms@gnu.org, 69097@debbugs.gnu.org > Date: Fri, 03 May 2024 19:41:43 +0000 > > Eli Zaretskii writes: > > > I don't think anyone wants the error, so doing something useful in > > that case should be a no-brainer. > > How does this look like: Looks good, but it needs some polish, I think: > +--- > +*** New user option 'kill-word-if-no-region'. > +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. This should be modified according to comments below, and also should say what is the default of this option. > +(defcustom kill-word-if-no-region nil > + "Non-nil means that `kill-region' without a region will kill the last word." > + :type 'boolean > + :group 'killing) This lacks the :version tag. > +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'. Instead of "the previous word", I would say "word characters before point", since we don't kill the entire word if point is inside a word. > Interactively, REGION is always non-nil, and so > +this command always kills the current region." This is not accurate, is it? If you invoke C-w immediately after starting "emacs -Q", C-w currently signals an error. Also, the new user option should be mentioned here with its effect on what happens in that case. > + (cond > + ((and beg end (use-region-p)) > + (list beg end 'region)) > + (kill-word-if-no-region > + (list beg end 'kill-word)) > + ((user-error "The mark is not set now, so there is no region")))))) > + If transient-mark-mode is OFF and kill-word-if-no-region is non-nil, this will always kill the previous word, right? I think this is not what we want, so I think the above should work specially if transient-mark-mode is turned OFF. Finally, this needs the suitable changes in the manuals. Thanks.