[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 50caf2c 1/5: Split `ivy-completions' into `ivy--filter' an
From: |
Oleh Krehel |
Subject: |
[elpa] master 50caf2c 1/5: Split `ivy-completions' into `ivy--filter' and `ivy--format' |
Date: |
Mon, 20 Apr 2015 17:32:58 +0000 |
branch: master
commit 50caf2c2f7d6b4f828af73ac62e36e78bffb1928
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
Split `ivy-completions' into `ivy--filter' and `ivy--format'
* ivy.el (ivy--exhibit): Update.
(ivy-completions): Remove.
(ivy--filter): New defun.
(ivy--format): New defun.
---
ivy.el | 75 ++++++++++++++++++++++++++++++++-------------------------------
1 files changed, 38 insertions(+), 37 deletions(-)
diff --git a/ivy.el b/ivy.el
index 0807907..315b9d9 100644
--- a/ivy.el
+++ b/ivy.el
@@ -554,9 +554,8 @@ Should be run via minibuffer `post-command-hook'."
(ivy--cd "/"))
(if (string-match "~$" ivy-text)
(ivy--cd (expand-file-name "~/")))))
- (let ((text (ivy-completions
- ivy-text
- ivy--all-candidates))
+ (let ((text (ivy--format
+ (ivy--filter ivy-text ivy--all-candidates)))
(buffer-undo-list t)
deactivate-mark)
(when ivy--update-fn
@@ -575,11 +574,9 @@ Should be run via minibuffer `post-command-hook'."
(font-lock-append-text-property 0 (length str) 'face face str)
str)
-(defun ivy-completions (name candidates)
- "Return as text the current completions.
-NAME is a string of words separated by spaces that is used to
-build a regex.
-CANDIDATES is a list of strings."
+(defun ivy--filter (name candidates)
+ "Return the matches for NAME for CANDIDATES.
+CANDIDATES are assumed to be static."
(let* ((re (ivy--regex name))
(cands (cond ((and (equal re ivy--old-re)
ivy--old-cands)
@@ -601,7 +598,6 @@ CANDIDATES is a list of strings."
(lambda (x) (string-match re x))
candidates)))))
(tail (nthcdr ivy--index ivy--old-cands))
- (ww (window-width))
idx)
(when (and tail ivy--old-cands)
(unless (and (not (equal re ivy--old-re))
@@ -611,34 +607,39 @@ CANDIDATES is a list of strings."
(setq idx (cl-position (pop tail) cands)))
(setq ivy--index (or idx 0))))
(setq ivy--old-re re)
- (setq ivy--length (length cands))
- (setq ivy--old-cands cands)
- (when (>= ivy--index ivy--length)
- (setq ivy--index (max (1- ivy--length) 0)))
- (if (null cands)
- ""
- (let* ((half-height (/ ivy-height 2))
- (start (max 0 (- ivy--index half-height)))
- (end (min (+ start (1- ivy-height)) ivy--length))
- (cands (cl-subseq cands start end))
- (index (min ivy--index half-height (1- (length cands)))))
- (when ivy--directory
- (setq cands (mapcar (lambda (x)
- (if (string-match-p "/$" x)
- (propertize x 'face 'ivy-subdir)
- x))
- cands)))
- (setq ivy--current (copy-sequence (nth index cands)))
- (setf (nth index cands)
- (ivy--add-face ivy--current 'ivy-current-match))
- (let ((res (concat "\n" (mapconcat
- (lambda (s)
- (if (> (length s) ww)
- (concat (substring s 0 (- ww 3)) "...")
- s))
- cands "\n"))))
- (put-text-property 0 (length res) 'read-only nil res)
- res)))))
+ (setq ivy--old-cands cands)))
+
+(defun ivy--format (cands)
+ "Return a string for CANDS suitable for display in the minibuffer.
+CANDS is a list of strings."
+ (setq ivy--length (length cands))
+ (when (>= ivy--index ivy--length)
+ (setq ivy--index (max (1- ivy--length) 0)))
+ (if (null cands)
+ ""
+ (let* ((half-height (/ ivy-height 2))
+ (start (max 0 (- ivy--index half-height)))
+ (end (min (+ start (1- ivy-height)) ivy--length))
+ (cands (cl-subseq cands start end))
+ (index (min ivy--index half-height (1- (length cands)))))
+ (when ivy--directory
+ (setq cands (mapcar (lambda (x)
+ (if (string-match-p "/$" x)
+ (propertize x 'face 'ivy-subdir)
+ x))
+ cands)))
+ (setq ivy--current (copy-sequence (nth index cands)))
+ (setf (nth index cands)
+ (ivy--add-face ivy--current 'ivy-current-match))
+ (let* ((ww (window-width))
+ (res (concat "\n" (mapconcat
+ (lambda (s)
+ (if (> (length s) ww)
+ (concat (substring s 0 (- ww 3)) "...")
+ s))
+ cands "\n"))))
+ (put-text-property 0 (length res) 'read-only nil res)
+ res))))
(provide 'ivy)