[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master e98883f 162/348: Improve fuzzy swiper highlight
From: |
Oleh Krehel |
Subject: |
[elpa] master e98883f 162/348: Improve fuzzy swiper highlight |
Date: |
Sat, 8 Apr 2017 11:03:47 -0400 (EDT) |
branch: master
commit e98883f50f5794c3bc79634a1fab6963a016a472
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
Improve fuzzy swiper highlight
* ivy.el (ivy--regex-fuzzy): Is non-greedy now - flx does the same.
(ivy--format-minibuffer-line): Ensure flx is available.
* ivy-test.el (ivy--regex-fuzzy): Update test.
* swiper.el (swiper--add-overlays): Join contiguous matches together.
(swiper--add-overlay): New defun.
Fixes #651
---
ivy-test.el | 6 +++---
ivy.el | 19 +++++++++++--------
swiper.el | 44 ++++++++++++++++++++++++++------------------
3 files changed, 40 insertions(+), 29 deletions(-)
diff --git a/ivy-test.el b/ivy-test.el
index f49982c..cb2befa 100644
--- a/ivy-test.el
+++ b/ivy-test.el
@@ -137,11 +137,11 @@
(ert-deftest ivy--regex-fuzzy ()
(should (string= (ivy--regex-fuzzy "tmux")
- "\\(t\\).*\\(m\\).*\\(u\\).*\\(x\\)"))
+ "\\(t\\).*?\\(m\\).*?\\(u\\).*?\\(x\\)"))
(should (string= (ivy--regex-fuzzy "^tmux")
- "^\\(t\\).*\\(m\\).*\\(u\\).*\\(x\\)"))
+ "^\\(t\\).*?\\(m\\).*?\\(u\\).*?\\(x\\)"))
(should (string= (ivy--regex-fuzzy "^tmux$")
- "^\\(t\\).*\\(m\\).*\\(u\\).*\\(x\\)$"))
+ "^\\(t\\).*?\\(m\\).*?\\(u\\).*?\\(x\\)$"))
(should (string= (ivy--regex-fuzzy "")
""))
(should (string= (ivy--regex-fuzzy "^")
diff --git a/ivy.el b/ivy.el
index aa90250..e74c0c5 100644
--- a/ivy.el
+++ b/ivy.el
@@ -1976,7 +1976,8 @@ Insert .* between each char."
(mapconcat
(lambda (x)
(format "\\(%c\\)" x))
- (string-to-list (match-string 2 str)) ".*")
+ (string-to-list (match-string 2 str))
+ ".*?")
(match-string 3 str))
(setq ivy--subexps (length (match-string 2 str))))
str))
@@ -2693,13 +2694,15 @@ SEPARATOR is used to join the candidates."
ivy-minibuffer-faces)
str))
(cl-incf i)))))
- ((or (eq ivy--regex-function 'ivy--regex-fuzzy)
- (and (eq ivy--regex-function 'swiper--re-builder)
- (let ((caller (ivy-state-caller ivy-last)))
- (eq (or (and caller
- (cdr (assoc caller
ivy-re-builders-alist)))
- (cdr (assoc t ivy-re-builders-alist)))
- 'ivy--regex-fuzzy))))
+ ((and
+ (require 'flx nil 'noerror)
+ (or (eq ivy--regex-function 'ivy--regex-fuzzy)
+ (and (eq ivy--regex-function 'swiper--re-builder)
+ (let ((caller (ivy-state-caller ivy-last)))
+ (eq (or (and caller
+ (cdr (assoc caller
ivy-re-builders-alist)))
+ (cdr (assoc t ivy-re-builders-alist)))
+ 'ivy--regex-fuzzy)))))
(let ((flx-name (if (string-match "^\\^" ivy-text)
(substring ivy-text 1)
ivy-text)))
diff --git a/swiper.el b/swiper.el
index d43244b..ed72d58 100644
--- a/swiper.el
+++ b/swiper.el
@@ -613,24 +613,32 @@ WND, when specified is the window."
;; RE can become an invalid regexp
(while (and (ignore-errors (re-search-forward re end t))
(> (- (match-end 0) (match-beginning 0)) 0))
- (let ((i 0))
- (while (<= i ivy--subexps)
- (when (match-beginning i)
- (let ((overlay (make-overlay (match-beginning i)
- (match-end i)))
- (face
- (cond ((zerop ivy--subexps)
- (cadr swiper-faces))
- ((zerop i)
- (car swiper-faces))
- (t
- (nth (1+ (mod (+ i 2) (1- (length
swiper-faces))))
- swiper-faces)))))
- (push overlay swiper--overlays)
- (overlay-put overlay 'face face)
- (overlay-put overlay 'window wnd)
- (overlay-put overlay 'priority i)))
- (cl-incf i)))))))))
+ (swiper--add-overlay (match-beginning 0) (match-end 0)
+ (if (zerop ivy--subexps)
+ (cadr swiper-faces)
+ (car swiper-faces))
+ wnd 0)
+ (let ((i 1)
+ (j 0))
+ (while (<= (cl-incf j) ivy--subexps)
+ (let ((bm (match-beginning j))
+ (em (match-end j)))
+ (while (and (< j ivy--subexps)
+ (= em (match-beginning (+ j 1))))
+ (setq em (match-end (cl-incf j))))
+ (swiper--add-overlay
+ bm em
+ (nth (1+ (mod (+ i 2) (1- (length swiper-faces))))
+ swiper-faces)
+ wnd i)
+ (cl-incf i))))))))))
+
+(defun swiper--add-overlay (beg end face wnd priority)
+ (let ((overlay (make-overlay beg end)))
+ (push overlay swiper--overlays)
+ (overlay-put overlay 'face face)
+ (overlay-put overlay 'window wnd)
+ (overlay-put overlay 'priority priority)))
(defcustom swiper-action-recenter nil
"When non-nil, recenter after exiting `swiper'."
- [elpa] master 89a6830 186/348: counsel.el (counsel-at-git-issue-p): Fix for newer magit, (continued)
- [elpa] master 89a6830 186/348: counsel.el (counsel-at-git-issue-p): Fix for newer magit, Oleh Krehel, 2017/04/08
- [elpa] master 3d0e4a5 184/348: counsel.el (counsel-locate-action-extern): Update on w32, Oleh Krehel, 2017/04/08
- [elpa] master db9d7b8 188/348: Fix counsel-grep for files with spaces in the name, Oleh Krehel, 2017/04/08
- [elpa] master e7d6dab 185/348: counsel.el (counsel-mode): Add "C-r" bindings, Oleh Krehel, 2017/04/08
- [elpa] master f180451 179/348: swiper.el (swiper-all): Fix window-width in -nw, Oleh Krehel, 2017/04/08
- [elpa] master e11c926 182/348: Allow to "C-y" a "/ssh:" file name, Oleh Krehel, 2017/04/08
- [elpa] master 4e6921f 153/348: ivy.el: Apply alist change to ivy-occur, Oleh Krehel, 2017/04/08
- [elpa] master 36b00cb 155/348: Use EVM in travis to test across multiple Emacs versions, Oleh Krehel, 2017/04/08
- [elpa] master f6bd64b 164/348: ivy.el (ivy--flx-featurep): New defvar, Oleh Krehel, 2017/04/08
- [elpa] master fc5c8fc 159/348: Fix ivy-occur-press for swiper, Oleh Krehel, 2017/04/08
- [elpa] master e98883f 162/348: Improve fuzzy swiper highlight,
Oleh Krehel <=
- [elpa] master 9b28927 187/348: counsel.el (counsel-hydra-heads): Fixup, Oleh Krehel, 2017/04/08
- [elpa] master 00219da 181/348: Fix for older Emacs, Oleh Krehel, 2017/04/08
- [elpa] master 8f87f74 178/348: counsel.el (counsel-git-grep): Update for Windows, Oleh Krehel, 2017/04/08
- [elpa] master 79105a5 208/348: counsel.el (counsel-info-lookup-symbol): Add preselect, Oleh Krehel, 2017/04/08
- [elpa] master 222a5e6 217/348: ivy.el (ivy--virtual-buffers): Move to silence compiler, Oleh Krehel, 2017/04/08
- [elpa] master 35b5d29 230/348: New example to show how to associate values, Oleh Krehel, 2017/04/08
- [elpa] master e9c274a 236/348: Allow to customize ivy-display-function per caller, Oleh Krehel, 2017/04/08
- [elpa] master c14ceac 245/348: Add support for counsel-find-library, Oleh Krehel, 2017/04/08
- [elpa] master ca84f24 269/348: Add highlighter function configuration to ivy, Oleh Krehel, 2017/04/08
- [elpa] master 5701444 314/348: ivy.el (ivy-occur-revert-buffer): Restore ivy-occur-last, Oleh Krehel, 2017/04/08