branch: master commit c307ae974c0224d47d038a3a260c64d4d8f8bed7 Author: Oleh Krehel <ohwoeo...@gmail.com> Commit: Oleh Krehel <ohwoeo...@gmail.com>
swiper.el (swiper--re-builder): Fix symbol bounds with char-fold-to-regexp With this setting: (setq search-default-mode #'char-fold-to-regexp) and the input "\_<symbol-name\_>", prevent the symbol bounds from being quoted by `char-fold-to-regexp'. * ivy-test.el (swiper--re-builder): Add test. Fixes #2177 --- ivy-test.el | 6 +++++- swiper.el | 17 +++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/ivy-test.el b/ivy-test.el index 2a9931b..2c859c1 100644 --- a/ivy-test.el +++ b/ivy-test.el @@ -186,7 +186,11 @@ will bring the behavior in line with the newer Emacsen." (should (string= (swiper--re-builder "^a") "^ ?\\(a\\)")) (should (string= (swiper--re-builder "^a b") - "^ \\(a\\).*?\\(b\\)"))) + "^ \\(a\\).*?\\(b\\)")) + (should + (string-match-p + "\\`\\\\_<.*\\\\_>\\'" + (swiper--re-builder "\\_<iv\\_>")))) (ert-deftest swiper--re-builder-char-fold () :expected-result (if (>= emacs-major-version 25) diff --git a/swiper.el b/swiper.el index 8ada395..2766485 100644 --- a/swiper.el +++ b/swiper.el @@ -731,12 +731,17 @@ line numbers. For the buffer, use `ivy--regex' instead." (setq ivy--subexps 1)) (format "^ %s" re)))) ((eq (bound-and-true-p search-default-mode) 'char-fold-to-regexp) - (let ((subs (ivy--split str))) - (setq ivy--subexps (length subs)) - (mapconcat - (lambda (s) (format "\\(%s\\)" (char-fold-to-regexp s))) - subs - ".*?"))) + (if (string-match "\\`\\\\_<\\(.+\\)\\\\_>\\'" str) + (concat + "\\_<" + (char-fold-to-regexp (match-string 1 str)) + "\\_>") + (let ((subs (ivy--split str))) + (setq ivy--subexps (length subs)) + (mapconcat + (lambda (s) (format "\\(%s\\)" (char-fold-to-regexp s))) + subs + ".*?")))) (t (funcall re-builder str))))) re))