branch: master commit 27add462e3d05961f5681e6dc09e39235362ff39 Author: CeleritasCelery <t.mac...@gmail.com> Commit: Oleh Krehel <ohwoeo...@gmail.com>
Anchor pcre lookaround patterns to bol Fixes #1976 Fixes #1979 --- counsel.el | 20 +++++++++++--------- ivy-test.el | 4 ++-- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/counsel.el b/counsel.el index fae7531..6aa0cba 100644 --- a/counsel.el +++ b/counsel.el @@ -63,14 +63,16 @@ Note that incorrect results may be returned for sufficiently complex regexes." (if (consp regex) (if look-around - (mapconcat - (lambda (pair) - (let ((subexp (counsel--elisp-to-pcre (car pair)))) - (format "(?%c.*%s)" - (if (cdr pair) ?= ?!) - subexp))) - regex - "") + (concat + "^" + (mapconcat + (lambda (pair) + (let ((subexp (counsel--elisp-to-pcre (car pair)))) + (format "(?%c.*%s)" + (if (cdr pair) ?= ?!) + subexp))) + regex + "")) (mapconcat (lambda (pair) (let ((subexp (counsel--elisp-to-pcre (car pair)))) @@ -2621,7 +2623,7 @@ NEEDLE is the search string." (let ((default-directory (ivy-state-directory ivy-last)) (regex (counsel--grep-regex search-term))) (if (and (stringp counsel--regex-look-around) - (string-match-p "\\`(\\?[=!]" regex)) ;; using look-arounds + (string-match-p "\\`\\^(\\?[=!]" regex)) ;; using look-arounds (setq switches (concat switches " " counsel--regex-look-around))) (counsel--async-command (counsel--format-ag-command switches diff --git a/ivy-test.el b/ivy-test.el index 0099615..c224bc9 100644 --- a/ivy-test.el +++ b/ivy-test.el @@ -347,7 +347,7 @@ will bring the behavior in line with the newer Emacsen." "(?:foo|bar).*blick.*(?:(baz)|quux)")) (should (equal (counsel--elisp-to-pcre '(("ivy" . t) ("-")) t) - "(?=.*ivy)(?!.*-)"))) + "^(?=.*ivy)(?!.*-)"))) (defmacro ivy--string-buffer (text &rest body) "Test helper that wraps TEXT in a temp buffer while running BODY." @@ -989,7 +989,7 @@ a buffer visiting a file." (let ((counsel--regex-look-around t) (ivy--regex-function 'ivy--regex-plus)) (counsel--grep-regex "ivy ! -")) - "(?=.*ivy)(?!.*-)")) + "^(?=.*ivy)(?!.*-)")) (should (string= (let ((counsel--regex-look-around t)