[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 94f3368 160/348: Extract ivy--flx-propertize from ivy--flx
From: |
Oleh Krehel |
Subject: |
[elpa] master 94f3368 160/348: Extract ivy--flx-propertize from ivy--flx-sort |
Date: |
Sat, 8 Apr 2017 11:03:47 -0400 (EDT) |
branch: master
commit 94f33684fae02349f31d1a9b310cba37a4979b43
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
Extract ivy--flx-propertize from ivy--flx-sort
* ivy.el (ivy--flx-propertize): New defun.
(ivy--flx-sort): Don't propertize any more, only sort.
(ivy--format-minibuffer-line): Add propertize for fuzzy.
With the new change, the minibuffer propertize is done always for fuzzy.
Previously it would only be done if the number of cands was less than
200 in `ivy--flx-sort'.
Now, `flx-score' is called `ivy-height' times. That info is used to
propertize the visible cands.
Fixes #651
---
ivy.el | 108 +++++++++++++++++++++++++++++++++++++----------------------------
1 file changed, 62 insertions(+), 46 deletions(-)
diff --git a/ivy.el b/ivy.el
index 3c75de3..aa90250 100644
--- a/ivy.el
+++ b/ivy.el
@@ -2566,6 +2566,22 @@ Prefer first \"^*NAME\", then \"^NAME\"."
When the amount of matching candidates exceeds this limit, then
no sorting is done.")
+(defun ivy--flx-propertize (x)
+ "X is (cons (flx-score STR ...) STR)."
+ (let ((str (copy-sequence (cdr x)))
+ (i 0)
+ (last-j -2))
+ (dolist (j (cdar x))
+ (unless (eq j (1+ last-j))
+ (cl-incf i))
+ (setq last-j j)
+ (ivy-add-face-text-property
+ j (1+ j)
+ (nth (1+ (mod (+ i 2) (1- (length ivy-minibuffer-faces))))
+ ivy-minibuffer-faces)
+ str))
+ str))
+
(defun ivy--flx-sort (name cands)
"Sort according to closeness to string NAME the string list CANDS."
(condition-case nil
@@ -2583,20 +2599,7 @@ no sorting is done.")
(cons score x))))
cands))))
(if cands-with-score
- (mapcar (lambda (x)
- (let ((str (copy-sequence (cdr x)))
- (i 0)
- (last-j -2))
- (dolist (j (cdar x))
- (unless (eq j (1+ last-j))
- (cl-incf i))
- (setq last-j j)
- (ivy-add-face-text-property
- j (1+ j)
- (nth (1+ (mod (+ i 2) (1- (length
ivy-minibuffer-faces))))
- ivy-minibuffer-faces)
- str))
- str))
+ (mapcar #'cdr
(sort cands-with-score
(lambda (x y)
(> (caar x) (caar y)))))
@@ -2678,39 +2681,52 @@ SEPARATOR is used to join the candidates."
(match-end 0)
0))
(str (copy-sequence str)))
- (cond ((eq ivy--regex-function 'ivy--regex-ignore-order)
- (when (consp ivy--old-re)
- (let ((i 1))
- (dolist (re ivy--old-re)
- (when (string-match (car re) str)
- (ivy-add-face-text-property
- (match-beginning 0) (match-end 0)
- (nth (1+ (mod (+ i 2) (1- (length ivy-minibuffer-faces))))
- ivy-minibuffer-faces)
- str))
- (cl-incf i)))))
- ((and (eq ivy-display-style 'fancy)
- (not (eq ivy--regex-function 'ivy--regex-fuzzy)))
- (unless ivy--old-re
- (setq ivy--old-re (funcall ivy--regex-function ivy-text)))
- (ignore-errors
- (while (and (string-match ivy--old-re str start)
- (> (- (match-end 0) (match-beginning 0)) 0))
- (setq start (match-end 0))
- (let ((i 0))
- (while (<= i ivy--subexps)
- (let ((face
- (cond ((zerop ivy--subexps)
- (cadr ivy-minibuffer-faces))
- ((zerop i)
- (car ivy-minibuffer-faces))
- (t
- (nth (1+ (mod (+ i 2) (1- (length
ivy-minibuffer-faces))))
- ivy-minibuffer-faces)))))
+ (when (eq ivy-display-style 'fancy)
+ (cond ((eq ivy--regex-function 'ivy--regex-ignore-order)
+ (when (consp ivy--old-re)
+ (let ((i 1))
+ (dolist (re ivy--old-re)
+ (when (string-match (car re) str)
(ivy-add-face-text-property
- (match-beginning i) (match-end i)
- face str))
- (cl-incf i)))))))
+ (match-beginning 0) (match-end 0)
+ (nth (1+ (mod (+ i 2) (1- (length
ivy-minibuffer-faces))))
+ 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))))
+ (let ((flx-name (if (string-match "^\\^" ivy-text)
+ (substring ivy-text 1)
+ ivy-text)))
+ (setq str
+ (ivy--flx-propertize
+ (cons (flx-score str flx-name ivy--flx-cache) str)))))
+ (t
+ (unless ivy--old-re
+ (setq ivy--old-re (funcall ivy--regex-function ivy-text)))
+ (ignore-errors
+ (while (and (string-match ivy--old-re str start)
+ (> (- (match-end 0) (match-beginning 0)) 0))
+ (setq start (match-end 0))
+ (let ((i 0))
+ (while (<= i ivy--subexps)
+ (let ((face
+ (cond ((zerop ivy--subexps)
+ (cadr ivy-minibuffer-faces))
+ ((zerop i)
+ (car ivy-minibuffer-faces))
+ (t
+ (nth (1+ (mod (+ i 2) (1- (length
ivy-minibuffer-faces))))
+ ivy-minibuffer-faces)))))
+ (ivy-add-face-text-property
+ (match-beginning i) (match-end i)
+ face str))
+ (cl-incf i))))))))
str))
(ivy-set-display-transformer
- [elpa] master 434ccce 150/348: swiper.el (swiper-font-lock-exclude): Add bookmark-bmenu-mode, (continued)
- [elpa] master 434ccce 150/348: swiper.el (swiper-font-lock-exclude): Add bookmark-bmenu-mode, Oleh Krehel, 2017/04/08
- [elpa] master 242ae95 148/348: ivy.el (ivy--reset-state): Fix read-only collection member, Oleh Krehel, 2017/04/08
- [elpa] master a99c125 161/348: counsel.el (counsel-grep): Specify :re-builder, Oleh Krehel, 2017/04/08
- [elpa] master 4e6145c 168/348: counsel.el (counsel-yank-pop-separator): New defcustom, Oleh Krehel, 2017/04/08
- [elpa] master b73264e 163/348: counsel.el (counsel-git-log-cmd): New defvar, Oleh Krehel, 2017/04/08
- [elpa] master 7457d1e 169/348: Add leading zeros to the hex representation to counsel-unicode-char, Oleh Krehel, 2017/04/08
- [elpa] master 8983f9d 167/348: counsel.el (counsel-recentf): Turn on recentf, Oleh Krehel, 2017/04/08
- [elpa] master 6961df6 166/348: doc/ivy.org: Replace swiper with counsel (MELPA), Oleh Krehel, 2017/04/08
- [elpa] master 3656dfe 171/348: ivy.el (ivy-exit-with-action): Remove with-ivy-window, Oleh Krehel, 2017/04/08
- [elpa] master 4c3ecb4 157/348: Restore window position after using swiper., Oleh Krehel, 2017/04/08
- [elpa] master 94f3368 160/348: Extract ivy--flx-propertize from ivy--flx-sort,
Oleh Krehel <=
- [elpa] master 6b574e4 173/348: ivy.el (ivy-call): expand-file-name, Oleh Krehel, 2017/04/08
- [elpa] master 93f9321 174/348: ivy.el: Fix byte compiler warnings, Oleh Krehel, 2017/04/08
- [elpa] master 2a9c3f3 191/348: swiper.el (swiper-multi): Don't use virtual buffers, Oleh Krehel, 2017/04/08
- [elpa] master 3a7c8cd 189/348: counsel.el (counsel-recentf): add extra actions, Oleh Krehel, 2017/04/08
- [elpa] master 955585e 190/348: counsel.el (counsel-describe-face): Ensure :preselect string, Oleh Krehel, 2017/04/08
- [elpa] master 3c904fa 192/348: counsel.el (counsel-git-grep-occur): Fix "g", Oleh Krehel, 2017/04/08
- [elpa] master 77ebfdb 196/348: Makefile: load ivy-overlay.el, Oleh Krehel, 2017/04/08
- [elpa] master f357cd2 198/348: ivy-overlay.el (ivy-overlay-cleanup): Restore cursor-type, Oleh Krehel, 2017/04/08
- [elpa] master f8d78eb 197/348: Add a fake cursor to inline completion display, Oleh Krehel, 2017/04/08
- [elpa] master 1bdc50b 200/348: ivy-overlay.el (ivy-overlay-cleanup): Don't trigger company, Oleh Krehel, 2017/04/08