[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master c2c0e2d 270/348: ivy.el: Simplify previous commit
From: |
Oleh Krehel |
Subject: |
[elpa] master c2c0e2d 270/348: ivy.el: Simplify previous commit |
Date: |
Sat, 8 Apr 2017 11:04:13 -0400 (EDT) |
branch: master
commit c2c0e2d7bd79a0c7cb8a6df98d2a87a0891730d8
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
ivy.el: Simplify previous commit
Re #691
---
ivy.el | 111 ++++++++++++++++++++++++++++----------------------------------
swiper.el | 11 -------
2 files changed, 50 insertions(+), 72 deletions(-)
diff --git a/ivy.el b/ivy.el
index 7c0400a..97c41b4 100644
--- a/ivy.el
+++ b/ivy.el
@@ -1303,17 +1303,8 @@ like.")
(defvar ivy-highlight-functions-alist
'((ivy--regex-ignore-order . ivy--highlight-ignore-order)
- (ivy--regex-fuzzy . (:eval (if ivy--flx-featurep 'ivy--highlight-fuzzy
'ivy--highlight-default))))
- "An alist of highlighting functions for each regex buidler function.
-
-Each value should be either:
-
-1. A function that takes two arguments, STR and START. The
-function should return a highlight STR from the index START, and
-return the result.
-
-2. A plist whose :eval entry is a form, which evaluates to a
-function as in point 1.")
+ (ivy--regex-fuzzy . ivy--highlight-fuzzy))
+ "An alist of highlighting functions for each regex buidler function.")
(defvar ivy-initial-inputs-alist
'((org-refile . "^")
@@ -1554,7 +1545,14 @@ This is useful for recursive `ivy-read'."
(setq ivy-text "")
(setq ivy-calling nil)
(setq ivy-use-ignore ivy-use-ignore-default)
- (setq ivy--highlight-function (ivy--highlight-function-for-regex-function
ivy--regex-function))
+ (setq ivy--highlight-function
+ (if (and (eq ivy--regex-function 'swiper--re-builder)
+ (eq (cdr (assoc t ivy-re-builders-alist))
+ 'ivy--regex-fuzzy))
+ #'ivy--highlight-fuzzy
+ (or (cdr (assoc ivy--regex-function
+ ivy-highlight-functions-alist))
+ #'ivy--highlight-default)))
(let (coll sort-fn)
(cond ((eq collection 'Info-read-node-name-1)
(if (equal Info-current-file "dir")
@@ -2458,7 +2456,7 @@ CANDIDATES are assumed to be static."
(setq ivy--old-cands (ivy--sort name cands))
(ivy--recompute-index name re-str ivy--old-cands))
(setq ivy--old-re
- (if (eq ivy--highlight-function 'ivy--highlight-ignore-order)
+ (if (eq ivy--regex-function 'ivy--regex-ignore-order)
re
(if ivy--old-cands
re-str
@@ -2792,9 +2790,8 @@ SEPARATOR is used to join the candidates."
(font-lock-append-text-property
start end 'face face str)))
-(defun ivy--highlight-ignore-order (str _start)
- "Highlight STR, starting from START, using the ignore-order method."
- ;; (message "ivy--highlight-ignore-order: old-re = %s" ivy--old-re)
+(defun ivy--highlight-ignore-order (str)
+ "Highlight STR, using the ignore-order method."
(when (consp ivy--old-re)
(let ((i 1))
(dolist (re ivy--old-re)
@@ -2807,57 +2804,49 @@ SEPARATOR is used to join the candidates."
(cl-incf i))))
str)
-(defun ivy--highlight-fuzzy (str _start)
- "Highlight STR, starting from START, using the fuzzy method."
- (let ((flx-name (if (string-match "^\\^" ivy-text)
- (substring ivy-text 1)
- ivy-text)))
- (ivy--flx-propertize
- (cons (flx-score str flx-name ivy--flx-cache) str))))
-
-(defun ivy--highlight-default (str start)
- "Highlight STR, starting from START, using the default method."
+(defun ivy--highlight-fuzzy (str)
+ "Highlight STR, using the fuzzy method."
+ (if ivy--flx-featurep
+ (let ((flx-name (if (string-match "^\\^" ivy-text)
+ (substring ivy-text 1)
+ ivy-text)))
+ (ivy--flx-propertize
+ (cons (flx-score str flx-name ivy--flx-cache) str)))
+ (ivy--highlight-default str)))
+
+(defun ivy--highlight-default (str)
+ "Highlight STR, using the default method."
(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)))))
+ (let ((start
+ (if (and (memq (ivy-state-caller ivy-last)
+ '(counsel-git-grep counsel-ag counsel-rg counsel-pt))
+ (string-match "^[^:]+:[^:]+:" str))
+ (match-end 0)
+ 0)))
+ (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)
-(defun ivy--highlight-function-for-regex-function (regex-fn)
- "Return a highlighting function which is appropriate for the regex builder
REGEX-FN."
- (let ((res (cdr (or (assoc regex-fn ivy-highlight-functions-alist)
- (cons t #'ivy--highlight-default)))))
- ;; note: alist-get is only available in emacs 25 and above.
- ;; (despite the documentation not mentioning this fact.)
- (if (listp res)
- (eval (plist-get res :eval))
- res)))
-
(defun ivy--format-minibuffer-line (str)
(when (eq ivy-display-style 'fancy)
- (let ((start
- (if (and (memq (ivy-state-caller ivy-last)
- '(counsel-git-grep counsel-ag counsel-rg counsel-pt))
- (string-match "^[^:]+:[^:]+:" str))
- (match-end 0)
- 0)))
- (funcall ivy--highlight-function (copy-sequence str) start))))
+ (funcall ivy--highlight-function (copy-sequence str))))
(ivy-set-display-transformer
'counsel-find-file 'ivy-read-file-transformer)
diff --git a/swiper.el b/swiper.el
index 1d6aa8a..56e8d54 100644
--- a/swiper.el
+++ b/swiper.el
@@ -420,17 +420,6 @@ When REVERT is non-nil, regenerate the current *ivy-occur*
buffer."
(when (bound-and-true-p evil-mode)
(evil-set-jump)))
-(defun swiper--highlighter ()
- "Return the correct highlighter for swiper."
- (let ((re-builder
- (or (cdr (assoc 'swiper ivy-re-builders-alist))
- (cdr (assoc t ivy-re-builders-alist))))
- (ivy-highlight-functions-alist
- (assq-delete-all 'swiper--re-builder (copy-alist
ivy-highlight-functions-alist))))
- (ivy--highlight-function-for-regex-function re-builder)))
-
-(push '(swiper--re-builder . (:eval (swiper--highlighter)))
ivy-highlight-functions-alist)
-
(defun swiper--re-builder (str)
"Transform STR into a swiper regex.
This is the regex used in the minibuffer where candidates have
- [elpa] master 61cdcd5 139/348: ivy.el (ivy-occur-press-and-switch): Use ivy-occur-last, (continued)
- [elpa] master 61cdcd5 139/348: ivy.el (ivy-occur-press-and-switch): Use ivy-occur-last, Oleh Krehel, 2017/04/08
- [elpa] master 9346e96 194/348: Improve the overlay offset, Oleh Krehel, 2017/04/08
- [elpa] master 6644d8e 195/348: ivy-display.el: Move to wiki, Oleh Krehel, 2017/04/08
- [elpa] master e49fb6e 205/348: ivy.el (ivy-call): Set default-directory, Oleh Krehel, 2017/04/08
- [elpa] master 714cb8c 209/348: ivy.el (ivy--sort-files-by-date): Fix docstring, Oleh Krehel, 2017/04/08
- [elpa] master 0fc1507 237/348: ivy.el (ivy-occur-mode): Set view-read-only to nil locally, Oleh Krehel, 2017/04/08
- [elpa] master ea260d1 249/348: counsel.el (counsel-grep-occur): Quote the directory name, Oleh Krehel, 2017/04/08
- [elpa] master 3b15585 256/348: Fix little typo, Oleh Krehel, 2017/04/08
- [elpa] master 7dea0ff 255/348: Use ivy-format-function approach for counsel-faces, Oleh Krehel, 2017/04/08
- [elpa] master 2989f25 268/348: swiper.el (swiper--update-input-ivy): Fix window-end call, Oleh Krehel, 2017/04/08
- [elpa] master c2c0e2d 270/348: ivy.el: Simplify previous commit,
Oleh Krehel <=
- [elpa] master 75f9ceb 286/348: Allow spaces in file names when running linux apps., Oleh Krehel, 2017/04/08
- [elpa] master 2f70c56 287/348: Revert "Add missing parameter for ag", Oleh Krehel, 2017/04/08
- [elpa] master 950545b 304/348: counsel.el (counsel-linux-apps-list): Check if dir exists, Oleh Krehel, 2017/04/08
- [elpa] master 65979f6 291/348: Heed non-sort entries in ivy-sort-functions-alist, Oleh Krehel, 2017/04/08
- [elpa] master ce3c0ec 317/348: ivy.el (ivy-completing-read): Adjust :caller, Oleh Krehel, 2017/04/08
- [elpa] master d9d7592 315/348: ivy.el (ivy-completion-in-region): Remove :require-match, Oleh Krehel, 2017/04/08
- [elpa] master 4d72dc1 327/348: ivy.el: Change recursive restore order, Oleh Krehel, 2017/04/08
- [elpa] master d82dc2c 328/348: counsel.el (counsel-colors--best-contrast-color): Return same color on error, Oleh Krehel, 2017/04/08
- [elpa] master 3fbeaa5 333/348: Define ivy-help-file with defconst, Oleh Krehel, 2017/04/08
- [elpa] master fee9810 336/348: ivy.el (ivy-partial): Fix for :dynamic-collection, Oleh Krehel, 2017/04/08