From 44b7436d4408ddfb72c1758d60395872791ae00d Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Thu, 28 Feb 2019 23:32:39 +0200 Subject: [PATCH] * lisp/replace.el (flush-lines): Return the number of deleted lines. When called interactively, also print the number. (Bug#34520) * doc/emacs/search.texi (Other Repeating Search): Update flush-lines that prints the number of deleted lines. --- doc/emacs/search.texi | 12 +++++++----- etc/NEWS | 4 ++++ lisp/replace.el | 21 ++++++++++++--------- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/doc/emacs/search.texi b/doc/emacs/search.texi index 25f0cc4183e..761fe929ae5 100644 --- a/doc/emacs/search.texi +++ b/doc/emacs/search.texi @@ -1872,11 +1872,13 @@ region instead. @findex flush-lines @item M-x flush-lines Prompt for a regexp, and delete each line that contains a match for -it, operating on the text after point. This command deletes the -current line if it contains a match starting after point. If the -region is active, it operates on the region instead; if a line -partially contained in the region contains a match entirely contained -in the region, it is deleted. +it, operating on the text after point. When the command finishes, +it prints the number of deleted matching lines. + +This command deletes the current line if it contains a match starting +after point. If the region is active, it operates on the region +instead; if a line partially contained in the region contains a match +entirely contained in the region, it is deleted. If a match is split across lines, @code{flush-lines} deletes all those lines. It deletes the lines before starting to look for the next diff --git a/etc/NEWS b/etc/NEWS index 8a34049cf0d..683a4279a35 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -850,6 +850,9 @@ and case-sensitivity together with search strings in the search ring. --- *** Isearch now has its own tool-bar and menu-bar menu. ++++ +*** flush-lines prints and returns the number of deleted matching lines. + ** Debugger +++ @@ -1146,6 +1149,7 @@ the 128...255 range, as expected. ** Frames ++++ *** New command 'make-frame-on-monitor' makes a frame on the specified monitor. diff --git a/lisp/replace.el b/lisp/replace.el index b482d76afc2..59ad1a375b8 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -850,7 +850,6 @@ If nil, uses `regexp-history'." (defalias 'delete-matching-lines 'flush-lines) (defalias 'count-matches 'how-many) - (defun keep-lines-read-args (prompt) "Read arguments for `keep-lines' and friends. Prompt for a regexp with PROMPT. @@ -930,9 +929,8 @@ a previously found match." (set-marker rend nil) nil) - (defun flush-lines (regexp &optional rstart rend interactive) - "Delete lines containing matches for REGEXP. + "Delete 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 deleted if and only if it contains a @@ -953,7 +951,10 @@ a non-nil INTERACTIVE argument. If a match is split across lines, all the lines it lies in are deleted. They are deleted _before_ looking for the next match. Hence, a match -starting on the same line at which another match ended is ignored." +starting on the same line at which another match ended is ignored. + +Return the number of deleted matching lines. When called interactively, +also print the number." (interactive (progn (barf-if-buffer-read-only) @@ -968,7 +969,8 @@ starting on the same line at which another match ended is ignored." (setq rstart (point) rend (point-max-marker))) (goto-char rstart)) - (let ((case-fold-search + (let ((count 0) + (case-fold-search (if (and case-fold-search search-upper-case) (isearch-no-upper-case-p regexp t) case-fold-search))) @@ -978,10 +980,11 @@ starting on the same line at which another match ended is ignored." (delete-region (save-excursion (goto-char (match-beginning 0)) (forward-line 0) (point)) - (progn (forward-line 1) (point)))))) - (set-marker rend nil) - nil) - + (progn (forward-line 1) (point))) + (setq count (1+ count)))) + (set-marker rend nil) + (when interactive (message "Deleted %d matching lines" count)) + count)) (defun how-many (regexp &optional rstart rend interactive) "Print and return number of matches for REGEXP following point. -- 2.39.2