comparison lisp/replace.el @ 91239:2fcaae6177a5

Merge from emacs--devo--0 Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-300
author Miles Bader <miles@gnu.org>
date Sun, 16 Dec 2007 05:08:49 +0000
parents 53108e6cea98 c2b1300a87e5
children 56a72e2bd635
comparison
equal deleted inserted replaced
91238:5cf14a2107b5 91239:2fcaae6177a5
550 "Delete all lines except those containing matches for REGEXP. 550 "Delete all lines except those containing matches for REGEXP.
551 A match split across lines preserves all the lines it lies in. 551 A match split across lines preserves all the lines it lies in.
552 When called from Lisp (and usually interactively as well, see below) 552 When called from Lisp (and usually interactively as well, see below)
553 applies to all lines starting after point. 553 applies to all lines starting after point.
554 554
555 If REGEXP contains upper case characters (excluding those preceded by `\\'), 555 If REGEXP contains upper case characters (excluding those preceded by `\\')
556 the matching is case-sensitive. 556 and `search-upper-case' is non-nil, the matching is case-sensitive.
557 557
558 Second and third arg RSTART and REND specify the region to operate on. 558 Second and third arg RSTART and REND specify the region to operate on.
559 This command operates on (the accessible part of) all lines whose 559 This command operates on (the accessible part of) all lines whose
560 accessible part is entirely contained in the region determined by RSTART 560 accessible part is entirely contained in the region determined by RSTART
561 and REND. (A newline ending a line counts as part of that line.) 561 and REND. (A newline ending a line counts as part of that line.)
595 rend (point-max-marker))) 595 rend (point-max-marker)))
596 (goto-char rstart)) 596 (goto-char rstart))
597 (save-excursion 597 (save-excursion
598 (or (bolp) (forward-line 1)) 598 (or (bolp) (forward-line 1))
599 (let ((start (point)) 599 (let ((start (point))
600 (case-fold-search (and case-fold-search 600 (case-fold-search
601 (isearch-no-upper-case-p regexp t)))) 601 (if (and case-fold-search search-upper-case)
602 (isearch-no-upper-case-p regexp t)
603 case-fold-search)))
602 (while (< (point) rend) 604 (while (< (point) rend)
603 ;; Start is first char not preserved by previous match. 605 ;; Start is first char not preserved by previous match.
604 (if (not (re-search-forward regexp rend 'move)) 606 (if (not (re-search-forward regexp rend 'move))
605 (delete-region start rend) 607 (delete-region start rend)
606 (let ((end (save-excursion (goto-char (match-beginning 0)) 608 (let ((end (save-excursion (goto-char (match-beginning 0))
624 When called from Lisp (and usually when called interactively as 626 When called from Lisp (and usually when called interactively as
625 well, see below), applies to the part of the buffer after point. 627 well, see below), applies to the part of the buffer after point.
626 The line point is in is deleted if and only if it contains a 628 The line point is in is deleted if and only if it contains a
627 match for regexp starting after point. 629 match for regexp starting after point.
628 630
629 If REGEXP contains upper case characters (excluding those preceded by `\\'), 631 If REGEXP contains upper case characters (excluding those preceded by `\\')
630 the matching is case-sensitive. 632 and `search-upper-case' is non-nil, the matching is case-sensitive.
631 633
632 Second and third arg RSTART and REND specify the region to operate on. 634 Second and third arg RSTART and REND specify the region to operate on.
633 Lines partially contained in this region are deleted if and only if 635 Lines partially contained in this region are deleted if and only if
634 they contain a match entirely contained in it. 636 they contain a match entirely contained in it.
635 637
655 (setq rstart (region-beginning) 657 (setq rstart (region-beginning)
656 rend (copy-marker (region-end))) 658 rend (copy-marker (region-end)))
657 (setq rstart (point) 659 (setq rstart (point)
658 rend (point-max-marker))) 660 rend (point-max-marker)))
659 (goto-char rstart)) 661 (goto-char rstart))
660 (let ((case-fold-search (and case-fold-search 662 (let ((case-fold-search
661 (isearch-no-upper-case-p regexp t)))) 663 (if (and case-fold-search search-upper-case)
664 (isearch-no-upper-case-p regexp t)
665 case-fold-search)))
662 (save-excursion 666 (save-excursion
663 (while (and (< (point) rend) 667 (while (and (< (point) rend)
664 (re-search-forward regexp rend t)) 668 (re-search-forward regexp rend t))
665 (delete-region (save-excursion (goto-char (match-beginning 0)) 669 (delete-region (save-excursion (goto-char (match-beginning 0))
666 (forward-line 0) 670 (forward-line 0)
674 "Print and return number of matches for REGEXP following point. 678 "Print and return number of matches for REGEXP following point.
675 When called from Lisp and INTERACTIVE is omitted or nil, just return 679 When called from Lisp and INTERACTIVE is omitted or nil, just return
676 the number, do not print it; if INTERACTIVE is t, the function behaves 680 the number, do not print it; if INTERACTIVE is t, the function behaves
677 in all respects has if it had been called interactively. 681 in all respects has if it had been called interactively.
678 682
679 If REGEXP contains upper case characters (excluding those preceded by `\\'), 683 If REGEXP contains upper case characters (excluding those preceded by `\\')
680 the matching is case-sensitive. 684 and `search-upper-case' is non-nil, the matching is case-sensitive.
681 685
682 Second and third arg RSTART and REND specify the region to operate on. 686 Second and third arg RSTART and REND specify the region to operate on.
683 687
684 Interactively, in Transient Mark mode when the mark is active, operate 688 Interactively, in Transient Mark mode when the mark is active, operate
685 on the contents of the region. Otherwise, operate from point to the 689 on the contents of the region. Otherwise, operate from point to the
702 (setq rstart (point) 706 (setq rstart (point)
703 rend (point-max))) 707 rend (point-max)))
704 (goto-char rstart)) 708 (goto-char rstart))
705 (let ((count 0) 709 (let ((count 0)
706 opoint 710 opoint
707 (case-fold-search (and case-fold-search 711 (case-fold-search
708 (isearch-no-upper-case-p regexp t)))) 712 (if (and case-fold-search search-upper-case)
713 (isearch-no-upper-case-p regexp t)
714 case-fold-search)))
709 (while (and (< (point) rend) 715 (while (and (< (point) rend)
710 (progn (setq opoint (point)) 716 (progn (setq opoint (point))
711 (re-search-forward regexp rend t))) 717 (re-search-forward regexp rend t)))
712 (if (= opoint (point)) 718 (if (= opoint (point))
713 (forward-char 1) 719 (forward-char 1)
1028 1034
1029 The lines are shown in a buffer named `*Occur*'. 1035 The lines are shown in a buffer named `*Occur*'.
1030 It serves as a menu to find any of the occurrences in this buffer. 1036 It serves as a menu to find any of the occurrences in this buffer.
1031 \\<occur-mode-map>\\[describe-mode] in that buffer will explain how. 1037 \\<occur-mode-map>\\[describe-mode] in that buffer will explain how.
1032 1038
1033 If REGEXP contains upper case characters (excluding those preceded by `\\'), 1039 If REGEXP contains upper case characters (excluding those preceded by `\\')
1034 the matching is case-sensitive." 1040 and `search-upper-case' is non-nil, the matching is case-sensitive."
1035 (interactive (occur-read-primary-args)) 1041 (interactive (occur-read-primary-args))
1036 (occur-1 regexp nlines (list (current-buffer)))) 1042 (occur-1 regexp nlines (list (current-buffer))))
1037 1043
1038 (defun multi-occur (bufs regexp &optional nlines) 1044 (defun multi-occur (bufs regexp &optional nlines)
1039 "Show all lines in buffers BUFS containing a match for REGEXP. 1045 "Show all lines in buffers BUFS containing a match for REGEXP.
1117 (buffer-undo-list t)) 1123 (buffer-undo-list t))
1118 (erase-buffer) 1124 (erase-buffer)
1119 (let ((count (occur-engine 1125 (let ((count (occur-engine
1120 regexp active-bufs occur-buf 1126 regexp active-bufs occur-buf
1121 (or nlines list-matching-lines-default-context-lines) 1127 (or nlines list-matching-lines-default-context-lines)
1122 (and case-fold-search 1128 (if (and case-fold-search search-upper-case)
1123 (isearch-no-upper-case-p regexp t)) 1129 (isearch-no-upper-case-p regexp t)
1130 case-fold-search)
1124 list-matching-lines-buffer-name-face 1131 list-matching-lines-buffer-name-face
1125 nil list-matching-lines-face 1132 nil list-matching-lines-face
1126 (not (eq occur-excluded-properties t))))) 1133 (not (eq occur-excluded-properties t)))))
1127 (let* ((bufcount (length active-bufs)) 1134 (let* ((bufcount (length active-bufs))
1128 (diff (- (length bufs) bufcount))) 1135 (diff (- (length bufs) bufcount)))
1457 make, or the user didn't cancel the call." 1464 make, or the user didn't cancel the call."
1458 (or map (setq map query-replace-map)) 1465 (or map (setq map query-replace-map))
1459 (and query-flag minibuffer-auto-raise 1466 (and query-flag minibuffer-auto-raise
1460 (raise-frame (window-frame (minibuffer-window)))) 1467 (raise-frame (window-frame (minibuffer-window))))
1461 (let* ((case-fold-search 1468 (let* ((case-fold-search
1462 (and case-fold-search 1469 (if (and case-fold-search search-upper-case)
1463 (isearch-no-upper-case-p from-string regexp-flag))) 1470 (isearch-no-upper-case-p from-string regexp-flag)
1471 case-fold-search))
1464 (nocasify (not (and case-replace case-fold-search))) 1472 (nocasify (not (and case-replace case-fold-search)))
1465 (literal (or (not regexp-flag) (eq regexp-flag 'literal))) 1473 (literal (or (not regexp-flag) (eq regexp-flag 'literal)))
1466 (search-function (if regexp-flag 're-search-forward 'search-forward)) 1474 (search-function (if regexp-flag 're-search-forward 'search-forward))
1467 (search-string from-string) 1475 (search-string from-string)
1468 (real-match-data nil) ; The match data for the current match. 1476 (real-match-data nil) ; The match data for the current match.