From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Sean Whitton Newsgroups: gmane.emacs.bugs Subject: bug#69097: [PATCH] Add 'kill-region-or-word' command Date: Sat, 07 Sep 2024 22:08:17 +0100 Message-ID: <871q1vuq7y.fsf@zephyr.silentflame.com> References: <871q9g8z8k.fsf@posteo.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> <86frqbyemw.fsf@gnu.org> 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="20945"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 69097@debbugs.gnu.org, acorallo@gnu.org, stefankangas@gmail.com, rms@gnu.org, juri@linkov.net To: Eli Zaretskii , philipk@posteo.net Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Sep 07 23:09:22 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 1sn2gL-0005Ix-Ku for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 07 Sep 2024 23:09:22 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sn2g2-0007Mb-SD; Sat, 07 Sep 2024 17:09:02 -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 1sn2g1-0007ME-4H for bug-gnu-emacs@gnu.org; Sat, 07 Sep 2024 17:09: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 1sn2g0-0003Rf-Rg for bug-gnu-emacs@gnu.org; Sat, 07 Sep 2024 17:09:00 -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=pgkp33m6T83BUhVVB49wp48mUmq1oKNRnbOmuQcbRfs=; b=r1Ey0Y08+N3dGH03TrFzi06DYkPdEnT8SX0IbcIfXkjqJfzOQo9g5E9C5AMLFEIBx7ozJsJzdKvgyUxv7kobeTy4qolZKGVcvYUAAeJDHzQ6EeR+/RZz/3M7TMtqVclCT3AbbYqLZ1Q4AaqjBBuWFv8eJAwi2vzY3bQki0m2BTrR/kG1FBJPgDMxeWtSsYFzHangzjF6zH4pHQLjaNQmXb354It0C2kl2LfTxjV+NxIneZQwx4bH7lhWBGA/HVjhIZN1dImaXMvABmm/gpWW6BtvCfvXdfOsrXeVNYs6HrdryGFOsLpUNp9D7RY+9Wl4K7miy1UevJqPNd9cEi3s0Q==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sn2g2-0004Vl-22 for bug-gnu-emacs@gnu.org; Sat, 07 Sep 2024 17:09:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Sean Whitton Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 07 Sep 2024 21:09: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.172574331517305 (code B ref 69097); Sat, 07 Sep 2024 21:09:02 +0000 Original-Received: (at 69097) by debbugs.gnu.org; 7 Sep 2024 21:08:35 +0000 Original-Received: from localhost ([127.0.0.1]:57712 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sn2fb-0004V3-1V for submit@debbugs.gnu.org; Sat, 07 Sep 2024 17:08:35 -0400 Original-Received: from sendmail.purelymail.com ([34.202.193.197]:49882) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sn2fY-0004Um-1h for 69097@debbugs.gnu.org; Sat, 07 Sep 2024 17:08:33 -0400 DKIM-Signature: a=rsa-sha256; b=A92X87Z/PZCQIe0SGJ8skYCMdo6D6qkWn2dpCE22CQR5gHvZP5bU+PJranzq9lqpiEL30/E9yUTZtL90o5Mvgk4a6o2RDbb9RDVA2f7GWyJ+VHHox7ONcOuN2j0St0ErDPofksGCLtLwiyrcK7iwV677ifh/Dre4P6qeag9Tz9t+buC7lJ8xA+gkrUekl3gJO5RN5W7ILYGRaAkTYIvT5c61oiOxEQQVyraV1iB85VTkDVBa6r6yBhlevgHMjWgI0mbwF/OGMYv9b7edvWaEyDqTEGqDJ3GeoucjpOs56g0ONAsE9w7QM1NWm4jOaPtJqzUn1DJ2vPu9V2izU9V2sQ==; s=purelymail1; d=spwhitton.name; v=1; bh=EMCAqQvpCdNpPOUOrZjHijp+1L9q4pf5R8JOQWwFbYE=; h=Received:Received:From:To:Subject:Date; DKIM-Signature: a=rsa-sha256; b=H5FR/SnYGdRFH0uJxEB+hBBM+twWA7h0bEMVZcsyRl7hZytiG3YZ2dNI+FwXMSN71ZM7qk0X0sFh0joh1p2W4P7TOTKMrr/IwaeGIaEwDn8EzK7rMmQ0CKDHvv0eqW7cE1uGMqO+uDlescgnZ6iE1Pqe2/aE/+CHN8uqIujsv4iB8ItcWgYRZ05TYxgA2+Y44fo4eN0pMqE84Uzj0+lDXW7uiVrYRchYAqGotFhbx4WbbrkdY1Uh1v6Er2ugxinuS4uM9Kp0a0rSJDCqxHB6+1UiVqcKrsqVVbBNxvZoW0rDJ7XdnvZdBOTJ17Yo6lDASCed0Q6UIG76AjVPzVPgiw==; s=purelymail1; d=purelymail.com; v=1; bh=EMCAqQvpCdNpPOUOrZjHijp+1L9q4pf5R8JOQWwFbYE=; h=Feedback-ID:Received:Received:From:To:Subject:Date; Feedback-ID: 20115:3760:null:purelymail X-Pm-Original-To: 69097@debbugs.gnu.org Original-Received: by smtp.purelymail.com (Purelymail SMTP) with ESMTPSA id 890174328; (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Sat, 07 Sep 2024 21:08:17 +0000 (UTC) Original-Received: by zephyr.silentflame.com (Postfix, from userid 1000) id 155E9947C7D; Sat, 7 Sep 2024 22:08:17 +0100 (BST) In-Reply-To: <86frqbyemw.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 07 Sep 2024 12:52:39 +0300") 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:291410 Archived-At: --=-=-= Content-Type: text/plain Hello, Thank you both for the feedback. Attached is an updated version. A few replies: On Fri 06 Sep 2024 at 04:32pm GMT, Philip Kaludercic wrote: > Won't there be an error here if the command is invoked with a negative > argument? Do you mean that you think there should be an error? I don't see any need for that. On Sat 07 Sep 2024 at 12:52pm +03, Eli Zaretskii wrote: > I again ask whether we need this command. It is okay to have a > function (perhaps even an internal one) to move by Unix-words, but > what are the use cases for such a command? That's fine. I've turned it back into a function. > Should we also treat a backslash as delimiter, for MS-Windows? Good idea. That's more useful. -- Sean Whitton --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=v3-0001-New-commands-for-moving-and-killing-unix-words.patch >From 9163f6ab16816702f8bc6acb6f22734eb57acfc7 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Fri, 6 Sep 2024 11:35:46 +0100 Subject: [PATCH v3] New commands for moving and killing unix-words * lisp/simple.el (forward-unix-word): New function. (unix-word-rubout, unix-filename-rubout): New commands. * etc/NEWS: Announce the new commands. --- etc/NEWS | 6 ++++++ lisp/simple.el | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/etc/NEWS b/etc/NEWS index f3e719a34d3..104941425c2 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -123,6 +123,12 @@ 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 'unix-word-rubout' and 'unix-filename-rubout'. +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 '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..1b910b0ed22 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 (n &optional delim) + "Move forward N Unix-words. +A Unix-word is whitespace-delimited. +A negative N 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 function +emulates how C-w at the Unix terminal or shell identifies words. + +Optional argument DELIM specifies what characters are considered +whitespace. It is a string as might be passed to `skip-chars-forward'. +The default is \"\\s\\f\\n\\r\\t\\v\". Do not prefix a `^' character." + (when (and delim (string-prefix-p "^" delim)) + (error "DELIM argument must not begin with `^'")) + (unless (zerop n) + ;; We do skip over newlines by default because `backward-word' does. + (let* ((delim (or delim "\s\f\n\r\t\v")) + (ndelim (format "^%s" delim)) + (start (point)) + (fun (if (> n 0) + #'skip-chars-forward + #'skip-chars-backward))) + (dotimes (_ (abs n)) + (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. +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)))) + +(defun unix-filename-rubout (arg) + "Kill ARG Unix-words backwards, also treating `/' as delimiting words. +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 treated as +a word delimiter. See this command's namesake in Info node +`(readline)Commands For Killing'." + (interactive "^p") + (let ((start (point))) + (forward-unix-word (- arg) "\\/\s\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." -- 2.39.2 --=-=-=--