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#49120: [PATCH] Add commands 'kill-lines' and 'copy-lines' Date: Sat, 19 Jun 2021 20:33:38 +0300 Message-ID: <831r8xwyh9.fsf@gnu.org> References: <337118f4-d1a2-ec51-fb29-a933a3cac785@protonmail.com> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17013"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 49120@debbugs.gnu.org To: Okam Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jun 19 19:42:53 2021 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 1luezd-00048v-7p for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 19 Jun 2021 19:42:53 +0200 Original-Received: from localhost ([::1]:45684 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1luezc-0005t3-9F for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 19 Jun 2021 13:42:52 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56408) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1luer4-0000ZI-Jo for bug-gnu-emacs@gnu.org; Sat, 19 Jun 2021 13:34:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:49178) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1luer4-0008LO-Av for bug-gnu-emacs@gnu.org; Sat, 19 Jun 2021 13:34:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1luer4-0003Cf-9H for bug-gnu-emacs@gnu.org; Sat, 19 Jun 2021 13:34:02 -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, 19 Jun 2021 17:34:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 49120 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 49120-submit@debbugs.gnu.org id=B49120.162412401912285 (code B ref 49120); Sat, 19 Jun 2021 17:34:02 +0000 Original-Received: (at 49120) by debbugs.gnu.org; 19 Jun 2021 17:33:39 +0000 Original-Received: from localhost ([127.0.0.1]:60724 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lueqg-0003C4-TP for submit@debbugs.gnu.org; Sat, 19 Jun 2021 13:33:39 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:58632) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lueqe-0003Bp-Uw for 49120@debbugs.gnu.org; Sat, 19 Jun 2021 13:33:37 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:43344) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lueqY-00085W-B0; Sat, 19 Jun 2021 13:33:31 -0400 Original-Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:4869 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lueqX-0007VF-Uy; Sat, 19 Jun 2021 13:33:30 -0400 In-Reply-To: <337118f4-d1a2-ec51-fb29-a933a3cac785@protonmail.com> (bug-gnu-emacs@gnu.org) 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" Xref: news.gmane.io gmane.emacs.bugs:208760 Archived-At: > Date: Sat, 19 Jun 2021 17:12:25 +0000 > From: Okam via "Bug reports for GNU Emacs, > the Swiss army knife of text editors" > > These commands work similarly to the 'flush-lines' command, but add the > lines to the kill ring as a single item. Thanks. However, the "as a single item" part is not clear enough and should be clarified. Do you mean "as a single string"? If so, I would suggest to say that, and also explicitly say that the string includes the newlines between the lines. > +@findex kill-lines > +@item M-x kill-lines > +Like @code{flush-lines}, but also add the matching lines to the kill > +ring as a single item. I'd suggest to reword: Like @code{flush-lines}, but also add the matching lines to the kill ring. The command adds the matching lines to the kill ring as a single string, including the newlines that separated the lines. The reason I think it's better to separate this into two sentences is that "also" is only relevant to the first part, not the second. > +(defalias 'kill-matching-lines 'kill-lines) > +(defalias 'copy-matching-lines 'copy-lines) I wonder why we need these aliases, and in fact why not have only kill-matching-lines without the shorter kill-lines? The latter omits the crucial reference to the "matching" part, and is too similar to kill-word, kill-paragraph, etc. > (defalias 'count-matches 'how-many) > > (defun keep-lines-read-args (prompt) > @@ -1054,6 +1056,134 @@ flush-lines > count)) > count)) > > +(defun kill-lines (regexp &optional rstart rend interactive) > + "Kill lines containing matches for REGEXP. > + > +When called from Lisp (and usually when called interactively as > +well, see below), applies to the part of the buffer after point. > +The line point is in is killed if and only if it contains a match > +for regexp starting after point. ^^^^^^ REGEXP should in all caps. > +Second and third arg RSTART and REND specify the region to ^^^ "args", in plural. > +operate on. Lines partially contained in this region are killed > +if and only if they contain a match entirely contained in it. ^^^^^ "in the region" will make this more clear. > + When > +calling this function from Lisp, you can pretend that it was > +called interactively by passing a non-nil INTERACTIVE argument. This is not specific to this command, so why tell it here? Same comments apply to copy-lines. > +(defun copy-lines (regexp &optional rstart rend interactive) > + "Copy lines containing matches for REGEXP to the kill ring. > + > +When called from Lisp (and usually when called interactively as > +well, see below), applies to the part of the buffer after point. > +The line point is in is copied if and only if it contains a match > +for regexp starting after point. > + > +If REGEXP contains upper case characters (excluding those > +preceded by `\\') and `search-upper-case' is non-nil, the > +matching is case-sensitive. > + > +Second and third arg RSTART and REND specify the region to > +operate on. Lines partially contained in this region are copied > +if and only if they contain a match entirely contained in it. > + > +Interactively, in Transient Mark mode when the mark is active, > +operate on the contents of the region. Otherwise, operate from > +point to the end of (the accessible portion of) the buffer. When > +calling this function from Lisp, you can pretend that it was > +called interactively by passing a non-nil INTERACTIVE argument. > + > +If a match is split across lines, all the lines it lies in are > +copied. > + > +Return the number of copied matching lines. When called > +interactively, also print the number." > + (interactive > + (progn > + (barf-if-buffer-read-only) Why barf? this command doesn't modify the buffer, does it?