diff options
| author | Juri Linkov | 2019-02-28 23:32:39 +0200 |
|---|---|---|
| committer | Juri Linkov | 2019-02-28 23:32:39 +0200 |
| commit | 44b7436d4408ddfb72c1758d60395872791ae00d (patch) | |
| tree | 5e8e95fadea6509e29e97374fc7445ec91165eae | |
| parent | 5d60229bf1a9a496102fc2a3ef9e57dcce7bef10 (diff) | |
| download | emacs-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.texi | 12 | ||||
| -rw-r--r-- | etc/NEWS | 4 | ||||
| -rw-r--r-- | 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. | |||
| 1872 | @findex flush-lines | 1872 | @findex flush-lines |
| 1873 | @item M-x flush-lines | 1873 | @item M-x flush-lines |
| 1874 | Prompt for a regexp, and delete each line that contains a match for | 1874 | Prompt for a regexp, and delete each line that contains a match for |
| 1875 | it, operating on the text after point. This command deletes the | 1875 | it, operating on the text after point. When the command finishes, |
| 1876 | current line if it contains a match starting after point. If the | 1876 | it prints the number of deleted matching lines. |
| 1877 | region is active, it operates on the region instead; if a line | 1877 | |
| 1878 | partially contained in the region contains a match entirely contained | 1878 | This command deletes the current line if it contains a match starting |
| 1879 | in the region, it is deleted. | 1879 | after point. If the region is active, it operates on the region |
| 1880 | instead; if a line partially contained in the region contains a match | ||
| 1881 | entirely contained in the region, it is deleted. | ||
| 1880 | 1882 | ||
| 1881 | If a match is split across lines, @code{flush-lines} deletes all those | 1883 | If a match is split across lines, @code{flush-lines} deletes all those |
| 1882 | lines. It deletes the lines before starting to look for the next | 1884 | lines. It deletes the lines before starting to look for the next |
| @@ -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. |
| 856 | Prompt for a regexp with PROMPT. | 855 | Prompt 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. |
| 936 | When called from Lisp (and usually when called interactively as | 934 | When called from Lisp (and usually when called interactively as |
| 937 | well, see below), applies to the part of the buffer after point. | 935 | well, see below), applies to the part of the buffer after point. |
| 938 | The line point is in is deleted if and only if it contains a | 936 | The line point is in is deleted if and only if it contains a |
| @@ -953,7 +951,10 @@ a non-nil INTERACTIVE argument. | |||
| 953 | 951 | ||
| 954 | If a match is split across lines, all the lines it lies in are deleted. | 952 | If a match is split across lines, all the lines it lies in are deleted. |
| 955 | They are deleted _before_ looking for the next match. Hence, a match | 953 | They are deleted _before_ looking for the next match. Hence, a match |
| 956 | starting on the same line at which another match ended is ignored." | 954 | starting on the same line at which another match ended is ignored. |
| 955 | |||
| 956 | Return the number of deleted matching lines. When called interactively, | ||
| 957 | also 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. |