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