]> code.delx.au - gnu-emacs-elpa/commitdiff
ivy.el (ivy--regex-fuzzy): Improve for "^" and "$"
authorOleh Krehel <ohwoeowho@gmail.com>
Fri, 12 Jun 2015 15:40:13 +0000 (17:40 +0200)
committerOleh Krehel <ohwoeowho@gmail.com>
Fri, 12 Jun 2015 15:40:13 +0000 (17:40 +0200)
* ivy.el (ivy--regex-fuzzy): Don't insert .* after ^ and before $.

* ivy-test.el (ivy--regex-fuzzy): Add test.

Fixes #139

ivy-test.el
ivy.el

index 91e0dc35d962cbc820cacfd8cbc804849dc0d74b..1062cd83310a34461896fa155e6896fc5335b727 100644 (file)
                  '("We're all Britons"
                   "and  I  am"
                    "your  king."))))
+
+(ert-deftest ivy--regex-fuzzy ()
+  (should (string= (ivy--regex-fuzzy "tmux")
+                   "t.*m.*u.*x"))
+  (should (string= (ivy--regex-fuzzy "^tmux")
+                   "^t.*m.*u.*x"))
+  (should (string= (ivy--regex-fuzzy "^tmux$")
+                   "^t.*m.*u.*x$"))
+  (should (string= (ivy--regex-fuzzy "")
+                   ""))
+  (should (string= (ivy--regex-fuzzy "^")
+                   "^"))
+  (should (string= (ivy--regex-fuzzy "$")
+                   "$")))
diff --git a/ivy.el b/ivy.el
index e002e64a00b44b516fef1985b3f99778a668bedf..07ad9bff7e658fb736bb50ea72995f6bd0325fca 100644 (file)
--- a/ivy.el
+++ b/ivy.el
@@ -966,7 +966,11 @@ Everything after \"!\" should not match."
 (defun ivy--regex-fuzzy (str)
   "Build a regex sequence from STR.
 Insert .* between each char."
-  (mapconcat #'string (string-to-list str) ".*"))
+  (if (string-match "\\`\\(\\^?\\)\\(.*?\\)\\(\\$?\\)\\'" str)
+      (concat (match-string 1 str)
+              (mapconcat #'string (string-to-list (match-string 2 str)) ".*")
+              (match-string 3 str))
+    str))
 
 ;;** Rest
 (defun ivy--minibuffer-setup ()