diff options
| author | Chong Yidong | 2007-02-28 18:54:43 +0000 |
|---|---|---|
| committer | Chong Yidong | 2007-02-28 18:54:43 +0000 |
| commit | b3aad29e4699da1f3b8d3bb05eb7f3ca695af7bf (patch) | |
| tree | e66e6e8ca50da9246925a2d60b0228ad06103f63 /lisp/replace.el | |
| parent | b0c39184d2faebc62e6af2a59e19c8073e0630fd (diff) | |
| download | emacs-b3aad29e4699da1f3b8d3bb05eb7f3ca695af7bf.tar.gz emacs-b3aad29e4699da1f3b8d3bb05eb7f3ca695af7bf.zip | |
(perform-replace): Undo forward-char immediately if non-adjacent
search fails.
Diffstat (limited to 'lisp/replace.el')
| -rw-r--r-- | lisp/replace.el | 56 |
1 files changed, 29 insertions, 27 deletions
diff --git a/lisp/replace.el b/lisp/replace.el index 9790dacd82b..20f38aec32f 100644 --- a/lisp/replace.el +++ b/lisp/replace.el | |||
| @@ -1466,27 +1466,35 @@ make, or the user didn't cancel the call." | |||
| 1466 | ;; otherwise, search for a match after moving forward | 1466 | ;; otherwise, search for a match after moving forward |
| 1467 | ;; one char if progress is required. | 1467 | ;; one char if progress is required. |
| 1468 | (setq real-match-data | 1468 | (setq real-match-data |
| 1469 | (if (consp match-again) | 1469 | (cond ((consp match-again) |
| 1470 | (progn (goto-char (nth 1 match-again)) | 1470 | (goto-char (nth 1 match-again)) |
| 1471 | (replace-match-data t | 1471 | (replace-match-data |
| 1472 | real-match-data | 1472 | t real-match-data match-again)) |
| 1473 | match-again)) | 1473 | ;; MATCH-AGAIN non-nil means accept an |
| 1474 | (and (or match-again | 1474 | ;; adjacent match. |
| 1475 | ;; MATCH-AGAIN non-nil means we | 1475 | (match-again |
| 1476 | ;; accept an adjacent match. If | 1476 | (and |
| 1477 | ;; we don't, move one char to the | 1477 | (funcall search-function search-string |
| 1478 | ;; right. This takes us a | 1478 | limit t) |
| 1479 | ;; character too far at the end, | 1479 | ;; For speed, use only integers and |
| 1480 | ;; but this is undone after the | 1480 | ;; reuse the list used last time. |
| 1481 | ;; while-loop. | 1481 | (replace-match-data t real-match-data))) |
| 1482 | (progn | 1482 | ((and (< (1+ (point)) (point-max)) |
| 1483 | (forward-char 1) | 1483 | (or (null limit) |
| 1484 | (not (or (eobp) | 1484 | (< (1+ (point)) limit))) |
| 1485 | (and limit (>= (point) limit)))))) | 1485 | ;; If not accepting adjacent matches, |
| 1486 | (funcall search-function search-string limit t) | 1486 | ;; move one char to the right before |
| 1487 | ;; For speed, use only integers and | 1487 | ;; searching again. Undo the motion |
| 1488 | ;; reuse the list used last time. | 1488 | ;; if the search fails. |
| 1489 | (replace-match-data t real-match-data))))) | 1489 | (let ((opoint (point))) |
| 1490 | (forward-char 1) | ||
| 1491 | (if (funcall | ||
| 1492 | search-function search-string | ||
| 1493 | limit t) | ||
| 1494 | (replace-match-data | ||
| 1495 | t real-match-data) | ||
| 1496 | (goto-char opoint) | ||
| 1497 | nil)))))) | ||
| 1490 | 1498 | ||
| 1491 | ;; Record whether the match is nonempty, to avoid an infinite loop | 1499 | ;; Record whether the match is nonempty, to avoid an infinite loop |
| 1492 | ;; repeatedly matching the same empty string. | 1500 | ;; repeatedly matching the same empty string. |
| @@ -1702,12 +1710,6 @@ make, or the user didn't cancel the call." | |||
| 1702 | (match-data t))) | 1710 | (match-data t))) |
| 1703 | stack))))) | 1711 | stack))))) |
| 1704 | 1712 | ||
| 1705 | ;; The code preventing adjacent regexp matches in the condition | ||
| 1706 | ;; of the while-loop above will haven taken us one character | ||
| 1707 | ;; beyond the last replacement. Undo that. | ||
| 1708 | (when (and regexp-flag (not match-again) (> replace-count 0)) | ||
| 1709 | (backward-char 1)) | ||
| 1710 | |||
| 1711 | (replace-dehighlight)) | 1713 | (replace-dehighlight)) |
| 1712 | (or unread-command-events | 1714 | (or unread-command-events |
| 1713 | (message "Replaced %d occurrence%s" | 1715 | (message "Replaced %d occurrence%s" |