aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/replace.el
diff options
context:
space:
mode:
authorJuri Linkov2019-02-28 23:32:39 +0200
committerJuri Linkov2019-02-28 23:32:39 +0200
commit44b7436d4408ddfb72c1758d60395872791ae00d (patch)
tree5e8e95fadea6509e29e97374fc7445ec91165eae /lisp/replace.el
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.
Diffstat (limited to 'lisp/replace.el')
-rw-r--r--lisp/replace.el21
1 files changed, 12 insertions, 9 deletions
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.