diff options
| -rw-r--r-- | lisp/replace.el | 59 |
1 files changed, 33 insertions, 26 deletions
diff --git a/lisp/replace.el b/lisp/replace.el index ee0cf5fa7a1..d40ff803464 100644 --- a/lisp/replace.el +++ b/lisp/replace.el | |||
| @@ -293,23 +293,9 @@ which will run faster and will not set the mark or print anything." | |||
| 293 | (defun keep-lines-read-args (prompt) | 293 | (defun keep-lines-read-args (prompt) |
| 294 | "Read arguments for `keep-lines' and friends. | 294 | "Read arguments for `keep-lines' and friends. |
| 295 | Prompt for a regexp with PROMPT. | 295 | Prompt for a regexp with PROMPT. |
| 296 | 296 | Value is a list, (REGEXP)." | |
| 297 | Value is a list (REGEXP START END). | 297 | (list (read-from-minibuffer prompt nil nil nil |
| 298 | 298 | 'regexp-history nil t))) | |
| 299 | If in Transient Mark mode, and the mark is active, START is the | ||
| 300 | start of the region, and END is a marker for the end of the region. | ||
| 301 | Otherwise, START is the current point, and END is the value of | ||
| 302 | function `point-max-marker'." | ||
| 303 | (let ((regexp (read-from-minibuffer prompt nil nil nil | ||
| 304 | 'regexp-history nil t)) | ||
| 305 | start end) | ||
| 306 | (if (and transient-mark-mode mark-active) | ||
| 307 | (setq start (region-beginning) | ||
| 308 | end (copy-marker (region-end))) | ||
| 309 | (setq start (point) | ||
| 310 | end (point-max-marker))) | ||
| 311 | (list regexp start end))) | ||
| 312 | |||
| 313 | 299 | ||
| 314 | (defun keep-lines (regexp &optional rstart rend) | 300 | (defun keep-lines (regexp &optional rstart rend) |
| 315 | "Delete all lines except those containing matches for REGEXP. | 301 | "Delete all lines except those containing matches for REGEXP. |
| @@ -321,13 +307,20 @@ the matching is case-sensitive. | |||
| 321 | 307 | ||
| 322 | Second and third arg RSTART and REND specify the region to operate on. | 308 | Second and third arg RSTART and REND specify the region to operate on. |
| 323 | 309 | ||
| 324 | In Transient Mark mode, if the mark is active, operate on the contents | 310 | Interactively, in Transient Mark mode when the mark is active, operate |
| 325 | of the region. Otherwise, operate from point to the end of the buffer." | 311 | on the contents of the region. Otherwise, operate from point to the |
| 312 | end of the buffer." | ||
| 313 | |||
| 326 | (interactive | 314 | (interactive |
| 327 | (keep-lines-read-args "Keep lines (containing match for regexp): ")) | 315 | (keep-lines-read-args "Keep lines (containing match for regexp): ")) |
| 328 | (if rstart | 316 | (if rstart |
| 329 | (goto-char (min rstart rend)) | 317 | (goto-char (min rstart rend)) |
| 330 | (setq rstart (point) rend (point-max-marker))) | 318 | (if (and transient-mark-mode mark-active) |
| 319 | (setq rstart (region-beginning) | ||
| 320 | rend (copy-marker (region-end))) | ||
| 321 | (setq rstart (point) | ||
| 322 | rend (point-max-marker))) | ||
| 323 | (goto-char rstart)) | ||
| 331 | (save-excursion | 324 | (save-excursion |
| 332 | (or (bolp) (forward-line 1)) | 325 | (or (bolp) (forward-line 1)) |
| 333 | (let ((start (point)) | 326 | (let ((start (point)) |
| @@ -361,13 +354,20 @@ the matching is case-sensitive. | |||
| 361 | 354 | ||
| 362 | Second and third arg RSTART and REND specify the region to operate on. | 355 | Second and third arg RSTART and REND specify the region to operate on. |
| 363 | 356 | ||
| 364 | In Transient Mark mode, if the mark is active, operate on the contents | 357 | Interactively, in Transient Mark mode when the mark is active, operate |
| 365 | of the region. Otherwise, operate from point to the end of the buffer." | 358 | on the contents of the region. Otherwise, operate from point to the |
| 359 | end of the buffer." | ||
| 360 | |||
| 366 | (interactive | 361 | (interactive |
| 367 | (keep-lines-read-args "Flush lines (containing match for regexp): ")) | 362 | (keep-lines-read-args "Flush lines (containing match for regexp): ")) |
| 368 | (if rstart | 363 | (if rstart |
| 369 | (goto-char (min rstart rend)) | 364 | (goto-char (min rstart rend)) |
| 370 | (setq rstart (point) rend (point-max-marker))) | 365 | (if (and transient-mark-mode mark-active) |
| 366 | (setq rstart (region-beginning) | ||
| 367 | rend (copy-marker (region-end))) | ||
| 368 | (setq rstart (point) | ||
| 369 | rend (point-max-marker))) | ||
| 370 | (goto-char rstart)) | ||
| 371 | (let ((case-fold-search (and case-fold-search | 371 | (let ((case-fold-search (and case-fold-search |
| 372 | (isearch-no-upper-case-p regexp t)))) | 372 | (isearch-no-upper-case-p regexp t)))) |
| 373 | (save-excursion | 373 | (save-excursion |
| @@ -387,14 +387,21 @@ the matching is case-sensitive. | |||
| 387 | 387 | ||
| 388 | Second and third arg RSTART and REND specify the region to operate on. | 388 | Second and third arg RSTART and REND specify the region to operate on. |
| 389 | 389 | ||
| 390 | In Transient Mark mode, if the mark is active, operate on the contents | 390 | Interactively, in Transient Mark mode when the mark is active, operate |
| 391 | of the region. Otherwise, operate from point to the end of the buffer." | 391 | on the contents of the region. Otherwise, operate from point to the |
| 392 | end of the buffer." | ||
| 393 | |||
| 392 | (interactive | 394 | (interactive |
| 393 | (keep-lines-read-args "How many matches for (regexp): ")) | 395 | (keep-lines-read-args "How many matches for (regexp): ")) |
| 394 | (save-excursion | 396 | (save-excursion |
| 395 | (if rstart | 397 | (if rstart |
| 396 | (goto-char (min rstart rend)) | 398 | (goto-char (min rstart rend)) |
| 397 | (setq rstart (point) rend (point-max-marker))) | 399 | (if (and transient-mark-mode mark-active) |
| 400 | (setq rstart (region-beginning) | ||
| 401 | rend (copy-marker (region-end))) | ||
| 402 | (setq rstart (point) | ||
| 403 | rend (point-max-marker))) | ||
| 404 | (goto-char rstart)) | ||
| 398 | (let ((count 0) | 405 | (let ((count 0) |
| 399 | opoint | 406 | opoint |
| 400 | (case-fold-search (and case-fold-search | 407 | (case-fold-search (and case-fold-search |