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: Fri, 06 Sep 2024 16:32:31 +0000 Message-ID: <87jzfozqsg.fsf@posteo.net> References: <871q9g8z8k.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> <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> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36483"; 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 Fri Sep 06 18:33:28 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 1smbtn-0009Ku-IL for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 06 Sep 2024 18:33:27 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1smbtT-0006AU-7d; Fri, 06 Sep 2024 12:33:07 -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 1smbtQ-00069k-OW for bug-gnu-emacs@gnu.org; Fri, 06 Sep 2024 12:33:05 -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 1smbtO-0004QJ-Py for bug-gnu-emacs@gnu.org; Fri, 06 Sep 2024 12:33:04 -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=i3Ue0CRROT3UM3ARHjskC997ZD/xNwiMCmaXwO1ae7k=; b=SgRBzN2GRTZp3YzEGwwdEvjmd3LU4p17muZx0GmuFjo+Qae41zzAaFd27RypvZ/X9Qhj89Ihy1YRAOnQW7DEhDbXnTLvBeADEf7zBSIQkzxn4bRynTGnhPRol+Zzow8MPUZwlp666JVoYH9MC8K2hy7ircv/HdJ+sEsqlpvJhR1yYHO8fDkkRNVCpeTQKlqQIgrMzWPSYECjYvR8mrDRjNKu+70bA0BFAf5k9DpZIRAAFNTLrRE8sn/ztTXrtaK/GBD/AL4DDHR9w8ldmibDCT+fhCq49vrADjuKM9CSeIWeYsCO9PuifACh8u2ypcF1++H12uY2DY7gRX4gV3858A==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1smbtO-0001Zk-4Q for bug-gnu-emacs@gnu.org; Fri, 06 Sep 2024 12:33: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: Fri, 06 Sep 2024 16:33: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.17256403665989 (code B ref 69097); Fri, 06 Sep 2024 16:33:02 +0000 Original-Received: (at 69097) by debbugs.gnu.org; 6 Sep 2024 16:32:46 +0000 Original-Received: from localhost ([127.0.0.1]:54083 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1smbt7-0001YV-Ox for submit@debbugs.gnu.org; Fri, 06 Sep 2024 12:32:46 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]:37631) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1smbt2-0001Xu-Fi for 69097@debbugs.gnu.org; Fri, 06 Sep 2024 12:32:44 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id D2D70240101 for <69097@debbugs.gnu.org>; Fri, 6 Sep 2024 18:32:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1725640354; bh=Dq9WCtgjKk2nf+KdVuPDXv2Skc9XTpz1B7liv2WzY6Q=; h=From:To:Cc:Subject:Autocrypt:OpenPGP:Date:Message-ID:MIME-Version: Content-Type:From; b=FKy1nTBURL5XDiva8mOfeprqerrGvumKQiG9kNPOyKgUfTyNVthnKFunTT+Z/fDBs 3hPvhVq8mFqcf7H55Q+b3VDczixHCnqQH5Uun8itrUOA+ErMvkJM+DV2Dx1bpN3DDF 8HUBTqD3BiU9pmsZvkFEJp1c226grBbNqUL1HYYZ+0mS2YTPPFS6fyyiMn6hZZfwHO CRTYKpKj+9DMl5C8ARPMS/IDdvsRdekG0WMnLIhaJ0GEOXxJqYBGOhPyIiLjUlH44/ v7z6PTcJUBwsVVEmPQ+Kk+eBhf/jBvd2qzgxB9gT5ymizje31d8OCopvyL7VUy9hvj yz2w4LC126PBA== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4X0hbN5Ppvz9rxK; Fri, 6 Sep 2024 18:32:32 +0200 (CEST) In-Reply-To: <87r09wvqdp.fsf@zephyr.silentflame.com> (Sean Whitton's message of "Fri, 06 Sep 2024 14:54:58 +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=7126E1DE2F0CE35C770BED01F2C3CC513DB89F66; url="https://keys.openpgp.org/vks/v1/by-fingerprint/7126E1DE2F0CE35C770BED01F2C3CC513DB89F66"; 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:291327 Archived-At: Sean Whitton writes: > Hello, > > On Fri 06 Sep 2024 at 02:30pm +03, Eli Zaretskii wrote: > >> Thanks, but I see no reason to document this command in the manual, >> certainly not in the ELisp reference (it's a command, not a function). >> IMO it's obscure enough to be documented only in NEWS. > > That's quite fine with me. > >> Should this be "[:space:]\\n\\r" instead? if not, why not? >> >> Also note that [:space:] depends on mode-specific syntax table, so I >> question the wisdom of using it in a command that's supposed to be >> mode-agnostic. > > Both excellent points, thank you. I looked at the POSIX standard and > came up with a new default value. > >>> +This command is like `forward-word' except that words are always >>> +delimited by whitespace, regardless of the buffer's syntax table. >>> +Like `forward-word', this command respects fields. >>> + >>> +This emulates how C-w at the Unix terminal or shell identifies words. >>> +See the `unix-word-rubout' command in Info node `(readline)Commands For >>> +Killing'." >> >> This should try to be more explicit about what "word" means for this >> command. Since it's so different from any notion of "word" in Emacs, >> I would even seriously consider not to use that word, or maybe quote >> it (in addition to explaining what it means). > > This is very helpful. You're right. In the attached, I've tried using > "unix-word". Let me know what you think of that. > >> Also, since this is a command, its doc string should clearly separate >> what happens in interactive invocation from what happens when called >> from Lisp. DELIM belongs to the latter. (Is it even useful to >> provide that option for Lisp-only calls? what's the use case for >> that?) >> >> And finally, I wonder why we need this command? AFAIU, the original >> intent was to implement something similar to unix-word-rubout, not a >> new movement command. If the plan has changed, I think we need to >> discuss the need once again. > > I think it was unhelpful of me to send this in without callers. > I'm sorry about that. > > The reason for adding this is that it factors out what is in common > between what Philip is doing, and unix-word-rubout. > So in the attached revised patch, I've included unix-word-rubout. Right, this is the command that we agreed on being necessary to appease both people who want C-w to kill the region when no transient region is active or to kill a word. > I've also included a second readline command which I have bound in my > own init. It demonstrates why there is a need for DELIM. > > By the way, forward-unix-word could also be a plain function. > I made it a command because, well, why not. Let me know if you think it > should be switched back to a function. > > -- > Sean Whitton > > From c047e640399bb923728ed9967e8545d53b22ea5c Mon Sep 17 00:00:00 2001 > From: Sean Whitton > Date: Fri, 6 Sep 2024 11:35:46 +0100 > Subject: [PATCH] New commands for moving and killing unix-words > > * lisp/simple.el (forward-unix-word, unix-word-rubout) > (unix-filename-rubout): New commands. > * etc/NEWS: Document them. > --- > etc/NEWS | 7 +++++++ > lisp/simple.el | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 64 insertions(+) > > diff --git a/etc/NEWS b/etc/NEWS > index f3e719a34d3..54cf0a3df52 100644 > --- a/etc/NEWS > +++ b/etc/NEWS > @@ -123,6 +123,13 @@ When using 'visual-wrap-prefix-mode' in buffers with variable-pitch > fonts, the wrapped text will now be lined up correctly so that it's > exactly below the text after the prefix on the first line. > > +--- > +** New commands for moving and killing unix-words. > +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 'forward-unix-word', 'unix-word-rubout' and > +'unix-filename-rubout' allow you to bind keys to operate more similarly > +to the terminal. > > * Changes in Specialized Modes and Packages in Emacs 31.1 > > diff --git a/lisp/simple.el b/lisp/simple.el > index 2453a129d0a..0322ac0cd8c 100644 > --- a/lisp/simple.el > +++ b/lisp/simple.el > @@ -8892,6 +8892,63 @@ current-word > ;; If we found something nonempty, return it as a string. > (unless (= start end) > (buffer-substring-no-properties start end))))) > + > +(defun forward-unix-word (arg &optional delim) > + "Move forward ARG unix-words. > +A unix-word is whitespace-delimited. > +Interactively, ARG is the numeric prefix argument, defaulting to 1. > +A negative ARG means go backwards to the beginning of unix-words. > + > +Unix-words differ from Emacs words in that they are always delimited by > +whitespace, regardless of the buffer's syntax table. This command > +emulates how C-w at the Unix terminal or shell identifies words. Should you mention the ^W notation here as well? > + > +When called from Lisp, DELIM specifies what characters are considered > +whitespace. It is a string as might be passed to `skip-chars-forward'. > +The default is \" \\f\\n\\r\\t\\v\". Do not prefix a `^' character." I think it would be worth checking for a ^ and then throwing a user-error. > + (interactive "^p") > + (unless (zerop arg) > + ;; We do skip over newlines by default because `backward-word' does. > + (let* ((delim (or delim " \f\n\r\t\v")) ^ I'd use "\s" here (and below). > + (ndelim (format "^%s" delim)) > + (start (point)) > + (fun (if (> arg 0) > + #'skip-chars-forward > + #'skip-chars-backward))) > + (dotimes (_ (abs arg)) > + (funcall fun delim) > + (funcall fun ndelim)) > + (constrain-to-field nil start)))) > + > +(defun unix-word-rubout (arg) > + "Kill ARG unix-words backwards. > +A unix-word is whitespace-delimited. > +Interactively, ARG is the numeric prefix argument, defaulting to 1. > +A negative ARG means to kill forwards. > + > +Unix-words differ from Emacs words in that they are always delimited by > +whitespace, regardless of the buffer's syntax table. Thus, this command > +emulates C-w at the Unix terminal or shell identifies words. > +See also this command's nakesake in Info node > +`(readline)Commands For Killing'." > + (interactive "^p") > + (let ((start (point))) > + (forward-unix-word (- arg)) > + (kill-region start (point)))) Won't there be an error here if the command is invoked with a negative argument? > + > +(defun unix-filename-rubout (arg) > + "Kill ARG unix-words backwards, also treating `/' as whitespace. > +A unix-word is whitespace-delimited. > +Interactively, ARG is the numeric prefix argument, defaulting to 1. > +A negative ARG means to kill forwards. > + > +This is like `unix-word-rubout' (which see), but `/' is also considered > +whitespace. See this command's namesake in Info node > +`(readline)Commands For Killing'." > + (interactive "^p") > + (let ((start (point))) > + (forward-unix-word (- arg) "/ \f\n\r\t\v") > + (kill-region start (point)))) > > (defcustom fill-prefix nil > "String for filling to insert at front of new line, or nil for none." -- Philip Kaludercic on siskin