diff options
Diffstat (limited to 'lisp/replace.el')
| -rw-r--r-- | lisp/replace.el | 87 |
1 files changed, 49 insertions, 38 deletions
diff --git a/lisp/replace.el b/lisp/replace.el index b41f2b71096..66636452fee 100644 --- a/lisp/replace.el +++ b/lisp/replace.el | |||
| @@ -512,24 +512,38 @@ the matching is case-sensitive." | |||
| 512 | (setq input default)) | 512 | (setq input default)) |
| 513 | input) | 513 | input) |
| 514 | current-prefix-arg)) | 514 | current-prefix-arg)) |
| 515 | (let ((nlines (if nlines | 515 | (let* ((nlines (if nlines |
| 516 | (prefix-numeric-value nlines) | 516 | (prefix-numeric-value nlines) |
| 517 | list-matching-lines-default-context-lines)) | 517 | list-matching-lines-default-context-lines)) |
| 518 | (first t) | 518 | (current-tab-width tab-width) |
| 519 | ;;flag to prevent printing separator for first match | 519 | ;; Minimum width of line number plus trailing colon. |
| 520 | (occur-num-matches 0) | 520 | (min-line-number-width 6) |
| 521 | (buffer (current-buffer)) | 521 | ;; Actual width of line number prefix. Choose a width that's |
| 522 | (dir default-directory) | 522 | ;; a multiple of `tab-width' in the original buffer so that |
| 523 | (linenum 1) | 523 | ;; lines in *Occur* appear right. |
| 524 | (prevpos | 524 | (line-number-width (* (/ (- (+ min-line-number-width |
| 525 | ;;position of most recent match | 525 | tab-width) |
| 526 | (point-min)) | 526 | 1) |
| 527 | (case-fold-search (and case-fold-search | 527 | tab-width) |
| 528 | (isearch-no-upper-case-p regexp t))) | 528 | tab-width)) |
| 529 | (final-context-start | 529 | ;; Format string for line numbers. |
| 530 | ;; Marker to the start of context immediately following | 530 | (line-number-format (format "%%%dd" line-number-width)) |
| 531 | ;; the matched text in *Occur*. | 531 | (empty (make-string line-number-width ?\ )) |
| 532 | (make-marker))) | 532 | (first t) |
| 533 | ;;flag to prevent printing separator for first match | ||
| 534 | (occur-num-matches 0) | ||
| 535 | (buffer (current-buffer)) | ||
| 536 | (dir default-directory) | ||
| 537 | (linenum 1) | ||
| 538 | (prevpos | ||
| 539 | ;;position of most recent match | ||
| 540 | (point-min)) | ||
| 541 | (case-fold-search (and case-fold-search | ||
| 542 | (isearch-no-upper-case-p regexp t))) | ||
| 543 | (final-context-start | ||
| 544 | ;; Marker to the start of context immediately following | ||
| 545 | ;; the matched text in *Occur*. | ||
| 546 | (make-marker))) | ||
| 533 | ;;; (save-excursion | 547 | ;;; (save-excursion |
| 534 | ;;; (beginning-of-line) | 548 | ;;; (beginning-of-line) |
| 535 | ;;; (setq linenum (1+ (count-lines (point-min) (point)))) | 549 | ;;; (setq linenum (1+ (count-lines (point-min) (point)))) |
| @@ -567,32 +581,27 @@ the matching is case-sensitive." | |||
| 567 | (setq linenum (+ linenum (count-lines prevpos (point))))) | 581 | (setq linenum (+ linenum (count-lines prevpos (point))))) |
| 568 | (setq prevpos (point)) | 582 | (setq prevpos (point)) |
| 569 | (goto-char (match-end 0)) | 583 | (goto-char (match-end 0)) |
| 570 | (let* ((start | 584 | (let* (;;start point of text in source buffer to be put |
| 571 | ;;start point of text in source buffer to be put | 585 | ;;into *Occur* |
| 572 | ;;into *Occur* | 586 | (start (save-excursion |
| 573 | (save-excursion | ||
| 574 | (goto-char (match-beginning 0)) | 587 | (goto-char (match-beginning 0)) |
| 575 | (forward-line (if (< nlines 0) | 588 | (forward-line (if (< nlines 0) |
| 576 | nlines | 589 | nlines |
| 577 | (- nlines))) | 590 | (- nlines))) |
| 578 | (point))) | 591 | (point))) |
| 579 | (end | ||
| 580 | ;; end point of text in source buffer to be put | 592 | ;; end point of text in source buffer to be put |
| 581 | ;; into *Occur* | 593 | ;; into *Occur* |
| 582 | (save-excursion | 594 | (end (save-excursion |
| 583 | (goto-char (match-end 0)) | 595 | (goto-char (match-end 0)) |
| 584 | (if (> nlines 0) | 596 | (if (> nlines 0) |
| 585 | (forward-line (1+ nlines)) | 597 | (forward-line (1+ nlines)) |
| 586 | (forward-line 1)) | 598 | (forward-line 1)) |
| 587 | (point))) | 599 | (point))) |
| 588 | (match-beg | ||
| 589 | ;; Amount of context before matching text | 600 | ;; Amount of context before matching text |
| 590 | (- (match-beginning 0) start)) | 601 | (match-beg (- (match-beginning 0) start)) |
| 591 | (match-len | ||
| 592 | ;; Length of matching text | 602 | ;; Length of matching text |
| 593 | (- (match-end 0) (match-beginning 0))) | 603 | (match-len (- (match-end 0) (match-beginning 0))) |
| 594 | (tag (format "%5d" linenum)) | 604 | (tag (format line-number-format linenum)) |
| 595 | (empty (make-string (length tag) ?\ )) | ||
| 596 | tem | 605 | tem |
| 597 | insertion-start | 606 | insertion-start |
| 598 | ;; Number of lines of context to show for current match. | 607 | ;; Number of lines of context to show for current match. |
| @@ -605,8 +614,7 @@ the matching is case-sensitive." | |||
| 605 | (text-end | 614 | (text-end |
| 606 | ;; Marker pointing to end of text for one match | 615 | ;; Marker pointing to end of text for one match |
| 607 | ;; in *Occur*. | 616 | ;; in *Occur*. |
| 608 | (make-marker)) | 617 | (make-marker))) |
| 609 | ) | ||
| 610 | (save-excursion | 618 | (save-excursion |
| 611 | (setq occur-marker (make-marker)) | 619 | (setq occur-marker (make-marker)) |
| 612 | (set-marker occur-marker (point)) | 620 | (set-marker occur-marker (point)) |
| @@ -615,6 +623,9 @@ the matching is case-sensitive." | |||
| 615 | (or first (zerop nlines) | 623 | (or first (zerop nlines) |
| 616 | (insert "--------\n")) | 624 | (insert "--------\n")) |
| 617 | (setq first nil) | 625 | (setq first nil) |
| 626 | (save-excursion | ||
| 627 | (set-buffer "*Occur*") | ||
| 628 | (setq tab-width current-tab-width)) | ||
| 618 | 629 | ||
| 619 | ;; Insert matching text including context lines from | 630 | ;; Insert matching text including context lines from |
| 620 | ;; source buffer into *Occur* | 631 | ;; source buffer into *Occur* |
| @@ -667,7 +678,7 @@ the matching is case-sensitive." | |||
| 667 | (let ((this-linenum linenum)) | 678 | (let ((this-linenum linenum)) |
| 668 | (while (< (point) final-context-start) | 679 | (while (< (point) final-context-start) |
| 669 | (if (null tag) | 680 | (if (null tag) |
| 670 | (setq tag (format "%5d" this-linenum))) | 681 | (setq tag (format line-number-format this-linenum))) |
| 671 | (insert tag ?:) | 682 | (insert tag ?:) |
| 672 | (forward-line 1) | 683 | (forward-line 1) |
| 673 | (setq tag nil) | 684 | (setq tag nil) |