[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master ca91c88 01/57: Add an option for out-of-order matching
From: |
Oleh Krehel |
Subject: |
[elpa] master ca91c88 01/57: Add an option for out-of-order matching |
Date: |
Tue, 19 May 2015 14:21:17 +0000 |
branch: master
commit ca91c88ca38a4f47d10430c73ad4ce8a85173b3d
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
Add an option for out-of-order matching
* ivy.el (ivy--regex-ignore-order): New defun.
* swiper.el (swiper--init): Set `ivy--regex-function'.
(swiper--update-input-ivy): Use `ivy--regex-function'.
(swiper--action): Use `ivy--regex-function'.
Example of use:
(setq ivy-re-builders-alist
'((t . ivy--regex-ignore-order)))
With this, e.g. swiper will match "bar foo" from input "foo bar".
---
ivy.el | 20 ++++++++++++++++++++
swiper.el | 8 +++++---
2 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/ivy.el b/ivy.el
index 721dafd..9a0557f 100644
--- a/ivy.el
+++ b/ivy.el
@@ -770,6 +770,26 @@ When GREEDY is non-nil, join words in a greedy way."
".*?")))))
ivy--regex-hash)))))
+(defun ivy--regex-ignore-order (str)
+ "Re-build regex from STR by splitting it on spaces.
+Ignore the order of each group."
+ (let* ((subs (split-string str " +" t))
+ (len (length subs)))
+ (cl-case len
+ (1
+ (setq ivy--subexps 0)
+ (car subs))
+ (t
+ (setq ivy--subexps len)
+ (let ((all (mapconcat #'identity subs "\\|")))
+ (mapconcat
+ (lambda (x)
+ (if (string-match "^\\\\(.*\\\\)$" x)
+ x
+ (format "\\(%s\\)" x)))
+ (make-list len all)
+ ".*?"))))))
+
(defun ivy--regex-plus (str)
"Build a regex sequence from STR.
Spaces are wild, everything before \"!\" should match.
diff --git a/swiper.el b/swiper.el
index 96e955d..2f8dc76 100644
--- a/swiper.el
+++ b/swiper.el
@@ -170,7 +170,9 @@ When non-nil, INITIAL-INPUT is the initial search pattern."
(setq swiper--opoint (point))
(setq swiper--len 0)
(setq swiper--anchor (line-number-at-pos))
- (setq swiper--window (selected-window)))
+ (setq swiper--window (selected-window))
+ (setq ivy--regex-function
+ (cdr (assoc t ivy-re-builders-alist))))
(defun swiper--ivy (&optional initial-input)
"`isearch' with an overview using `ivy'.
@@ -227,7 +229,7 @@ Please remove it and update the \"swiper\" package."))
(defun swiper--update-input-ivy ()
"Called when `ivy' input is updated."
(swiper--cleanup)
- (let* ((re (ivy--regex ivy-text))
+ (let* ((re (funcall ivy--regex-function ivy-text))
(str ivy--current)
(num (if (string-match "^[0-9]+" str)
(string-to-number (match-string 0 str))
@@ -292,7 +294,7 @@ BEG and END, when specified, are the point bounds."
(goto-char (point-min))
(forward-line (1- (read x)))
(re-search-forward
- (ivy--regex input) (line-end-position) t)
+ (funcall ivy--regex-function input) (line-end-position) t)
(swiper--ensure-visible)
(when (/= (point) swiper--opoint)
(unless (and transient-mark-mode mark-active)
- [elpa] master updated (e559638 -> 155f2a6), Oleh Krehel, 2015/05/19
- [elpa] master ca91c88 01/57: Add an option for out-of-order matching,
Oleh Krehel <=
- [elpa] master 4ad1ab2 02/57: ivy.el (ivy-tab-space): New defcustom, Oleh Krehel, 2015/05/19
- [elpa] master 41bc3e8 03/57: Ignore case for "TAB", Oleh Krehel, 2015/05/19
- [elpa] master 2c39e10 04/57: "TAB" shouldn't delete input when no candidate, Oleh Krehel, 2015/05/19
- [elpa] master 2d7f287 09/57: Improve "TAB" interaction with `confirm-nonexistent-file-or-buffer', Oleh Krehel, 2015/05/19
- [elpa] master 03ab827 07/57: Merge ivy--collection into ivy-last, Oleh Krehel, 2015/05/19
- [elpa] master dc219b3 12/57: Add counsel-load-library, Oleh Krehel, 2015/05/19
- [elpa] master 8b08cc0 08/57: ivy.el (ivy-done): Simplify and improve, Oleh Krehel, 2015/05/19
- [elpa] master cd083cc 18/57: Add swiper -> avy finalizer, Oleh Krehel, 2015/05/19
- [elpa] master f2a0966 16/57: Add ivy-partial: partial complete without exiting, Oleh Krehel, 2015/05/19
- [elpa] master 386184b 14/57: Merge ivy--update-fn into ivy-last, Oleh Krehel, 2015/05/19