diff options
Diffstat (limited to 'lisp/replace.el')
| -rw-r--r-- | lisp/replace.el | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/lisp/replace.el b/lisp/replace.el index 8229eda85a4..46f672a8d1a 100644 --- a/lisp/replace.el +++ b/lisp/replace.el | |||
| @@ -1474,32 +1474,33 @@ make, or the user didn't cancel the call." | |||
| 1474 | ;; For speed, use only integers and | 1474 | ;; For speed, use only integers and |
| 1475 | ;; reuse the list used last time. | 1475 | ;; reuse the list used last time. |
| 1476 | (replace-match-data t real-match-data))))) | 1476 | (replace-match-data t real-match-data))))) |
| 1477 | |||
| 1478 | ;; Record whether the match is nonempty, to avoid an infinite loop | ||
| 1479 | ;; repeatedly matching the same empty string. | ||
| 1480 | (setq nonempty-match | ||
| 1481 | (/= (nth 0 real-match-data) (nth 1 real-match-data))) | ||
| 1482 | |||
| 1483 | ;; If the match is empty, record that the next one can't be | ||
| 1484 | ;; adjacent. | ||
| 1485 | |||
| 1486 | ;; Otherwise, if matching a regular expression, do the next | ||
| 1487 | ;; match now, since the replacement for this match may | ||
| 1488 | ;; affect whether the next match is adjacent to this one. | ||
| 1489 | ;; If that match is empty, don't use it. | ||
| 1490 | (setq match-again | ||
| 1491 | (and nonempty-match | ||
| 1492 | (or (not regexp-flag) | ||
| 1493 | (and (looking-at search-string) | ||
| 1494 | (let ((match (match-data))) | ||
| 1495 | (and (/= (nth 0 match) (nth 1 match)) | ||
| 1496 | match)))))) | ||
| 1497 | |||
| 1477 | ;; Optionally ignore matches that have a read-only property. | 1498 | ;; Optionally ignore matches that have a read-only property. |
| 1478 | (unless (and query-replace-skip-read-only | 1499 | (unless (and query-replace-skip-read-only |
| 1479 | (text-property-not-all | 1500 | (text-property-not-all |
| 1480 | (match-beginning 0) (match-end 0) | 1501 | (nth 0 real-match-data) (nth 1 real-match-data) |
| 1481 | 'read-only nil)) | 1502 | 'read-only nil)) |
| 1482 | 1503 | ||
| 1483 | ;; Record whether the match is nonempty, to avoid an infinite loop | ||
| 1484 | ;; repeatedly matching the same empty string. | ||
| 1485 | (setq nonempty-match | ||
| 1486 | (/= (nth 0 real-match-data) (nth 1 real-match-data))) | ||
| 1487 | |||
| 1488 | ;; If the match is empty, record that the next one can't be | ||
| 1489 | ;; adjacent. | ||
| 1490 | |||
| 1491 | ;; Otherwise, if matching a regular expression, do the next | ||
| 1492 | ;; match now, since the replacement for this match may | ||
| 1493 | ;; affect whether the next match is adjacent to this one. | ||
| 1494 | ;; If that match is empty, don't use it. | ||
| 1495 | (setq match-again | ||
| 1496 | (and nonempty-match | ||
| 1497 | (or (not regexp-flag) | ||
| 1498 | (and (looking-at search-string) | ||
| 1499 | (let ((match (match-data))) | ||
| 1500 | (and (/= (nth 0 match) (nth 1 match)) | ||
| 1501 | match)))))) | ||
| 1502 | |||
| 1503 | ;; Calculate the replacement string, if necessary. | 1504 | ;; Calculate the replacement string, if necessary. |
| 1504 | (when replacements | 1505 | (when replacements |
| 1505 | (set-match-data real-match-data) | 1506 | (set-match-data real-match-data) |