From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#69097: [PATCH] Add 'kill-region-or-word' command Date: Tue, 17 Sep 2024 20:58:07 +0300 Organization: LINKOV.NET Message-ID: <86v7yuupqo.fsf@mail.linkov.net> References: <871q9g8z8k.fsf@posteo.net> <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> <87plp62uj1.fsf@posteo.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7341"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu) Cc: 69097@debbugs.gnu.org To: Philip Kaludercic Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Sep 17 20:01:26 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 1sqcVx-0001h2-PD for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 17 Sep 2024 20:01:25 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sqcVg-0002gK-Ae; Tue, 17 Sep 2024 14:01:08 -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 1sqcVM-0002f9-08 for bug-gnu-emacs@gnu.org; Tue, 17 Sep 2024 14:00:59 -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 1sqcVK-0001j2-VC for bug-gnu-emacs@gnu.org; Tue, 17 Sep 2024 14:00:47 -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=GKfTC4X4zRRd3Nif2m1j/P83ySBCb8dYQis4f9Iv/n8=; b=K3QPZ2ikbpkJjkRq4JIEXYRv5q7Sx/W9XM90JbC4Z1JRBiS/6H58CvtgUGH59/OLqw9dGgffANajjxQYguaqJnfKn27PDAFUPVP1duJZ32dyS59dxPcGjAinfW5Rhbc2sWOTxEaCeW5vRwNC/k4V9sdvyKbroyedTzijuecsF5a2AXk/00Ckcdo5Sn+wENHXUrBfEiCKvxlfReHYQCPeqW1CAKhVaukg2dt6PNF/8HDgBkCUyRixCaL+dZurIdTqn9GTHpbWmX34ONyzjuTFUMN3qZRqhJD7tLw2U6zinxRSlmvNLAghMywsnHMbyKkLks3zyEsg0vLeH2i/Ugipqg==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sqcVZ-0003GE-Kz for bug-gnu-emacs@gnu.org; Tue, 17 Sep 2024 14:01:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 17 Sep 2024 18:01: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.172659603112468 (code B ref 69097); Tue, 17 Sep 2024 18:01:01 +0000 Original-Received: (at 69097) by debbugs.gnu.org; 17 Sep 2024 18:00:31 +0000 Original-Received: from localhost ([127.0.0.1]:55884 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sqcV3-0003Ey-LE for submit@debbugs.gnu.org; Tue, 17 Sep 2024 14:00:31 -0400 Original-Received: from relay2-d.mail.gandi.net ([217.70.183.194]:50677) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sqcUy-00036e-5C for 69097@debbugs.gnu.org; Tue, 17 Sep 2024 14:00:28 -0400 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id CFF2740004; Tue, 17 Sep 2024 17:59:40 +0000 (UTC) In-Reply-To: <87plp62uj1.fsf@posteo.net> (Philip Kaludercic's message of "Sat, 14 Sep 2024 14:13:06 +0000") X-GND-Sasl: juri@linkov.net 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:291955 Archived-At: Thanks for the new command! I'd like to use it, but currently can't because I have customized 'mark-even-if-inactive' to nil. > +** 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. This could mention the default keybindings of 'kill-region' ('C-w'). > +(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)) Usually the default value 'nil' comes first. This helps to disable an option by always selecting 0 from the Customization menu. > (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'." I tried to use this command with `emacs -Q`, and typed 'C-w C-w' twice, but it fails with Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p nil) kill-region(nil 16 emacs-word) funcall-interactively(kill-region nil 16 emacs-word) command-execute(kill-region) because for the second 'C-w' it calls 'kill-append': (if (eq last-command 'kill-region) (kill-append string (< end beg)) (kill-new string))