diff options
| author | Richard M. Stallman | 1998-10-14 12:47:18 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1998-10-14 12:47:18 +0000 |
| commit | d2a0ee8b79c91c5f0ae1a0f841a1e67f7e1b26a2 (patch) | |
| tree | 5a3eb1fc712a2245c2ce47bda1bc2db451b47fef | |
| parent | 0513425723f80d58b8e12ae1f6b859772b8f2ed2 (diff) | |
| download | emacs-d2a0ee8b79c91c5f0ae1a0f841a1e67f7e1b26a2.tar.gz emacs-d2a0ee8b79c91c5f0ae1a0f841a1e67f7e1b26a2.zip | |
(keep-lines, flush-lines, how-many):
Don't ignore case if arg has upper case letters.
| -rw-r--r-- | lisp/replace.el | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/lisp/replace.el b/lisp/replace.el index d50f0d6ee30..5412b127624 100644 --- a/lisp/replace.el +++ b/lisp/replace.el | |||
| @@ -80,7 +80,8 @@ If `query-replace-interactive' is non-nil, the last incremental search | |||
| 80 | string is used as FROM-STRING--you don't have to specify it with the | 80 | string is used as FROM-STRING--you don't have to specify it with the |
| 81 | minibuffer. | 81 | minibuffer. |
| 82 | 82 | ||
| 83 | Preserves case in each replacement if `case-replace' and `case-fold-search' | 83 | Replacement transfers the case of the old text to the new text, |
| 84 | if `case-replace' and `case-fold-search' | ||
| 84 | are non-nil and FROM-STRING has no uppercase letters. | 85 | are non-nil and FROM-STRING has no uppercase letters. |
| 85 | \(Preserving case means that if the string matched is all caps, or capitalized, | 86 | \(Preserving case means that if the string matched is all caps, or capitalized, |
| 86 | then its replacement is upcased or capitalized.) | 87 | then its replacement is upcased or capitalized.) |
| @@ -220,13 +221,18 @@ which will run faster and will not set the mark or print anything." | |||
| 220 | (defun keep-lines (regexp) | 221 | (defun keep-lines (regexp) |
| 221 | "Delete all lines except those containing matches for REGEXP. | 222 | "Delete all lines except those containing matches for REGEXP. |
| 222 | A match split across lines preserves all the lines it lies in. | 223 | A match split across lines preserves all the lines it lies in. |
| 223 | Applies to all lines after point." | 224 | Applies to all lines after point. |
| 225 | |||
| 226 | If REGEXP contains upper case characters (excluding those preceded by `\\'), | ||
| 227 | the matching is case-sensitive." | ||
| 224 | (interactive (list (read-from-minibuffer | 228 | (interactive (list (read-from-minibuffer |
| 225 | "Keep lines (containing match for regexp): " | 229 | "Keep lines (containing match for regexp): " |
| 226 | nil nil nil 'regexp-history nil t))) | 230 | nil nil nil 'regexp-history nil t))) |
| 227 | (save-excursion | 231 | (save-excursion |
| 228 | (or (bolp) (forward-line 1)) | 232 | (or (bolp) (forward-line 1)) |
| 229 | (let ((start (point))) | 233 | (let ((start (point)) |
| 234 | (case-fold-search (and case-fold-search | ||
| 235 | (isearch-no-upper-case-p regexp t)))) | ||
| 230 | (while (not (eobp)) | 236 | (while (not (eobp)) |
| 231 | ;; Start is first char not preserved by previous match. | 237 | ;; Start is first char not preserved by previous match. |
| 232 | (if (not (re-search-forward regexp nil 'move)) | 238 | (if (not (re-search-forward regexp nil 'move)) |
| @@ -247,25 +253,35 @@ Applies to all lines after point." | |||
| 247 | (defun flush-lines (regexp) | 253 | (defun flush-lines (regexp) |
| 248 | "Delete lines containing matches for REGEXP. | 254 | "Delete lines containing matches for REGEXP. |
| 249 | If a match is split across lines, all the lines it lies in are deleted. | 255 | If a match is split across lines, all the lines it lies in are deleted. |
| 250 | Applies to lines after point." | 256 | Applies to lines after point. |
| 257 | |||
| 258 | If REGEXP contains upper case characters (excluding those preceded by `\\'), | ||
| 259 | the matching is case-sensitive." | ||
| 251 | (interactive (list (read-from-minibuffer | 260 | (interactive (list (read-from-minibuffer |
| 252 | "Flush lines (containing match for regexp): " | 261 | "Flush lines (containing match for regexp): " |
| 253 | nil nil nil 'regexp-history nil t))) | 262 | nil nil nil 'regexp-history nil t))) |
| 254 | (save-excursion | 263 | (let ((case-fold-search (and case-fold-search |
| 255 | (while (and (not (eobp)) | 264 | (isearch-no-upper-case-p regexp t)))) |
| 256 | (re-search-forward regexp nil t)) | 265 | (save-excursion |
| 257 | (delete-region (save-excursion (goto-char (match-beginning 0)) | 266 | (while (and (not (eobp)) |
| 258 | (beginning-of-line) | 267 | (re-search-forward regexp nil t)) |
| 259 | (point)) | 268 | (delete-region (save-excursion (goto-char (match-beginning 0)) |
| 260 | (progn (forward-line 1) (point)))))) | 269 | (beginning-of-line) |
| 270 | (point)) | ||
| 271 | (progn (forward-line 1) (point))))))) | ||
| 261 | 272 | ||
| 262 | (defalias 'count-matches 'how-many) | 273 | (defalias 'count-matches 'how-many) |
| 263 | (defun how-many (regexp) | 274 | (defun how-many (regexp) |
| 264 | "Print number of matches for REGEXP following point." | 275 | "Print number of matches for REGEXP following point. |
| 276 | |||
| 277 | If REGEXP contains upper case characters (excluding those preceded by `\\'), | ||
| 278 | the matching is case-sensitive." | ||
| 265 | (interactive (list (read-from-minibuffer | 279 | (interactive (list (read-from-minibuffer |
| 266 | "How many matches for (regexp): " | 280 | "How many matches for (regexp): " |
| 267 | nil nil nil 'regexp-history nil t))) | 281 | nil nil nil 'regexp-history nil t))) |
| 268 | (let ((count 0) opoint) | 282 | (let ((count 0) opoint |
| 283 | (case-fold-search (and case-fold-search | ||
| 284 | (isearch-no-upper-case-p regexp t)))) | ||
| 269 | (save-excursion | 285 | (save-excursion |
| 270 | (while (and (not (eobp)) | 286 | (while (and (not (eobp)) |
| 271 | (progn (setq opoint (point)) | 287 | (progn (setq opoint (point)) |