diff options
| author | Luc Teirlinck | 2005-06-26 02:38:08 +0000 |
|---|---|---|
| committer | Luc Teirlinck | 2005-06-26 02:38:08 +0000 |
| commit | bace72098d62721fe00c8f0ff40b1e25f1f418a9 (patch) | |
| tree | fb46592eb34d9405cca20abcb38bcca836336c51 /lisp/replace.el | |
| parent | dd716cec1d25185142da0ddb3c16905b4cb98599 (diff) | |
| download | emacs-bace72098d62721fe00c8f0ff40b1e25f1f418a9.tar.gz emacs-bace72098d62721fe00c8f0ff40b1e25f1f418a9.zip | |
(keep-lines-read-args): Add INTERACTIVE arg.
(keep-lines): Add INTERACTIVE arg. Never delete lines only
partially contained in the active region. Do not take active
region into account when called from Lisp, unless INTERACTIVE arg
is non-nil. Use `forward-line' instead of `beginning-of-line' to
avoid trouble with fields. Make marker point nowhere when no
longer used. Always return nil. Doc fix.
(flush-lines): Add INTERACTIVE arg. Do not take active region
into account when called from Lisp, unless INTERACTIVE arg is
non-nil. Use `forward-line' instead of `beginning-of-line' to
avoid trouble with fields. Make marker point nowhere when no
longer used. Always return nil. Doc fix.
(how-many): Add INTERACTIVE arg. Make RSTART and REND args
interchangeable. Do not take active region into account when
called from Lisp, unless INTERACTIVE arg is non-nil. Do not print
message in echo area when called from Lisp, unless INTERACTIVE arg
is non-nil. Avoid saying "1 occurrences". Do not use markers.
Return the number of matches. Doc fix.
(occur): Doc fix.
(perform-replace): Make comment follow double space convention for
the sake of `outline-minor-mode'.
Diffstat (limited to 'lisp/replace.el')
| -rw-r--r-- | lisp/replace.el | 120 |
1 files changed, 83 insertions, 37 deletions
diff --git a/lisp/replace.el b/lisp/replace.el index 2896ce133de..0b19d72178f 100644 --- a/lisp/replace.el +++ b/lisp/replace.el | |||
| @@ -516,21 +516,32 @@ which will run faster and will not set the mark or print anything." | |||
| 516 | Prompt for a regexp with PROMPT. | 516 | Prompt for a regexp with PROMPT. |
| 517 | Value is a list, (REGEXP)." | 517 | Value is a list, (REGEXP)." |
| 518 | (list (read-from-minibuffer prompt nil nil nil | 518 | (list (read-from-minibuffer prompt nil nil nil |
| 519 | 'regexp-history nil t))) | 519 | 'regexp-history nil t) |
| 520 | nil nil t)) | ||
| 520 | 521 | ||
| 521 | (defun keep-lines (regexp &optional rstart rend) | 522 | (defun keep-lines (regexp &optional rstart rend interactive) |
| 522 | "Delete all lines except those containing matches for REGEXP. | 523 | "Delete all lines except those containing matches for REGEXP. |
| 523 | A match split across lines preserves all the lines it lies in. | 524 | A match split across lines preserves all the lines it lies in. |
| 524 | Applies to all lines after point. | 525 | When called from Lisp (and usually interactively as well, see below) |
| 526 | applies to all lines starting after point. | ||
| 525 | 527 | ||
| 526 | If REGEXP contains upper case characters (excluding those preceded by `\\'), | 528 | If REGEXP contains upper case characters (excluding those preceded by `\\'), |
| 527 | the matching is case-sensitive. | 529 | the matching is case-sensitive. |
| 528 | 530 | ||
| 529 | Second and third arg RSTART and REND specify the region to operate on. | 531 | Second and third arg RSTART and REND specify the region to operate on. |
| 532 | This command operates on (the accessible part of) all lines whose | ||
| 533 | accessible part is entirely contained in the region determined by RSTART | ||
| 534 | and REND. (A newline ending a line counts as part of that line.) | ||
| 530 | 535 | ||
| 531 | Interactively, in Transient Mark mode when the mark is active, operate | 536 | Interactively, in Transient Mark mode when the mark is active, operate |
| 532 | on the contents of the region. Otherwise, operate from point to the | 537 | on all lines whose accessible part is entirely contained in the region. |
| 533 | end of the buffer." | 538 | Otherwise, the command applies to all lines starting after point. |
| 539 | When calling this function from Lisp, you can pretend that it was | ||
| 540 | called interactively by passing a non-nil INTERACTIVE argument. | ||
| 541 | |||
| 542 | This function starts looking for the next match from the end of | ||
| 543 | the previous match. Hence, it ignores matches that overlap | ||
| 544 | a previously found match." | ||
| 534 | 545 | ||
| 535 | (interactive | 546 | (interactive |
| 536 | (progn | 547 | (progn |
| @@ -539,10 +550,20 @@ end of the buffer." | |||
| 539 | (if rstart | 550 | (if rstart |
| 540 | (progn | 551 | (progn |
| 541 | (goto-char (min rstart rend)) | 552 | (goto-char (min rstart rend)) |
| 542 | (setq rend (copy-marker (max rstart rend)))) | 553 | (setq rend |
| 543 | (if (and transient-mark-mode mark-active) | 554 | (progn |
| 555 | (save-excursion | ||
| 556 | (goto-char (max rstart rend)) | ||
| 557 | (unless (or (bolp) (eobp)) | ||
| 558 | (forward-line 0)) | ||
| 559 | (point-marker))))) | ||
| 560 | (if (and interactive transient-mark-mode mark-active) | ||
| 544 | (setq rstart (region-beginning) | 561 | (setq rstart (region-beginning) |
| 545 | rend (copy-marker (region-end))) | 562 | rend (progn |
| 563 | (goto-char (region-end)) | ||
| 564 | (unless (or (bolp) (eobp)) | ||
| 565 | (forward-line 0)) | ||
| 566 | (point-marker))) | ||
| 546 | (setq rstart (point) | 567 | (setq rstart (point) |
| 547 | rend (point-max-marker))) | 568 | rend (point-max-marker))) |
| 548 | (goto-char rstart)) | 569 | (goto-char rstart)) |
| @@ -556,7 +577,7 @@ end of the buffer." | |||
| 556 | (if (not (re-search-forward regexp rend 'move)) | 577 | (if (not (re-search-forward regexp rend 'move)) |
| 557 | (delete-region start rend) | 578 | (delete-region start rend) |
| 558 | (let ((end (save-excursion (goto-char (match-beginning 0)) | 579 | (let ((end (save-excursion (goto-char (match-beginning 0)) |
| 559 | (beginning-of-line) | 580 | (forward-line 0) |
| 560 | (point)))) | 581 | (point)))) |
| 561 | ;; Now end is first char preserved by the new match. | 582 | ;; Now end is first char preserved by the new match. |
| 562 | (if (< start end) | 583 | (if (< start end) |
| @@ -566,22 +587,34 @@ end of the buffer." | |||
| 566 | ;; If the match was empty, avoid matching again at same place. | 587 | ;; If the match was empty, avoid matching again at same place. |
| 567 | (and (< (point) rend) | 588 | (and (< (point) rend) |
| 568 | (= (match-beginning 0) (match-end 0)) | 589 | (= (match-beginning 0) (match-end 0)) |
| 569 | (forward-char 1)))))) | 590 | (forward-char 1))))) |
| 591 | (set-marker rend nil) | ||
| 592 | nil) | ||
| 570 | 593 | ||
| 571 | 594 | ||
| 572 | (defun flush-lines (regexp &optional rstart rend) | 595 | (defun flush-lines (regexp &optional rstart rend interactive) |
| 573 | "Delete lines containing matches for REGEXP. | 596 | "Delete lines containing matches for REGEXP. |
| 574 | If a match is split across lines, all the lines it lies in are deleted. | 597 | When called from Lisp (and usually when called interactively as |
| 575 | Applies to lines after point. | 598 | well, see below), applies to the part of the buffer after point. |
| 599 | The line point is in is deleted if and only if it contains a | ||
| 600 | match for regexp starting after point. | ||
| 576 | 601 | ||
| 577 | If REGEXP contains upper case characters (excluding those preceded by `\\'), | 602 | If REGEXP contains upper case characters (excluding those preceded by `\\'), |
| 578 | the matching is case-sensitive. | 603 | the matching is case-sensitive. |
| 579 | 604 | ||
| 580 | Second and third arg RSTART and REND specify the region to operate on. | 605 | Second and third arg RSTART and REND specify the region to operate on. |
| 606 | Lines partially contained in this region are deleted if and only if | ||
| 607 | they contain a match entirely contained in it. | ||
| 581 | 608 | ||
| 582 | Interactively, in Transient Mark mode when the mark is active, operate | 609 | Interactively, in Transient Mark mode when the mark is active, operate |
| 583 | on the contents of the region. Otherwise, operate from point to the | 610 | on the contents of the region. Otherwise, operate from point to the |
| 584 | end of the buffer." | 611 | end of (the accessible portion of) the buffer. When calling this function |
| 612 | from Lisp, you can pretend that it was called interactively by passing | ||
| 613 | a non-nil INTERACTIVE argument. | ||
| 614 | |||
| 615 | If a match is split across lines, all the lines it lies in are deleted. | ||
| 616 | They are deleted _before_ looking for the next match. Hence, a match | ||
| 617 | starting on the same line at which another match ended is ignored." | ||
| 585 | 618 | ||
| 586 | (interactive | 619 | (interactive |
| 587 | (progn | 620 | (progn |
| @@ -591,7 +624,7 @@ end of the buffer." | |||
| 591 | (progn | 624 | (progn |
| 592 | (goto-char (min rstart rend)) | 625 | (goto-char (min rstart rend)) |
| 593 | (setq rend (copy-marker (max rstart rend)))) | 626 | (setq rend (copy-marker (max rstart rend)))) |
| 594 | (if (and transient-mark-mode mark-active) | 627 | (if (and interactive transient-mark-mode mark-active) |
| 595 | (setq rstart (region-beginning) | 628 | (setq rstart (region-beginning) |
| 596 | rend (copy-marker (region-end))) | 629 | rend (copy-marker (region-end))) |
| 597 | (setq rstart (point) | 630 | (setq rstart (point) |
| @@ -603,13 +636,18 @@ end of the buffer." | |||
| 603 | (while (and (< (point) rend) | 636 | (while (and (< (point) rend) |
| 604 | (re-search-forward regexp rend t)) | 637 | (re-search-forward regexp rend t)) |
| 605 | (delete-region (save-excursion (goto-char (match-beginning 0)) | 638 | (delete-region (save-excursion (goto-char (match-beginning 0)) |
| 606 | (beginning-of-line) | 639 | (forward-line 0) |
| 607 | (point)) | 640 | (point)) |
| 608 | (progn (forward-line 1) (point))))))) | 641 | (progn (forward-line 1) (point)))))) |
| 642 | (set-marker rend nil) | ||
| 643 | nil) | ||
| 609 | 644 | ||
| 610 | 645 | ||
| 611 | (defun how-many (regexp &optional rstart rend) | 646 | (defun how-many (regexp &optional rstart rend interactive) |
| 612 | "Print number of matches for REGEXP following point. | 647 | "Print and return number of matches for REGEXP following point. |
| 648 | When called from Lisp and INTERACTIVE is omitted or nil, just return | ||
| 649 | the number, do not print it; if INTERACTIVE is t, the function behaves | ||
| 650 | in all respects has if it had been called interactively. | ||
| 613 | 651 | ||
| 614 | If REGEXP contains upper case characters (excluding those preceded by `\\'), | 652 | If REGEXP contains upper case characters (excluding those preceded by `\\'), |
| 615 | the matching is case-sensitive. | 653 | the matching is case-sensitive. |
| @@ -618,18 +656,24 @@ Second and third arg RSTART and REND specify the region to operate on. | |||
| 618 | 656 | ||
| 619 | Interactively, in Transient Mark mode when the mark is active, operate | 657 | Interactively, in Transient Mark mode when the mark is active, operate |
| 620 | on the contents of the region. Otherwise, operate from point to the | 658 | on the contents of the region. Otherwise, operate from point to the |
| 621 | end of the buffer." | 659 | end of (the accessible portion of) the buffer. |
| 660 | |||
| 661 | This function starts looking for the next match from the end of | ||
| 662 | the previous match. Hence, it ignores matches that overlap | ||
| 663 | a previously found match." | ||
| 622 | 664 | ||
| 623 | (interactive | 665 | (interactive |
| 624 | (keep-lines-read-args "How many matches for (regexp): ")) | 666 | (keep-lines-read-args "How many matches for (regexp): ")) |
| 625 | (save-excursion | 667 | (save-excursion |
| 626 | (if rstart | 668 | (if rstart |
| 627 | (goto-char (min rstart rend)) | 669 | (progn |
| 628 | (if (and transient-mark-mode mark-active) | 670 | (goto-char (min rstart rend)) |
| 671 | (setq rend (max rstart rend))) | ||
| 672 | (if (and interactive transient-mark-mode mark-active) | ||
| 629 | (setq rstart (region-beginning) | 673 | (setq rstart (region-beginning) |
| 630 | rend (copy-marker (region-end))) | 674 | rend (region-end)) |
| 631 | (setq rstart (point) | 675 | (setq rstart (point) |
| 632 | rend (point-max-marker))) | 676 | rend (point-max))) |
| 633 | (goto-char rstart)) | 677 | (goto-char rstart)) |
| 634 | (let ((count 0) | 678 | (let ((count 0) |
| 635 | opoint | 679 | opoint |
| @@ -641,7 +685,10 @@ end of the buffer." | |||
| 641 | (if (= opoint (point)) | 685 | (if (= opoint (point)) |
| 642 | (forward-char 1) | 686 | (forward-char 1) |
| 643 | (setq count (1+ count)))) | 687 | (setq count (1+ count)))) |
| 644 | (message "%d occurrences" count)))) | 688 | (when interactive (message "%d occurrence%s" |
| 689 | count | ||
| 690 | (if (= count 1) "" "s"))) | ||
| 691 | count))) | ||
| 645 | 692 | ||
| 646 | 693 | ||
| 647 | (defvar occur-mode-map | 694 | (defvar occur-mode-map |
| @@ -892,8 +939,7 @@ buffer for each buffer where you invoke `occur'." | |||
| 892 | 939 | ||
| 893 | (defun occur (regexp &optional nlines) | 940 | (defun occur (regexp &optional nlines) |
| 894 | "Show all lines in the current buffer containing a match for REGEXP. | 941 | "Show all lines in the current buffer containing a match for REGEXP. |
| 895 | 942 | This function can not handle matches that span more than one line. | |
| 896 | If a match spreads across multiple lines, all those lines are shown. | ||
| 897 | 943 | ||
| 898 | Each line is displayed with NLINES lines before and after, or -NLINES | 944 | Each line is displayed with NLINES lines before and after, or -NLINES |
| 899 | before if NLINES is negative. | 945 | before if NLINES is negative. |
| @@ -1603,15 +1649,15 @@ make, or the user didn't cancel the call." | |||
| 1603 | ;; Change markers to numbers in the match data | 1649 | ;; Change markers to numbers in the match data |
| 1604 | ;; since lots of markers slow down editing. | 1650 | ;; since lots of markers slow down editing. |
| 1605 | (push (list (point) replaced | 1651 | (push (list (point) replaced |
| 1606 | ;;; If the replacement has already happened, all we need is the | 1652 | ;;; If the replacement has already happened, all we need is the |
| 1607 | ;;; current match start and end. We could get this with a trivial | 1653 | ;;; current match start and end. We could get this with a trivial |
| 1608 | ;;; match like | 1654 | ;;; match like |
| 1609 | ;;; (save-excursion (goto-char (match-beginning 0)) | 1655 | ;;; (save-excursion (goto-char (match-beginning 0)) |
| 1610 | ;;; (search-forward (match-string 0)) | 1656 | ;;; (search-forward (match-string 0)) |
| 1611 | ;;; (match-data t)) | 1657 | ;;; (match-data t)) |
| 1612 | ;;; if we really wanted to avoid manually constructing match data. | 1658 | ;;; if we really wanted to avoid manually constructing match data. |
| 1613 | ;;; Adding current-buffer is necessary so that match-data calls can | 1659 | ;;; Adding current-buffer is necessary so that match-data calls can |
| 1614 | ;;; return markers which are appropriate for editing. | 1660 | ;;; return markers which are appropriate for editing. |
| 1615 | (if replaced | 1661 | (if replaced |
| 1616 | (list | 1662 | (list |
| 1617 | (match-beginning 0) | 1663 | (match-beginning 0) |