aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuri Linkov2019-02-28 23:32:39 +0200
committerJuri Linkov2019-02-28 23:32:39 +0200
commit44b7436d4408ddfb72c1758d60395872791ae00d (patch)
tree5e8e95fadea6509e29e97374fc7445ec91165eae
parent5d60229bf1a9a496102fc2a3ef9e57dcce7bef10 (diff)
downloademacs-44b7436d4408ddfb72c1758d60395872791ae00d.tar.gz
emacs-44b7436d4408ddfb72c1758d60395872791ae00d.zip
* 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.
-rw-r--r--doc/emacs/search.texi12
-rw-r--r--etc/NEWS4
-rw-r--r--lisp/replace.el21
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.
1872@findex flush-lines 1872@findex flush-lines
1873@item M-x flush-lines 1873@item M-x flush-lines
1874Prompt for a regexp, and delete each line that contains a match for 1874Prompt for a regexp, and delete each line that contains a match for
1875it, operating on the text after point. This command deletes the 1875it, operating on the text after point. When the command finishes,
1876current line if it contains a match starting after point. If the 1876it prints the number of deleted matching lines.
1877region is active, it operates on the region instead; if a line 1877
1878partially contained in the region contains a match entirely contained 1878This command deletes the current line if it contains a match starting
1879in the region, it is deleted. 1879after point. If the region is active, it operates on the region
1880instead; if a line partially contained in the region contains a match
1881entirely contained in the region, it is deleted.
1880 1882
1881If a match is split across lines, @code{flush-lines} deletes all those 1883If a match is split across lines, @code{flush-lines} deletes all those
1882lines. It deletes the lines before starting to look for the next 1884lines. 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.
850--- 850---
851*** Isearch now has its own tool-bar and menu-bar menu. 851*** Isearch now has its own tool-bar and menu-bar menu.
852 852
853+++
854*** flush-lines prints and returns the number of deleted matching lines.
855
853** Debugger 856** Debugger
854 857
855+++ 858+++
@@ -1146,6 +1149,7 @@ the 128...255 range, as expected.
1146 1149
1147** Frames 1150** Frames
1148 1151
1152+++
1149*** New command 'make-frame-on-monitor' makes a frame on the specified monitor. 1153*** New command 'make-frame-on-monitor' makes a frame on the specified monitor.
1150 1154
1151 1155
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'."
850(defalias 'delete-matching-lines 'flush-lines) 850(defalias 'delete-matching-lines 'flush-lines)
851(defalias 'count-matches 'how-many) 851(defalias 'count-matches 'how-many)
852 852
853
854(defun keep-lines-read-args (prompt) 853(defun keep-lines-read-args (prompt)
855 "Read arguments for `keep-lines' and friends. 854 "Read arguments for `keep-lines' and friends.
856Prompt for a regexp with PROMPT. 855Prompt for a regexp with PROMPT.
@@ -930,9 +929,8 @@ a previously found match."
930 (set-marker rend nil) 929 (set-marker rend nil)
931 nil) 930 nil)
932 931
933
934(defun flush-lines (regexp &optional rstart rend interactive) 932(defun flush-lines (regexp &optional rstart rend interactive)
935 "Delete lines containing matches for REGEXP. 933 "Delete lines containing matches for REGEXP.
936When called from Lisp (and usually when called interactively as 934When called from Lisp (and usually when called interactively as
937well, see below), applies to the part of the buffer after point. 935well, see below), applies to the part of the buffer after point.
938The line point is in is deleted if and only if it contains a 936The line point is in is deleted if and only if it contains a
@@ -953,7 +951,10 @@ a non-nil INTERACTIVE argument.
953 951
954If a match is split across lines, all the lines it lies in are deleted. 952If a match is split across lines, all the lines it lies in are deleted.
955They are deleted _before_ looking for the next match. Hence, a match 953They are deleted _before_ looking for the next match. Hence, a match
956starting on the same line at which another match ended is ignored." 954starting on the same line at which another match ended is ignored.
955
956Return the number of deleted matching lines. When called interactively,
957also print the number."
957 (interactive 958 (interactive
958 (progn 959 (progn
959 (barf-if-buffer-read-only) 960 (barf-if-buffer-read-only)
@@ -968,7 +969,8 @@ starting on the same line at which another match ended is ignored."
968 (setq rstart (point) 969 (setq rstart (point)
969 rend (point-max-marker))) 970 rend (point-max-marker)))
970 (goto-char rstart)) 971 (goto-char rstart))
971 (let ((case-fold-search 972 (let ((count 0)
973 (case-fold-search
972 (if (and case-fold-search search-upper-case) 974 (if (and case-fold-search search-upper-case)
973 (isearch-no-upper-case-p regexp t) 975 (isearch-no-upper-case-p regexp t)
974 case-fold-search))) 976 case-fold-search)))
@@ -978,10 +980,11 @@ starting on the same line at which another match ended is ignored."
978 (delete-region (save-excursion (goto-char (match-beginning 0)) 980 (delete-region (save-excursion (goto-char (match-beginning 0))
979 (forward-line 0) 981 (forward-line 0)
980 (point)) 982 (point))
981 (progn (forward-line 1) (point)))))) 983 (progn (forward-line 1) (point)))
982 (set-marker rend nil) 984 (setq count (1+ count))))
983 nil) 985 (set-marker rend nil)
984 986 (when interactive (message "Deleted %d matching lines" count))
987 count))
985 988
986(defun how-many (regexp &optional rstart rend interactive) 989(defun how-many (regexp &optional rstart rend interactive)
987 "Print and return number of matches for REGEXP following point. 990 "Print and return number of matches for REGEXP following point.