branch: elpa/evil commit 2a5360eccc9bcb784e61c3b58ebe4690f2c7ea49 Author: Tom Dalziel <tom...@hotmail.com> Commit: Tom Dalziel <33435574+tomd...@users.noreply.github.com>
Exclude final empty line from implicit inclusion in substitution Fixes #1321 --- evil-commands.el | 16 ++++++++++------ evil-tests.el | 11 ++++++++++- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/evil-commands.el b/evil-commands.el index 8a54de7321..3344c42322 100644 --- a/evil-commands.el +++ b/evil-commands.el @@ -3826,13 +3826,17 @@ reveal.el. OPEN-SPOTS is a local version of `reveal-open-spots'." (string-match-p "\n" (buffer-substring-no-properties match-beg match-end))) (setq zero-length-match (= match-beg match-end)) - (when (and (string= "^" evil-ex-substitute-regex) - (= (point) end-marker)) + (when (= match-end end-marker) ;; The range (beg end) includes the final newline which means - ;; end-marker is on one line down. With the regex "^" the - ;; beginning of this last line will be matched which we don't - ;; want, so we abort here. - (throw 'exit-search t)) + ;; end-marker is on one line down, causing some issues... + (when (and (not match-contains-newline) (bolp)) + ;; With the exception of explicitly substituting newlines, + ;; we abort when the match ends here and it's an empty line + (throw 'exit-search t)) + (when (string= "^" evil-ex-substitute-regex) + ;; With the regex "^" the beginning of this last line + ;; will be matched which we don't want, so we abort here + (throw 'exit-search t))) (setq evil-ex-substitute-last-point match-beg) (if confirm (let ((prompt diff --git a/evil-tests.el b/evil-tests.el index ad47b5daae..b1ea72f194 100644 --- a/evil-tests.el +++ b/evil-tests.el @@ -7590,7 +7590,16 @@ echo foxtrot\ngolf hotel" (evil-test-buffer "[x]xyxxz" (":%s/x//g" [return]) - "[y]z"))) + "[y]z")) + (ert-info ("Substitute doesn't match final empty line") + (evil-test-buffer + "abc\n[d]ef\n\nghi" + (":s/$/4") + "abc\n[d]ef4\n\nghi") + (evil-test-buffer + "abc\n[d]ef\n\nghi" + (":s/f\\w*/4") + "abc\n[d]e4\n\nghi"))) (ert-deftest evil-test-ex-repeat-substitute-replacement () "Test `evil-ex-substitute' with repeating of previous substitutions."