Skip to content

Commit 200da7f

Browse files
authored
Support / and // shorthand for repeated search motions (#1484)
1 parent f20d442 commit 200da7f

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

evil-search.el

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,8 @@ any error conditions."
957957
(let* ((res (evil-ex-split-search-pattern pattern-string direction))
958958
(pat (pop res))
959959
(offset (pop res))
960-
(next-pat (pop res)))
960+
(next-pat (pop res))
961+
(orig-pat pat))
961962
;; use last pattern if no new pattern has been specified
962963
(if (not (zerop (length pat)))
963964
(setq pat (evil-ex-make-search-pattern pat))
@@ -982,15 +983,21 @@ any error conditions."
982983
((zerop (length next-pat))
983984
(evil-ex-search-goto-offset offset)
984985
(throw 'done (list search-result pat offset)))
985-
;; next pattern but empty
986+
;; single `?' or `/' means repeat last pattern and finish
986987
((= 1 (length next-pat))
987988
(evil-ex-search-goto-offset offset)
988-
(throw 'done (list 'empty-pattern pat offset)))
989+
(setq count 1
990+
pattern-string orig-pat
991+
direction (if (string= "/" next-pat) 'forward 'backward)))
989992
;; next non-empty pattern, next search iteration
990993
(t
991994
(evil-ex-search-goto-offset offset)
992995
(setq count 1
993-
pattern-string (substring next-pat 1)
996+
pattern-string (if (and (<= 2 (length next-pat))
997+
(member (substring next-pat 0 2) '("//" "??")))
998+
;; double `?' or `/' means repeat last pattern
999+
(concat orig-pat (substring next-pat 1))
1000+
(substring next-pat 1))
9941001
direction (if (= (aref next-pat 0) ?/)
9951002
'forward
9961003
'backward)))))))))

evil-tests.el

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7518,7 +7518,16 @@ if no previous selection")
75187518
(evil-test-buffer
75197519
"[f]oo foo\nbar bar\nbaz baz\nAnother line\nAnd yet another line"
75207520
("/bar/e" [return] "//b+1" [return])
7521-
"foo foo\nbar b[a]r\nbaz baz\nAnother line\nAnd yet another line"))))
7521+
"foo foo\nbar b[a]r\nbaz baz\nAnother line\nAnd yet another line"))
7522+
(ert-info ("Test repeat of pattern in the same search")
7523+
(evil-test-buffer
7524+
"[a]lpha bravo charlie delta charlie alpha bravo alpha"
7525+
("/charlie/;/")
7526+
"alpha bravo charlie delta [c]harlie alpha bravo alpha"
7527+
("/alpha/;//")
7528+
"alpha bravo charlie delta charlie alpha bravo [a]lpha"
7529+
("?charlie?;?")
7530+
"alpha bravo [c]harlie delta charlie alpha bravo alpha"))))
75227531

75237532
(ert-deftest evil-test-ex-search-word ()
75247533
"Test search for word under point."

0 commit comments

Comments
 (0)