* ivy.el (ivy--regex-fuzzy): Don't insert .* after ^ and before $.
* ivy-test.el (ivy--regex-fuzzy): Add test.
Fixes #139
'("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 "$")
+ "$")))
(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 ()