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:17:38 +0100 Message-ID: <87wmjntb7x.fsf@zephyr.silentflame.com> References: <871q9g8z8k.fsf@posteo.net> <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> <871q1vuq7y.fsf@zephyr.silentflame.com> 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="10488"; 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:18: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 1sn2p3-0002dS-I3 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 07 Sep 2024 23:18:22 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sn2om-0000EZ-HB; Sat, 07 Sep 2024 17:18: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 1sn2oj-0000E8-K4 for bug-gnu-emacs@gnu.org; Sat, 07 Sep 2024 17:18: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 1sn2oj-0004DO-AR for bug-gnu-emacs@gnu.org; Sat, 07 Sep 2024 17:18: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=FnRbkq9k3BIyGQfRajDlqHZaTQgU+p2vogvp5OMa3Yk=; b=o23rlRBxDh6kVGH8jtFYOWHcolDV2s/7BGpE0fzBoJiAou2lFGZSscXqSUnhiIno+KaVGFfLlH87ROlWu4h4RvPyMeGtc5Rvi6w0T2tAgehZNwj0fuc/FrMSG81GYi/6B3I1jJKiCdd0T8aMFH2GgR2yjuMZ8kH0Ra0u1ei2yILzaJQjMP2ZJetqZnTeeW7LbV7d4W1WQzZ1t0pHCbBb9CRBMc9g0mln/BluPyMjl8d2zS7GhBAEoHy4MxloeUOB2htmuxfKJd+75NZVmoqUhJj3uJKdQNGSrAeMZfeIQ8XUl/FYH0JWgHSiIA/ddPQzSfK10g6hY08VlJm2KVdhhA==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sn2ok-0004zZ-Hn for bug-gnu-emacs@gnu.org; Sat, 07 Sep 2024 17:18: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:18: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.172574387119169 (code B ref 69097); Sat, 07 Sep 2024 21:18:02 +0000 Original-Received: (at 69097) by debbugs.gnu.org; 7 Sep 2024 21:17:51 +0000 Original-Received: from localhost ([127.0.0.1]:57718 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sn2oZ-0004z5-9b for submit@debbugs.gnu.org; Sat, 07 Sep 2024 17:17:51 -0400 Original-Received: from sendmail.purelymail.com ([34.202.193.197]:51266) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sn2oX-0004yr-CN for 69097@debbugs.gnu.org; Sat, 07 Sep 2024 17:17:50 -0400 DKIM-Signature: a=rsa-sha256; b=kP1khnfHietKMj/deJutfl0CZrFHDysRbmXZxQYWTn7PwkAodlu9kTwhErUJ/PQIM8LbQ3WzxlsTtUs9d88zxybila1HF7/HlD1GRtftxS3a7Qsblzidg0tBXvOYygxTt4hLoJDau4qzprkVDLsnHa5D9KMCutTOMO9G3qfoxbplOUJUuLgB9J321CTJaLLcke2cJhc2XIkoVF+AvJmMbDgOcG4oD6ywIU62TokKzjHVt0EZZx5pqjQNKYUmCvecgAo6DPY8PTq4kQHuf6skb3paIIjzX85csuFSMqS2uQXtyO4vjNTlMRnctRDCqJQg9tlrvk/g1jmVq1IKRgJ4sw==; s=purelymail1; d=spwhitton.name; v=1; bh=urrdWD7DGU26KtOXhXuxjKbj+wcSPLks6kzN+/PdfSU=; h=Received:Received:From:To:Subject:Date; DKIM-Signature: a=rsa-sha256; b=sGwKHtpetc3lWkKE/KFV98lDOOwsEJSw7Hhc2fCWCsvoWf0mVYVTwdhtjEMHftZ8dXrKD8kUFuPcNnuOfVBDjcT2yGokJAFCQO/JJ+YgsYAIbP4whJeTY37RGav9IlUn1ttkiPVhL3koEJLTnz4ifstCDEhsZUDp8cPzXt2S0CgsyFMv1Jlp7ifLUkeN+MqTzqMEtt79TdqHe4Rh7eASZq2xOSgThmX6Bt95hJt4TAkn4Uz/yH6Dta3RjTPoUVEYjmIbRQ8oWIlH/GkDysz2reFbulx+Ii3O6XPgyuaVa2mTEnanAi3NNpixEGa+7qjFgxW/D9MJVTrbiAD4rCZGSw==; s=purelymail1; d=purelymail.com; v=1; bh=urrdWD7DGU26KtOXhXuxjKbj+wcSPLks6kzN+/PdfSU=; 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 -111460925; (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Sat, 07 Sep 2024 21:17:39 +0000 (UTC) Original-Received: by zephyr.silentflame.com (Postfix, from userid 1000) id E212B947C7D; Sat, 7 Sep 2024 22:17:38 +0100 (BST) In-Reply-To: <871q1vuq7y.fsf@zephyr.silentflame.com> (Sean Whitton's message of "Sat, 07 Sep 2024 22:08:17 +0100") 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:291411 Archived-At: --=-=-= Content-Type: text/plain Hello, On Sat 07 Sep 2024 at 10:08pm +01, Sean Whitton wrote: > Hello, > > Thank you both for the feedback. Attached is an updated version. I neglected to update the docstring for adding backslashes as delimiters in unix-filename-rubout. Fixed in the attached, along with a another few small fixes. -- Sean Whitton --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=v4-0001-New-commands-unix-word-rubout-unix-filename-rubou.patch >From 059ca7388494f21d13c87f114965a2ec1fc1cc55 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Fri, 6 Sep 2024 11:35:46 +0100 Subject: [PATCH v4] New commands unix-word-rubout, unix-filename-rubout * 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..18cc15f6f5d 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 (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 slashes as word delimiters. +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 `/' and `\\' are also +treated as delimiting words. 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 --=-=-=--