* 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.
This commit is contained in:
Juri Linkov 2019-02-28 23:32:39 +02:00
parent 5d60229bf1
commit 44b7436d44
3 changed files with 23 additions and 14 deletions

View file

@ -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

View file

@ -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.

View file

@ -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.