Skip to content

Commit

Permalink
Disable vim-style-regexp conversions of already converted patterns (#…
Browse files Browse the repository at this point in the history
…1827)

* (Failing) test for `&` with very-magic vim-style backreferences

* Disable vim-style-regexp conversions of already converted patterns
  • Loading branch information
tomdl89 authored Sep 19, 2023
1 parent 5fc1677 commit d28206c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
10 changes: 8 additions & 2 deletions evil-search.el
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ special situations like empty patterns or repetition of previous
substitution commands. If IMPLICIT-R is non-nil, then the \"r\" flag
is assumed, i.e. in case of an empty pattern the last search pattern
is used. It is meant for :substitute commands with arguments."
(let (pattern replacement flags)
(let (pattern replacement flags using-prev-pattern)
(cond
((or (string= string "") (string-match-p "\\`[a-zA-Z]" string))
;; No pattern, since it starts with a letter which cannot be a
Expand Down Expand Up @@ -1191,16 +1191,22 @@ is used. It is meant for :substitute commands with arguments."
(if (eq evil-search-module 'evil-search)
(if (and evil-ex-last-was-search (memq ?r flags))
(and evil-ex-search-pattern
(setq using-prev-pattern t)
(evil-ex-pattern-regex evil-ex-search-pattern))
(and evil-ex-substitute-pattern
(setq using-prev-pattern t)
(evil-ex-pattern-regex evil-ex-substitute-pattern)))
(if (eq case-fold-search t)
isearch-string
(concat isearch-string "\\C")))
flags (remq ?r flags)))
;; generate pattern
(when pattern
(setq pattern (evil-ex-make-substitute-pattern pattern flags)))
;; Disable vim-style regexp conversion if using a previous pattern, because
;; this conversion will already have been done before storing it
(let ((evil-ex-search-vim-style-regexp (and evil-ex-search-vim-style-regexp
(not using-prev-pattern))))
(setq pattern (evil-ex-make-substitute-pattern pattern flags))))
(list pattern replacement flags)))

(defun evil-ex-nohighlight ()
Expand Down
15 changes: 14 additions & 1 deletion evil-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -7997,7 +7997,20 @@ golf h[o]>tel")))
(":s/foo/AAA/g" [return])
"[x]xx AAA bar AAA bar AAA bar\nxxx foo bar foo bar foo bar"
("g&")
"xxx AAA bar AAA bar AAA bar\n[x]xx AAA bar AAA bar AAA bar")))
"xxx AAA bar AAA bar AAA bar\n[x]xx AAA bar AAA bar AAA bar"))
(ert-info ("Repeat magic multiple times")
(let ((evil-magic 'very-magic)
(evil-ex-search-vim-style-regexp t))
(evil-test-buffer
"[b]ravo, alpha\ndelta, charlie\nfoxtrot, echo\nhotel, golf"
(":s/(.*), (.*)/\\2 \\1" [return])
"alpha bravo\ndelta, charlie\nfoxtrot, echo\nhotel, golf"
("j&")
"alpha bravo\ncharlie delta\nfoxtrot, echo\nhotel, golf"
("j&")
"alpha bravo\ncharlie delta\necho foxtrot\nhotel, golf"
("j&")
"alpha bravo\ncharlie delta\necho foxtrot\ngolf hotel"))))

(ert-deftest evil-test-ex-regex-without-case ()
"Test `evil-ex-regex-without-case'"
Expand Down

0 comments on commit d28206c

Please sign in to comment.