comparison lisp/replace.el @ 34480:816fa0390935

(perform-replace): Don't use an empty match adjacent to a non-empty match when computing the next match before the replacement is performed.
author Gerd Moellmann <gerd@gnu.org>
date Tue, 12 Dec 2000 14:13:13 +0000
parents 2f5e050486ce
children b7b3034a7f6d
comparison
equal deleted inserted replaced
34479:aab24f62ad6b 34480:816fa0390935
963 ;; Record whether the match is nonempty, to avoid an infinite loop 963 ;; Record whether the match is nonempty, to avoid an infinite loop
964 ;; repeatedly matching the same empty string. 964 ;; repeatedly matching the same empty string.
965 (setq nonempty-match 965 (setq nonempty-match
966 (/= (nth 0 real-match-data) (nth 1 real-match-data))) 966 (/= (nth 0 real-match-data) (nth 1 real-match-data)))
967 967
968 ;; If the match is empty, record that the next one can't be adjacent. 968 ;; If the match is empty, record that the next one can't be
969 ;; adjacent.
970
969 ;; Otherwise, if matching a regular expression, do the next 971 ;; Otherwise, if matching a regular expression, do the next
970 ;; match now, since the replacement for this match may 972 ;; match now, since the replacement for this match may
971 ;; affect whether the next match is adjacent to this one. 973 ;; affect whether the next match is adjacent to this one.
974 ;; If that match is empty, don't use it.
972 (setq match-again 975 (setq match-again
973 (and nonempty-match 976 (and nonempty-match
974 (or (not regexp-flag) 977 (or (not regexp-flag)
975 (and (looking-at search-string) 978 (and (looking-at search-string)
976 (match-data))))) 979 (let ((match (match-data)))
980 (and (/= (nth 0 match) (nth 1 match))
981 match))))))
977 982
978 ;; Calculate the replacement string, if necessary. 983 ;; Calculate the replacement string, if necessary.
979 (when replacements 984 (when replacements
980 (set-match-data real-match-data) 985 (set-match-data real-match-data)
981 (setq next-replacement 986 (setq next-replacement