[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 28abaa9 12/22: Allow to customize the regex matching per-c
From: |
Oleh Krehel |
Subject: |
[elpa] master 28abaa9 12/22: Allow to customize the regex matching per-collection |
Date: |
Wed, 22 Apr 2015 19:51:50 +0000 |
branch: master
commit 28abaa94348feef0642c619765374605b329aeb1
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
Allow to customize the regex matching per-collection
* ivy.el (ivy--regex-function): New defvar.
(ivy-re-builders-alist): New defvar, use this to customize.
(ivy-read): Update.
(ivy--filter): Update.
Currently, it only works for function collections. Example:
(setq ivy-re-builders-alist
'((read-file-name-internal . regexp-quote)
(t . ivy--regex)))
Re #48
---
ivy.el | 20 ++++++++++++++++++--
1 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/ivy.el b/ivy.el
index e6b07d4..be4dc8e 100644
--- a/ivy.el
+++ b/ivy.el
@@ -160,6 +160,9 @@ When non-nil, it should contain one %d.")
(defvar ivy--old-cands nil
"Store the candidates matched by `ivy--old-re'.")
+(defvar ivy--regex-function 'ivy--regex
+ "Current function for building a regex.")
+
;;** Commands
(defun ivy-done ()
"Exit the minibuffer with the selected candidate."
@@ -363,10 +366,17 @@ Prioritize directories."
(internal-complete-buffer . nil)
(counsel-git-grep-function . nil)
(t . string-lessp))
- "And alist of sorting functions for each collection function.
+ "An alist of sorting functions for each collection function.
For each entry, nil means no sorting.
The entry associated to t is used for all fall-through cases.")
+(defvar ivy-re-builders-alist
+ '((t . ivy--regex))
+ "An alist of regex building functions for each collection function.
+Each function should take a string and return a valid regex.
+The entry associated to t is used for all fall-through cases.
+Possible choices: `ivy--regex', `regexp-quote'.")
+
(defcustom ivy-sort-max-size 30000
"Sorting won't be done for collections larger than this."
:type 'integer)
@@ -418,6 +428,12 @@ When SORT is t, refer to `ivy-sort-functions-alist' for
sorting."
(setq ivy--directory nil)
(setq ivy-require-match require-match)
(setq ivy-window (selected-window))
+ (setq ivy--regex-function
+ (or (and (functionp collection)
+ (cdr (assoc collection ivy-re-builders-alist)))
+ (cdr (assoc t ivy-re-builders-alist))
+ 'ivy--regex))
+ (setq ivy--subexps 0)
(let (coll sort-fn)
(cond ((eq collection 'Info-read-node-name-1)
(if (equal Info-current-file "dir")
@@ -701,7 +717,7 @@ Should be run via minibuffer `post-command-hook'."
(defun ivy--filter (name candidates)
"Return the matches for NAME for CANDIDATES.
CANDIDATES are assumed to be static."
- (let* ((re (ivy--regex name))
+ (let* ((re (funcall ivy--regex-function name))
(cands (cond ((and (equal re ivy--old-re)
ivy--old-cands)
ivy--old-cands)
- [elpa] master 37d371c 05/22: Add a way to exit ignoring the candidates, (continued)
- [elpa] master 37d371c 05/22: Add a way to exit ignoring the candidates, Oleh Krehel, 2015/04/22
- [elpa] master 4adc074 06/22: Fix the default-directory for `counsel-git-grep', Oleh Krehel, 2015/04/22
- [elpa] master dd559ad 07/22: ivy.el (ivy--filter): Try directory expansion with "/", Oleh Krehel, 2015/04/22
- [elpa] master 6da7819 09/22: ivy.el (ivy--filter): Update prefix optimization, Oleh Krehel, 2015/04/22
- [elpa] master 533b788 11/22: ivy.el (ivy-done): Be more strict for `require-match', Oleh Krehel, 2015/04/22
- [elpa] master fb805a0 08/22: README.md: Add a note on outdated ivy package, Oleh Krehel, 2015/04/22
- [elpa] master 70c5fe8 13/22: Bind "M-q" to `ivy-toggle-regexp-quote', Oleh Krehel, 2015/04/22
- [elpa] master 7edfbc9 14/22: ivy.el (ivy--exhibit): Wrap in `while-no-input', Oleh Krehel, 2015/04/22
- [elpa] master 1fad831 10/22: Change `ivy-read' to a cl-defun, Oleh Krehel, 2015/04/22
- [elpa] master e78557a 15/22: swiper.el (swiper--ivy): Fix preselect being added, Oleh Krehel, 2015/04/22
- [elpa] master 28abaa9 12/22: Allow to customize the regex matching per-collection,
Oleh Krehel <=
- [elpa] master dd4aced 16/22: ivy.el (ivy--add-face): Don't fail for weird str, Oleh Krehel, 2015/04/22
- [elpa] master 6d801a6 19/22: ivy-test.el (ivy-read): Update test., Oleh Krehel, 2015/04/22
- [elpa] master 5c03c2b 18/22: ivy.el (ivy-read): Fix preselect logic, Oleh Krehel, 2015/04/22
- [elpa] master f9947de 20/22: Fixup `swiper-query-replace', Oleh Krehel, 2015/04/22
- [elpa] master 632af83 17/22: ivy.el (ivy-done): Fixup, Oleh Krehel, 2015/04/22
- [elpa] master e2452a3 21/22: README.md: Update video link, Oleh Krehel, 2015/04/22
- [elpa] master c7a6156 22/22: Merge commit 'e2452a3e77ef6ea6b193292d2c0bbbe93dd4b078' from swiper, Oleh Krehel, 2015/04/22