Mercurial > emacs
comparison lisp/isearch.el @ 109715:843bffdd92eb
Fix query-replace-regexp incomplete highlighting (Bug#6808).
* replace.el (replace-highlight): Bind isearch-forward and
isearch-error, ensuring that highlighting is updated if the user
switches the search direction (Bug#6808).
* isearch.el (isearch-lazy-highlight-forward): New var.
(isearch-lazy-highlight-new-loop, isearch-lazy-highlight-search):
(isearch-lazy-highlight-update): Use it.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Sun, 08 Aug 2010 16:55:52 -0400 |
parents | e8c35d7a4eac |
children | df8e0cd18128 7060c3b16693 |
comparison
equal
deleted
inserted
replaced
109714:091f3ff9a59e | 109715:843bffdd92eb |
---|---|
2572 (defvar isearch-lazy-highlight-window-start nil) | 2572 (defvar isearch-lazy-highlight-window-start nil) |
2573 (defvar isearch-lazy-highlight-window-end nil) | 2573 (defvar isearch-lazy-highlight-window-end nil) |
2574 (defvar isearch-lazy-highlight-case-fold-search nil) | 2574 (defvar isearch-lazy-highlight-case-fold-search nil) |
2575 (defvar isearch-lazy-highlight-regexp nil) | 2575 (defvar isearch-lazy-highlight-regexp nil) |
2576 (defvar isearch-lazy-highlight-space-regexp nil) | 2576 (defvar isearch-lazy-highlight-space-regexp nil) |
2577 (defvar isearch-lazy-highlight-forward nil) | |
2577 | 2578 |
2578 (defun lazy-highlight-cleanup (&optional force) | 2579 (defun lazy-highlight-cleanup (&optional force) |
2579 "Stop lazy highlighting and remove extra highlighting from current buffer. | 2580 "Stop lazy highlighting and remove extra highlighting from current buffer. |
2580 FORCE non-nil means do it whether or not `lazy-highlight-cleanup' | 2581 FORCE non-nil means do it whether or not `lazy-highlight-cleanup' |
2581 is nil. This function is called when exiting an incremental search if | 2582 is nil. This function is called when exiting an incremental search if |
2611 (not (eq isearch-lazy-highlight-regexp | 2612 (not (eq isearch-lazy-highlight-regexp |
2612 isearch-regexp)) | 2613 isearch-regexp)) |
2613 (not (= (window-start) | 2614 (not (= (window-start) |
2614 isearch-lazy-highlight-window-start)) | 2615 isearch-lazy-highlight-window-start)) |
2615 (not (= (window-end) ; Window may have been split/joined. | 2616 (not (= (window-end) ; Window may have been split/joined. |
2616 isearch-lazy-highlight-window-end)))) | 2617 isearch-lazy-highlight-window-end)) |
2618 (not (eq isearch-forward | |
2619 isearch-lazy-highlight-forward)))) | |
2617 ;; something important did indeed change | 2620 ;; something important did indeed change |
2618 (lazy-highlight-cleanup t) ;kill old loop & remove overlays | 2621 (lazy-highlight-cleanup t) ;kill old loop & remove overlays |
2619 (when (not isearch-error) | 2622 (when (not isearch-error) |
2620 (setq isearch-lazy-highlight-start-limit beg | 2623 (setq isearch-lazy-highlight-start-limit beg |
2621 isearch-lazy-highlight-end-limit end) | 2624 isearch-lazy-highlight-end-limit end) |
2626 isearch-lazy-highlight-end (point) | 2629 isearch-lazy-highlight-end (point) |
2627 isearch-lazy-highlight-last-string isearch-string | 2630 isearch-lazy-highlight-last-string isearch-string |
2628 isearch-lazy-highlight-case-fold-search isearch-case-fold-search | 2631 isearch-lazy-highlight-case-fold-search isearch-case-fold-search |
2629 isearch-lazy-highlight-regexp isearch-regexp | 2632 isearch-lazy-highlight-regexp isearch-regexp |
2630 isearch-lazy-highlight-wrapped nil | 2633 isearch-lazy-highlight-wrapped nil |
2631 isearch-lazy-highlight-space-regexp search-whitespace-regexp) | 2634 isearch-lazy-highlight-space-regexp search-whitespace-regexp |
2635 isearch-lazy-highlight-forward isearch-forward) | |
2632 (unless (equal isearch-string "") | 2636 (unless (equal isearch-string "") |
2633 (setq isearch-lazy-highlight-timer | 2637 (setq isearch-lazy-highlight-timer |
2634 (run-with-idle-timer lazy-highlight-initial-delay nil | 2638 (run-with-idle-timer lazy-highlight-initial-delay nil |
2635 'isearch-lazy-highlight-update)))))) | 2639 'isearch-lazy-highlight-update)))))) |
2636 | 2640 |
2642 (isearch-regexp isearch-lazy-highlight-regexp) | 2646 (isearch-regexp isearch-lazy-highlight-regexp) |
2643 (search-spaces-regexp isearch-lazy-highlight-space-regexp) | 2647 (search-spaces-regexp isearch-lazy-highlight-space-regexp) |
2644 (search-invisible nil) ; don't match invisible text | 2648 (search-invisible nil) ; don't match invisible text |
2645 (retry t) | 2649 (retry t) |
2646 (success nil) | 2650 (success nil) |
2647 (bound (if isearch-forward | 2651 (isearch-forward isearch-lazy-highlight-forward) |
2652 (bound (if isearch-lazy-highlight-forward | |
2648 (min (or isearch-lazy-highlight-end-limit (point-max)) | 2653 (min (or isearch-lazy-highlight-end-limit (point-max)) |
2649 (if isearch-lazy-highlight-wrapped | 2654 (if isearch-lazy-highlight-wrapped |
2650 isearch-lazy-highlight-start | 2655 isearch-lazy-highlight-start |
2651 (window-end))) | 2656 (window-end))) |
2652 (max (or isearch-lazy-highlight-start-limit (point-min)) | 2657 (max (or isearch-lazy-highlight-start-limit (point-min)) |
2676 (if (and (window-live-p isearch-lazy-highlight-window) | 2681 (if (and (window-live-p isearch-lazy-highlight-window) |
2677 (not (eq (selected-window) isearch-lazy-highlight-window))) | 2682 (not (eq (selected-window) isearch-lazy-highlight-window))) |
2678 (select-window isearch-lazy-highlight-window)) | 2683 (select-window isearch-lazy-highlight-window)) |
2679 (save-excursion | 2684 (save-excursion |
2680 (save-match-data | 2685 (save-match-data |
2681 (goto-char (if isearch-forward | 2686 (goto-char (if isearch-lazy-highlight-forward |
2682 isearch-lazy-highlight-end | 2687 isearch-lazy-highlight-end |
2683 isearch-lazy-highlight-start)) | 2688 isearch-lazy-highlight-start)) |
2684 (while looping | 2689 (while looping |
2685 (let ((found (isearch-lazy-highlight-search))) | 2690 (let ((found (isearch-lazy-highlight-search))) |
2686 (when max | 2691 (when max |
2689 (setq looping nil))) | 2694 (setq looping nil))) |
2690 (if found | 2695 (if found |
2691 (let ((mb (match-beginning 0)) | 2696 (let ((mb (match-beginning 0)) |
2692 (me (match-end 0))) | 2697 (me (match-end 0))) |
2693 (if (= mb me) ;zero-length match | 2698 (if (= mb me) ;zero-length match |
2694 (if isearch-forward | 2699 (if isearch-lazy-highlight-forward |
2695 (if (= mb (if isearch-lazy-highlight-wrapped | 2700 (if (= mb (if isearch-lazy-highlight-wrapped |
2696 isearch-lazy-highlight-start | 2701 isearch-lazy-highlight-start |
2697 (window-end))) | 2702 (window-end))) |
2698 (setq found nil) | 2703 (setq found nil) |
2699 (forward-char 1)) | 2704 (forward-char 1)) |
2709 ;; 1000 is higher than ediff's 100+, | 2714 ;; 1000 is higher than ediff's 100+, |
2710 ;; but lower than isearch main overlay's 1001 | 2715 ;; but lower than isearch main overlay's 1001 |
2711 (overlay-put ov 'priority 1000) | 2716 (overlay-put ov 'priority 1000) |
2712 (overlay-put ov 'face lazy-highlight-face) | 2717 (overlay-put ov 'face lazy-highlight-face) |
2713 (overlay-put ov 'window (selected-window)))) | 2718 (overlay-put ov 'window (selected-window)))) |
2714 (if isearch-forward | 2719 (if isearch-lazy-highlight-forward |
2715 (setq isearch-lazy-highlight-end (point)) | 2720 (setq isearch-lazy-highlight-end (point)) |
2716 (setq isearch-lazy-highlight-start (point))))) | 2721 (setq isearch-lazy-highlight-start (point))))) |
2717 | 2722 |
2718 ;; not found or zero-length match at the search bound | 2723 ;; not found or zero-length match at the search bound |
2719 (if (not found) | 2724 (if (not found) |
2720 (if isearch-lazy-highlight-wrapped | 2725 (if isearch-lazy-highlight-wrapped |
2721 (setq looping nil | 2726 (setq looping nil |
2722 nomore t) | 2727 nomore t) |
2723 (setq isearch-lazy-highlight-wrapped t) | 2728 (setq isearch-lazy-highlight-wrapped t) |
2724 (if isearch-forward | 2729 (if isearch-lazy-highlight-forward |
2725 (progn | 2730 (progn |
2726 (setq isearch-lazy-highlight-end (window-start)) | 2731 (setq isearch-lazy-highlight-end (window-start)) |
2727 (goto-char (max (or isearch-lazy-highlight-start-limit (point-min)) | 2732 (goto-char (max (or isearch-lazy-highlight-start-limit (point-min)) |
2728 (window-start)))) | 2733 (window-start)))) |
2729 (setq isearch-lazy-highlight-start (window-end)) | 2734 (setq isearch-lazy-highlight-start (window-end)) |