emacs-elpa-diffs
[Top][All Lists]
Advanced

[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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]