[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 9d5b60f 09/12: ivy.el (ivy--regex): Add optional greedy ar
From: |
Oleh Krehel |
Subject: |
[elpa] master 9d5b60f 09/12: ivy.el (ivy--regex): Add optional greedy arg |
Date: |
Tue, 21 Apr 2015 12:09:22 +0000 |
branch: master
commit 9d5b60fd74a33dfcbd1bbab57eb51b1b43bc7eb7
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
ivy.el (ivy--regex): Add optional greedy arg
* ivy.el (ivy--regex): When optional greedy arg is t, be greedy. Don't
wrap a sub-expr in a group if it's already a group, for instance
"forward \(char\|list\)".
Greedy is needed, for instance, for "git grep", which doesn't work great
with non-greedy regex.
Re #47
---
ivy.el | 17 ++++++++++++-----
1 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/ivy.el b/ivy.el
index 1353bf0..3b4fd5d 100644
--- a/ivy.el
+++ b/ivy.el
@@ -538,9 +538,11 @@ Turning on Ivy mode will set `completing-read-function' to
(make-hash-table :test 'equal)
"Store pre-computed regex.")
-(defun ivy--regex (str)
- "Re-build regex from STR in case it has a space."
- (let ((hashed (gethash str ivy--regex-hash)))
+(defun ivy--regex (str &optional greedy)
+ "Re-build regex from STR in case it has a space.
+When GREEDY is non-nil, join words in a greedy way."
+ (let ((hashed (unless greedy
+ (gethash str ivy--regex-hash))))
(if hashed
(prog1 (cdr hashed)
(setq ivy--subexps (car hashed)))
@@ -553,9 +555,14 @@ Turning on Ivy mode will set `completing-read-function' to
(cons
(setq ivy--subexps (length subs))
(mapconcat
- (lambda (x) (format "\\(%s\\)" x))
+ (lambda (x)
+ (if (string-match "^\\\\(.*\\\\)$" x)
+ x
+ (format "\\(%s\\)" x)))
subs
- ".*?"))))
+ (if greedy
+ ".*"
+ ".*?")))))
ivy--regex-hash)))))
;;** Rest
- [elpa] master updated (3d54459 -> e86b27e), Oleh Krehel, 2015/04/21
- [elpa] master 0d1fa17 01/12: ivy.el (ivy-done): Expand file name for empty text, Oleh Krehel, 2015/04/21
- [elpa] master 36b15f3 02/12: ivy.el (ivy--regex): Switch to non-greedy ".*?" joiner, Oleh Krehel, 2015/04/21
- [elpa] master 49638b4 04/12: ivy.el (ivy--sorted-files): Avoid returning an empty list, Oleh Krehel, 2015/04/21
- [elpa] master 2a5d3fc 05/12: Fix double-sorting for file names, Oleh Krehel, 2015/04/21
- [elpa] master bb89c9d 03/12: Allow to customize the sorting methods, Oleh Krehel, 2015/04/21
- [elpa] master 94c124d 07/12: ivy.el (ivy-done): Don't directory-expand glob filename, Oleh Krehel, 2015/04/21
- [elpa] master 5268d10 06/12: Add an option to call the completion action without exiting, Oleh Krehel, 2015/04/21
- [elpa] master 9d5b60f 09/12: ivy.el (ivy--regex): Add optional greedy arg,
Oleh Krehel <=
- [elpa] master be716a1 08/12: swiper.el (swiper--add-overlays): Update arglist, Oleh Krehel, 2015/04/21
- [elpa] master b724678 10/12: counsel.el: Add awesome swiper highlighting to git grep, Oleh Krehel, 2015/04/21
- [elpa] master 675bd5f 11/12: Fix describe-function / -variable "C-." interaction, Oleh Krehel, 2015/04/21
- [elpa] master e86b27e 12/12: Merge commit '675bd5ff97f75fb7d838e6056442ce71adf85e56' from swiper, Oleh Krehel, 2015/04/21