From d1216eb0ca3eaa878a7a2efbd961ed4d0d8d7d16 Mon Sep 17 00:00:00 2001 From: Samuel Loury Date: Tue, 12 Jan 2016 10:28:30 +0100 Subject: [PATCH] Add the '!' behavior into `ivy--regex-ignore-order' --- ivy.el | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/ivy.el b/ivy.el index 9e456aeb7..6ff1e876b 100644 --- a/ivy.el +++ b/ivy.el @@ -1522,7 +1522,7 @@ When GREEDY is non-nil, join words in a greedy way." ".*?"))))) ivy--regex-hash))))) -(defun ivy--regex-ignore-order (str) +(defun ivy--regex-ignore-order--part (str &optional discard) "Re-build regex from STR by splitting at spaces. Ignore the order of each group." (let* ((subs (split-string str " +" t)) @@ -1531,9 +1531,28 @@ Ignore the order of each group." (0 "") (t - (mapcar (lambda (x) (cons x t)) + (mapcar (lambda (x) (cons x (not discard))) subs))))) +(defun ivy--regex-ignore-order (str) + "Re-build regex from STR by splitting at spaces. +Ignore the order of each group. Everything before \"!\" should +match. Everything after \"!\" should not match." + (let ((parts (split-string str "!" t))) + (cl-case (length parts) + (0 + "") + (1 + (if (string= (substring str 0 1) "!") + (list (cons "" t) + (ivy--regex-ignore-order--part (car parts) t)) + (ivy--regex-ignore-order--part (car parts)))) + (2 + (append + (ivy--regex-ignore-order--part (car parts)) + (ivy--regex-ignore-order--part (cadr parts) t))) + (t (error "Unexpected: use only one !"))))) + (defun ivy--regex-plus (str) "Build a regex sequence from STR. Spaces are wild card characters, everything before \"!\" should -- 2.39.2